Search in sources :

Example 71 with IBinding

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

the class ScopeAnalyzer method getDeclarationsInScope.

public IBinding[] getDeclarationsInScope(int offset, int flags) {
    org.eclipse.jdt.core.dom.NodeFinder finder = new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0);
    ASTNode node = finder.getCoveringNode();
    if (node == null) {
        return NO_BINDING;
    }
    if (node instanceof SimpleName) {
        return getDeclarationsInScope((SimpleName) node, flags);
    }
    try {
        ITypeBinding binding = Bindings.getBindingOfParentType(node);
        DefaultBindingRequestor requestor = new DefaultBindingRequestor(binding, flags);
        addLocalDeclarations(node, offset, flags, requestor);
        if (binding != null) {
            addTypeDeclarations(binding, flags, requestor);
        }
        List<IBinding> result = requestor.getResult();
        return result.toArray(new IBinding[result.size()]);
    } finally {
        clearLists();
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode)

Example 72 with IBinding

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

the class GetterSetterCorrectionSubProcessor method addGetterSetterProposal.

private static boolean addGetterSetterProposal(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> proposals, int relevance) {
    if (!(coveringNode instanceof SimpleName)) {
        return false;
    }
    SimpleName sn = (SimpleName) coveringNode;
    IBinding binding = sn.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return false;
    IVariableBinding variableBinding = (IVariableBinding) binding;
    if (!variableBinding.isField())
        return false;
    if (proposals == null)
        return true;
    ChangeCorrectionProposal proposal = getProposal(context.getCompilationUnit(), sn, variableBinding, relevance);
    if (proposal != null)
        proposals.add(proposal);
    return true;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal)

Example 73 with IBinding

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

the class JavadocTagsSubProcessor method getInvalidQualificationProposals.

public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    ASTNode node = problem.getCoveringNode(context.getASTRoot());
    if (!(node instanceof Name)) {
        return;
    }
    Name name = (Name) node;
    IBinding binding = name.resolveBinding();
    if (!(binding instanceof ITypeBinding)) {
        return;
    }
    ITypeBinding typeBinding = (ITypeBinding) binding;
    AST ast = node.getAST();
    ASTRewrite rewrite = ASTRewrite.create(ast);
    rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null);
    String label = CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME, image);
    proposals.add(proposal);
}
Also used : ASTRewriteCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal) AST(org.eclipse.jdt.core.dom.AST) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) Image(org.eclipse.swt.graphics.Image) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name)

Example 74 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.

the class StubUtility method getBaseNameFromExpression.

private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) {
    String name = null;
    if (assignedExpression instanceof CastExpression) {
        assignedExpression = ((CastExpression) assignedExpression).getExpression();
    }
    if (assignedExpression instanceof Name) {
        Name simpleNode = (Name) assignedExpression;
        IBinding binding = simpleNode.resolveBinding();
        if (binding instanceof IVariableBinding)
            return getBaseName((IVariableBinding) binding, project);
        return ASTNodes.getSimpleNameIdentifier(simpleNode);
    } else if (assignedExpression instanceof MethodInvocation) {
        name = ((MethodInvocation) assignedExpression).getName().getIdentifier();
    } else if (assignedExpression instanceof SuperMethodInvocation) {
        name = ((SuperMethodInvocation) assignedExpression).getName().getIdentifier();
    } else if (assignedExpression instanceof FieldAccess) {
        return ((FieldAccess) assignedExpression).getName().getIdentifier();
    } else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) {
        String string = assignedExpression instanceof StringLiteral ? ((StringLiteral) assignedExpression).getLiteralValue() : ((NumberLiteral) assignedExpression).getToken();
        StringBuffer res = new StringBuffer();
        boolean needsUnderscore = false;
        for (int i = 0; i < string.length(); i++) {
            char ch = string.charAt(i);
            if (Character.isJavaIdentifierPart(ch)) {
                if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
                    res.append('_');
                }
                res.append(ch);
                needsUnderscore = false;
            } else {
                needsUnderscore = res.length() > 0;
            }
        }
        if (res.length() > 0) {
            return res.toString();
        }
    }
    if (name != null) {
        for (int i = 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
            String curr = KNOWN_METHOD_NAME_PREFIXES[i];
            if (name.startsWith(curr)) {
                if (name.equals(curr)) {
                    // don't suggest 'get' as variable name
                    return null;
                } else if (Character.isUpperCase(name.charAt(curr.length()))) {
                    return name.substring(curr.length());
                }
            }
        }
    }
    return name;
}
Also used : IBinding(org.eclipse.jdt.core.dom.IBinding) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) Name(org.eclipse.jdt.core.dom.Name) StringLiteral(org.eclipse.jdt.core.dom.StringLiteral) CastExpression(org.eclipse.jdt.core.dom.CastExpression) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) NumberLiteral(org.eclipse.jdt.core.dom.NumberLiteral)

Example 75 with IBinding

use of org.eclipse.jdt.core.dom.IBinding in project flux by eclipse.

the class LinkedNodeFinder method findByNode.

/**
	 * Find all nodes connected to the given name node. If the node has a binding then all nodes connected
	 * to this binding are returned. If the node has no binding, then all nodes that also miss a binding and have
	 * the same name are returned.
	 * @param root The root of the AST tree to search
	 * @param name The node to find linked nodes for
	 * @return Return
	 */
public static SimpleName[] findByNode(ASTNode root, SimpleName name) {
    IBinding binding = name.resolveBinding();
    if (binding != null) {
        return findByBinding(root, binding);
    }
    SimpleName[] names = findByProblems(root, name);
    if (names != null) {
        return names;
    }
    int parentKind = name.getParent().getNodeType();
    if (parentKind == ASTNode.LABELED_STATEMENT || parentKind == ASTNode.BREAK_STATEMENT || parentKind == ASTNode.CONTINUE_STATEMENT) {
        ArrayList<SimpleName> res = new ArrayList<SimpleName>();
        LabelFinder nodeFinder = new LabelFinder(name, res);
        root.accept(nodeFinder);
        return res.toArray(new SimpleName[res.size()]);
    }
    return new SimpleName[] { name };
}
Also used : IBinding(org.eclipse.jdt.core.dom.IBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ArrayList(java.util.ArrayList)

Aggregations

IBinding (org.eclipse.jdt.core.dom.IBinding)103 SimpleName (org.eclipse.jdt.core.dom.SimpleName)59 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)48 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)41 ASTNode (org.eclipse.jdt.core.dom.ASTNode)40 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)25 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)25 Name (org.eclipse.jdt.core.dom.Name)20 Expression (org.eclipse.jdt.core.dom.Expression)19 ArrayList (java.util.ArrayList)16 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13 CastExpression (org.eclipse.jdt.core.dom.CastExpression)12 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)11 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)11 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)11 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)11 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)11 AST (org.eclipse.jdt.core.dom.AST)10 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)10