mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correct containingClass and other properties of stub-based groovy enum constants (EA-31346)
This commit is contained in:
+14
-3
@@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
|
||||
@@ -45,6 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.blocks.GrOpenBlockI
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.enumConstant.GrEnumConstantListImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrAnnotationMethodImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrConstructorImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrMethodImpl;
|
||||
@@ -176,8 +178,12 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
|
||||
|
||||
GroovyElementType BLOCK_STATEMENT = new GroovyElementType("Block statement");
|
||||
|
||||
// Enum
|
||||
GroovyElementType ENUM_CONSTANTS = new GroovyElementType("Enumeration constants");
|
||||
EmptyStubElementType<GrEnumConstantList> ENUM_CONSTANTS = new EmptyStubElementType<GrEnumConstantList>("Enumeration constants", GroovyFileType.GROOVY_LANGUAGE) {
|
||||
@Override
|
||||
public GrEnumConstantList createPsi(@NotNull EmptyStub stub) {
|
||||
return new GrEnumConstantListImpl(stub);
|
||||
}
|
||||
};
|
||||
GroovyElementType IMPORT_STATEMENT = new GroovyElementType("Import statement");
|
||||
//Branch statements
|
||||
GroovyElementType BREAK_STATEMENT = new GroovyElementType("Break statement");
|
||||
@@ -374,7 +380,12 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
|
||||
}
|
||||
};
|
||||
|
||||
IElementType ENUM_BODY = new GroovyElementType("enum block");
|
||||
EmptyStubElementType<GrEnumDefinitionBody> ENUM_BODY = new EmptyStubElementType<GrEnumDefinitionBody>("enum block", GroovyFileType.GROOVY_LANGUAGE) {
|
||||
@Override
|
||||
public GrEnumDefinitionBody createPsi(@NotNull EmptyStub stub) {
|
||||
return new GrTypeDefinitionBodyBase.GrEnumBody(stub);
|
||||
}
|
||||
};
|
||||
//statements
|
||||
GroovyElementType IF_STATEMENT = new GroovyElementType("if statement");
|
||||
GroovyElementType FOR_STATEMENT = new GroovyElementType("for statement");
|
||||
|
||||
+2
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public interface GrEnumDefinitionBody extends GrTypeDefinitionBody {
|
||||
@Nullable
|
||||
GrEnumConstantList getEnumConstantList();
|
||||
}
|
||||
|
||||
+7
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members;
|
||||
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
@@ -29,6 +30,12 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConsta
|
||||
*/
|
||||
public interface GrEnumConstant extends GrField, GrConstructorCall, PsiEnumConstant {
|
||||
GrEnumConstant[] EMPTY_ARRAY = new GrEnumConstant[0];
|
||||
ArrayFactory<GrEnumConstant> ARRAY_FACTORY = new ArrayFactory<GrEnumConstant>() {
|
||||
@Override
|
||||
public GrEnumConstant[] create(int count) {
|
||||
return new GrEnumConstant[count];
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
GrEnumConstantInitializer getInitializingClass();
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class GrEnumTypeDefinitionImpl extends GrTypeDefinitionImpl implements Gr
|
||||
}
|
||||
|
||||
public GrEnumDefinitionBody getBody() {
|
||||
return (GrEnumDefinitionBody)findChildByType(GroovyElementTypes.ENUM_BODY);
|
||||
return getStubOrPsiChild(GroovyElementTypes.ENUM_BODY);
|
||||
}
|
||||
|
||||
public boolean isEnum() {
|
||||
|
||||
+7
-2
@@ -173,13 +173,18 @@ public abstract class GrTypeDefinitionBodyBase extends GrStubElementBase<EmptySt
|
||||
|
||||
}
|
||||
|
||||
public static class GrEnumBody extends GrTypeDefinitionBodyBase implements GrEnumDefinitionBody {
|
||||
public static class GrEnumBody extends GrTypeDefinitionBodyBase implements GrEnumDefinitionBody, StubBasedPsiElement<EmptyStub> {
|
||||
public GrEnumBody(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public GrEnumBody(EmptyStub stub) {
|
||||
super(stub, GroovyElementTypes.ENUM_BODY);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public GrEnumConstantList getEnumConstantList() {
|
||||
return findChildByClass(GrEnumConstantList.class);
|
||||
return getStubOrPsiChild(GroovyElementTypes.ENUM_CONSTANTS);
|
||||
}
|
||||
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
|
||||
+18
-4
@@ -17,21 +17,30 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.enumConstant;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.EmptyStub;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
|
||||
|
||||
/**
|
||||
* @author: Dmitry.Krasilschikov
|
||||
* @date: 06.04.2007
|
||||
*/
|
||||
public class GrEnumConstantListImpl extends GroovyPsiElementImpl implements GrEnumConstantList {
|
||||
public class GrEnumConstantListImpl extends GrStubElementBase<EmptyStub> implements GrEnumConstantList, StubBasedPsiElement<EmptyStub> {
|
||||
|
||||
public GrEnumConstantListImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public GrEnumConstantListImpl(EmptyStub stub) {
|
||||
super(stub, GroovyElementTypes.ENUM_CONSTANTS);
|
||||
}
|
||||
|
||||
public void accept(GroovyElementVisitor visitor) {
|
||||
visitor.visitEnumConstants(this);
|
||||
}
|
||||
@@ -41,6 +50,11 @@ public class GrEnumConstantListImpl extends GroovyPsiElementImpl implements GrEn
|
||||
}
|
||||
|
||||
public GrEnumConstant[] getEnumConstants() {
|
||||
return findChildrenByClass(GrEnumConstant.class);
|
||||
return getStubOrPsiChildren(GroovyElementTypes.ENUM_CONSTANT, GrEnumConstant.ARRAY_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getParent() {
|
||||
return getParentByStub();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class GrStubFileElementType extends IStubFileElementType<GrFileStub> {
|
||||
|
||||
@Override
|
||||
public int getStubVersion() {
|
||||
return super.getStubVersion() + 10;
|
||||
return super.getStubVersion() + 11;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang
|
||||
|
||||
import com.intellij.psi.impl.source.PsiFileImpl
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.PsiShortNamesCache
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumDefinitionBody
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class GroovyStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testEnumConstant() {
|
||||
myFixture.tempDirFixture.createFile('A.groovy', 'enum A { MyEnumConstant }')
|
||||
GrEnumConstant ec = (GrEnumConstant)PsiShortNamesCache.getInstance(project).getFieldsByName("MyEnumConstant", GlobalSearchScope.allScope(project))[0]
|
||||
def file = (PsiFileImpl)ec.containingFile
|
||||
assert file.stub
|
||||
assert ec.containingClass.qualifiedName == 'A'
|
||||
assert file.stub
|
||||
|
||||
assert ec in ec.containingClass.fields
|
||||
assert ec in ((GrEnumDefinitionBody)((GrTypeDefinition)ec.containingClass).body).enumConstantList.enumConstants
|
||||
assert file.stub
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user