Search in sources :

Example 56 with IBinding

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

the class VariableDeclarationFix method createAddFinalOperation.

private static ModifierChangeOperation createAddFinalOperation(SimpleName name, ASTNode decl) {
    if (decl == null)
        return null;
    IBinding binding = name.resolveBinding();
    if (!canAddFinal(binding, decl))
        return null;
    if (decl instanceof SingleVariableDeclaration) {
        return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
    } else if (decl instanceof VariableDeclarationExpression) {
        return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
    } else if (decl instanceof VariableDeclarationFragment) {
        VariableDeclarationFragment frag = (VariableDeclarationFragment) decl;
        decl = decl.getParent();
        if (decl instanceof FieldDeclaration || decl instanceof VariableDeclarationStatement) {
            List<VariableDeclarationFragment> list = new ArrayList<VariableDeclarationFragment>();
            list.add(frag);
            return new ModifierChangeOperation(decl, list, Modifier.FINAL, Modifier.NONE);
        } else if (decl instanceof VariableDeclarationExpression) {
            return new ModifierChangeOperation(decl, new ArrayList<VariableDeclarationFragment>(), Modifier.FINAL, Modifier.NONE);
        }
    }
    return null;
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) IBinding(org.eclipse.jdt.core.dom.IBinding) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) ArrayList(java.util.ArrayList) VariableDeclarationStatement(org.eclipse.jdt.core.dom.VariableDeclarationStatement) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 57 with IBinding

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

the class UnusedCodeFix method createUnusedTypeParameterFix.

public static UnusedCodeFix createUnusedTypeParameterFix(CompilationUnit compilationUnit, IProblemLocation problemLoc) {
    if (problemLoc.getProblemId() == IProblem.UnusedTypeParameter) {
        SimpleName name = getUnusedName(compilationUnit, problemLoc);
        if (name != null) {
            IBinding binding = name.resolveBinding();
            if (binding != null) {
                String label = FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description;
                RemoveUnusedTypeParameterOperation operation = new RemoveUnusedTypeParameterOperation(name);
                return new UnusedCodeFix(label, compilationUnit, new CompilationUnitRewriteOperation[] { operation }, getCleanUpOptions(binding, false));
            }
        }
    }
    return null;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) IBinding(org.eclipse.jdt.core.dom.IBinding)

Example 58 with IBinding

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

the class InlineConstantRefactoring method findConstantNameNode.

private Name findConstantNameNode() {
    ASTNode node = NodeFinder.perform(fSelectionCuRewrite.getRoot(), fSelectionStart, fSelectionLength);
    if (node == null)
        return null;
    if (node instanceof FieldAccess)
        node = ((FieldAccess) node).getName();
    if (!(node instanceof Name))
        return null;
    Name name = (Name) node;
    IBinding binding = name.resolveBinding();
    if (!(binding instanceof IVariableBinding))
        return null;
    IVariableBinding variableBinding = (IVariableBinding) binding;
    if (!variableBinding.isField() || variableBinding.isEnumConstant())
        return null;
    int modifiers = binding.getModifiers();
    if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)))
        return null;
    return name;
}
Also used : IBinding(org.eclipse.jdt.core.dom.IBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Example 59 with IBinding

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

the class ConvertAnonymousToNestedRefactoring method getUsedLocalVariables.

private IVariableBinding[] getUsedLocalVariables() {
    final Set<IBinding> result = new HashSet<IBinding>(0);
    collectRefrencedVariables(fAnonymousInnerClassNode, result);
    ArrayList<IVariableBinding> usedLocals = new ArrayList<IVariableBinding>();
    for (Iterator<IBinding> iterator = result.iterator(); iterator.hasNext(); ) {
        IVariableBinding next = (IVariableBinding) iterator.next();
        if (isBindingToTemp(next)) {
            usedLocals.add(next);
        }
    }
    return usedLocals.toArray(new IVariableBinding[usedLocals.size()]);
}
Also used : IBinding(org.eclipse.jdt.core.dom.IBinding) ArrayList(java.util.ArrayList) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) HashSet(java.util.HashSet)

Example 60 with IBinding

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

the class CompletionProposalReplacementProvider method getExpectedTypeForGenericParameters.

private ITypeBinding getExpectedTypeForGenericParameters() {
    char[][] chKeys = context.getExpectedTypesKeys();
    if (chKeys == null || chKeys.length == 0)
        return null;
    String[] keys = new String[chKeys.length];
    for (int i = 0; i < keys.length; i++) {
        keys[i] = String.valueOf(chKeys[0]);
    }
    final ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setProject(compilationUnit.getJavaProject());
    parser.setResolveBindings(true);
    parser.setStatementsRecovery(true);
    final Map<String, IBinding> bindings = new HashMap<String, IBinding>();
    ASTRequestor requestor = new ASTRequestor() {

        @Override
        public void acceptBinding(String bindingKey, IBinding binding) {
            bindings.put(bindingKey, binding);
        }
    };
    parser.createASTs(new ICompilationUnit[0], keys, requestor, null);
    if (bindings.size() > 0)
        return (ITypeBinding) bindings.get(keys[0]);
    return null;
}
Also used : HashMap(java.util.HashMap) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) ASTParser(org.eclipse.jdt.core.dom.ASTParser)

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