use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class GroovySynchronizedUnwrapper method doUnwrap.
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
GrOpenBlock body = ((GrSynchronizedStatement) element).getBody();
context.extractFromCodeBlock(body, element);
context.delete(element);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class ControlFlowUtils method isInFinallyBlock.
public static boolean isInFinallyBlock(@NotNull GroovyPsiElement element) {
final GrFinallyClause containingClause = PsiTreeUtil.getParentOfType(element, GrFinallyClause.class);
if (containingClause == null) {
return false;
}
final GrOpenBlock body = containingClause.getBody();
return PsiTreeUtil.isAncestor(body, element, true);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class EquivalenceChecker method tryStatementsAreEquivalent.
private static boolean tryStatementsAreEquivalent(@NotNull GrTryCatchStatement statement1, @NotNull GrTryCatchStatement statement2) {
final GrOpenBlock tryBlock1 = statement1.getTryBlock();
final GrOpenBlock tryBlock2 = statement2.getTryBlock();
if (!openBlocksAreEquivalent(tryBlock1, tryBlock2)) {
return false;
}
final GrFinallyClause finallyBlock1 = statement1.getFinallyClause();
final GrFinallyClause finallyBlock2 = statement2.getFinallyClause();
if (finallyBlock1 != null) {
if (finallyBlock2 == null || !openBlocksAreEquivalent(finallyBlock1.getBody(), finallyBlock2.getBody())) {
return false;
}
} else if (finallyBlock2 != null) {
return false;
}
final GrCatchClause[] catchBlocks1 = statement1.getCatchClauses();
final GrCatchClause[] catchBlocks2 = statement2.getCatchClauses();
if (catchBlocks1.length != catchBlocks2.length) {
return false;
}
for (int i = 0; i < catchBlocks2.length; i++) {
if (!catchClausesAreEquivalent(catchBlocks1[i], catchBlocks2[i])) {
return false;
}
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class PsiImplUtil method getChainingConstructorInvocation.
@Nullable
public static GrConstructorInvocation getChainingConstructorInvocation(GrMethod constructor) {
if (constructor instanceof GrReflectedMethod && ((GrReflectedMethod) constructor).getSkippedParameters().length > 0)
return null;
LOG.assertTrue(constructor.isConstructor());
GrOpenBlock body = constructor.getBlock();
if (body == null)
return null;
GrStatement[] statements = body.getStatements();
if (statements.length > 0 && statements[0] instanceof GrConstructorInvocation) {
return (GrConstructorInvocation) statements[0];
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class ConvertMethodToClosureIntention method execute.
private static void execute(final GrMethod method, final Collection<GrReferenceExpression> usagesToConvert) {
ApplicationManager.getApplication().runWriteAction(() -> {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(method.getProject());
StringBuilder builder = new StringBuilder(method.getTextLength());
String modifiers = method.getModifierList().getText();
if (modifiers.trim().isEmpty()) {
modifiers = GrModifier.DEF;
}
builder.append(modifiers).append(' ');
builder.append(method.getName()).append("={");
builder.append(method.getParameterList().getText()).append(" ->");
final GrOpenBlock block = method.getBlock();
builder.append(block.getText().substring(1));
final GrVariableDeclaration variableDeclaration = GroovyPsiElementFactory.getInstance(method.getProject()).createFieldDeclarationFromText(builder.toString());
method.replace(variableDeclaration);
for (GrReferenceExpression element : usagesToConvert) {
final PsiElement qualifier = element.getQualifier();
final StringBuilder text = new StringBuilder(qualifier.getText());
element.setQualifier(null);
text.append('.').append(element.getText());
element.replace(factory.createExpressionFromText(text.toString()));
}
});
}
Aggregations