From 7499ba025576be4aee42bd5731fd9a7f129fec54 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 25 Jun 2012 11:41:34 +0400 Subject: [PATCH] Stub for enum entry --- .../src/org/jetbrains/jet/JetNodeTypes.java | 2 +- .../jetbrains/jet/lang/psi/JetEnumEntry.java | 18 +++++++ .../jet/lang/psi/stubs/PsiJetClassStub.java | 2 + .../stubs/elements/JetClassElementType.java | 18 +++++-- .../stubs/elements/JetFileElementType.java | 2 +- .../stubs/elements/JetStubElementTypes.java | 1 + .../psi/stubs/impl/PsiJetClassStubImpl.java | 47 ++++++++++++------- .../jet/plugin/stubs/JetStubsTest.java | 12 +++++ 8 files changed, 77 insertions(+), 25 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 060c9d20b1e..171f269aa00 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -38,7 +38,7 @@ public interface JetNodeTypes { JetNodeType CLASS_OBJECT = new JetNodeType("CLASS_OBJECT", JetClassObject.class); JetNodeType CONSTRUCTOR = new JetNodeType("CONSTRUCTOR", JetSecondaryConstructor.class); - JetNodeType ENUM_ENTRY = new JetNodeType("ENUM_ENTRY", JetEnumEntry.class); + IElementType ENUM_ENTRY = JetStubElementTypes.ENUM_ENTRY; JetNodeType ANONYMOUS_INITIALIZER = new JetNodeType("ANONYMOUS_INITIALIZER", JetClassInitializer.class); IElementType TYPE_PARAMETER_LIST = JetStubElementTypes.TYPE_PARAMETER_LIST; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetEnumEntry.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetEnumEntry.java index ea6ec073273..e7d2990429d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetEnumEntry.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetEnumEntry.java @@ -18,10 +18,13 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; +import com.intellij.psi.stubs.IStubElementType; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import java.util.Collections; import java.util.List; @@ -34,8 +37,17 @@ public class JetEnumEntry extends JetClass { super(node); } + public JetEnumEntry(@NotNull PsiJetClassStub stub) { + super(stub); + } + @Override public String getName() { + PsiJetClassStub classStub = getStub(); + if (classStub != null) { + return classStub.getName(); + } + JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); return nameAsDeclaration == null ? "" : nameAsDeclaration.getName(); } @@ -46,6 +58,12 @@ public class JetEnumEntry extends JetClass { return nameAsDeclaration == null ? null : nameAsDeclaration.getNameIdentifier(); } + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.ENUM_ENTRY; + } + @Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java index 94cc619a8a8..e6461a20343 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java @@ -34,6 +34,8 @@ public interface PsiJetClassStub extends NamedStub { boolean isTrait(); + boolean isEnumEntry(); + @NotNull List getSuperNames(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java index 03482399ba0..86ab6bcd982 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java @@ -25,6 +25,7 @@ import com.intellij.util.io.StringRef; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetClass; +import org.jetbrains.jet.lang.psi.JetEnumEntry; import org.jetbrains.jet.lang.psi.JetPsiUtil; import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub; import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassStubImpl; @@ -44,19 +45,20 @@ public class JetClassElementType extends JetStubElementType superNames = stub.getSuperNames(); dataStream.writeVarInt(superNames.size()); @@ -77,6 +80,7 @@ public class JetClassElementType extends JetStubElementType { - public static final int STUB_VERSION = 13; + public static final int STUB_VERSION = 14; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java index 849f5a0ac3b..4b151366397 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java @@ -25,6 +25,7 @@ public interface JetStubElementTypes { JetClassElementType CLASS = new JetClassElementType("CLASS"); JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN"); JetPropertyElementType PROPERTY = new JetPropertyElementType("PROPERTY"); + JetClassElementType ENUM_ENTRY = new JetClassElementType("ENUM_ENTRY"); JetParameterElementType VALUE_PARAMETER = new JetParameterElementType("VALUE_PARAMETER"); JetParameterListElementType VALUE_PARAMETER_LIST = new JetParameterListElementType("VALUE_PARAMETER_LIST"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java index d4109d87438..9e1b3169aec 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java @@ -34,11 +34,11 @@ import java.util.List; * @author Nikolay Krasko */ public class PsiJetClassStubImpl extends StubBase implements PsiJetClassStub { - private final StringRef qualifiedName; private final StringRef name; private final StringRef[] superNames; private final boolean isTrait; + private final boolean isEnumEntry; public PsiJetClassStubImpl( JetClassElementType type, @@ -46,8 +46,25 @@ public class PsiJetClassStubImpl extends StubBase implements PsiJetCla @Nullable final String qualifiedName, String name, List superNames, - boolean isTrait) { - this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames), isTrait); + boolean isTrait, boolean isEnumEntry) { + this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames), + isTrait, isEnumEntry); + } + + public PsiJetClassStubImpl( + JetClassElementType type, + StubElement parent, + StringRef qualifiedName, + StringRef name, + StringRef[] superNames, + boolean isTrait, boolean isEnumEntry + ) { + super(parent, type); + this.qualifiedName = qualifiedName; + this.name = name; + this.superNames = superNames; + this.isTrait = isTrait; + this.isEnumEntry = isEnumEntry; } private static StringRef[] wrapStrings(List names) { @@ -58,21 +75,6 @@ public class PsiJetClassStubImpl extends StubBase implements PsiJetCla return refs; } - public PsiJetClassStubImpl( - JetClassElementType type, - StubElement parent, - StringRef qualifiedName, - StringRef name, - StringRef[] superNames, - boolean isTrait) { - - super(parent, type); - this.qualifiedName = qualifiedName; - this.name = name; - this.superNames = superNames; - this.isTrait = isTrait; - } - @Override public String getQualifiedName() { return StringRef.toString(qualifiedName); @@ -83,6 +85,11 @@ public class PsiJetClassStubImpl extends StubBase implements PsiJetCla return isTrait; } + @Override + public boolean isEnumEntry() { + return isEnumEntry; + } + @Override public String getName() { return StringRef.toString(name); @@ -103,6 +110,10 @@ public class PsiJetClassStubImpl extends StubBase implements PsiJetCla StringBuilder builder = new StringBuilder(); builder.append("PsiJetClassStubImpl["); + if (isEnumEntry()) { + builder.append("enumEntry "); + } + if (isTrait()) { builder.append("trait "); } diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java index a03ac7e9974..944cd15f0bf 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java @@ -91,6 +91,18 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); } + public void testSimpleEnumBuild() { + doBuildTest("enum class Test { First\n Second\n }", + "PsiJetFileStubImpl[package=]\n" + + " CLASS:PsiJetClassStubImpl[name=Test fqn=Test superNames=[]]\n" + + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n" + + " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=First fqn=Test.First superNames=[]]\n" + + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n" + + " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=Second fqn=Test.Second superNames=[]]\n" + + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n" + ); + } + private void doBuildTest(@NonNls final String source, @NonNls @NotNull final String tree) { final JetFile file = (JetFile) createLightFile(JetFileType.INSTANCE, source); final FileASTNode fileNode = file.getNode();