Search in sources :

Example 66 with BodyDeclaration

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);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) Type(org.eclipse.jdt.core.dom.Type) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) Expression(org.eclipse.jdt.core.dom.Expression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration)

Example 67 with BodyDeclaration

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()]);
}
Also used : MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ArrayList(java.util.ArrayList) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration)

Example 68 with BodyDeclaration

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") };
        }
    }
}
Also used : BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration)

Example 69 with BodyDeclaration

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));
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) TypeDeclarationStatement(org.eclipse.jdt.core.dom.TypeDeclarationStatement) NotImplementedException(org.autorefactor.util.NotImplementedException) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 70 with BodyDeclaration

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;
}
Also used : BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) ASTBuilder(org.autorefactor.refactoring.ASTBuilder) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration)

Aggregations

BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)98 ASTNode (org.eclipse.jdt.core.dom.ASTNode)61 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)53 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)28 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)27 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)26 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)26 Type (org.eclipse.jdt.core.dom.Type)25 AST (org.eclipse.jdt.core.dom.AST)23 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)18 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)17 Expression (org.eclipse.jdt.core.dom.Expression)16 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)15 Initializer (org.eclipse.jdt.core.dom.Initializer)15 SimpleName (org.eclipse.jdt.core.dom.SimpleName)15 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)15 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)14 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)14 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)13 ArrayList (java.util.ArrayList)12