Search in sources :

Example 21 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class UpdateGroovyCopyrightsProvider method createInstance.

@Override
public UpdateCopyright createInstance(Project project, Module module, VirtualFile file, FileType base, CopyrightProfile options) {
    return new UpdateJavaFileCopyright(project, module, file, options) {

        @Override
        protected boolean accept() {
            return getFile() instanceof GroovyFile;
        }

        @Override
        protected PsiElement[] getImportsList() {
            return ((GroovyFile) getFile()).getImportStatements();
        }

        @Override
        protected PsiElement getPackageStatement() {
            return ((GroovyFile) getFile()).getPackageDefinition();
        }

        @Override
        protected void checkCommentsForTopClass(PsiClass topclass, int location, List<PsiComment> comments) {
            if (!(topclass instanceof GroovyScriptClass)) {
                super.checkCommentsForTopClass(topclass, location, comments);
                return;
            }
            final GroovyFile containingFile = (GroovyFile) topclass.getContainingFile();
            PsiElement last = containingFile.getFirstChild();
            while (last != null && !(last instanceof GrStatement)) {
                last = last.getNextSibling();
            }
            checkComments(last, location == JavaOptions.LOCATION_BEFORE_CLASS, comments);
        }
    };
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) UpdateJavaFileCopyright(com.maddyhome.idea.copyright.psi.UpdateJavaFileCopyright) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 22 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class GrIntroduceFieldProcessor method createField.

@NotNull
private GrVariableDeclaration createField(@NotNull PsiClass targetClass) {
    final String name = mySettings.getName();
    final PsiType type = mySettings.getSelectedType();
    final String modifier = mySettings.getVisibilityModifier();
    List<String> modifiers = new ArrayList<>();
    if (targetClass instanceof GroovyScriptClass) {
        modifiers.add("@" + GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD);
    }
    if (mySettings.isStatic())
        modifiers.add(PsiModifier.STATIC);
    if (!PsiModifier.PACKAGE_LOCAL.equals(modifier))
        modifiers.add(modifier);
    if (mySettings.declareFinal())
        modifiers.add(PsiModifier.FINAL);
    final String[] arr_modifiers = ArrayUtil.toStringArray(modifiers);
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject());
    if (targetClass instanceof GroovyScriptClass) {
        return factory.createVariableDeclaration(arr_modifiers, ((GrExpression) null), type, name);
    } else {
        return factory.createFieldDeclaration(arr_modifiers, name, null, type);
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) ArrayList(java.util.ArrayList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class GrIntroduceFieldProcessor method generateConstructor.

@NotNull
private PsiMethod generateConstructor(@NotNull PsiClass scope) {
    final String name = scope.getName();
    LOG.assertTrue(name != null, scope.getText());
    GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject());
    final GrMethod constructor = factory.createConstructorFromText(name, ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, "{}", scope);
    if (scope instanceof GroovyScriptClass)
        constructor.getModifierList().setModifierProperty(GrModifier.DEF, true);
    return (PsiMethod) scope.add(constructor);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class GrIntroduceHandlerBase method collectVariableUsages.

public static PsiElement[] collectVariableUsages(GrVariable variable, PsiElement scope) {
    final List<PsiElement> list = Collections.synchronizedList(new ArrayList<PsiElement>());
    if (scope instanceof GroovyScriptClass) {
        scope = scope.getContainingFile();
    }
    ReferencesSearch.search(variable, new LocalSearchScope(scope)).forEach(psiReference -> {
        final PsiElement element = psiReference.getElement();
        if (element != null) {
            list.add(element);
        }
        return true;
    });
    return list.toArray(new PsiElement[list.size()]);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 25 with GroovyScriptClass

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.

the class StubGenerator method collectMethods.

@Override
public Collection<PsiMethod> collectMethods(PsiClass typeDefinition) {
    List<PsiMethod> methods = new ArrayList<>();
    for (PsiMethod method : typeDefinition.getMethods()) {
        if (method instanceof DelegatedMethod) {
            PsiMethod prototype = ((DelegatedMethod) method).getPrototype();
            PsiClass aClass = prototype.getContainingClass();
            if (prototype.hasModifierProperty(PsiModifier.FINAL) && aClass != null && typeDefinition.isInheritor(aClass, true)) {
                //skip final super methods
                continue;
            }
        }
        methods.add(method);
    }
    boolean isClass = !typeDefinition.isInterface() && !typeDefinition.isAnnotationType() && !typeDefinition.isEnum() && !(typeDefinition instanceof GroovyScriptClass);
    if (isClass) {
        final Collection<MethodSignature> toOverride = OverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition);
        for (MethodSignature signature : toOverride) {
            if (!(signature instanceof MethodSignatureBackedByPsiMethod))
                continue;
            final PsiMethod method = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
            final PsiClass baseClass = method.getContainingClass();
            if (baseClass == null)
                continue;
            final String qname = baseClass.getQualifiedName();
            if (GroovyCommonClassNames.GROOVY_OBJECT.equals(qname) || GroovyCommonClassNames.GROOVY_OBJECT_SUPPORT.equals(qname) || method.hasModifierProperty(PsiModifier.ABSTRACT) && typeDefinition.isInheritor(baseClass, true)) {
                if (method.isConstructor())
                    continue;
                methods.add(mirrorMethod(typeDefinition, method, baseClass, signature.getSubstitutor()));
            }
        }
        final Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition);
        for (MethodSignature signature : toImplement) {
            if (!(signature instanceof MethodSignatureBackedByPsiMethod))
                continue;
            final PsiMethod resolved = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
            final PsiClass baseClass = resolved.getContainingClass();
            if (baseClass == null)
                continue;
            if (!GroovyCommonClassNames.GROOVY_OBJECT.equals(baseClass.getQualifiedName()))
                continue;
            methods.add(mirrorMethod(typeDefinition, resolved, baseClass, signature.getSubstitutor()));
        }
    }
    return methods;
}
Also used : DelegatedMethod(org.jetbrains.plugins.groovy.lang.resolve.ast.DelegatedMethod) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) MethodSignature(com.intellij.psi.util.MethodSignature) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod)

Aggregations

GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)26 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)6 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)4 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)3 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)3 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)3 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)3 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)3 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)3 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)3 PsiClass (com.intellij.psi.PsiClass)2 LightMethodBuilder (com.intellij.psi.impl.light.LightMethodBuilder)2 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)2 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrPackageDefinition (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition)2 Template (com.intellij.codeInsight.template.Template)1 TemplateManager (com.intellij.codeInsight.template.TemplateManager)1