use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ControlFlowUtils method openBlockCompletesWithStatement.
public static boolean openBlockCompletesWithStatement(@NotNull GrCodeBlock body, @NotNull GrStatement statement) {
GroovyPsiElement elementToCheck = statement;
while (true) {
if (elementToCheck == null)
return false;
final GroovyPsiElement container = PsiTreeUtil.getParentOfType(elementToCheck, GrStatement.class, GrCodeBlock.class, GrCaseSection.class);
if (container == null)
return false;
if (isLoop(container))
return false;
if (container instanceof GrCaseSection) {
final GrSwitchStatement switchStatement = (GrSwitchStatement) container.getParent();
final GrCaseSection[] sections = switchStatement.getCaseSections();
if (container == sections[sections.length - 1])
return false;
}
if (container instanceof GrCodeBlock) {
if (elementToCheck instanceof GrStatement) {
final GrCodeBlock codeBlock = (GrCodeBlock) container;
if (!statementIsLastInBlock(codeBlock, (GrStatement) elementToCheck)) {
return false;
}
}
if (container instanceof GrOpenBlock || container instanceof GrClosableBlock) {
if (container.equals(body)) {
return true;
}
elementToCheck = PsiTreeUtil.getParentOfType(container, GrStatement.class);
} else {
elementToCheck = container;
}
} else {
elementToCheck = container;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ControlFlowUtils method blockCompletesWithStatement.
public static boolean blockCompletesWithStatement(@NotNull GrBlockStatement body, @NotNull GrStatement statement) {
GrStatement statementToCheck = statement;
while (true) {
if (statementToCheck == null) {
return false;
}
final PsiElement container = statementToCheck.getParent();
if (container == null) {
return false;
}
if (container instanceof GrLoopStatement) {
return false;
} else if (container instanceof GrCaseSection) {
final GrCaseSection caseSection = (GrCaseSection) container;
if (!statementIsLastInBlock(caseSection, statementToCheck))
return false;
final PsiElement parent = container.getParent();
assert parent instanceof GrSwitchStatement;
final GrSwitchStatement switchStatement = (GrSwitchStatement) parent;
final GrCaseSection[] sections = switchStatement.getCaseSections();
if (ArrayUtil.getLastElement(sections) != caseSection) {
return false;
}
} else if (container instanceof GrOpenBlock) {
final GrOpenBlock block = (GrOpenBlock) container;
if (!statementIsLastInBlock(block, statementToCheck))
return false;
final PsiElement parent = block.getParent();
if (parent instanceof GrBlockStatement) {
final GrBlockStatement blockStatement = (GrBlockStatement) parent;
if (blockStatement == body)
return true;
}
} else if (container instanceof GrClosableBlock) {
return false;
}
statementToCheck = getContainingStatement(statementToCheck);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyDslDefaultMembers method enclosingCall.
/**
* Returns enclosing method call of a given context's place
*/
@Nullable
public GrCall enclosingCall(String name, GdslMembersHolderConsumer consumer) {
final PsiElement place = consumer.getPlace();
if (place == null)
return null;
GrCall call = PsiTreeUtil.getParentOfType(place, GrCall.class, true);
if (call == null)
return null;
while (call != null && !name.equals(getInvokedMethodName(call))) {
call = PsiTreeUtil.getParentOfType(call, GrCall.class, true);
}
if (call == null)
return null;
final GrArgumentList argumentList = call.getArgumentList();
if (argumentList != null) {
for (GrExpression arg : argumentList.getExpressionArguments()) {
if (arg instanceof GrClosableBlock && PsiTreeUtil.findCommonParent(place, arg) == arg) {
return call;
}
}
}
if (call instanceof GrMethodCallExpression) {
for (GrExpression arg : call.getClosureArguments()) {
if (arg instanceof GrClosableBlock && PsiTreeUtil.findCommonParent(place, arg) == arg) {
return call;
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GebPageMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
if (!ResolveUtil.shouldProcessProperties(processor.getHint(ElementClassHint.KEY)))
return;
PsiElement grCall = place.getParent();
if (grCall instanceof GrMethodCall) {
PsiElement grClosure = grCall.getParent();
if (grClosure instanceof GrClosableBlock) {
PsiElement contentField = grClosure.getParent();
if (contentField instanceof GrField) {
GrField f = (GrField) contentField;
if ("content".equals(f.getName()) && f.hasModifierProperty(PsiModifier.STATIC) && f.getContainingClass() == aClass) {
Map<String, PsiField> elements = GebUtil.getContentElements(aClass);
for (PsiField field : elements.values()) {
if (field.getNavigationElement() == place) {
// Don't resolve variable definition.
return;
}
}
}
}
}
}
processPageFields(processor, aClass, state);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GrReassignedLocalVarsChecker method getUsedVarsInsideBlock.
@NotNull
private static Set<String> getUsedVarsInsideBlock(@NotNull final GrCodeBlock block) {
return CachedValuesManager.getCachedValue(block, () -> {
final Set<String> result = ContainerUtil.newHashSet();
block.acceptChildren(new GroovyRecursiveElementVisitor() {
@Override
public void visitOpenBlock(@NotNull GrOpenBlock openBlock) {
result.addAll(getUsedVarsInsideBlock(openBlock));
}
@Override
public void visitClosure(@NotNull GrClosableBlock closure) {
result.addAll(getUsedVarsInsideBlock(closure));
}
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
if (referenceExpression.getQualifier() == null && referenceExpression.getReferenceName() != null) {
result.add(referenceExpression.getReferenceName());
}
}
});
return CachedValueProvider.Result.create(result, block);
});
}
Aggregations