use of org.eclipse.jdt.core.dom.Block in project che by eclipse.
the class ChangeSignatureProcessor method containsImplicitCallToSuperConstructor.
private static boolean containsImplicitCallToSuperConstructor(MethodDeclaration constructor) {
Assert.isTrue(constructor.isConstructor());
Block body = constructor.getBody();
if (body == null)
return false;
if (body.statements().size() == 0)
return true;
if (body.statements().get(0) instanceof ConstructorInvocation)
return false;
if (body.statements().get(0) instanceof SuperConstructorInvocation)
return false;
return true;
}
use of org.eclipse.jdt.core.dom.Block in project che by eclipse.
the class ChangeSignatureProcessor method addNewConstructorToSubclass.
private void addNewConstructorToSubclass(AbstractTypeDeclaration subclass, CompilationUnitRewrite cuRewrite) {
AST ast = subclass.getAST();
MethodDeclaration newConstructor = ast.newMethodDeclaration();
newConstructor.setName(ast.newSimpleName(subclass.getName().getIdentifier()));
newConstructor.setConstructor(true);
newConstructor.setJavadoc(null);
newConstructor.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getAccessModifier(subclass)));
newConstructor.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));
Block body = ast.newBlock();
newConstructor.setBody(body);
SuperConstructorInvocation superCall = ast.newSuperConstructorInvocation();
addArgumentsToNewSuperConstructorCall(superCall, cuRewrite);
body.statements().add(superCall);
String msg = RefactoringCoreMessages.ChangeSignatureRefactoring_add_constructor;
TextEditGroup description = cuRewrite.createGroupDescription(msg);
cuRewrite.getASTRewrite().getListRewrite(subclass, subclass.getBodyDeclarationsProperty()).insertFirst(newConstructor, description);
// TODO use AbstractTypeDeclaration
}
use of org.eclipse.jdt.core.dom.Block in project che by eclipse.
the class SelfEncapsulateFieldRefactoring method createSetterMethod.
private MethodDeclaration createSetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
FieldDeclaration field = (FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
Type type = field.getType();
MethodDeclaration result = ast.newMethodDeclaration();
result.setName(ast.newSimpleName(fSetterName));
result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
if (fSetterMustReturnValue) {
result.setReturnType2((Type) rewriter.createCopyTarget(type));
}
SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
result.parameters().add(param);
param.setName(ast.newSimpleName(fArgName));
param.setType((Type) rewriter.createCopyTarget(type));
List<Dimension> extraDimensions = DimensionRewrite.copyDimensions(fFieldDeclaration.extraDimensions(), rewriter);
param.extraDimensions().addAll(extraDimensions);
Block block = ast.newBlock();
result.setBody(block);
String fieldAccess = createFieldAccess();
String body = CodeGeneration.getSetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fieldAccess, fArgName, lineDelimiter);
if (body != null) {
ASTNode setterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
block.statements().add(setterNode);
} else {
Assignment ass = ast.newAssignment();
ass.setLeftHandSide((Expression) rewriter.createStringPlaceholder(fieldAccess, ASTNode.QUALIFIED_NAME));
ass.setRightHandSide(ast.newSimpleName(fArgName));
block.statements().add(ass);
}
if (fSetterMustReturnValue) {
ReturnStatement rs = ast.newReturnStatement();
rs.setExpression(ast.newSimpleName(fArgName));
block.statements().add(rs);
}
if (fGenerateJavadoc) {
String string = CodeGeneration.getSetterComment(fField.getCompilationUnit(), getTypeName(field.getParent()), fSetterName, fField.getElementName(), ASTNodes.asString(type), fArgName, StubUtility.getBaseName(fField), lineDelimiter);
if (string != null) {
Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
result.setJavadoc(javadoc);
}
}
return result;
}
use of org.eclipse.jdt.core.dom.Block in project processing by processing.
the class CompletionGenerator method findClosestNode.
protected static ASTNode findClosestNode(int lineNumber, ASTNode node) {
log("findClosestNode to line " + lineNumber);
ASTNode parent = findClosestParentNode(lineNumber, node);
log("findClosestParentNode returned " + getNodeAsString(parent));
if (parent == null)
return null;
if (getLineNumber(parent) == lineNumber) {
log(parent + "|PNode " + getLineNumber(parent) + ", lfor " + lineNumber);
return parent;
}
List<ASTNode> nodes;
if (parent instanceof TypeDeclaration) {
nodes = ((TypeDeclaration) parent).bodyDeclarations();
} else if (parent instanceof Block) {
nodes = ((Block) parent).statements();
} else {
log("findClosestNode() found " + getNodeAsString(parent));
return null;
}
if (nodes.size() > 0) {
ASTNode retNode = parent;
for (ASTNode cNode : nodes) {
log(cNode + "|cNode " + getLineNumber(cNode) + ", lfor " + lineNumber);
if (getLineNumber(cNode) <= lineNumber)
retNode = cNode;
}
return retNode;
}
return parent;
}
use of org.eclipse.jdt.core.dom.Block in project AutoRefactor by JnRouvignac.
the class AddBracketsToControlStatementRefactoring method setBlock.
private boolean setBlock(Statement statement) {
if (statement == null) {
return VISIT_SUBTREE;
}
final ASTBuilder b = this.ctx.getASTBuilder();
final Block block = b.block(b.copy(statement));
block.accept(this);
this.ctx.getRefactorings().replace(statement, block);
return DO_NOT_VISIT_SUBTREE;
}
Aggregations