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));
}
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"));
}
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());
}
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);
}
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;
}
Aggregations