Exemplo n.º 1
0
  public static void removeDuplicates(@NotNull CompositePackagingElement<?> parent) {
    List<PackagingElement<?>> prevChildren = new ArrayList<PackagingElement<?>>();

    List<PackagingElement<?>> toRemove = new ArrayList<PackagingElement<?>>();
    for (PackagingElement<?> child : parent.getChildren()) {
      if (child instanceof CompositePackagingElement<?>) {
        removeDuplicates((CompositePackagingElement<?>) child);
      }
      boolean merged = false;
      for (PackagingElement<?> prevChild : prevChildren) {
        if (child.isEqualTo(prevChild)) {
          if (child instanceof CompositePackagingElement<?>) {
            for (PackagingElement<?> childElement :
                ((CompositePackagingElement<?>) child).getChildren()) {
              ((CompositePackagingElement<?>) prevChild).addOrFindChild(childElement);
            }
          }
          merged = true;
          break;
        }
      }
      if (merged) {
        toRemove.add(child);
      } else {
        prevChildren.add(child);
      }
    }

    for (PackagingElement<?> child : toRemove) {
      parent.removeChild(child);
    }
  }
Exemplo n.º 2
0
 @NotNull
 private static <S> PackagingElement<S> copyElement(
     @NotNull PackagingElement<S> element, @NotNull Project project) {
   //noinspection unchecked
   final PackagingElement<S> copy = (PackagingElement<S>) element.getType().createEmpty(project);
   copy.loadState(element.getState());
   return copy;
 }
Exemplo n.º 3
0
 private static Element serializePackagingElement(PackagingElement<?> packagingElement) {
   Element element = new Element(PACKAGING_ELEMENT_NAME);
   element.setAttribute(TYPE_ID_ATTRIBUTE, packagingElement.getType().getId());
   final Object bean = packagingElement.getState();
   if (bean != null) {
     XmlSerializer.serializeInto(bean, element, new SkipDefaultValuesSerializationFilters());
   }
   if (packagingElement instanceof CompositePackagingElement) {
     for (PackagingElement<?> child :
         ((CompositePackagingElement<?>) packagingElement).getChildren()) {
       element.addContent(serializePackagingElement(child));
     }
   }
   return element;
 }
  public void selectNode(@NotNull String parentPath, @NotNull PackagingElement<?> element) {
    final PackagingElementNode<?> parent = myTree.findCompositeNodeByPath(parentPath);
    if (parent == null) return;

    for (SimpleNode node : parent.getChildren()) {
      if (node instanceof PackagingElementNode) {
        final List<? extends PackagingElement<?>> elements =
            ((PackagingElementNode<?>) node).getPackagingElements();
        for (PackagingElement<?> packagingElement : elements) {
          if (packagingElement.isEqualTo(element)) {
            myBuilder.select(node);
            return;
          }
        }
      }
    }
  }
Exemplo n.º 5
0
 @Override
 public String getPlacePath() {
   if (myParentPath != null && myPackagingElement != null) {
     // todo[nik] use id of element?
     return myParentPath + "/" + myPackagingElement.getType().getId();
   }
   return null;
 }
Exemplo n.º 6
0
  private <T> PackagingElement<T> deserializeElement(Element element)
      throws UnknownPackagingElementTypeException {
    final String id = element.getAttributeValue(TYPE_ID_ATTRIBUTE);
    PackagingElementType<?> type = PackagingElementFactory.getInstance().findElementType(id);
    if (type == null) {
      throw new UnknownPackagingElementTypeException(id);
    }

    PackagingElement<T> packagingElement = (PackagingElement<T>) type.createEmpty(myProject);
    T state = packagingElement.getState();
    if (state != null) {
      XmlSerializer.deserializeInto(state, element);
      packagingElement.loadState(state);
    }
    final List children = element.getChildren(PACKAGING_ELEMENT_NAME);
    //noinspection unchecked
    for (Element child : (List<? extends Element>) children) {
      ((CompositePackagingElement<?>) packagingElement).addOrFindChild(deserializeElement(child));
    }
    return packagingElement;
  }
Exemplo n.º 7
0
 private static <E extends PackagingElement<?>> boolean processElementRecursively(
     @NotNull PackagingElement<?> element,
     @Nullable PackagingElementType<E> type,
     @NotNull PackagingElementProcessor<? super E> processor,
     @NotNull PackagingElementResolvingContext resolvingContext,
     final boolean processSubstitutions,
     ArtifactType artifactType,
     @NotNull PackagingElementPath path,
     Set<PackagingElement<?>> processed) {
   if (!processor.shouldProcess(element) || !processed.add(element)) {
     return true;
   }
   if (type == null || element.getType().equals(type)) {
     if (!processor.process((E) element, path)) {
       return false;
     }
   }
   if (element instanceof CompositePackagingElement<?>) {
     final CompositePackagingElement<?> composite = (CompositePackagingElement<?>) element;
     return processElementsRecursively(
         composite.getChildren(),
         type,
         processor,
         resolvingContext,
         processSubstitutions,
         artifactType,
         path.appendComposite(composite),
         processed);
   } else if (element instanceof ComplexPackagingElement<?> && processSubstitutions) {
     final ComplexPackagingElement<?> complexElement = (ComplexPackagingElement<?>) element;
     if (processor.shouldProcessSubstitution(complexElement)) {
       final List<? extends PackagingElement<?>> substitution =
           complexElement.getSubstitution(resolvingContext, artifactType);
       if (substitution != null) {
         return processElementsRecursively(
             substitution,
             type,
             processor,
             resolvingContext,
             processSubstitutions,
             artifactType,
             path.appendComplex(complexElement),
             processed);
       }
     }
   }
   return true;
 }