Search in sources :

Example 1 with GrImplementsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause in project intellij-community by JetBrains.

the class GrMemberInfoStorage method buildSubClassesMap.

@Override
protected void buildSubClassesMap(PsiClass aClass) {
    if (aClass instanceof GrTypeDefinition) {
        final GrExtendsClause extendsList = ((GrTypeDefinition) aClass).getExtendsClause();
        if (extendsList != null) {
            buildSubClassesMapForList(extendsList.getReferencedTypes(), (GrTypeDefinition) aClass);
        }
        final GrImplementsClause implementsList = ((GrTypeDefinition) aClass).getImplementsClause();
        if (implementsList != null) {
            buildSubClassesMapForList(implementsList.getReferencedTypes(), (GrTypeDefinition) aClass);
        }
    }
}
Also used : GrExtendsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrImplementsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause)

Example 2 with GrImplementsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause in project intellij-community by JetBrains.

the class GrHighlightUtil method getClassHeaderTextRange.

public static TextRange getClassHeaderTextRange(GrTypeDefinition clazz) {
    final GrModifierList modifierList = clazz.getModifierList();
    final int startOffset = modifierList != null ? modifierList.getTextOffset() : clazz.getTextOffset();
    final GrImplementsClause implementsClause = clazz.getImplementsClause();
    final int endOffset;
    if (implementsClause != null) {
        endOffset = implementsClause.getTextRange().getEndOffset();
    } else {
        final GrExtendsClause extendsClause = clazz.getExtendsClause();
        if (extendsClause != null) {
            endOffset = extendsClause.getTextRange().getEndOffset();
        } else {
            endOffset = clazz.getNameIdentifierGroovy().getTextRange().getEndOffset();
        }
    }
    return new TextRange(startOffset, endOffset);
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrExtendsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause) GrImplementsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with GrImplementsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause in project intellij-community by JetBrains.

the class GrPullUpHelper method addClassToSupers.

private void addClassToSupers(MemberInfo info, PsiClass aClass, PsiSubstitutor substitutor, GrTypeDefinition targetSuperClass) {
    final PsiReferenceList sourceReferenceList = info.getSourceReferenceList();
    LOG.assertTrue(sourceReferenceList != null);
    PsiQualifiedReferenceElement ref = mySourceClass.equals(sourceReferenceList.getParent()) ? removeFromReferenceList(sourceReferenceList, aClass) : findReferenceToClass(sourceReferenceList, aClass);
    if (ref != null && !targetSuperClass.isInheritor(aClass, false)) {
        GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
        replaceMovedMemberTypeParameters(ref, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
        GrReferenceList referenceList;
        if (targetSuperClass.isInterface()) {
            referenceList = targetSuperClass.getExtendsClause();
            if (referenceList == null) {
                GrExtendsClause newClause = GroovyPsiElementFactory.getInstance(myProject).createExtendsClause();
                PsiElement anchor = targetSuperClass.getTypeParameterList() != null ? targetSuperClass.getTypeParameterList() : targetSuperClass.getNameIdentifierGroovy();
                referenceList = (GrReferenceList) targetSuperClass.addAfter(newClause, anchor);
                addSpacesAround(referenceList);
            }
        } else {
            referenceList = targetSuperClass.getImplementsClause();
            if (referenceList == null) {
                GrImplementsClause newClause = GroovyPsiElementFactory.getInstance(myProject).createImplementsClause();
                PsiElement anchor = targetSuperClass.getExtendsClause() != null ? targetSuperClass.getExtendsClause() : targetSuperClass.getTypeParameterList() != null ? targetSuperClass.getTypeParameterList() : targetSuperClass.getNameIdentifierGroovy();
                referenceList = (GrReferenceList) targetSuperClass.addAfter(newClause, anchor);
                addSpacesAround(referenceList);
            }
        }
        assert referenceList != null;
        referenceList.add(ref);
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrExtendsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause) GrImplementsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 4 with GrImplementsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause in project intellij-community by JetBrains.

the class GrTypeDefinitionRangeHandler method getDeclarationRange.

@NotNull
@Override
public TextRange getDeclarationRange(@NotNull GrTypeDefinition aClass) {
    if (aClass instanceof GrAnonymousClassDefinition) {
        GrNewExpression call = (GrNewExpression) aClass.getParent();
        int startOffset = call.getTextRange().getStartOffset();
        int endOffset = call.getArgumentList().getTextRange().getEndOffset();
        return new TextRange(startOffset, endOffset);
    } else {
        final PsiModifierList modifierList = aClass.getModifierList();
        int startOffset = modifierList == null ? aClass.getTextRange().getStartOffset() : modifierList.getTextRange().getStartOffset();
        final GrImplementsClause implementsList = aClass.getImplementsClause();
        int endOffset = implementsList == null ? aClass.getTextRange().getEndOffset() : implementsList.getTextRange().getEndOffset();
        return new TextRange(startOffset, endOffset);
    }
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrImplementsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause) GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) TextRange(com.intellij.openapi.util.TextRange) PsiModifierList(com.intellij.psi.PsiModifierList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrImplementsClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause)4 GrExtendsClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause)3 TextRange (com.intellij.openapi.util.TextRange)2 PsiModifierList (com.intellij.psi.PsiModifierList)1 NotNull (org.jetbrains.annotations.NotNull)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)1 GrNewExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression)1 GrAnonymousClassDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition)1 GrReferenceList (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1