Search in sources :

Example 36 with AST

use of org.eclipse.jdt.core.dom.AST in project che by eclipse.

the class NewDefiningMethodProposal method addNewParameters.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#addNewParameters(org.eclipse.jdt.core
	 * .dom.rewrite.ASTRewrite, java.util.List, java.util.List)
	 */
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params) throws CoreException {
    AST ast = rewrite.getAST();
    ImportRewrite importRewrite = getImportRewrite();
    ITypeBinding[] bindings = fMethod.getParameterTypes();
    IJavaProject project = getCompilationUnit().getJavaProject();
    String[][] paramNames = StubUtility.suggestArgumentNamesWithProposals(project, fParamNames);
    for (int i = 0; i < bindings.length; i++) {
        ITypeBinding curr = bindings[i];
        String[] proposedNames = paramNames[i];
        SingleVariableDeclaration newParam = ast.newSingleVariableDeclaration();
        newParam.setType(importRewrite.addImport(curr, ast));
        newParam.setName(ast.newSimpleName(proposedNames[0]));
        params.add(newParam);
        //$NON-NLS-1$
        String groupId = "arg_name_" + i;
        addLinkedPosition(rewrite.track(newParam.getName()), false, groupId);
        for (int k = 0; k < proposedNames.length; k++) {
            addLinkedPositionProposal(groupId, proposedNames[k], null);
        }
    }
}
Also used : AST(org.eclipse.jdt.core.dom.AST) IJavaProject(org.eclipse.jdt.core.IJavaProject) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 37 with AST

use of org.eclipse.jdt.core.dom.AST in project che by eclipse.

the class NewDefiningMethodProposal method getNewName.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#getNewName(org.eclipse.jdt.core.dom.rewrite.ASTRewrite)
	 */
@Override
protected SimpleName getNewName(ASTRewrite rewrite) {
    AST ast = rewrite.getAST();
    SimpleName nameNode = ast.newSimpleName(fMethod.getName());
    return nameNode;
}
Also used : AST(org.eclipse.jdt.core.dom.AST) SimpleName(org.eclipse.jdt.core.dom.SimpleName)

Example 38 with AST

use of org.eclipse.jdt.core.dom.AST in project che by eclipse.

the class NewDefiningMethodProposal method addNewExceptions.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#addNewExceptions(org.eclipse.jdt.core.dom.rewrite.ASTRewrite, java.util.List)
	 */
@Override
protected void addNewExceptions(ASTRewrite rewrite, List<Type> exceptions) throws CoreException {
    AST ast = rewrite.getAST();
    ImportRewrite importRewrite = getImportRewrite();
    ITypeBinding[] bindings = fMethod.getExceptionTypes();
    for (int i = 0; i < bindings.length; i++) {
        Type newType = importRewrite.addImport(bindings[i], ast);
        exceptions.add(newType);
        //$NON-NLS-1$
        addLinkedPosition(rewrite.track(newType), false, "exc_type_" + i);
    }
}
Also used : AST(org.eclipse.jdt.core.dom.AST) Type(org.eclipse.jdt.core.dom.Type) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 39 with AST

use of org.eclipse.jdt.core.dom.AST in project che by eclipse.

the class NewMethodCorrectionProposal method getNewMethodType.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#getNewMethodType(org.eclipse.jdt.core.dom.rewrite.ASTRewrite)
	 */
@Override
protected Type getNewMethodType(ASTRewrite rewrite) throws CoreException {
    ASTNode node = getInvocationNode();
    AST ast = rewrite.getAST();
    Type newTypeNode = null;
    ITypeBinding[] otherProposals = null;
    ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(node, getImportRewrite());
    if (node.getParent() instanceof MethodInvocation) {
        MethodInvocation parent = (MethodInvocation) node.getParent();
        if (parent.getExpression() == node) {
            ITypeBinding[] bindings = ASTResolving.getQualifierGuess(node.getRoot(), parent.getName().getIdentifier(), parent.arguments(), getSenderBinding());
            if (bindings.length > 0) {
                newTypeNode = getImportRewrite().addImport(bindings[0], ast, importRewriteContext);
                otherProposals = bindings;
            }
        }
    }
    if (newTypeNode == null) {
        ITypeBinding binding = ASTResolving.guessBindingForReference(node);
        if (binding != null && binding.isWildcardType()) {
            binding = ASTResolving.normalizeWildcardType(binding, false, ast);
        }
        if (binding != null) {
            newTypeNode = getImportRewrite().addImport(binding, ast, importRewriteContext);
        } else {
            ASTNode parent = node.getParent();
            if (parent instanceof ExpressionStatement) {
                newTypeNode = ast.newPrimitiveType(PrimitiveType.VOID);
            } else {
                newTypeNode = ASTResolving.guessTypeForReference(ast, node);
                if (newTypeNode == null) {
                    //$NON-NLS-1$
                    newTypeNode = ast.newSimpleType(ast.newSimpleName("Object"));
                }
            }
        }
    }
    addLinkedPosition(rewrite.track(newTypeNode), false, KEY_TYPE);
    if (otherProposals != null) {
        for (int i = 0; i < otherProposals.length; i++) {
            addLinkedPositionProposal(KEY_TYPE, otherProposals[i]);
        }
    }
    return newTypeNode;
}
Also used : AST(org.eclipse.jdt.core.dom.AST) Type(org.eclipse.jdt.core.dom.Type) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ImportRewriteContext(org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation)

Example 40 with AST

use of org.eclipse.jdt.core.dom.AST in project che by eclipse.

the class NewMethodCorrectionProposal method addNewParameters.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.proposals.AbstractMethodCorrectionProposal#addNewParameters(org.eclipse.jdt.core.dom.rewrite.ASTRewrite, java.util.List, java.util.List)
	 */
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params) throws CoreException {
    AST ast = rewrite.getAST();
    List<Expression> arguments = fArguments;
    ImportRewriteContext context = new ContextSensitiveImportRewriteContext(ASTResolving.findParentBodyDeclaration(getInvocationNode()), getImportRewrite());
    for (int i = 0; i < arguments.size(); i++) {
        Expression elem = arguments.get(i);
        SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
        // argument type
        //$NON-NLS-1$
        String argTypeKey = "arg_type_" + i;
        Type type = evaluateParameterType(ast, elem, argTypeKey, context);
        param.setType(type);
        // argument name
        //$NON-NLS-1$
        String argNameKey = "arg_name_" + i;
        String name = evaluateParameterName(takenNames, elem, type, argNameKey);
        param.setName(ast.newSimpleName(name));
        params.add(param);
        addLinkedPosition(rewrite.track(param.getType()), false, argTypeKey);
        addLinkedPosition(rewrite.track(param.getName()), false, argNameKey);
    }
}
Also used : AST(org.eclipse.jdt.core.dom.AST) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) Type(org.eclipse.jdt.core.dom.Type) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) ImportRewriteContext(org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext) ContextSensitiveImportRewriteContext(org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext) Expression(org.eclipse.jdt.core.dom.Expression) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration)

Aggregations

AST (org.eclipse.jdt.core.dom.AST)169 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)78 Expression (org.eclipse.jdt.core.dom.Expression)77 ASTNode (org.eclipse.jdt.core.dom.ASTNode)70 Type (org.eclipse.jdt.core.dom.Type)52 SimpleName (org.eclipse.jdt.core.dom.SimpleName)51 Block (org.eclipse.jdt.core.dom.Block)44 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)43 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)42 CastExpression (org.eclipse.jdt.core.dom.CastExpression)40 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)40 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)39 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)38 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)38 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)34 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)33 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)33 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)33 ConditionalExpression (org.eclipse.jdt.core.dom.ConditionalExpression)30 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)30