Search in sources :

Example 21 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.

the class GradleBuildFileTest method testGetIntegerOrStringAsInteger.

public void testGetIntegerOrStringAsInteger() throws Exception {
    final GradleBuildFile file = getTestFile("android {\n" + "    defaultConfig {\n" + "        targetSdkVersion 5\n" + "    }\n" + "}\n");
    GrStatementOwner closure = file.getClosure("android/defaultConfig");
    assertNotNull(closure);
    assertEquals("5", file.getValue(closure, BuildFileKey.TARGET_SDK_VERSION));
}
Also used : GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)

Example 22 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project intellij-community by JetBrains.

the class GroovyAnnotator method visitTypeDefinitionBody.

@Override
public void visitTypeDefinitionBody(@NotNull GrTypeDefinitionBody typeDefinitionBody) {
    final PsiElement parent = typeDefinitionBody.getParent();
    if (!(parent instanceof GrAnonymousClassDefinition))
        return;
    final PsiElement prev = typeDefinitionBody.getPrevSibling();
    if (!PsiUtil.isLineFeed(prev))
        return;
    final PsiElement newExpression = parent.getParent();
    if (!(newExpression instanceof GrNewExpression))
        return;
    final GrStatementOwner statementOwner = PsiTreeUtil.getParentOfType(newExpression, GrStatementOwner.class);
    final GrParenthesizedExpression parenthesizedExpression = PsiTreeUtil.getParentOfType(newExpression, GrParenthesizedExpression.class);
    if (parenthesizedExpression != null && PsiTreeUtil.isAncestor(statementOwner, parenthesizedExpression, true))
        return;
    final GrArgumentList argumentList = PsiTreeUtil.getParentOfType(newExpression, GrArgumentList.class);
    if (argumentList != null && !(argumentList instanceof GrCommandArgumentList)) {
        if (PsiTreeUtil.isAncestor(statementOwner, argumentList, true))
            return;
    }
    myHolder.createErrorAnnotation(typeDefinitionBody, GroovyBundle.message("ambiguous.code.block"));
}
Also used : GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)

Example 23 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project intellij-community by JetBrains.

the class GrRedundantElseIntention method processIntention.

@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final PsiElement parent = element.getParent();
    if (!(parent instanceof GrIfStatement))
        return;
    final GrIfStatement ifStatement = GroovyRefactoringUtil.addBlockIntoParent((GrIfStatement) parent);
    assert ifStatement.getParent() instanceof GrStatementOwner;
    final PsiElement statementOwner = ifStatement.getParent();
    final GrStatement branch = ifStatement.getElseBranch();
    if (branch == null)
        return;
    final PsiElement pos;
    if (branch instanceof GrBlockStatement) {
        final GrOpenBlock block = ((GrBlockStatement) branch).getBlock();
        final PsiElement first = inferFirst(block.getLBrace());
        final PsiElement last = inferLast(block.getRBrace());
        pos = statementOwner.addRangeAfter(first, last, ifStatement);
    } else {
        pos = statementOwner.addAfter(branch, ifStatement);
    }
    branch.delete();
    editor.getCaretModel().moveToOffset(pos.getTextRange().getStartOffset());
}
Also used : GrIfStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) GrBlockStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)

Example 24 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project intellij-community by JetBrains.

the class InvertIfIntention method generateElseBranchTextAndRemoveTailStatements.

private static void generateElseBranchTextAndRemoveTailStatements(@NotNull GrIfStatement ifStatement, @NotNull GrIfStatement newIf) {
    final GrStatement thenBranch = newIf.getThenBranch();
    assert thenBranch != null;
    GrStatement elseBranch = ifStatement.getElseBranch();
    if (elseBranch != null) {
        thenBranch.replaceWithStatement(elseBranch);
        return;
    }
    PsiElement parent = ifStatement.getParent();
    if (!(parent instanceof GrStatementOwner))
        return;
    if (!isTailAfterIf(ifStatement, ((GrStatementOwner) parent)))
        return;
    final PsiElement start = ifStatement.getNextSibling();
    PsiElement end = parent instanceof GrCodeBlock ? ((GrCodeBlock) parent).getRBrace().getPrevSibling() : parent.getLastChild();
    final GrOpenBlock block = ((GrBlockStatement) thenBranch).getBlock();
    block.addRangeAfter(start, end, block.getLBrace());
    parent.deleteChildRange(start, end);
}
Also used : GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) GrOpenBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock) GrBlockStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement) PsiElement(com.intellij.psi.PsiElement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) GrCodeBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock)

Example 25 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project intellij-community by JetBrains.

the class ResolveUtil method processCategoryMembers.

public static boolean processCategoryMembers(@NotNull PsiElement place, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
    boolean inCodeBlock = true;
    PsiElement run = place;
    PsiElement lastParent = null;
    while (run != null) {
        ProgressManager.checkCanceled();
        if (run instanceof GrMember) {
            inCodeBlock = false;
        }
        if (run instanceof GrClosableBlock) {
            if (inCodeBlock) {
                if (!GdkMethodUtil.categoryIteration((GrClosableBlock) run, processor, state))
                    return false;
            }
            PsiClass superClass = getLiteralSuperClass((GrClosableBlock) run);
            if (superClass != null && !GdkMethodUtil.processCategoryMethods(run, processor, state, superClass))
                return false;
        }
        if (run instanceof GrStatementOwner) {
            if (!GdkMethodUtil.processMixinToMetaclass((GrStatementOwner) run, processor, state, lastParent, place))
                return false;
        }
        lastParent = run;
        run = run.getContext();
    }
    return true;
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Aggregations

GrStatementOwner (org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)38 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)11 PsiElement (com.intellij.psi.PsiElement)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 List (java.util.List)4 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)4 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 ImmutableList (com.google.common.collect.ImmutableList)3 GrControlStatement (org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement)3 GrBlockStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement)3 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)2 NamedObject (com.android.tools.idea.gradle.parser.NamedObject)2 ValueFactory (com.android.tools.idea.gradle.parser.ValueFactory)2 ASTNode (com.intellij.lang.ASTNode)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 IElementType (com.intellij.psi.tree.IElementType)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 NotNull (org.jetbrains.annotations.NotNull)2