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 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; }
void visitXmlElement(XmlElement element, ElementStub parent, int index) { DomInvocationHandler handler = myManager.getDomHandler(element); if (handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed()) return; AbstractDomChildrenDescription description = handler.getChildDescription(); String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription)description).getXmlName().getNamespaceKey() : ""; if (element instanceof XmlTag) { XmlTag tag = (XmlTag)element; String elementClass = null; if (handler.getAnnotation(StubbedOccurrence.class) != null) { final Type type = description.getType(); elementClass = ((Class)type).getName(); } ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass), tag.getSubTags().length == 0 ? tag.getValue().getTrimmedText() : ""); for (XmlAttribute attribute : tag.getAttributes()) { visitXmlElement(attribute, stub, 0); } Map<String, Integer> indices = new HashMap<String, Integer>(); for (final XmlTag subTag : tag.getSubTags()) { String name = subTag.getName(); Integer i = indices.get(name); i = i == null ? 0 : i + 1; visitXmlElement(subTag, stub, i); indices.put(name, i); } } else if (element instanceof XmlAttribute) { new AttributeStub(parent, StringRef.fromString(((XmlAttribute)element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute)element).getValue()); } }
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; }
@NotNull final IndexedElementInvocationHandler getFixedChild(final Pair<FixedChildDescriptionImpl, Integer> info) { final FixedChildDescriptionImpl description = info.first; XmlName xmlName = description.getXmlName(); final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName); if (myStub != null && description.isStubbed()) { List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey()); DomStub stub = stubs.isEmpty() ? null : stubs.get(0); DomParentStrategy strategy = stub == null ? new StubParentStrategy.Empty(myStub) : new StubParentStrategy(stub); return new IndexedElementInvocationHandler(evaluatedXmlName, description, 0, strategy, myManager, (ElementStub)stub); } final XmlTag tag = getXmlTag(); final int index = info.second; if (tag != null) { if (!tag.isValid()) { throw new PsiInvalidElementAccessException(tag); } final XmlTag[] subTags = tag.getSubTags(); for (int i = 0, subTagsLength = subTags.length; i < subTagsLength; i++) { XmlTag xmlTag = subTags[i]; if (!xmlTag.isValid()) { throw new PsiInvalidElementAccessException(xmlTag, "invalid children of valid tag: " + tag.getText() + "; subtag=" + xmlTag + "; index=" + i); } } final List<XmlTag> tags = DomImplUtil.findSubTags(subTags, evaluatedXmlName, getFile()); if (tags.size() > index) { final XmlTag child = tags.get(index); final IndexedElementInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child); if (semElement == null) { final IndexedElementInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child); throw new AssertionError("No DOM at XML. Parent=" + tag + "; child=" + child + "; index=" + index+ "; second attempt=" + take2); } return semElement; } } return new IndexedElementInvocationHandler(evaluatedXmlName, description, index, new VirtualDomParentStrategy(this), myManager, null); }
public CollectionElementInvocationHandler(final Type type, @NotNull final XmlTag tag, final AbstractCollectionChildDescription description, final DomInvocationHandler parent, @Nullable ElementStub stub) { super(type, new PhysicalDomParentStrategy(tag, parent.getManager()), description.createEvaluatedXmlName(parent, tag), (AbstractDomChildDescriptionImpl)description, parent.getManager(), true, stub); }
@Override public int hashCode() { ElementStub stub = getStub(); if (stub != null) { return stub.getName().hashCode() + stub.id; } final XmlElement element = getXmlElement(); return element == null ? super.hashCode() : element.hashCode(); }
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); }
void visitXmlElement(XmlElement element, ElementStub parent, int index) { DomInvocationHandler handler = myManager.getDomHandler(element); if(handler == null || handler.getAnnotation(Stubbed.class) == null && !handler.getChildDescription().isStubbed()) { return; } AbstractDomChildrenDescription description = handler.getChildDescription(); String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription) description).getXmlName().getNamespaceKey() : ""; if(element instanceof XmlTag) { XmlTag tag = (XmlTag) element; String elementClass = null; if(handler.getAnnotation(StubbedOccurrence.class) != null) { final Type type = description.getType(); elementClass = ((Class) type).getName(); } ElementStub stub = new ElementStub(parent, StringRef.fromString(tag.getName()), StringRef.fromNullableString(nsKey), index, description instanceof CustomDomChildrenDescription, elementClass == null ? null : StringRef.fromNullableString(elementClass)); for(XmlAttribute attribute : tag.getAttributes()) { visitXmlElement(attribute, stub, 0); } Map<String, Integer> indices = new HashMap<String, Integer>(); for(final XmlTag subTag : tag.getSubTags()) { String name = subTag.getName(); Integer i = indices.get(name); i = i == null ? 0 : i + 1; visitXmlElement(subTag, stub, i); indices.put(name, i); } } else if(element instanceof XmlAttribute) { new AttributeStub(parent, StringRef.fromString(((XmlAttribute) element).getLocalName()), StringRef.fromNullableString(nsKey), ((XmlAttribute) element).getValue()); } }