예제 #1
0
  public static List<XmlTag> getCustomSubTags(
      final DomInvocationHandler handler, final XmlTag[] subTags, final XmlFile file) {
    if (subTags.length == 0) {
      return Collections.emptyList();
    }

    final DomGenericInfoEx info = handler.getGenericInfo();
    final Set<XmlName> usedNames = new THashSet<XmlName>();
    List<? extends DomCollectionChildDescription> collectionChildrenDescriptions =
        info.getCollectionChildrenDescriptions();
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0, size = collectionChildrenDescriptions.size(); i < size; i++) {
      DomCollectionChildDescription description = collectionChildrenDescriptions.get(i);
      usedNames.add(description.getXmlName());
    }
    List<? extends DomFixedChildDescription> fixedChildrenDescriptions =
        info.getFixedChildrenDescriptions();
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0, size = fixedChildrenDescriptions.size(); i < size; i++) {
      DomFixedChildDescription description = fixedChildrenDescriptions.get(i);
      usedNames.add(description.getXmlName());
    }
    return ContainerUtil.findAll(
        subTags,
        tag -> {
          if (StringUtil.isEmpty(tag.getName())) return false;

          for (final XmlName name : usedNames) {
            if (isNameSuitable(name, tag, handler, file)) {
              return false;
            }
          }
          return true;
        });
  }
예제 #2
0
 public static <T extends DomElement> T addElementAfter(@NotNull final T anchor) {
   final DomElement parent = anchor.getParent();
   final DomCollectionChildDescription childDescription =
       (DomCollectionChildDescription) anchor.getChildDescription();
   assert parent != null;
   final List<? extends DomElement> list = childDescription.getValues(parent);
   final int i = list.indexOf(anchor);
   assert i >= 0;
   return (T) childDescription.addValue(parent, i + 1);
 }
예제 #3
0
 @NotNull
 public static MavenDomDependency createDomDependency(
     @NotNull MavenDomDependencies dependencies, @Nullable Editor editor) {
   int index = getCollectionIndex(dependencies, editor);
   if (index >= 0) {
     DomCollectionChildDescription childDescription =
         dependencies.getGenericInfo().getCollectionChildDescription("dependency");
     if (childDescription != null) {
       DomElement element = childDescription.addValue(dependencies, index);
       if (element instanceof MavenDomDependency) {
         return (MavenDomDependency) element;
       }
     }
   }
   return dependencies.addDependency();
 }
예제 #4
0
  public static List<? extends DomElement> getIdentitySiblings(DomElement element) {
    final GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element);
    if (nameDomElement == null) return Collections.emptyList();

    final NameValue nameValue = nameDomElement.getAnnotation(NameValue.class);
    if (nameValue == null || !nameValue.unique()) return Collections.emptyList();

    final String stringValue = ElementPresentationManager.getElementName(element);
    if (stringValue == null) return Collections.emptyList();

    final DomElement scope = element.getManager().getIdentityScope(element);
    if (scope == null) return Collections.emptyList();

    final DomGenericInfo domGenericInfo = scope.getGenericInfo();
    final String tagName = element.getXmlElementName();
    final DomCollectionChildDescription childDescription =
        domGenericInfo.getCollectionChildDescription(tagName, element.getXmlElementNamespaceKey());
    if (childDescription != null) {
      final ArrayList<DomElement> list = new ArrayList<>(childDescription.getValues(scope));
      list.remove(element);
      return list;
    }
    return Collections.emptyList();
  }