mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed stub creation for local variable annotations, sorry
This commit is contained in:
+15
-2
@@ -16,8 +16,8 @@
|
||||
package com.intellij.psi.impl.java.stubs;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LighterASTNode;
|
||||
import com.intellij.lang.LighterAST;
|
||||
import com.intellij.lang.LighterASTNode;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.impl.cache.RecordUtil;
|
||||
import com.intellij.psi.impl.compiled.ClsModifierListImpl;
|
||||
@@ -29,6 +29,7 @@ import com.intellij.psi.stubs.IndexSink;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.stubs.StubInputStream;
|
||||
import com.intellij.psi.stubs.StubOutputStream;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -75,7 +76,19 @@ public class JavaModifierListElementType extends JavaStubElementType<PsiModifier
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateStub(final ASTNode node) {
|
||||
return node.getTreeParent().getElementType() != JavaElementType.LOCAL_VARIABLE;
|
||||
final IElementType parentType = node.getTreeParent().getElementType();
|
||||
return shouldCreateStub(parentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
|
||||
final LighterASTNode parent = tree.getParent(node);
|
||||
final IElementType parentType = parent != null ? parent.getTokenType() : null;
|
||||
return shouldCreateStub(parentType);
|
||||
}
|
||||
|
||||
private static boolean shouldCreateStub(final IElementType parentType) {
|
||||
return parentType != null && parentType != JavaElementType.LOCAL_VARIABLE && parentType != JavaElementType.RESOURCE_VARIABLE;
|
||||
}
|
||||
|
||||
public PsiModifierListStub deserialize(final StubInputStream dataStream, final StubElement parentStub) throws IOException {
|
||||
|
||||
@@ -163,8 +163,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
builder.append("deprecated ");
|
||||
}
|
||||
|
||||
builder.append(getName()).
|
||||
append(":").append(TypeInfo.createTypeText(getReturnTypeText(true)));
|
||||
builder.append(getName()).append(":").append(TypeInfo.createTypeText(getReturnTypeText(false)));
|
||||
|
||||
if (getDefaultValueText() != null) {
|
||||
builder.append(" default=").append(getDefaultValueText());
|
||||
|
||||
@@ -43,7 +43,7 @@ import java.io.IOException;
|
||||
public class JavaFileElementType extends ILightStubFileElementType<PsiJavaFileStub> {
|
||||
public static boolean USE_NEW_STUB_BUILDER = true;
|
||||
|
||||
public static final int STUB_VERSION = (USE_NEW_STUB_BUILDER ? 6 : 5) + 1;
|
||||
public static final int STUB_VERSION = (USE_NEW_STUB_BUILDER ? 6 : 5) + 2;
|
||||
|
||||
public JavaFileElementType() {
|
||||
super("java.FILE", StdLanguages.JAVA);
|
||||
|
||||
@@ -49,7 +49,6 @@ public class JavaLightStubBuilder extends LightStubBuilder {
|
||||
|
||||
@Override
|
||||
public boolean skipChildProcessingWhenBuildingStubs(final IElementType nodeType, final IElementType childType) {
|
||||
return childType == JavaElementType.PARAMETER && nodeType != JavaElementType.PARAMETER_LIST ||
|
||||
childType == JavaElementType.MODIFIER_LIST && (nodeType == JavaElementType.LOCAL_VARIABLE || nodeType == JavaElementType.RESOURCE_VARIABLE);
|
||||
return childType == JavaElementType.PARAMETER && nodeType != JavaElementType.PARAMETER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ public class PsiLocalVariableImpl extends CompositePsiElement implements PsiLoca
|
||||
|
||||
private volatile String myCachedName = null;
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
public PsiLocalVariableImpl() {
|
||||
this(LOCAL_VARIABLE);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
doTest("package p;\n" +
|
||||
"import a/*comment to skip*/.b;\n" +
|
||||
"import static c.d.*;\n" +
|
||||
"import static java.util.Arrays.sort",
|
||||
"import static java.util.Arrays.sort;",
|
||||
|
||||
"PsiJavaFileStub [p]\n" +
|
||||
" IMPORT_LIST:PsiImportListStub\n" +
|
||||
@@ -117,7 +117,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
"}\n" +
|
||||
"private class C {\n" +
|
||||
" public C() throws Exception { }\n" +
|
||||
" public abstract void m(final int i, int[] a1, int a2[], int[] a3[])\n" +
|
||||
" public abstract void m(final int i, int[] a1, int a2[], int[] a3[]);\n" +
|
||||
" private static int v2a(int... v) [] { return v; }\n" +
|
||||
"}",
|
||||
|
||||
@@ -209,7 +209,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
public void testAnonymousClasses() {
|
||||
doTest("class C { {\n" +
|
||||
" new O.P() { };\n" +
|
||||
" X.new Y() { }\n" +
|
||||
" X.new Y() { };\n" +
|
||||
"} }",
|
||||
|
||||
"PsiJavaFileStub []\n" +
|
||||
@@ -227,7 +227,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
|
||||
public void testEnums() {
|
||||
doTest("enum E {\n" +
|
||||
" E1() { }" +
|
||||
" E1() { };\n" +
|
||||
" abstract void m();\n" +
|
||||
"}\n" +
|
||||
"public enum U { U1, U2 }",
|
||||
@@ -262,10 +262,13 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
doTest("class C {\n" +
|
||||
" void m() {\n" +
|
||||
" int local = 0;\n" +
|
||||
" Object r = new Runnable() {\n" +
|
||||
" public void run() { }\n" +
|
||||
" };\n" +
|
||||
" for (int loop = 0; loop < 10; loop++) ;\n" +
|
||||
" try (Resource r = new Resource()) { }\n" +
|
||||
" try (Resource r = new Resource() {\n" +
|
||||
" public void close() { }\n" +
|
||||
" @Override public void close() { }\n" +
|
||||
" }) { }\n" +
|
||||
" }\n" +
|
||||
"}",
|
||||
@@ -282,9 +285,16 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" PARAMETER_LIST:PsiParameterListStub\n" +
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n" +
|
||||
" ANONYMOUS_CLASS:PsiClassStub[anonymous name=null fqn=null baseref=Runnable]\n" +
|
||||
" METHOD:PsiMethodStub[run:void]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=1]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" PARAMETER_LIST:PsiParameterListStub\n" +
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n" +
|
||||
" ANONYMOUS_CLASS:PsiClassStub[anonymous name=null fqn=null baseref=Resource]\n" +
|
||||
" METHOD:PsiMethodStub[close:void]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=1]\n" +
|
||||
" ANNOTATION:PsiAnnotationStub[@Override]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" PARAMETER_LIST:PsiParameterListStub\n" +
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n");
|
||||
@@ -294,6 +304,9 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
doTest("class C {\n" +
|
||||
" {\n" +
|
||||
" for (int i : arr) ;\n" +
|
||||
" for (String s : new Iterable<String>() {\n" +
|
||||
" @Override public Iterator<String> iterator() { return null; }\n" +
|
||||
" }) ;\n" +
|
||||
" try { }\n" +
|
||||
" catch (Throwable t) { }\n" +
|
||||
" catch (E1|E2 e) { }\n" +
|
||||
@@ -308,7 +321,14 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
" EXTENDS_LIST:PsiRefListStub[EXTENDS_LIST:]\n" +
|
||||
" IMPLEMENTS_LIST:PsiRefListStub[IMPLEMENTS_LIST:]\n" +
|
||||
" CLASS_INITIALIZER:PsiClassInitializerStub\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=4096]\n");
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=4096]\n" +
|
||||
" ANONYMOUS_CLASS:PsiClassStub[anonymous name=null fqn=null baseref=Iterable<String>]\n" +
|
||||
" METHOD:PsiMethodStub[iterator:Iterator<String>]\n" +
|
||||
" MODIFIER_LIST:PsiModifierListStub[mask=1]\n" +
|
||||
" ANNOTATION:PsiAnnotationStub[@Override]\n" +
|
||||
" TYPE_PARAMETER_LIST:PsiTypeParameterListStub\n" +
|
||||
" PARAMETER_LIST:PsiParameterListStub\n" +
|
||||
" THROWS_LIST:PsiRefListStub[THROWS_LIST:]\n");
|
||||
}
|
||||
|
||||
public void testSOEProof() {
|
||||
@@ -343,6 +363,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", new String(source));
|
||||
|
||||
IdeaTestUtil.assertTiming("Source file size: " + source.length, 2000, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NEW_BUILDER.buildStubTree(file);
|
||||
}
|
||||
@@ -373,6 +394,14 @@ public class JavaStubBuilderTest extends LightIdeaTestCase {
|
||||
OLD_BUILDER.buildStubTree(file);
|
||||
t4 = Math.max((System.nanoTime() - t4)/1000, 1);
|
||||
|
||||
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
assert !(element instanceof PsiErrorElement) : element;
|
||||
super.visitElement(element);
|
||||
}
|
||||
});
|
||||
|
||||
final String lightStr = DebugUtil.stubTreeToString(lighterTree);
|
||||
final String originalStr = DebugUtil.stubTreeToString(originalTree);
|
||||
final String lightStr2 = DebugUtil.stubTreeToString(lighterTree2);
|
||||
|
||||
Reference in New Issue
Block a user