Search in sources :

Example 1 with SuperFieldAccess

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

the class ModifierCorrectionSubProcessor method addNonAccessibleReferenceProposal.

public static void addNonAccessibleReferenceProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals, int kind, int relevance) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;
    }
    IBinding binding = null;
    switch(selectedNode.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
            binding = ((SimpleName) selectedNode).resolveBinding();
            break;
        case ASTNode.QUALIFIED_NAME:
            binding = ((QualifiedName) selectedNode).resolveBinding();
            break;
        case ASTNode.SIMPLE_TYPE:
            binding = ((SimpleType) selectedNode).resolveBinding();
            break;
        case ASTNode.NAME_QUALIFIED_TYPE:
            binding = ((NameQualifiedType) selectedNode).resolveBinding();
            break;
        case ASTNode.METHOD_INVOCATION:
            binding = ((MethodInvocation) selectedNode).getName().resolveBinding();
            break;
        case ASTNode.SUPER_METHOD_INVOCATION:
            binding = ((SuperMethodInvocation) selectedNode).getName().resolveBinding();
            break;
        case ASTNode.FIELD_ACCESS:
            binding = ((FieldAccess) selectedNode).getName().resolveBinding();
            break;
        case ASTNode.SUPER_FIELD_ACCESS:
            binding = ((SuperFieldAccess) selectedNode).getName().resolveBinding();
            break;
        case ASTNode.CLASS_INSTANCE_CREATION:
            binding = ((ClassInstanceCreation) selectedNode).resolveConstructorBinding();
            break;
        case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
            binding = ((SuperConstructorInvocation) selectedNode).resolveConstructorBinding();
            break;
        default:
            return;
    }
    ITypeBinding typeBinding = null;
    String name;
    IBinding bindingDecl;
    boolean isLocalVar = false;
    if (binding instanceof IVariableBinding && problem.getProblemId() == IProblem.NotVisibleType) {
        binding = ((IVariableBinding) binding).getType();
    }
    if (binding instanceof IMethodBinding && problem.getProblemId() == IProblem.NotVisibleType) {
        binding = ((IMethodBinding) binding).getReturnType();
    }
    if (binding instanceof IMethodBinding) {
        IMethodBinding methodDecl = (IMethodBinding) binding;
        if (methodDecl.isDefaultConstructor()) {
            UnresolvedElementsSubProcessor.getConstructorProposals(context, problem, proposals);
            return;
        }
        bindingDecl = methodDecl.getMethodDeclaration();
        typeBinding = methodDecl.getDeclaringClass();
        //$NON-NLS-1$
        name = BasicElementLabels.getJavaElementName(methodDecl.getName() + "()");
    } else if (binding instanceof IVariableBinding) {
        IVariableBinding varDecl = (IVariableBinding) binding;
        typeBinding = varDecl.getDeclaringClass();
        name = BasicElementLabels.getJavaElementName(binding.getName());
        isLocalVar = !varDecl.isField();
        bindingDecl = varDecl.getVariableDeclaration();
    } else if (binding instanceof ITypeBinding) {
        typeBinding = (ITypeBinding) binding;
        bindingDecl = typeBinding.getTypeDeclaration();
        name = BasicElementLabels.getJavaElementName(binding.getName());
    } else {
        return;
    }
    if (typeBinding != null && typeBinding.isFromSource() || isLocalVar) {
        int includedModifiers = 0;
        int excludedModifiers = 0;
        String label;
        switch(kind) {
            case TO_VISIBLE:
                excludedModifiers = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
                includedModifiers = getNeededVisibility(selectedNode, typeBinding, binding);
                label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changevisibility_description, new String[] { name, getVisibilityString(includedModifiers) });
                break;
            case TO_STATIC:
                label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertostatic_description, name);
                includedModifiers = Modifier.STATIC;
                if (bindingDecl.getKind() == IBinding.METHOD) {
                    excludedModifiers = Modifier.DEFAULT | Modifier.ABSTRACT;
                }
                break;
            case TO_NON_STATIC:
                if (typeBinding != null && typeBinding.isInterface())
                    return;
                label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertononstatic_description, name);
                excludedModifiers = Modifier.STATIC;
                break;
            case TO_NON_PRIVATE:
                int visibility;
                if (cu.getParent().getElementName().equals(typeBinding.getPackage().getName())) {
                    visibility = Modifier.NONE;
                    excludedModifiers = Modifier.PRIVATE;
                } else {
                    visibility = Modifier.PUBLIC;
                    includedModifiers = Modifier.PUBLIC;
                    excludedModifiers = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
                }
                label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changevisibility_description, new String[] { name, getVisibilityString(visibility) });
                break;
            case TO_NON_FINAL:
                if (typeBinding != null && typeBinding.isInterface())
                    return;
                label = Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_changemodifiertononfinal_description, name);
                excludedModifiers = Modifier.FINAL;
                break;
            default:
                //$NON-NLS-1$
                throw new IllegalArgumentException("not supported");
        }
        ICompilationUnit targetCU = isLocalVar ? cu : ASTResolving.findCompilationUnitForBinding(cu, context.getASTRoot(), typeBinding.getTypeDeclaration());
        if (targetCU != null) {
            Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
            proposals.add(new ModifierChangeCorrectionProposal(label, targetCU, bindingDecl, selectedNode, includedModifiers, excludedModifiers, relevance, image));
        }
    }
    if (kind == TO_VISIBLE && bindingDecl.getKind() == IBinding.VARIABLE) {
        UnresolvedElementsSubProcessor.getVariableProposals(context, problem, (IVariableBinding) bindingDecl, proposals);
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IBinding(org.eclipse.jdt.core.dom.IBinding) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) 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) Image(org.eclipse.swt.graphics.Image) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ModifierChangeCorrectionProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.ModifierChangeCorrectionProposal) ASTNode(org.eclipse.jdt.core.dom.ASTNode) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess)

Example 2 with SuperFieldAccess

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

the class ConvertAnonymousToNestedRefactoring method getAllAccessedFields.

private List<IBinding> getAllAccessedFields() {
    final List<IBinding> accessedFields = new ArrayList<IBinding>();
    ASTVisitor visitor = new ASTVisitor() {

        @Override
        public boolean visit(FieldAccess node) {
            final IVariableBinding binding = node.resolveFieldBinding();
            if (binding != null && !binding.isEnumConstant())
                accessedFields.add(binding);
            return super.visit(node);
        }

        @Override
        public boolean visit(QualifiedName node) {
            final IBinding binding = node.resolveBinding();
            if (binding != null && binding instanceof IVariableBinding) {
                IVariableBinding variable = (IVariableBinding) binding;
                if (!variable.isEnumConstant() && variable.isField())
                    accessedFields.add(binding);
            }
            return super.visit(node);
        }

        @Override
        public boolean visit(SimpleName node) {
            final IBinding binding = node.resolveBinding();
            if (binding != null && binding instanceof IVariableBinding) {
                IVariableBinding variable = (IVariableBinding) binding;
                if (!variable.isEnumConstant() && variable.isField())
                    accessedFields.add(binding);
            }
            return super.visit(node);
        }

        @Override
        public boolean visit(SuperFieldAccess node) {
            final IVariableBinding binding = node.resolveFieldBinding();
            if (binding != null && !binding.isEnumConstant())
                accessedFields.add(binding);
            return super.visit(node);
        }
    };
    fAnonymousInnerClassNode.accept(visitor);
    return accessedFields;
}
Also used : IBinding(org.eclipse.jdt.core.dom.IBinding) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ArrayList(java.util.ArrayList) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 3 with SuperFieldAccess

use of org.eclipse.jdt.core.dom.SuperFieldAccess in project AutoRefactor by JnRouvignac.

the class CFGBuilder method addVariableAccess.

/**
 * @return whether the current variable access can throw an exception.
 */
@SuppressWarnings("unchecked")
private boolean addVariableAccess(CFGBasicBlock basicBlock, Expression node, int flags, ThrowerBlocks throwers) {
    if (node == null) {
        return false;
    }
    switch(node.getNodeType()) {
        case ARRAY_ACCESS:
            ArrayAccess aa = (ArrayAccess) node;
            addVariableAccess(basicBlock, aa.getArray(), flags, throwers);
            addVariableAccess(basicBlock, aa.getIndex(), flags, throwers);
            throwers.addThrow(aa, newException(node, "java.lang.ArrayIndexOutOfBoundsException"));
            return true;
        case ARRAY_CREATION:
            ArrayCreation ac = (ArrayCreation) node;
            boolean acMightThrow1 = addVariableAccess(basicBlock, ac.getInitializer(), flags, throwers);
            boolean acMightThrow2 = addVariableAccesses(basicBlock, ac.dimensions(), flags, throwers);
            return acMightThrow1 || acMightThrow2;
        case ARRAY_INITIALIZER:
            ArrayInitializer ai = (ArrayInitializer) node;
            return addVariableAccesses(basicBlock, ai.expressions(), flags, throwers);
        case ASSIGNMENT:
            Assignment a = (Assignment) node;
            boolean aMightThrow1 = addVariableAccess(basicBlock, a.getLeftHandSide(), WRITE, throwers);
            boolean aMightThrow2 = addVariableAccess(basicBlock, a.getRightHandSide(), READ, throwers);
            return aMightThrow1 || aMightThrow2;
        case BOOLEAN_LITERAL:
        case CHARACTER_LITERAL:
        case NULL_LITERAL:
        case NUMBER_LITERAL:
        case STRING_LITERAL:
        case TYPE_LITERAL:
            // nothing to do
            return false;
        case CAST_EXPRESSION:
            CastExpression cae = (CastExpression) node;
            return addVariableAccess(basicBlock, cae.getExpression(), flags, throwers);
        case CLASS_INSTANCE_CREATION:
            ClassInstanceCreation cic = (ClassInstanceCreation) node;
            addVariableAccess(basicBlock, cic.getExpression(), flags, throwers);
            addVariableAccesses(basicBlock, cic.arguments(), flags, throwers);
            IMethodBinding cicBinding = cic.resolveConstructorBinding();
            if (cicBinding != null) {
                ITypeBinding[] declaredThrows = cicBinding.getExceptionTypes();
                throwers.addThrow(cic, declaredThrows);
                return declaredThrows.length > 0;
            }
            return false;
        case CONDITIONAL_EXPRESSION:
            ConditionalExpression coe = (ConditionalExpression) node;
            boolean mightThrow1 = addVariableAccess(basicBlock, coe.getExpression(), flags, throwers);
            boolean mightThrow2 = addVariableAccess(basicBlock, coe.getThenExpression(), flags, throwers);
            boolean mightThrow3 = addVariableAccess(basicBlock, coe.getElseExpression(), flags, throwers);
            return mightThrow1 || mightThrow2 || mightThrow3;
        case FIELD_ACCESS:
            FieldAccess fa = (FieldAccess) node;
            boolean mightThrow = addVariableAccess(basicBlock, fa.getExpression(), flags, throwers);
            basicBlock.addVariableAccess(new VariableAccess(fa, flags));
            if (is(flags, READ)) {
                throwers.addThrow(fa, newException(node, "java.lang.NullPointerException"));
                mightThrow = true;
            }
            return mightThrow;
        case INFIX_EXPRESSION:
            InfixExpression ie = (InfixExpression) node;
            boolean ieMightThrow1 = addVariableAccess(basicBlock, ie.getLeftOperand(), flags, throwers);
            boolean ieMightThrow2 = addVariableAccess(basicBlock, ie.getRightOperand(), flags, throwers);
            return ieMightThrow1 || ieMightThrow2;
        case INSTANCEOF_EXPRESSION:
            InstanceofExpression ioe = (InstanceofExpression) node;
            return addVariableAccess(basicBlock, ioe.getLeftOperand(), flags, throwers);
        case METHOD_INVOCATION:
            MethodInvocation mi = (MethodInvocation) node;
            addVariableAccess(basicBlock, mi.getExpression(), flags, throwers);
            addVariableAccesses(basicBlock, mi.arguments(), flags, throwers);
            IMethodBinding methodBinding = mi.resolveMethodBinding();
            if (methodBinding != null) {
                ITypeBinding[] declaredThrows = methodBinding.getExceptionTypes();
                throwers.addThrow(mi, declaredThrows);
                return declaredThrows.length > 0;
            }
            return false;
        case SIMPLE_NAME:
            SimpleName sn = (SimpleName) node;
            basicBlock.addVariableAccess(new VariableAccess(sn, flags));
            if (is(flags, READ)) {
                throwers.addThrow(sn, newException(node, "java.lang.NullPointerException"));
                return true;
            }
            return false;
        case QUALIFIED_NAME:
            QualifiedName qn = (QualifiedName) node;
            basicBlock.addVariableAccess(new VariableAccess(qn, flags));
            throwers.addThrow(qn, newException(node, "java.lang.NullPointerException"));
            return true;
        case PARENTHESIZED_EXPRESSION:
            ParenthesizedExpression pe = (ParenthesizedExpression) node;
            return addVariableAccess(basicBlock, pe.getExpression(), flags, throwers);
        case POSTFIX_EXPRESSION:
            PostfixExpression poe = (PostfixExpression) node;
            return addVariableAccess(basicBlock, poe.getOperand(), flags, throwers);
        case PREFIX_EXPRESSION:
            PrefixExpression pre = (PrefixExpression) node;
            return addVariableAccess(basicBlock, pre.getOperand(), flags, throwers);
        case SUPER_FIELD_ACCESS:
            SuperFieldAccess sfa = (SuperFieldAccess) node;
            boolean sfaMightThrow1 = addVariableAccess(basicBlock, sfa.getQualifier(), flags, throwers);
            boolean sfaMightThrow2 = addVariableAccess(basicBlock, sfa.getName(), flags, throwers);
            return sfaMightThrow1 || sfaMightThrow2;
        case SUPER_METHOD_INVOCATION:
            SuperMethodInvocation smi = (SuperMethodInvocation) node;
            addVariableAccess(basicBlock, smi.getQualifier(), flags, throwers);
            addVariableAccess(basicBlock, smi.getName(), flags, throwers);
            IMethodBinding sMethodBinding = smi.resolveMethodBinding();
            if (sMethodBinding != null) {
                ITypeBinding[] declaredThrows = sMethodBinding.getExceptionTypes();
                throwers.addThrow(smi, declaredThrows);
                return declaredThrows.length > 0;
            }
            return false;
        case THIS_EXPRESSION:
            ThisExpression te = (ThisExpression) node;
            // TODO JNR remember use of "this" here
            return addVariableAccess(basicBlock, te.getQualifier(), flags, throwers);
        case VARIABLE_DECLARATION_EXPRESSION:
            return addDeclarations(basicBlock, (VariableDeclarationExpression) node, throwers);
        default:
            throw new NotImplementedException(node);
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) NotImplementedException(org.autorefactor.util.NotImplementedException) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) SuperMethodInvocation(org.eclipse.jdt.core.dom.SuperMethodInvocation) Assignment(org.eclipse.jdt.core.dom.Assignment) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) ArrayAccess(org.eclipse.jdt.core.dom.ArrayAccess) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) VariableAccess(org.autorefactor.cfg.VariableAccess) InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) ClassInstanceCreation(org.eclipse.jdt.core.dom.ClassInstanceCreation) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) ArrayCreation(org.eclipse.jdt.core.dom.ArrayCreation) PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) ArrayInitializer(org.eclipse.jdt.core.dom.ArrayInitializer)

Example 4 with SuperFieldAccess

use of org.eclipse.jdt.core.dom.SuperFieldAccess in project whole by wholeplatform.

the class CompilationUnitBuilder method newSuperFieldAccess.

public SuperFieldAccess newSuperFieldAccess(String fName) {
    SuperFieldAccess fieldExp = ast.newSuperFieldAccess();
    fieldExp.setName(ast.newSimpleName(fName));
    return fieldExp;
}
Also used : SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess)

Example 5 with SuperFieldAccess

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

the class UnresolvedElementsSubProcessor method getVariableProposals.

public static void getVariableProposals(IInvocationContext context, IProblemLocation problem, IVariableBinding resolvedField, Collection<ICommandAccess> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();
    CompilationUnit astRoot = context.getASTRoot();
    ASTNode selectedNode = problem.getCoveredNode(astRoot);
    if (selectedNode == null) {
        return;
    }
    // type that defines the variable
    ITypeBinding binding = null;
    ITypeBinding declaringTypeBinding = Bindings.getBindingOfParentTypeContext(selectedNode);
    if (declaringTypeBinding == null) {
        return;
    }
    // possible type kind of the node
    boolean suggestVariableProposals = true;
    int typeKind = 0;
    while (selectedNode instanceof ParenthesizedExpression) {
        selectedNode = ((ParenthesizedExpression) selectedNode).getExpression();
    }
    Name node = null;
    switch(selectedNode.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
            node = (SimpleName) selectedNode;
            ASTNode parent = node.getParent();
            StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
            if (locationInParent == ExpressionMethodReference.EXPRESSION_PROPERTY) {
                typeKind = SimilarElementsRequestor.REF_TYPES;
            } else if (locationInParent == MethodInvocation.EXPRESSION_PROPERTY) {
                if (JavaModelUtil.is18OrHigher(cu.getJavaProject())) {
                    typeKind = SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES | SimilarElementsRequestor.ENUMS;
                } else {
                    typeKind = SimilarElementsRequestor.CLASSES;
                }
            } else if (locationInParent == FieldAccess.NAME_PROPERTY) {
                Expression expression = ((FieldAccess) parent).getExpression();
                if (expression != null) {
                    binding = expression.resolveTypeBinding();
                    if (binding == null) {
                        node = null;
                    }
                }
            } else if (parent instanceof SimpleType || parent instanceof NameQualifiedType) {
                suggestVariableProposals = false;
                typeKind = SimilarElementsRequestor.REF_TYPES_AND_VAR;
            } else if (parent instanceof QualifiedName) {
                Name qualifier = ((QualifiedName) parent).getQualifier();
                if (qualifier != node) {
                    binding = qualifier.resolveTypeBinding();
                } else {
                    typeKind = SimilarElementsRequestor.REF_TYPES;
                }
                ASTNode outerParent = parent.getParent();
                while (outerParent instanceof QualifiedName) {
                    outerParent = outerParent.getParent();
                }
                if (outerParent instanceof SimpleType || outerParent instanceof NameQualifiedType) {
                    typeKind = SimilarElementsRequestor.REF_TYPES;
                    suggestVariableProposals = false;
                }
            } else if (locationInParent == SwitchCase.EXPRESSION_PROPERTY) {
                ITypeBinding switchExp = ((SwitchStatement) node.getParent().getParent()).getExpression().resolveTypeBinding();
                if (switchExp != null && switchExp.isEnum()) {
                    binding = switchExp;
                }
            } else if (locationInParent == SuperFieldAccess.NAME_PROPERTY) {
                binding = declaringTypeBinding.getSuperclass();
            }
            break;
        case ASTNode.QUALIFIED_NAME:
            QualifiedName qualifierName = (QualifiedName) selectedNode;
            ITypeBinding qualifierBinding = qualifierName.getQualifier().resolveTypeBinding();
            if (qualifierBinding != null) {
                node = qualifierName.getName();
                binding = qualifierBinding;
            } else {
                node = qualifierName.getQualifier();
                typeKind = SimilarElementsRequestor.REF_TYPES;
                suggestVariableProposals = node.isSimpleName();
            }
            if (selectedNode.getParent() instanceof SimpleType || selectedNode.getParent() instanceof NameQualifiedType) {
                typeKind = SimilarElementsRequestor.REF_TYPES;
                suggestVariableProposals = false;
            }
            break;
        case ASTNode.FIELD_ACCESS:
            FieldAccess access = (FieldAccess) selectedNode;
            Expression expression = access.getExpression();
            if (expression != null) {
                binding = expression.resolveTypeBinding();
                if (binding != null) {
                    node = access.getName();
                }
            }
            break;
        case ASTNode.SUPER_FIELD_ACCESS:
            binding = declaringTypeBinding.getSuperclass();
            node = ((SuperFieldAccess) selectedNode).getName();
            break;
        default:
    }
    if (node == null) {
        return;
    }
    // add type proposals
    if (typeKind != 0) {
        if (!JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
            typeKind &= ~(SimilarElementsRequestor.ANNOTATIONS | SimilarElementsRequestor.ENUMS | SimilarElementsRequestor.VARIABLES);
        }
        int relevance = Character.isUpperCase(ASTNodes.getSimpleNameIdentifier(node).charAt(0)) ? IProposalRelevance.VARIABLE_TYPE_PROPOSAL_1 : IProposalRelevance.VARIABLE_TYPE_PROPOSAL_2;
        addSimilarTypeProposals(typeKind, cu, node, relevance + 1, proposals);
        typeKind &= ~SimilarElementsRequestor.ANNOTATIONS;
        addNewTypeProposals(cu, node, typeKind, relevance, proposals);
        ReorgCorrectionsSubProcessor.addProjectSetupFixProposal(context, problem, node.getFullyQualifiedName(), proposals);
    }
    if (!suggestVariableProposals) {
        return;
    }
    SimpleName simpleName = node.isSimpleName() ? (SimpleName) node : ((QualifiedName) node).getName();
    boolean isWriteAccess = ASTResolving.isWriteAccess(node);
    // similar variables
    addSimilarVariableProposals(cu, astRoot, binding, resolvedField, simpleName, isWriteAccess, proposals);
    if (binding == null) {
        addStaticImportFavoriteProposals(context, simpleName, false, proposals);
    }
    if (resolvedField == null || binding == null || resolvedField.getDeclaringClass() != binding.getTypeDeclaration() && Modifier.isPrivate(resolvedField.getModifiers())) {
        // new fields
        addNewFieldProposals(cu, astRoot, binding, declaringTypeBinding, simpleName, isWriteAccess, proposals);
        // new parameters and local variables
        if (binding == null) {
            addNewVariableProposals(cu, node, simpleName, proposals);
        }
    }
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) SimpleName(org.eclipse.jdt.core.dom.SimpleName) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name) SimpleType(org.eclipse.jdt.core.dom.SimpleType) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) FieldAccess(org.eclipse.jdt.core.dom.FieldAccess) SuperFieldAccess(org.eclipse.jdt.core.dom.SuperFieldAccess) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) StructuralPropertyDescriptor(org.eclipse.jdt.core.dom.StructuralPropertyDescriptor)

Aggregations

SuperFieldAccess (org.eclipse.jdt.core.dom.SuperFieldAccess)7 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)6 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)4 SimpleName (org.eclipse.jdt.core.dom.SimpleName)4 CastExpression (org.eclipse.jdt.core.dom.CastExpression)3 IBinding (org.eclipse.jdt.core.dom.IBinding)3 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)3 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)3 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)3 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)3 SuperMethodInvocation (org.eclipse.jdt.core.dom.SuperMethodInvocation)3 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)2 Expression (org.eclipse.jdt.core.dom.Expression)2 Name (org.eclipse.jdt.core.dom.Name)2 NameQualifiedType (org.eclipse.jdt.core.dom.NameQualifiedType)2 SimpleType (org.eclipse.jdt.core.dom.SimpleType)2