Search in sources :

Example 66 with QualifiedName

use of org.eclipse.jdt.core.dom.QualifiedName in project eclipse.jdt.ls 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 67 with QualifiedName

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

the class SemanticTokensVisitor method visitSimpleNamesOfName.

/**
 * Helper method to recursively visit all the simple names of a {@link Name} node
 * using the specified {@link NodeVisitor}.
 *
 * @param name A {@link Name} node (may be {@code null}).
 * @param visitor The {@link NodeVisitor} to use.
 */
private void visitSimpleNamesOfName(Name name, NodeVisitor<SimpleName> visitor) {
    if (name == null) {
        return;
    }
    if (name instanceof SimpleName) {
        visitor.visit((SimpleName) name);
    } else {
        QualifiedName qualifiedName = (QualifiedName) name;
        visitSimpleNamesOfName(qualifiedName.getQualifier(), visitor);
        visitor.visit(qualifiedName.getName());
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName)

Example 68 with QualifiedName

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

the class SemanticTokensVisitor method nonPackageNameOfImportDeclarationVisitor.

/**
 * {@link NodeVisitor} for {@link Name} nodes inside an import declaration that are not package names.
 *
 * @param nonPackageName
 */
private void nonPackageNameOfImportDeclarationVisitor(Name nonPackageName) {
    if (nonPackageName instanceof SimpleName) {
        nonPackageName.accept(this);
    } else {
        QualifiedName qualifiedName = (QualifiedName) nonPackageName;
        Name qualifier = qualifiedName.getQualifier();
        if (hasPackageQualifier(qualifiedName)) {
            addTokenToSimpleNamesOfName(qualifier, TokenType.NAMESPACE);
        } else {
            nonPackageNameOfImportDeclarationVisitor(qualifier);
        }
        qualifiedName.getName().accept(this);
    }
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) 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)68 SimpleName (org.eclipse.jdt.core.dom.SimpleName)47 ASTNode (org.eclipse.jdt.core.dom.ASTNode)36 Name (org.eclipse.jdt.core.dom.Name)26 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)22 Expression (org.eclipse.jdt.core.dom.Expression)20 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)18 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)17 IBinding (org.eclipse.jdt.core.dom.IBinding)16 SimpleType (org.eclipse.jdt.core.dom.SimpleType)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)14 ArrayList (java.util.ArrayList)13 NameQualifiedType (org.eclipse.jdt.core.dom.NameQualifiedType)12 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)10 Type (org.eclipse.jdt.core.dom.Type)10 CastExpression (org.eclipse.jdt.core.dom.CastExpression)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)9 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)9 IType (org.eclipse.jdt.core.IType)8 Assignment (org.eclipse.jdt.core.dom.Assignment)8