use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList in project intellij-community by JetBrains.
the class GrClassImplUtil method getInnerClassesForResolve.
@NotNull
private static List<PsiClass> getInnerClassesForResolve(@NotNull final GrTypeDefinition grType, @Nullable final PsiElement lastParent, @NotNull final PsiElement place) {
if (lastParent instanceof GrReferenceList || PsiTreeUtil.getParentOfType(place, GrReferenceList.class) != null) {
return Arrays.asList(grType.getCodeInnerClasses());
}
boolean includeSynthetic = !PsiTreeUtil.isContextAncestor(grType, place, true);
Object key = Trinity.create(grType, lastParent, place);
List<PsiClass> classes = RecursionManager.doPreventingRecursion(key, false, () -> {
List<PsiClass> result = new ArrayList<>();
for (CandidateInfo info : CollectClassMembersUtil.getAllInnerClasses(grType, includeSynthetic).values()) {
final PsiClass inner = (PsiClass) info.getElement();
final PsiClass containingClass = inner.getContainingClass();
assert containingClass != null;
if (lastParent == null || !containingClass.isInterface() || PsiTreeUtil.isAncestor(containingClass, place, false)) {
ContainerUtil.addIfNotNull(result, inner);
}
}
return result;
});
if (classes == null) {
return Arrays.asList(grType.getCodeInnerClasses());
}
return classes;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList in project intellij-community by JetBrains.
the class GrHighlightHandlerFactory method createHighlightUsagesHandler.
@Override
public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement target) {
ASTNode node = target.getNode();
if (node == null)
return null;
IElementType type = node.getElementType();
if (type == GroovyTokenTypes.kIMPLEMENTS || type == GroovyTokenTypes.kEXTENDS) {
PsiElement parent = target.getParent();
if (!(parent instanceof GrReferenceList))
return null;
PsiElement grand = parent.getParent();
if (!(grand instanceof GrTypeDefinition))
return null;
return new GrHighlightOverridingMethodsHandler(editor, file, target, (GrTypeDefinition) grand);
} else if (type == GroovyTokenTypes.kRETURN || type == GroovyTokenTypes.kTHROW) {
return new GrHighlightExitPointHandler(editor, file, target);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList in project intellij-community by JetBrains.
the class GrHighlightOverridingMethodsHandler method getTargets.
@Override
public List<PsiClass> getTargets() {
GrReferenceList list = GroovyTokenTypes.kEXTENDS == myTarget.getNode().getElementType() ? myClass.getExtendsClause() : myClass.getImplementsClause();
if (list == null)
return Collections.emptyList();
final PsiClassType[] classTypes = list.getReferencedTypes();
return ChooseClassAndDoHighlightRunnable.resolveClasses(classTypes);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList in project intellij-community by JetBrains.
the class AddClassToExtendsFix method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
GrReferenceList list;
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
final PsiClass comparable = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_COMPARABLE, myPsiClass.getResolveScope());
PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
boolean addTypeParam = false;
if (comparable != null) {
final PsiTypeParameter[] typeParameters = comparable.getTypeParameters();
if (typeParameters.length == 1) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final PsiTypeParameter[] classParams = myPsiClass.getTypeParameters();
PsiSubstitutor innerSubstitutor = PsiSubstitutor.EMPTY;
for (PsiTypeParameter classParam : classParams) {
innerSubstitutor = innerSubstitutor.put(classParam, elementFactory.createType(classParam));
}
substitutor = substitutor.put(typeParameters[0], elementFactory.createType(myPsiClass, innerSubstitutor));
addTypeParam = true;
}
}
if (!InheritanceUtil.isInheritor(myPsiClass, CommonClassNames.JAVA_LANG_COMPARABLE)) {
if (myPsiClass.isInterface()) {
list = myPsiClass.getExtendsClause();
if (list == null) {
list = factory.createExtendsClause();
PsiElement anchor = myPsiClass.getImplementsClause();
if (anchor == null) {
anchor = myPsiClass.getBody();
}
if (anchor == null)
return;
list = (GrReferenceList) myPsiClass.addBefore(list, anchor);
myPsiClass.getNode().addLeaf(TokenType.WHITE_SPACE, " ", anchor.getNode());
myPsiClass.getNode().addLeaf(TokenType.WHITE_SPACE, " ", list.getNode());
}
} else {
list = myPsiClass.getImplementsClause();
if (list == null) {
list = factory.createImplementsClause();
PsiElement anchor = myPsiClass.getBody();
if (anchor == null)
return;
list = (GrReferenceList) myPsiClass.addBefore(list, anchor);
myPsiClass.getNode().addLeaf(TokenType.WHITE_SPACE, " ", list.getNode());
myPsiClass.getNode().addLeaf(TokenType.WHITE_SPACE, " ", anchor.getNode());
}
}
final GrCodeReferenceElement _ref = factory.createReferenceElementFromText(myInterfaceName + (addTypeParam ? "<" + AddMethodFix.generateTypeText(myPsiClass) + ">" : ""));
final GrCodeReferenceElement ref = (GrCodeReferenceElement) list.add(_ref);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(ref);
}
if (comparable != null && !myPsiClass.isInterface()) {
final PsiMethod baseMethod = comparable.getMethods()[0];
OverrideImplementUtil.overrideOrImplement(myPsiClass, baseMethod);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList in project intellij-community by JetBrains.
the class GrMemberInfo method extractClassMembers.
public static void extractClassMembers(PsiClass subclass, List<GrMemberInfo> result, Filter<GrMember> filter, final boolean extractInterfacesDeep) {
if (!(subclass instanceof GrTypeDefinition))
return;
if (extractInterfacesDeep) {
extractSuperInterfaces(subclass, filter, result, ContainerUtil.<PsiClass>newHashSet());
} else {
PsiClass[] interfaces = subclass.getInterfaces();
GrReferenceList sourceRefList = subclass.isInterface() ? ((GrTypeDefinition) subclass).getExtendsClause() : ((GrTypeDefinition) subclass).getImplementsClause();
for (PsiClass anInterface : interfaces) {
if (anInterface instanceof GrTypeDefinition && filter.includeMember((GrMember) anInterface)) {
result.add(new GrMemberInfo((GrMember) anInterface, true, sourceRefList));
}
}
}
PsiClass[] innerClasses = subclass.getInnerClasses();
for (PsiClass innerClass : innerClasses) {
if (innerClass instanceof GrTypeDefinition && filter.includeMember((GrMember) innerClass)) {
result.add(new GrMemberInfo((GrMember) innerClass));
}
}
GrMethod[] methods = ((GrTypeDefinition) subclass).getCodeMethods();
for (GrMethod method : methods) {
if (!method.isConstructor() && filter.includeMember(method)) {
result.add(new GrMemberInfo(method));
}
}
GrField[] fields = ((GrTypeDefinition) subclass).getCodeFields();
for (final GrField field : fields) {
if (filter.includeMember(field)) {
result.add(new GrMemberInfo(field));
}
}
}
Aggregations