mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
xinclude support for stubbed dom: preserving elements order
This commit is contained in:
@@ -609,7 +609,7 @@ public abstract class DomInvocationHandler<T extends AbstractDomChildDescription
|
||||
XmlName xmlName = description.getXmlName();
|
||||
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName);
|
||||
if (myStub != null && description.isStubbed()) {
|
||||
List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
|
||||
List<DomStub> stubs = myStub.getChildrenByName(xmlName);
|
||||
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);
|
||||
@@ -836,10 +836,17 @@ 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(), xmlName.getNamespaceKey());
|
||||
List<DomElement> elements =
|
||||
ContainerUtil.map(stubs, stub -> stub.getOrCreateHandler((DomChildDescriptionImpl)description, myManager).getProxy());
|
||||
return addIncludedElements(elements, xmlName);
|
||||
SmartList<DomElement> result = new SmartList<>();
|
||||
List<? extends Stub> stubs = myStub.getChildrenStubs();
|
||||
for (Stub stub : stubs) {
|
||||
if (stub instanceof DomStub && ((DomStub)stub).matches(xmlName)) {
|
||||
result.add(((DomStub)stub).getOrCreateHandler((DomChildDescriptionImpl)description, myManager).getProxy());
|
||||
}
|
||||
else if (stub instanceof XIncludeStub) {
|
||||
((XIncludeStub)stub).resolve(this, result, xmlName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (description instanceof CustomDomChildrenDescriptionImpl) {
|
||||
List<? extends Stub> stubs = myStub.getChildrenStubs();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.util.xml.stubs;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.stubs.ObjectStubBase;
|
||||
import com.intellij.psi.stubs.Stub;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -60,19 +61,21 @@ public abstract class DomStub extends ObjectStubBase<DomStub> {
|
||||
return myNamespace == null ? null : myNamespace.getString();
|
||||
}
|
||||
|
||||
public List<DomStub> getChildrenByName(final CharSequence name, @Nullable final String nsKey) {
|
||||
public boolean matches(XmlName name) {
|
||||
return name.getLocalName().equals(getName()) && StringUtil.notNullize(name.getNamespaceKey()).equals(getNamespaceKey());
|
||||
}
|
||||
|
||||
public List<DomStub> getChildrenByName(XmlName xmlName) {
|
||||
final List<? extends Stub> stubs = getChildrenStubs();
|
||||
if (stubs.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final String s = nsKey == null ? "" : nsKey;
|
||||
final List<DomStub> result = new SmartList<>();
|
||||
//noinspection ForLoopReplaceableByForEach
|
||||
for (int i = 0, size = stubs.size(); i < size; i++) {
|
||||
final Stub stub = stubs.get(i);
|
||||
if (stub instanceof DomStub && XmlUtil.getLocalName(((DomStub)stub).getName()).equals(name) &&
|
||||
Comparing.equal(s, ((DomStub)stub).getNamespaceKey())) {
|
||||
if (stub instanceof DomStub && matches(xmlName)) {
|
||||
result.add((DomStub)stub);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.intellij.util.xml.impl.DomFileElementImpl;
|
||||
import com.intellij.util.xml.impl.DomInvocationHandler;
|
||||
import com.intellij.util.xmlb.JDOMXIncluder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -27,21 +28,13 @@ public class XIncludeStub extends ObjectStubBase<ElementStub> {
|
||||
private final String myHref;
|
||||
private final String myXpointer;
|
||||
|
||||
public XIncludeStub(ElementStub parent, String href, String xpointer) {
|
||||
public XIncludeStub(ElementStub parent, @Nullable String href, @Nullable String xpointer) {
|
||||
super(parent);
|
||||
myHref = href;
|
||||
myXpointer = xpointer;
|
||||
parent.addChild(this);
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return myHref;
|
||||
}
|
||||
|
||||
public String getXpointer() {
|
||||
return myXpointer;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends Stub> getChildrenStubs() {
|
||||
@@ -95,10 +88,10 @@ public class XIncludeStub extends ObjectStubBase<ElementStub> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "href=" + getHref() + " xpointer=" + getXpointer();
|
||||
return "href=" + myHref + " xpointer=" + myXpointer;
|
||||
}
|
||||
|
||||
public final static ObjectStubSerializer ourSerializer = new ObjectStubSerializer<XIncludeStub, ElementStub>() {
|
||||
final static ObjectStubSerializer ourSerializer = new ObjectStubSerializer<XIncludeStub, ElementStub>() {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -108,8 +101,8 @@ public class XIncludeStub extends ObjectStubBase<ElementStub> {
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull XIncludeStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeUTFFast(StringUtil.notNullize(stub.getHref()));
|
||||
dataStream.writeUTFFast(StringUtil.notNullize(stub.getXpointer()));
|
||||
dataStream.writeUTFFast(StringUtil.notNullize(stub.myHref));
|
||||
dataStream.writeUTFFast(StringUtil.notNullize(stub.myXpointer));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -96,6 +96,6 @@ public class DomStubBuilder implements BinaryFileStubBuilder {
|
||||
|
||||
@Override
|
||||
public int getStubVersion() {
|
||||
return 21 + DomApplicationComponent.getInstance().getCumulativeVersion(true);
|
||||
return 22 + DomApplicationComponent.getInstance().getCumulativeVersion(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ import com.intellij.util.xml.stubs.model.Custom;
|
||||
import com.intellij.util.xml.stubs.model.Foo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
@@ -120,7 +122,9 @@ public class DomStubBuilderTest extends DomStubTest {
|
||||
|
||||
DomFileElement<Foo> element = DomManager.getDomManager(getProject()).getFileElement((XmlFile)file, Foo.class);
|
||||
assert element != null;
|
||||
assertEquals(3, element.getRootElement().getBars().size());
|
||||
List<Bar> bars = element.getRootElement().getBars();
|
||||
assertEquals(3, bars.size());
|
||||
assertEquals("include.xml", bars.get(0).getXmlTag().getContainingFile().getName());
|
||||
}
|
||||
|
||||
public static class TestExtender extends DomExtender<Bar> {
|
||||
|
||||
Reference in New Issue
Block a user