use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method setupTraitMethodBody.
private static void setupTraitMethodBody(Project project, GrMethod resultMethod, GrTraitMethod traitMethod) {
PsiClass traitClass = traitMethod.getPrototype().getContainingClass();
StringBuilder builder = new StringBuilder();
builder.append("\nreturn ");
builder.append(traitClass.getQualifiedName());
builder.append(".super.");
builder.append(traitMethod.getName());
builder.append("(");
GrParameter[] parameters = resultMethod.getParameters();
for (GrParameter parameter : parameters) {
builder.append(parameter.getName()).append(",");
}
if (parameters.length > 0) {
builder.replace(builder.length() - 1, builder.length(), ")\n");
} else {
builder.append(")\n");
}
GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile(builder, false, null);
GrOpenBlock block = resultMethod.getBlock();
block.getNode().addChildren(file.getFirstChild().getNode(), null, block.getRBrace().getNode());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method setupOverridingMethodBody.
private static void setupOverridingMethodBody(Project project, PsiMethod method, GrMethod resultMethod, FileTemplate template, PsiSubstitutor substitutor) {
final PsiType returnType = substitutor.substitute(getSuperReturnType(method));
String returnTypeText = "";
if (returnType != null) {
returnTypeText = returnType.getPresentableText();
}
Properties properties = FileTemplateManager.getInstance(project).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnTypeText);
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(method, resultMethod));
JavaTemplateUtil.setClassAndMethodNameProperties(properties, method.getContainingClass(), resultMethod);
try {
String bodyText = StringUtil.replace(template.getText(properties), ";", "");
GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile("\n " + bodyText + "\n", false, null);
GrOpenBlock block = resultMethod.getBlock();
block.getNode().addChildren(file.getFirstChild().getNode(), null, block.getRBrace().getNode());
} catch (IOException e) {
LOG.error(e);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class GrHighlightUtil method getInitializerHeaderTextRange.
public static TextRange getInitializerHeaderTextRange(GrClassInitializer initializer) {
final PsiModifierList modifierList = initializer.getModifierList();
final GrOpenBlock block = initializer.getBlock();
final TextRange textRange = modifierList.getTextRange();
LOG.assertTrue(textRange != null, initializer.getClass() + ":" + initializer.getText());
int startOffset = textRange.getStartOffset();
int endOffset = block.getLBrace().getTextRange().getEndOffset() + 1;
return new TextRange(startOffset, endOffset);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class GrMethodBaseImpl method setBlock.
@Override
public void setBlock(GrCodeBlock newBlock) {
ASTNode newNode = newBlock.getNode().copyElement();
final GrOpenBlock oldBlock = getBlock();
if (oldBlock == null) {
getNode().addChild(newNode);
return;
}
getNode().replaceChild(oldBlock.getNode(), newNode);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock in project intellij-community by JetBrains.
the class ConditionalUtils method stripBraces.
public static GrStatement stripBraces(GrStatement branch) {
if (branch instanceof GrBlockStatement) {
final GrBlockStatement block = (GrBlockStatement) branch;
final GrOpenBlock codeBlock = block.getBlock();
final GrStatement[] statements = codeBlock.getStatements();
if (statements.length == 1) {
return statements[0];
} else {
return block;
}
} else {
return branch;
}
}
Aggregations