use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class ReturnTypeSubProcessor method addMethodRetunsVoidProposals.
public static void addMethodRetunsVoidProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws JavaModelException {
CompilationUnit astRoot = context.getASTRoot();
ASTNode selectedNode = problem.getCoveringNode(astRoot);
if (!(selectedNode instanceof ReturnStatement)) {
return;
}
ReturnStatement returnStatement = (ReturnStatement) selectedNode;
Expression expression = returnStatement.getExpression();
if (expression == null) {
return;
}
BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(selectedNode);
if (decl instanceof MethodDeclaration) {
MethodDeclaration methDecl = (MethodDeclaration) decl;
Type retType = methDecl.getReturnType2();
if (retType == null || retType.resolveBinding() == null) {
return;
}
TypeMismatchSubProcessor.addChangeSenderTypeProposals(context, expression, retType.resolveBinding(), false, IProposalRelevance.METHOD_RETURNS_VOID, proposals);
}
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class ChangeSignatureProcessor method getAllConstructors.
private MethodDeclaration[] getAllConstructors(AbstractTypeDeclaration typeDeclaration) {
BodyDeclaration decl;
List<BodyDeclaration> result = new ArrayList<BodyDeclaration>(1);
for (Iterator<BodyDeclaration> it = typeDeclaration.bodyDeclarations().listIterator(); it.hasNext(); ) {
decl = it.next();
if (decl instanceof MethodDeclaration && ((MethodDeclaration) decl).isConstructor())
result.add(decl);
}
return result.toArray(new MethodDeclaration[result.size()]);
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project che by eclipse.
the class SurroundWithTryCatchAnalyzer method endVisit.
@Override
public void endVisit(CompilationUnit node) {
BodyDeclaration enclosingNode = null;
if (!getStatus().hasFatalError() && hasSelectedNodes())
enclosingNode = (BodyDeclaration) ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
super.endVisit(node);
if (enclosingNode != null && !getStatus().hasFatalError()) {
fExceptions = ExceptionAnalyzer.perform(enclosingNode, getSelection());
if (fExceptions == null || fExceptions.length == 0) {
//$NON-NLS-1$
fExceptions = new ITypeBinding[] { node.getAST().resolveWellKnownType("java.lang.Exception") };
}
}
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project AutoRefactor by JnRouvignac.
the class RemoveSemiColonRefactoring method visit.
private boolean visit(BodyDeclaration node) {
final BodyDeclaration nextSibling = getNextSibling(node);
final ASTNode parent = node.getParent();
if (nextSibling != null) {
return removeSuperfluousSemiColons(node, getEndPosition(node), nextSibling.getStartPosition());
} else if (parent instanceof AbstractTypeDeclaration) {
final AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) parent;
return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(typeDecl) - 1);
} else if (parent instanceof AnonymousClassDeclaration) {
final AnonymousClassDeclaration classDecl = (AnonymousClassDeclaration) parent;
return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(classDecl) - 1);
} else if (parent instanceof CompilationUnit) {
final CompilationUnit cu = (CompilationUnit) parent;
return removeSuperfluousSemiColons(node, getEndPosition(node), getEndPosition(cu) - 1);
} else if (parent instanceof TypeDeclarationStatement) {
return VISIT_SUBTREE;
}
throw new NotImplementedException(node, "for a parent of type " + (parent != null ? parent.getClass().getSimpleName() : null));
}
use of org.eclipse.jdt.core.dom.BodyDeclaration in project AutoRefactor by JnRouvignac.
the class AndroidViewHolderRefactoring method createViewHolderItemClass.
private TypeDeclaration createViewHolderItemClass(FindViewByIdVisitor findViewByIdVisitor, SimpleName typeName, TypeNameDecider typeNameDecider) {
final ASTBuilder b = this.ctx.getASTBuilder();
TypeDeclaration result = b.getAST().newTypeDeclaration();
modifiers(result).addAll(asList(b.private0(), b.static0()));
result.setName(typeName);
List<BodyDeclaration> viewItemsFieldDecls = bodyDeclarations(result);
for (FindViewByIdVisitor.FindViewByIdItem item : findViewByIdVisitor.items) {
viewItemsFieldDecls.add(item.toFieldDecl(b, typeNameDecider));
}
return result;
}
Aggregations