mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
namespace support for DOM stubs
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package com.intellij.util.io;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
@@ -98,6 +100,11 @@ public class StringRef {
|
||||
return source == null ? null : new StringRef(source);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StringRef fromNullableString(String source) {
|
||||
return source == null ? new StringRef("") : new StringRef(source);
|
||||
}
|
||||
|
||||
public static StringRef fromStream(DataInput in, AbstractStringEnumerator store) throws IOException {
|
||||
final int nameId = DataInputOutputUtil.readINT(in);
|
||||
|
||||
|
||||
@@ -557,9 +557,10 @@ public abstract class DomInvocationHandler<T extends AbstractDomChildDescription
|
||||
@NotNull
|
||||
final IndexedElementInvocationHandler getFixedChild(final Pair<FixedChildDescriptionImpl, Integer> info) {
|
||||
final FixedChildDescriptionImpl description = info.first;
|
||||
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
|
||||
XmlName xmlName = description.getXmlName();
|
||||
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName);
|
||||
if (myStub != null && description.isStubbed()) {
|
||||
List<DomStub> stubs = myStub.getChildrenByName(description.getXmlName().getLocalName());
|
||||
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);
|
||||
@@ -771,7 +772,7 @@ public abstract class DomInvocationHandler<T extends AbstractDomChildDescription
|
||||
if (myStub != null && description.isStubbed()) {
|
||||
if (description instanceof DomChildDescriptionImpl) {
|
||||
XmlName xmlName = ((DomChildDescriptionImpl)description).getXmlName();
|
||||
List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName());
|
||||
List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
|
||||
return ContainerUtil.map(stubs, new Function<DomStub, DomElement>() {
|
||||
@Override
|
||||
public DomElement fun(DomStub stub) {
|
||||
|
||||
@@ -29,8 +29,8 @@ public class AttributeStub extends DomStub {
|
||||
|
||||
private final String myValue;
|
||||
|
||||
public AttributeStub(DomStub parent, StringRef name, String value) {
|
||||
super(parent, name);
|
||||
public AttributeStub(DomStub parent, StringRef name, StringRef namespace, String value) {
|
||||
super(parent, name, namespace);
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,12 +38,13 @@ public class AttributeStubSerializer implements ObjectStubSerializer<AttributeSt
|
||||
@Override
|
||||
public void serialize(AttributeStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeName(stub.getNamespaceKey());
|
||||
dataStream.writeUTFFast(stub.getValue() == null ? "" : stub.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeStub deserialize(StubInputStream dataStream, ElementStub parentStub) throws IOException {
|
||||
return new AttributeStub(parentStub, dataStream.readName(), dataStream.readUTFFast());
|
||||
return new AttributeStub(parentStub, dataStream.readName(), dataStream.readName(), dataStream.readUTFFast());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,8 +21,12 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import com.intellij.util.xml.EvaluatedXmlNameImpl;
|
||||
import com.intellij.util.xml.XmlName;
|
||||
import com.intellij.util.xml.impl.*;
|
||||
import com.intellij.util.xml.impl.CollectionElementInvocationHandler;
|
||||
import com.intellij.util.xml.impl.DomChildDescriptionImpl;
|
||||
import com.intellij.util.xml.impl.DomInvocationHandler;
|
||||
import com.intellij.util.xml.impl.DomManagerImpl;
|
||||
import com.intellij.xml.util.XmlUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -33,33 +37,40 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class DomStub extends ObjectStubBase<DomStub> {
|
||||
|
||||
protected final StringRef myName;
|
||||
protected final StringRef myLocalName;
|
||||
private final StringRef myNamespace;
|
||||
private DomInvocationHandler myHandler;
|
||||
|
||||
public DomStub(DomStub parent, StringRef name) {
|
||||
public DomStub(DomStub parent, @NotNull StringRef localName, StringRef namespace) {
|
||||
super(parent);
|
||||
myNamespace = namespace;
|
||||
if (parent != null) {
|
||||
((ElementStub)parent).addChild(this);
|
||||
}
|
||||
myName = name;
|
||||
myLocalName = localName;
|
||||
}
|
||||
|
||||
public abstract List<DomStub> getChildrenStubs();
|
||||
|
||||
public int getChildIndex(DomStub child) {
|
||||
List<DomStub> stubs = getChildrenByName(XmlUtil.getLocalName(child.getName()));
|
||||
List<DomStub> stubs = getChildrenByName(XmlUtil.getLocalName(child.getName()), child.getNamespaceKey());
|
||||
return stubs.indexOf(child);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName.getString();
|
||||
return myLocalName.getString();
|
||||
}
|
||||
|
||||
public List<DomStub> getChildrenByName(final CharSequence localName) {
|
||||
public String getNamespaceKey() {
|
||||
return myNamespace.getString();
|
||||
}
|
||||
|
||||
public List<DomStub> getChildrenByName(final CharSequence name, final String nsKey) {
|
||||
final String s = nsKey == null ? "" : nsKey;
|
||||
return ContainerUtil.filter(getChildrenStubs(), new Condition<DomStub>() {
|
||||
@Override
|
||||
public boolean value(DomStub stub) {
|
||||
return stub instanceof ElementStub && XmlUtil.getLocalName(stub.getName()).equals(localName);
|
||||
return XmlUtil.getLocalName(stub.getName()).equals(name) && stub.getNamespaceKey().equals(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.util.xml.stubs;
|
||||
import com.intellij.psi.stubs.ObjectStubSerializer;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -31,8 +32,8 @@ public class ElementStub extends DomStub {
|
||||
private final List<DomStub> myChildren = new SmartList<DomStub>();
|
||||
private final boolean myCustom;
|
||||
|
||||
public ElementStub(@Nullable ElementStub parent, StringRef name, boolean custom) {
|
||||
super(parent, name);
|
||||
public ElementStub(@Nullable ElementStub parent, @NotNull StringRef name, StringRef namespace, boolean custom) {
|
||||
super(parent, name, namespace);
|
||||
myCustom = custom;
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ElementStub extends DomStub {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
return obj instanceof ElementStub && id == ((ElementStub)obj).id && myName.equals(((ElementStub)obj).myName);
|
||||
return obj instanceof ElementStub && id == ((ElementStub)obj).id && myLocalName.equals(((ElementStub)obj).myLocalName);
|
||||
}
|
||||
|
||||
public boolean isCustom() {
|
||||
|
||||
@@ -33,12 +33,13 @@ public class ElementStubSerializer implements ObjectStubSerializer<ElementStub,
|
||||
@Override
|
||||
public void serialize(ElementStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeName(stub.getNamespaceKey());
|
||||
dataStream.writeBoolean(stub.isCustom());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementStub deserialize(StubInputStream dataStream, ElementStub parentStub) throws IOException {
|
||||
return new ElementStub(parentStub, dataStream.readName(), dataStream.readBoolean());
|
||||
return new ElementStub(parentStub, dataStream.readName(), dataStream.readName(), dataStream.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ public class FileStub extends ElementStub {
|
||||
private final XmlFileHeader myHeader;
|
||||
|
||||
public FileStub(StringRef tagName, StringRef tagNamespace, StringRef publicId, StringRef systemId) {
|
||||
super(null, tagName, false);
|
||||
super(null, tagName, tagNamespace, false);
|
||||
myHeader = new XmlFileHeader(tagName == null ? null : tagName.getString(),
|
||||
tagNamespace == null ? null : tagNamespace.getString(),
|
||||
publicId == null ? null : publicId.getString(),
|
||||
@@ -40,7 +40,7 @@ public class FileStub extends ElementStub {
|
||||
}
|
||||
|
||||
public FileStub(XmlFileHeader header) {
|
||||
super(null, StringRef.fromString(header.getRootTagLocalName()), false);
|
||||
super(null, StringRef.fromString(header.getRootTagLocalName()), StringRef.fromString(header.getRootTagNamespace()), false);
|
||||
myHeader = header;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DomStubBuilder implements BinaryFileStubBuilder {
|
||||
|
||||
@Override
|
||||
public int getStubVersion() {
|
||||
int version = 6;
|
||||
int version = 8;
|
||||
DomFileDescription[] descriptions = Extensions.getExtensions(DomFileDescription.EP_NAME);
|
||||
for (DomFileDescription description : descriptions) {
|
||||
version += description.getStubVersion();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.util.xml.stubs.builder;
|
||||
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.stubs.Stubbed;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlElement;
|
||||
@@ -24,7 +23,9 @@ import com.intellij.util.io.StringRef;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.DomElementVisitor;
|
||||
import com.intellij.util.xml.DomUtil;
|
||||
import com.intellij.util.xml.reflect.AbstractDomChildrenDescription;
|
||||
import com.intellij.util.xml.reflect.CustomDomChildrenDescription;
|
||||
import com.intellij.util.xml.reflect.DomChildrenDescription;
|
||||
import com.intellij.util.xml.stubs.AttributeStub;
|
||||
import com.intellij.util.xml.stubs.ElementStub;
|
||||
import com.intellij.util.xml.stubs.FileStub;
|
||||
@@ -50,10 +51,14 @@ public class DomStubBuilderVisitor implements DomElementVisitor {
|
||||
element.getChildDescription().isStubbed()) {
|
||||
|
||||
XmlElement xmlElement = element.getXmlElement();
|
||||
AbstractDomChildrenDescription description = element.getChildDescription();
|
||||
String nsKey = description instanceof DomChildrenDescription ? ((DomChildrenDescription)description).getXmlName().getNamespaceKey() : "";
|
||||
if (xmlElement instanceof XmlTag) {
|
||||
ElementStub old = myRoot;
|
||||
boolean custom = element.getChildDescription() instanceof CustomDomChildrenDescription;
|
||||
myRoot = new ElementStub(myRoot, StringRef.fromString(((PsiNamedElement)xmlElement).getName()), custom);
|
||||
myRoot = new ElementStub(myRoot,
|
||||
StringRef.fromString(((XmlTag)xmlElement).getName()),
|
||||
StringRef.fromNullableString(nsKey),
|
||||
description instanceof CustomDomChildrenDescription);
|
||||
List<DomElement> children = DomUtil.getDefinedChildren(element, true, true);
|
||||
for (DomElement child : children) {
|
||||
visitDomElement(child);
|
||||
@@ -64,6 +69,7 @@ public class DomStubBuilderVisitor implements DomElementVisitor {
|
||||
}
|
||||
else if (xmlElement instanceof XmlAttribute) {
|
||||
new AttributeStub(myRoot, StringRef.fromString(((XmlAttribute)xmlElement).getLocalName()),
|
||||
StringRef.fromNullableString(nsKey),
|
||||
((XmlAttribute)xmlElement).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user