use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock 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.statements.blocks.GrCodeBlock in project intellij-community by JetBrains.
the class GroovyPropertyUtils method generateGetterPrototype.
public static GrMethod generateGetterPrototype(PsiField field) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(field.getProject());
String name = field.getName();
String getName = getGetterNameNonBoolean(field.getName());
try {
PsiType type = field instanceof GrField ? ((GrField) field).getDeclaredType() : field.getType();
GrMethod getter = factory.createMethod(getName, type);
if (field.hasModifierProperty(PsiModifier.STATIC)) {
PsiUtil.setModifierProperty(getter, PsiModifier.STATIC, true);
}
annotateWithNullableStuff(field, getter);
GrCodeBlock body = factory.createMethodBodyFromText("\nreturn " + name + "\n");
getter.getBlock().replace(body);
return getter;
} catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
Aggregations