Search in sources :

Example 21 with QualifiedName

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

the class UnresolvedElementsSubProcessor method getTypeProposals.

public static void getTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;
    }
    int kind = evauateTypeKind(selectedNode, cu.getJavaProject());
    if (kind == SimilarElementsRequestor.REF_TYPES) {
        addEnhancedForWithoutTypeProposals(cu, selectedNode, proposals);
    }
    while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
        selectedNode = selectedNode.getParent();
    }
    Name node = null;
    if (selectedNode instanceof SimpleType) {
        node = ((SimpleType) selectedNode).getName();
    } else if (selectedNode instanceof NameQualifiedType) {
        node = ((NameQualifiedType) selectedNode).getName();
    } else if (selectedNode instanceof ArrayType) {
        Type elementType = ((ArrayType) selectedNode).getElementType();
        if (elementType.isSimpleType()) {
            node = ((SimpleType) elementType).getName();
        } else if (elementType.isNameQualifiedType()) {
            node = ((NameQualifiedType) elementType).getName();
        } else {
            return;
        }
    } else if (selectedNode instanceof Name) {
        node = (Name) selectedNode;
    } else {
        return;
    }
    // change to similar type proposals
    addSimilarTypeProposals(kind, cu, node, IProposalRelevance.SIMILAR_TYPE, proposals);
    while (node.getParent() instanceof QualifiedName) {
        node = (Name) node.getParent();
    }
    if (selectedNode != node) {
        kind = evauateTypeKind(node, cu.getJavaProject());
    }
    if ((kind & (SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES)) != 0) {
        // only propose annotations when there are no other suggestions
        kind &= ~SimilarElementsRequestor.ANNOTATIONS;
    }
    addNewTypeProposals(cu, node, kind, IProposalRelevance.NEW_TYPE, proposals);
    ReorgCorrectionsSubProcessor.addProjectSetupFixProposal(context, problem, node.getFullyQualifiedName(), proposals);
}
Also used : ArrayType(org.eclipse.jdt.core.dom.ArrayType) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SimpleType(org.eclipse.jdt.core.dom.SimpleType) IType(org.eclipse.jdt.core.IType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Example 22 with QualifiedName

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

the class ReorgCorrectionsSubProcessor method importNotFoundProposals.

public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    ICompilationUnit cu = context.getCompilationUnit();
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;
    }
    ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
    if (importDeclaration == null) {
        return;
    }
    if (!importDeclaration.isOnDemand()) {
        Name name = importDeclaration.getName();
        if (importDeclaration.isStatic() && name.isQualifiedName()) {
            name = ((QualifiedName) name).getQualifier();
        }
        int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES;
        UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals);
    }
    String name = ASTNodes.asString(importDeclaration.getName());
    if (importDeclaration.isOnDemand()) {
        //$NON-NLS-1$
        name = JavaModelUtil.concatenateName(name, "*");
    }
    addProjectSetupFixProposal(context, problem, name, proposals);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ImportDeclaration(org.eclipse.jdt.core.dom.ImportDeclaration) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Example 23 with QualifiedName

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

the class NewVariableCorrectionProposal method evaluateFieldModifiers.

private int evaluateFieldModifiers(ASTNode newTypeDecl) {
    if (fSenderBinding.isAnnotation()) {
        return 0;
    }
    if (fSenderBinding.isInterface()) {
        // for interface members copy the modifiers from an existing field
        FieldDeclaration[] fieldDecls = ((TypeDeclaration) newTypeDecl).getFields();
        if (fieldDecls.length > 0) {
            return fieldDecls[0].getModifiers();
        }
        return 0;
    }
    int modifiers = 0;
    if (fVariableKind == CONST_FIELD) {
        modifiers |= Modifier.FINAL | Modifier.STATIC;
    } else {
        ASTNode parent = fOriginalNode.getParent();
        if (parent instanceof QualifiedName) {
            IBinding qualifierBinding = ((QualifiedName) parent).getQualifier().resolveBinding();
            if (qualifierBinding instanceof ITypeBinding) {
                modifiers |= Modifier.STATIC;
            }
        } else if (ASTResolving.isInStaticContext(fOriginalNode)) {
            modifiers |= Modifier.STATIC;
        }
    }
    ASTNode node = ASTResolving.findParentType(fOriginalNode, true);
    if (newTypeDecl.equals(node)) {
        modifiers |= Modifier.PRIVATE;
    } else if (node instanceof AnonymousClassDeclaration) {
        modifiers |= Modifier.PROTECTED;
    } else {
        modifiers |= Modifier.PUBLIC;
    }
    return modifiers;
}
Also used : QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) IBinding(org.eclipse.jdt.core.dom.IBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 24 with QualifiedName

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

the class Java50Fix method getRawReference.

private static SimpleType getRawReference(MethodInvocation invocation, CompilationUnit compilationUnit) {
    Name name1 = (Name) invocation.getStructuralProperty(MethodInvocation.NAME_PROPERTY);
    if (name1 instanceof SimpleName) {
        SimpleType rawReference = getRawReference((SimpleName) name1, compilationUnit);
        if (rawReference != null) {
            return rawReference;
        }
    }
    Expression expr = (Expression) invocation.getStructuralProperty(MethodInvocation.EXPRESSION_PROPERTY);
    if (expr instanceof SimpleName) {
        SimpleType rawReference = getRawReference((SimpleName) expr, compilationUnit);
        if (rawReference != null) {
            return rawReference;
        }
    } else if (expr instanceof QualifiedName) {
        Name name = (Name) expr;
        while (name instanceof QualifiedName) {
            SimpleName simpleName = (SimpleName) name.getStructuralProperty(QualifiedName.NAME_PROPERTY);
            SimpleType rawReference = getRawReference(simpleName, compilationUnit);
            if (rawReference != null) {
                return rawReference;
            }
            name = (Name) name.getStructuralProperty(QualifiedName.QUALIFIER_PROPERTY);
        }
        if (name instanceof SimpleName) {
            SimpleType rawReference = getRawReference((SimpleName) name, compilationUnit);
            if (rawReference != null) {
                return rawReference;
            }
        }
    } else if (expr instanceof MethodInvocation) {
        SimpleType rawReference = getRawReference((MethodInvocation) expr, compilationUnit);
        if (rawReference != null) {
            return rawReference;
        }
    }
    return null;
}
Also used : SimpleType(org.eclipse.jdt.core.dom.SimpleType) Expression(org.eclipse.jdt.core.dom.Expression) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Example 25 with QualifiedName

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

the class PotentialProgrammingProblemsFix method getSelectedName.

private static SimpleName getSelectedName(CompilationUnit compilationUnit, IProblemLocation problem) {
    final ASTNode selection = problem.getCoveredNode(compilationUnit);
    if (selection == null)
        return null;
    Name name = null;
    if (selection instanceof SimpleType) {
        name = ((SimpleType) selection).getName();
    } else if (selection instanceof NameQualifiedType) {
        name = ((NameQualifiedType) selection).getName();
    } else if (selection instanceof QualifiedType) {
        name = ((QualifiedType) selection).getName();
    } else if (selection instanceof ParameterizedType) {
        final ParameterizedType type = (ParameterizedType) selection;
        final Type raw = type.getType();
        if (raw instanceof SimpleType)
            name = ((SimpleType) raw).getName();
        else if (raw instanceof NameQualifiedType)
            name = ((NameQualifiedType) raw).getName();
        else if (raw instanceof QualifiedType)
            name = ((QualifiedType) raw).getName();
    } else if (selection instanceof Name) {
        name = (Name) selection;
    }
    if (name == null)
        return null;
    if (name.isSimpleName()) {
        return (SimpleName) name;
    } else {
        return ((QualifiedName) name).getName();
    }
}
Also used : ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) IType(org.eclipse.jdt.core.IType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName)

Aggregations

QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)30 SimpleName (org.eclipse.jdt.core.dom.SimpleName)22 ASTNode (org.eclipse.jdt.core.dom.ASTNode)18 Name (org.eclipse.jdt.core.dom.Name)13 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)12 Expression (org.eclipse.jdt.core.dom.Expression)10 IBinding (org.eclipse.jdt.core.dom.IBinding)9 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)9 SimpleType (org.eclipse.jdt.core.dom.SimpleType)9 ArrayList (java.util.ArrayList)7 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)7 Type (org.eclipse.jdt.core.dom.Type)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)5 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)5 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)5 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)5 List (java.util.List)4 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)4 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)4