Search in sources :

Example 1 with GrExtendsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause 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 GrExtendsClause

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

the class GroovyTestGenerator method addSuperClass.

private static void addSuperClass(@NotNull GrTypeDefinition targetClass, @NotNull Project project, @Nullable String superClassName) throws IncorrectOperationException {
    if (superClassName == null)
        return;
    GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
    PsiClass superClass = findClass(project, superClassName);
    GrCodeReferenceElement superClassRef;
    if (superClass != null) {
        superClassRef = factory.createCodeReferenceElementFromClass(superClass);
    } else {
        superClassRef = factory.createCodeReferenceElementFromText(superClassName);
    }
    GrExtendsClause extendsClause = targetClass.getExtendsClause();
    if (extendsClause == null) {
        extendsClause = (GrExtendsClause) targetClass.addAfter(factory.createExtendsClause(), targetClass.getNameIdentifierGroovy());
    }
    extendsClause.add(superClassRef);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrExtendsClause(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)

Example 3 with GrExtendsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause 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 4 with GrExtendsClause

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause 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)

Aggregations

GrExtendsClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause)4 GrImplementsClause (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause)3 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)2 TextRange (com.intellij.openapi.util.TextRange)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)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 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1