@Override public XmlAttributeDescriptor[] getAttributesDescriptors(final @Nullable XmlTag context) { if (context == null) return XmlAttributeDescriptor.EMPTY; DomElement domElement = myManager.getDomElement(context); if (domElement == null) return XmlAttributeDescriptor.EMPTY; final List<? extends DomAttributeChildDescription> descriptions = domElement.getGenericInfo().getAttributeChildrenDescriptions(); List<XmlAttributeDescriptor> descriptors = new ArrayList<XmlAttributeDescriptor>(); for (DomAttributeChildDescription description : descriptions) { descriptors.add(new DomAttributeXmlDescriptor(description, myManager.getProject())); } List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription(); for (CustomDomChildrenDescription custom : customs) { CustomDomChildrenDescription.AttributeDescriptor descriptor = custom.getCustomAttributeDescriptor(); if (descriptor != null) { for (EvaluatedXmlName variant : descriptor.getCompletionVariants(domElement)) { AttributeChildDescriptionImpl childDescription = new AttributeChildDescriptionImpl(variant.getXmlName(), String.class); descriptors.add(new DomAttributeXmlDescriptor(childDescription, myManager.getProject())); } } } return descriptors.toArray(new XmlAttributeDescriptor[descriptors.size()]); }
@Nullable private static <T extends DomChildrenDescription> T findChildrenDescription(List<T> descriptions, XmlTag tag, DomInvocationHandler parent) { final String localName = tag.getLocalName(); String namespace = null; final String qName = tag.getName(); final XmlFile file = parent.getFile(); //noinspection ForLoopReplaceableByForEach for (int i = 0, size = descriptions.size(); i < size; i++) { final T description = descriptions.get(i); final XmlName xmlName = description.getXmlName(); if (localName.equals(xmlName.getLocalName()) || qName.equals(xmlName.getLocalName())) { final EvaluatedXmlName evaluatedXmlName = parent.createEvaluatedXmlName(xmlName); if (DomImplUtil.isNameSuitable(evaluatedXmlName, localName, qName, namespace == null ? namespace = tag.getNamespace() : namespace, file)) { return description; } } } return null; }
public DomRootInvocationHandler(final Class aClass, final RootDomParentStrategy strategy, @NotNull final DomFileElementImpl fileElement, @NotNull final EvaluatedXmlName tagName, @Nullable ElementStub stub ) { super(aClass, strategy, tagName, new AbstractDomChildDescriptionImpl(aClass) { @Override @NotNull public List<? extends DomElement> getValues(@NotNull final DomElement parent) { throw new UnsupportedOperationException(); } @Override public int compareTo(final AbstractDomChildDescriptionImpl o) { throw new UnsupportedOperationException(); } }, fileElement.getManager(), true, stub); myParent = fileElement; }
public XmlAttributeDescriptor[] getAttributesDescriptors(final @Nullable XmlTag context) { if (context == null) return XmlAttributeDescriptor.EMPTY; DomElement domElement = myManager.getDomElement(context); if (domElement == null) return XmlAttributeDescriptor.EMPTY; final List<? extends DomAttributeChildDescription> descriptions = domElement.getGenericInfo().getAttributeChildrenDescriptions(); List<XmlAttributeDescriptor> descriptors = new ArrayList<XmlAttributeDescriptor>(); for (DomAttributeChildDescription description : descriptions) { descriptors.add(new DomAttributeXmlDescriptor(description, myManager.getProject())); } List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription(); for (CustomDomChildrenDescription custom : customs) { CustomDomChildrenDescription.AttributeDescriptor descriptor = custom.getCustomAttributeDescriptor(); if (descriptor != null) { for (EvaluatedXmlName variant : descriptor.getCompletionVariants(domElement)) { AttributeChildDescriptionImpl childDescription = new AttributeChildDescriptionImpl(variant.getXmlName(), String.class); descriptors.add(new DomAttributeXmlDescriptor(childDescription, myManager.getProject())); } } } return descriptors.toArray(new XmlAttributeDescriptor[descriptors.size()]); }
public DomRootInvocationHandler(final Class aClass, final RootDomParentStrategy strategy, @NotNull final DomFileElementImpl fileElement, @NotNull final EvaluatedXmlName tagName, @Nullable ElementStub stub ) { super(aClass, strategy, tagName, new AbstractDomChildDescriptionImpl(aClass) { @NotNull public List<? extends DomElement> getValues(@NotNull final DomElement parent) { throw new UnsupportedOperationException(); } public int compareTo(final AbstractDomChildDescriptionImpl o) { throw new UnsupportedOperationException(); } }, fileElement.getManager(), true, stub); myParent = fileElement; }
public Set<EvaluatedXmlName> getCompletionVariants(@NotNull DomElement parent) { if (!(parent instanceof AntDomElement)) { return Collections.emptySet(); } final AntDomElement element = (AntDomElement)parent; final AntDomProject antDomProject = element.getAntProject(); if (antDomProject == null) { return Collections.emptySet(); } final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(antDomProject); final Set<EvaluatedXmlName> result = new HashSet<EvaluatedXmlName>(); for (XmlName variant : registry.getCompletionVariants(element)) { final String ns = variant.getNamespaceKey(); result.add(new DummyEvaluatedXmlName(variant, ns != null? ns : "")); } return result; }
public IndexedElementInvocationHandler(final EvaluatedXmlName tagName, final FixedChildDescriptionImpl description, final int index, final DomParentStrategy strategy, final DomManagerImpl manager, @Nullable ElementStub stub) { super(description.getType(), strategy, tagName, description, manager, strategy.isPhysical(), stub); myIndex = index; }
protected AttributeChildInvocationHandler(final EvaluatedXmlName attributeName, final AttributeChildDescriptionImpl description, final DomManagerImpl manager, final DomParentStrategy strategy, @Nullable AttributeStub stub) { super(description.getType(), strategy, attributeName, description, manager, false, stub); }
public IndexedElementInvocationHandler(final EvaluatedXmlName tagName, final FixedChildDescriptionImpl description, final int index, final DomParentStrategy strategy, final DomManagerImpl manager, @Nullable ElementStub stub) { super(description.getType(), strategy, tagName, description, manager, strategy.getXmlElement() != null, stub); myIndex = index; }
public CollectionElementInvocationHandler(@NotNull EvaluatedXmlName tagName, AbstractDomChildDescriptionImpl childDescription, DomManagerImpl manager, ElementStub stub) { super(childDescription.getType(), new StubParentStrategy(stub), tagName, childDescription, manager, true, stub); }
public Set<EvaluatedXmlName> getCompletionVariants(@NotNull DomElement parent) { return Collections.emptySet(); }
@Nullable public PomTarget findDeclaration(DomElement parent, @NotNull EvaluatedXmlName name) { return null; }
public Object invoke(final DomInvocationHandler<?, ?> handler, final Object[] args) throws Throwable { Set<XmlTag> set = ContainerUtil.newTroveSet(); for (final CollectionChildDescriptionImpl qname : myQnames) { set.addAll(qname.getTagsGetter().fun(handler)); } final XmlTag tag = handler.ensureTagExists(); int index = args != null && args.length == 1 ? (Integer)args[0] : Integer.MAX_VALUE; XmlTag lastTag = null; int i = 0; final XmlTag[] tags = tag.getSubTags(); for (final XmlTag subTag : tags) { if (i == index) break; if (set.contains(subTag)) { lastTag = subTag; i++; } } final DomManagerImpl manager = handler.getManager(); final boolean b = manager.setChanging(true); try { final EvaluatedXmlName evaluatedXmlName = handler.createEvaluatedXmlName(myMainDescription.getXmlName()); final XmlTag emptyTag = handler.createChildTag(evaluatedXmlName); final XmlTag newTag; if (lastTag == null) { if (tags.length == 0) { newTag = (XmlTag)tag.add(emptyTag); } else { newTag = (XmlTag)tag.addBefore(emptyTag, tags[0]); } } else { newTag = (XmlTag)tag.addAfter(emptyTag, lastTag); } return new CollectionElementInvocationHandler(myType, newTag, myMainDescription, handler, null).getProxy(); } finally { manager.setChanging(b); } }
@Nullable public PomTarget findDeclaration(DomElement parent, @NotNull EvaluatedXmlName name) { final XmlName xmlName = name.getXmlName(); return doFindDeclaration(parent, xmlName); }
EvaluatedXmlName createEvaluatedXmlName(DomInvocationHandler parent, XmlTag childTag);