Search in sources :

Example 1 with GroovyFileImpl

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

the class ClosureGenerator method generateClosureMethod.

@NotNull
private GrMethod generateClosureMethod(@NotNull GrClosableBlock block) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(context.project);
    final GrMethod method = factory.createMethodFromText("def doCall(){}", block);
    GrReferenceAdjuster.shortenAllReferencesIn(method.setReturnType(context.typeProvider.getReturnType(block)));
    if (block.hasParametersSection()) {
        method.getParameterList().replace(block.getParameterList());
    } else {
        final GrParameter[] allParameters = block.getAllParameters();
        LOG.assertTrue(allParameters.length == 1);
        final GrParameter itParameter = allParameters[0];
        final GrParameter parameter = factory.createParameter("it", itParameter.getType().getCanonicalText(), "null", block);
        method.getParameterList().add(parameter);
    }
    ((GroovyFileImpl) method.getContainingFile()).setContextNullable(null);
    return method;
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyFileImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GroovyFileImpl

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

the class GroovyShellRunnerImpl method createConsoleView.

@Override
protected LanguageConsoleView createConsoleView() {
    final LanguageConsoleView res = new GroovyShellLanguageConsoleView(getProject(), getConsoleTitle());
    final GroovyFileImpl file = (GroovyFileImpl) res.getFile();
    assert file.getContext() == null;
    file.putUserData(GROOVY_SHELL_FILE, Boolean.TRUE);
    file.setContext(myShellRunner.getContext(myModule));
    return res;
}
Also used : LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) GroovyFileImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl)

Example 3 with GroovyFileImpl

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

the class GrTypeDefinitionImpl method delete.

@Override
public void delete() throws IncorrectOperationException {
    PsiElement parent = getParent();
    if (parent instanceof GroovyFileImpl) {
        GroovyFileImpl file = (GroovyFileImpl) parent;
        if (file.getTypeDefinitions().length == 1 && !file.isScript()) {
            file.delete();
            return;
        }
    }
    super.delete();
}
Also used : GroovyFileImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 4 with GroovyFileImpl

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

the class GrAssignmentExpressionImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (!ResolveUtil.shouldProcessProperties(classHint))
        return true;
    final DynamicMembersHint dynamicMembersHint = processor.getHint(DynamicMembersHint.KEY);
    if (dynamicMembersHint != null && !dynamicMembersHint.shouldProcessProperties())
        return true;
    if (!(getParent() instanceof GroovyFileImpl))
        return true;
    final GroovyFileImpl file = (GroovyFileImpl) getParent();
    if (!file.isInScriptBody(lastParent, place))
        return true;
    final GrExpression lValue = getLValue();
    if (!processLValue(processor, state, place, file, lValue))
        return false;
    if (lValue instanceof GrTupleExpression) {
        for (GrExpression expression : ((GrTupleExpression) lValue).getExpressions()) {
            if (!processLValue(processor, state, place, file, expression))
                return false;
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) GroovyFileImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl) DynamicMembersHint(org.jetbrains.plugins.groovy.lang.resolve.processors.DynamicMembersHint)

Aggregations

GroovyFileImpl (org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl)4 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 ElementClassHint (com.intellij.psi.scope.ElementClassHint)1 NotNull (org.jetbrains.annotations.NotNull)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1 DynamicMembersHint (org.jetbrains.plugins.groovy.lang.resolve.processors.DynamicMembersHint)1