Search in sources :

Example 11 with GrTypeDefinition

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

the class GroovyScriptRunConfiguration method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    super.checkConfiguration();
    final String scriptPath = getScriptPath();
    final VirtualFile script = ScriptFileUtil.findScriptFileByPath(scriptPath);
    if (script == null)
        throw new RuntimeConfigurationException("Cannot find script " + scriptPath);
    final GroovyScriptRunner scriptRunner = getScriptRunner();
    if (scriptRunner == null)
        throw new RuntimeConfigurationException("Unknown script type " + scriptPath);
    scriptRunner.ensureRunnerConfigured(this);
    final PsiFile file = PsiManager.getInstance(getProject()).findFile(script);
    final PsiClass toRun = GroovyRunnerPsiUtil.getRunningClass(file);
    if (toRun == null) {
        throw new RuntimeConfigurationWarning(GroovyBundle.message("class.does.not.exist"));
    }
    if (toRun instanceof GrTypeDefinition) {
        if (!GroovyRunnerPsiUtil.canBeRunByGroovy(toRun)) {
            throw new RuntimeConfigurationWarning(GroovyBundle.message("class.cannot.be.executed"));
        }
    } else {
        throw new RuntimeConfigurationWarning(GroovyBundle.message("script.file.is.not.groovy.file"));
    }
    JavaParametersUtil.checkAlternativeJRE(this);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile)

Example 12 with GrTypeDefinition

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

the class CompleteReferenceExpression method getBindings.

private void getBindings() {
    final PsiClass containingClass = PsiTreeUtil.getParentOfType(myRefExpr, PsiClass.class);
    if (containingClass != null)
        return;
    final PsiFile file = FileContextUtil.getContextFile(myRefExpr);
    if (file instanceof GroovyFile) {
        ((GroovyFile) file).accept(new GroovyRecursiveElementVisitor() {

            @Override
            public void visitAssignmentExpression(@NotNull GrAssignmentExpression expression) {
                super.visitAssignmentExpression(expression);
                final GrExpression value = expression.getLValue();
                if (value instanceof GrReferenceExpression && !((GrReferenceExpression) value).isQualified()) {
                    final PsiElement resolved = ((GrReferenceExpression) value).resolve();
                    if (resolved instanceof GrBindingVariable) {
                        myProcessor.execute(resolved, ResolveState.initial());
                    } else if (resolved == null) {
                        myProcessor.execute(new GrBindingVariable((GroovyFile) file, ((GrReferenceExpression) value).getReferenceName(), true), ResolveState.initial());
                    }
                }
            }

            @Override
            public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
            //don't go into classes
            }
        });
    }
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) GroovyRecursiveElementVisitor(org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 13 with GrTypeDefinition

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

the class GdslClosureCompleter method getParameterInfos.

@Override
protected List<ClosureParameterInfo> getParameterInfos(InsertionContext context, PsiMethod method, PsiSubstitutor substitutor, PsiElement place) {
    final ArrayList<ClosureDescriptor> descriptors = new ArrayList<>();
    GrReferenceExpression ref = (GrReferenceExpression) place;
    PsiType qtype = PsiImplUtil.getQualifierType(ref);
    if (qtype == null)
        return null;
    GrExpression qualifier = ref.getQualifier();
    if (qualifier != null) {
        PsiType type = qualifier.getType();
        if (type == null)
            return null;
        processExecutors(qtype, ref, descriptors);
    } else {
        PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
        for (PsiElement parent = ref.getParent(); parent != null; parent = parent.getParent()) {
            if (parent instanceof GrClosableBlock) {
                processExecutors(TypesUtil.createTypeByFQClassName(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, ref), ref, descriptors);
            } else if (parent instanceof GrTypeDefinition) {
                processExecutors(factory.createType(((GrTypeDefinition) parent), PsiType.EMPTY_ARRAY), ref, descriptors);
            }
        }
    }
    for (ClosureDescriptor descriptor : descriptors) {
        if (descriptor.isMethodApplicable(method, ref)) {
            return descriptor.getParameters();
        }
    }
    return null;
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ArrayList(java.util.ArrayList) ClosureDescriptor(org.jetbrains.plugins.groovy.lang.completion.closureParameters.ClosureDescriptor) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 14 with GrTypeDefinition

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

the class AbstractFolderNode method createFolderNode.

private AbstractFolderNode createFolderNode(PsiDirectory directory) {
    PsiDirectory realDirectory = directory;
    StringBuilder textBuilder = null;
    if (getSettings().isHideEmptyMiddlePackages()) {
        do {
            if (realDirectory.getFiles().length > 0)
                break;
            PsiDirectory[] subdirectories = realDirectory.getSubdirectories();
            if (subdirectories.length != 1)
                break;
            if (textBuilder == null) {
                textBuilder = new StringBuilder();
                textBuilder.append(realDirectory.getName());
            }
            realDirectory = subdirectories[0];
            textBuilder.append('.').append(realDirectory.getName());
        } while (true);
    }
    String presentableText = textBuilder == null ? directory.getName() : textBuilder.toString();
    return new AbstractFolderNode(getModule(), realDirectory, presentableText, getSettings(), FOLDER) {

        @Override
        protected void processNotDirectoryFile(List<AbstractTreeNode> nodes, PsiFile file) {
            AbstractFolderNode.this.processNotDirectoryFile(nodes, file);
        }

        @Override
        protected AbstractTreeNode createClassNode(GrTypeDefinition typeDefinition) {
            return AbstractFolderNode.this.createClassNode(typeDefinition);
        }
    };
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiDirectory(com.intellij.psi.PsiDirectory) List(java.util.List) PsiFile(com.intellij.psi.PsiFile)

Example 15 with GrTypeDefinition

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

the class GrIntroduceFieldProcessor method insertField.

@NotNull
protected GrVariableDeclaration insertField(@NotNull PsiClass targetClass) {
    GrVariableDeclaration declaration = createField(targetClass);
    if (targetClass instanceof GrEnumTypeDefinition) {
        final GrEnumConstantList enumConstants = ((GrEnumTypeDefinition) targetClass).getEnumConstantList();
        return (GrVariableDeclaration) targetClass.addAfter(declaration, enumConstants);
    }
    if (targetClass instanceof GrTypeDefinition) {
        PsiElement anchor = getAnchorForDeclaration((GrTypeDefinition) targetClass);
        return (GrVariableDeclaration) targetClass.addAfter(declaration, anchor);
    } else {
        assert targetClass instanceof GroovyScriptClass;
        final GroovyFile file = ((GroovyScriptClass) targetClass).getContainingFile();
        PsiElement[] elements = file.getMethods();
        if (elements.length == 0)
            elements = file.getStatements();
        final PsiElement anchor = ArrayUtil.getFirstElement(elements);
        return (GrVariableDeclaration) file.addBefore(declaration, anchor);
    }
}
Also used : GrEnumConstantList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList) GrEnumTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)78 PsiElement (com.intellij.psi.PsiElement)17 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)17 PsiClass (com.intellij.psi.PsiClass)16 NotNull (org.jetbrains.annotations.NotNull)15 Nullable (org.jetbrains.annotations.Nullable)14 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)9 PsiFile (com.intellij.psi.PsiFile)8 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)8 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)8 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 Editor (com.intellij.openapi.editor.Editor)5 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4