Java Code Examples for com.sun.source.tree.Tree.Kind#PARAMETERIZED_TYPE

The following examples show how to use com.sun.source.tree.Tree.Kind#PARAMETERIZED_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementOverlay.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String fqnFor(Tree t) {
    Element el = ASTService.getElementImpl(t);

    if (el != null) {
        if (el.getKind().isClass() || el.getKind().isInterface() || el.getKind() == ElementKind.PACKAGE) {
            return ((QualifiedNameable) el).getQualifiedName().toString();
        } else {
            Logger.getLogger(ElementOverlay.class.getName()).log(Level.SEVERE, "Not a QualifiedNameable: {0}", el);
            return null;
        }
    } else if (t instanceof QualIdentTree) {
        return ((QualIdentTree) t).getFQN();
    } else if (t.getKind() == Kind.PARAMETERIZED_TYPE) {
        return fqnFor(((ParameterizedTypeTree) t).getType());
    } else {
        Logger.getLogger(ElementOverlay.class.getName()).log(Level.FINE, "No element and no QualIdent");
        return null;
    }
}
 
Example 2
Source File: UnusedImports.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void typeUsed(Element decl, TreePath expr, boolean methodInvocation) {
    if (decl != null && (expr == null || expr.getLeaf().getKind() == Kind.IDENTIFIER || expr.getLeaf().getKind() == Kind.PARAMETERIZED_TYPE)) {
        if (!isErroneous(decl)) {
            ImportTree imp = element2Import.get(decl);

            if (imp != null) {
                addUsage(imp);
                if (isStar(imp)) {
                    //TODO: explain
                    handleUnresolvableImports(decl, methodInvocation, false);
                }
            }
        } else {
            handleUnresolvableImports(decl, methodInvocation, true);
            
            for (Entry<Element, ImportTree> e : element2Import.entrySet()) {
                if (importedBySingleImport.contains(e.getKey())) continue;
                
                if (e.getKey().getSimpleName().equals(decl.getSimpleName())) {
                    import2Highlight.remove(e.getValue());
                }
            }
        }
    }
}
 
Example 3
Source File: CreateElementUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    NewClassTree nct = (NewClassTree) parent.getLeaf();
    boolean errorInRealArguments = false;
    
    for (Tree param : nct.getArguments()) {
        errorInRealArguments |= param == error;
    }
    
    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }

    Tree id = nct.getIdentifier();

    if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
        id = ((ParameterizedTypeTree) id).getType();
    }

    if (id == error) {
        return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
    }
    
    return null;
}
 
Example 4
Source File: CreateElementUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> computeNewClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    NewClassTree nct = (NewClassTree) parent.getLeaf();
    boolean errorInRealArguments = false;
    
    for (Tree param : nct.getArguments()) {
        errorInRealArguments |= param == error;
    }
    
    if (errorInRealArguments) {
        List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>();
        int[] proposedIndex = new int[1];
        List<ExecutableElement> ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex);
        
        if (ee.isEmpty()) { //cannot be resolved
            return null;
        }
        
        types.add(ElementKind.PARAMETER);
        types.add(ElementKind.LOCAL_VARIABLE);
        types.add(ElementKind.FIELD);
        
        return proposedTypes;
    }

    Tree id = nct.getIdentifier();

    if (id.getKind() == Kind.PARAMETERIZED_TYPE) {
        id = ((ParameterizedTypeTree) id).getType();
    }

    if (id == error) {
        return resolveType(EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null);
    }
    
    return null;
}
 
Example 5
Source File: Utilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String simpleName(Tree t) {
    if (t == null) {
        return Bundle.DisplayName_Unknown();
    }
    if (t.getKind() == Kind.IDENTIFIER) {
        return ((IdentifierTree) t).getName().toString();
    }

    if (t.getKind() == Kind.MEMBER_SELECT) {
        return ((MemberSelectTree) t).getIdentifier().toString();
    }

    if (t.getKind() == Kind.METHOD_INVOCATION) {
        return scan(t, null);
    }

    if (t.getKind() == Kind.PARAMETERIZED_TYPE) {
        return simpleName(((ParameterizedTypeTree) t).getType()) + "<...>"; // NOI18N
    }

    if (t.getKind() == Kind.ARRAY_ACCESS) {
        return simpleName(((ArrayAccessTree) t).getExpression()) + "[]"; //NOI18N
    }

    if (t.getKind() == Kind.PARENTHESIZED) {
        return "(" + simpleName(((ParenthesizedTree)t).getExpression()) + ")"; //NOI18N
    }

    if (t.getKind() == Kind.TYPE_CAST) {
        return simpleName(((TypeCastTree)t).getType());
    }

    if (t.getKind() == Kind.ARRAY_TYPE) {
        return simpleName(((ArrayTypeTree)t).getType());
    }

    if (t.getKind() == Kind.PRIMITIVE_TYPE) {
        return ((PrimitiveTypeTree) t).getPrimitiveTypeKind().name().toLowerCase();
    }
    
    throw new IllegalStateException("Currently unsupported kind of tree: " + t.getKind()); // NOI18N
}