Java Code Examples for javax.lang.model.util.Elements.isDeprecated()

The following are Jave code examples for showing how to use isDeprecated() of the javax.lang.model.util.Elements class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: JavaCompletionTask.java   View Source Code Vote up 6 votes
private void addPackageContent(final Env env, PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, boolean insideNew, boolean srcOnly) throws IOException {
    Set<? extends TypeMirror> smartTypes = options.contains(Options.ALL_COMPLETION) ? null : getSmartTypes(env);
    CompilationController controller = env.getController();
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    ElementUtilities eu = controller.getElementUtilities();
    Scope scope = env.getScope();
    for (Element e : pe.getEnclosedElements()) {
        if (e.getKind().isClass() || e.getKind().isInterface()) {
            String name = e.getSimpleName().toString();
            if ((env.getExcludes() == null || !env.getExcludes().contains(e))
                    && startsWith(env, name) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, (TypeElement) e)
                    && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
                    && !Utilities.isExcluded(eu.getElementName(e, true))) {
                results.add(itemFactory.createTypeItem(env.getController(), (TypeElement) e, (DeclaredType) e.asType(), anchorOffset, null, elements.isDeprecated(e), insideNew, insideNew || env.isInsideClass(), true, isOfSmartType(env, e.asType(), smartTypes), false));
            }
        }
    }
    String pkgName = pe.getQualifiedName() + "."; //NOI18N
    addPackages(env, pkgName, srcOnly);
}
 
Example 2
Project: incubator-netbeans   File: JavaCompletionTask.java   View Source Code Vote up 6 votes
private void addTypes(Env env, EnumSet<ElementKind> kinds, DeclaredType baseType) throws IOException {
    if (options.contains(Options.ALL_COMPLETION)) {
        if (baseType == null) {
            addAllTypes(env, kinds);
        } else {
            Elements elements = env.getController().getElements();
            Set<? extends Element> excludes = env.getExcludes();
            for (DeclaredType subtype : getSubtypesOf(env, baseType)) {
                TypeElement elem = (TypeElement) subtype.asElement();
                if ((excludes == null || !excludes.contains(elem)) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(elem)) && !Utilities.isExcluded(elem.getQualifiedName()) && (!env.isAfterExtends() || !elem.getModifiers().contains(Modifier.FINAL))) {
                    results.add(itemFactory.createTypeItem(env.getController(), elem, subtype, anchorOffset, env.getReferencesCount(), elements.isDeprecated(elem), env.isInsideNew(), env.isInsideNew() || env.isInsideClass(), false, true, false));
                }
            }
        }
    } else {
        addLocalAndImportedTypes(env, kinds, baseType);
        hasAdditionalClasses = true;
    }
    addPackages(env, null, kinds.isEmpty());
}
 
Example 3
Project: incubator-netbeans   File: JavadocCompletionQuery.java   View Source Code Vote up 6 votes
private void addTypes(EnumSet<ElementKind> kinds, DeclaredType baseType,
        Set<? extends Element> toExclude, String prefix,
        int substitutionOffset, JavadocContext jdctx) {
    
    if (queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
        if (baseType == null) {
            addAllTypes(jdctx, kinds, toExclude, prefix, substitutionOffset);
        } else {
            Elements elements = jdctx.javac.getElements();
            for(DeclaredType subtype : getSubtypesOf(baseType, prefix, jdctx)) {
                TypeElement elem = (TypeElement)subtype.asElement();
                if ((toExclude == null || !toExclude.contains(elem)) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(elem)))
                    items.add(JavaCompletionItem.createTypeItem(jdctx.javac, elem, subtype, substitutionOffset, jdctx.getReferencesCount(), elements.isDeprecated(elem), false, false, false, false, false, null));
            }
        }
    } else {
        addLocalAndImportedTypes(jdctx, kinds, baseType, toExclude, prefix, substitutionOffset);
        hasAdditionalItems = true;
    }
}
 
Example 4
Project: incubator-netbeans   File: JavadocCompletionQuery.java   View Source Code Vote up 6 votes
private void addInnerClasses(TypeElement te, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for (Element e : controller.getElementUtilities().getMembers(te.asType(), null)) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e)) && trees.isAccessible(scope, (TypeElement)e) && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: JavadocCompletionQuery.java   View Source Code Vote up 6 votes
private void addPackageContent(PackageElement pe, EnumSet<ElementKind> kinds, DeclaredType baseType, Set<? extends Element> toExclude, String prefix, int substitutionOffset, JavadocContext jdctx) {
    CompilationInfo controller = jdctx.javac;
    Element srcEl = jdctx.handle.resolve(controller);
    Elements elements = controller.getElements();
    Types types = controller.getTypes();
    Trees trees = controller.getTrees();
    TreeUtilities tu = controller.getTreeUtilities();
    ElementUtilities eu = controller.getElementUtilities();
    TreePath docpath = srcEl != null ? trees.getPath(srcEl) : null;
    Scope scope = docpath != null ? trees.getScope(docpath) : tu.scopeFor(caretOffset);
    for(Element e : pe.getEnclosedElements()) {
        if ((e.getKind().isClass() || e.getKind().isInterface()) && (toExclude == null || !toExclude.contains(e))) {
            String name = e.getSimpleName().toString();
                if (Utilities.startsWith(name, prefix) && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, (TypeElement)e)
                    && isOfKindAndType(e.asType(), e, kinds, baseType, scope, trees, types)
                    && !Utilities.isExcluded(eu.getElementName(e, true))) {
                    items.add(JavadocCompletionItem.createTypeItem(jdctx.javac, (TypeElement) e, substitutionOffset, null, elements.isDeprecated(e)/*, isOfSmartType(env, e.asType(), smartTypes)*/));
            }
        }
    }
}
 
Example 6
Project: incubator-netbeans   File: JavaCompletionItem.java   View Source Code Vote up 6 votes
public static JavaCompletionItem createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements, WhiteListQuery.WhiteList whiteList) {
    int dim = 0;
    TypeMirror tm = type;
    while(tm.getKind() == TypeKind.ARRAY) {
        tm = ((ArrayType)tm).getComponentType();
        dim++;
    }
    if (tm.getKind().isPrimitive()) {
        return new KeywordItem(tm.toString(), dim, null, substitutionOffset, true);
    }
    if (tm.getKind() == TypeKind.DECLARED || tm.getKind() == TypeKind.ERROR) {
        DeclaredType dt = (DeclaredType)tm;
        TypeElement elem = (TypeElement)dt.asElement();
        switch (elem.getKind()) {
            case CLASS:
                return new ClassItem(info, elem, dt, dim, substitutionOffset, referencesCount, elements.isDeprecated(elem), false, false, false, true, false, whiteList);
            case INTERFACE:
                return new InterfaceItem(info, elem, dt, dim, substitutionOffset, referencesCount, elements.isDeprecated(elem), false, false, false, true, false, whiteList);
            case ENUM:
                return new EnumItem(info, elem, dt, dim, substitutionOffset, referencesCount, elements.isDeprecated(elem), false, false, true, false, whiteList);
            case ANNOTATION_TYPE:
                return new AnnotationTypeItem(info, elem, dt, dim, substitutionOffset, referencesCount, elements.isDeprecated(elem), false, false, true, false, whiteList);
        }
    }
    throw new IllegalArgumentException("array element kind=" + tm.getKind());
}
 
Example 7
Project: incubator-netbeans   File: CheckSums.java   View Source Code Vote up 5 votes
private static String getExtendedModifiers(Elements elements, Element el) {
    StringBuilder sb = new StringBuilder();
    for (Modifier m : el.getModifiers())
        sb.append(m.name());
    if (elements.isDeprecated(el))
        sb.append(DEPRECATED);
    if (el.getKind() == ElementKind.FIELD) {
        Object v = ((VariableElement) el).getConstantValue();
        if (v != null) {
            sb.append(v.getClass().getName());
            sb.append(String.valueOf(v));
        }
    }
    return sb.toString();
}
 
Example 8
Project: incubator-netbeans   File: JavaCompletionTask.java   View Source Code Vote up 5 votes
private void insideCatch(Env env) throws IOException {
    TreePath path = env.getPath();
    CatchTree ct = (CatchTree) path.getLeaf();
    CompilationController controller = env.getController();
    TokenSequence<JavaTokenId> last = findLastNonWhitespaceToken(env, ct, env.getOffset());
    if (last != null && last.token().id() == JavaTokenId.LPAREN) {
        addKeyword(env, FINAL_KEYWORD, SPACE, false);
        if (!options.contains(Options.ALL_COMPLETION)) {
            TreeUtilities tu = controller.getTreeUtilities();
            TreePath tryPath = tu.getPathElementOfKind(Tree.Kind.TRY, path);
            Set<TypeMirror> exs = tu.getUncaughtExceptions(tryPath != null ? tryPath : path.getParentPath());
            Elements elements = controller.getElements();
            for (TypeMirror ex : exs) {
                if (ex.getKind() == TypeKind.DECLARED && startsWith(env, ((DeclaredType) ex).asElement().getSimpleName().toString())
                        && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(((DeclaredType) ex).asElement()))
                        && !Utilities.isExcluded(((TypeElement)((DeclaredType) ex).asElement()).getQualifiedName())) {
                    env.addToExcludes(((DeclaredType) ex).asElement());
                    results.add(itemFactory.createTypeItem(env.getController(), (TypeElement) ((DeclaredType) ex).asElement(), (DeclaredType) ex, anchorOffset, env.getReferencesCount(), elements.isDeprecated(((DeclaredType) ex).asElement()), false, false, false, true, false));
                }
            }
        }
        TypeElement te = controller.getElements().getTypeElement("java.lang.Throwable"); //NOI18N
        if (te != null) {
            addTypes(env, EnumSet.of(CLASS, INTERFACE, TYPE_PARAMETER), controller.getTypes().getDeclaredType(te));
        }
    }
}
 
Example 9
Project: incubator-netbeans   File: JavaCompletionTask.java   View Source Code Vote up 5 votes
private void insideUnionType(Env env) throws IOException {
    TreePath path = env.getPath();
    UnionTypeTree dtt = (UnionTypeTree) path.getLeaf();
    CompilationController controller = env.getController();
    TokenSequence<JavaTokenId> last = findLastNonWhitespaceToken(env, dtt, env.getOffset());
    if (last != null && last.token().id() == JavaTokenId.BAR) {
        if (!options.contains(Options.ALL_COMPLETION)) {
            TreeUtilities tu = controller.getTreeUtilities();
            TreePath tryPath = tu.getPathElementOfKind(Tree.Kind.TRY, path);
            Set<TypeMirror> exs = tu.getUncaughtExceptions(tryPath);
            if (!exs.isEmpty()) {
                Trees trees = controller.getTrees();
                Types types = controller.getTypes();
                for (Tree t : dtt.getTypeAlternatives()) {
                    TypeMirror tm = trees.getTypeMirror(new TreePath(path, t));
                    if (tm != null && tm.getKind() != TypeKind.ERROR) {
                        for (Iterator<TypeMirror> it = exs.iterator(); it.hasNext();) {
                            if (types.isSubtype(tm, it.next())) {
                                it.remove();
                            }
                        }
                    }
                }
                Elements elements = controller.getElements();
                for (TypeMirror ex : exs) {
                    if (ex.getKind() == TypeKind.DECLARED && startsWith(env, ((DeclaredType) ex).asElement().getSimpleName().toString())
                            && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(((DeclaredType) ex).asElement()))
                            && !Utilities.isExcluded(((TypeElement)((DeclaredType) ex).asElement()).getQualifiedName())) {
                        env.addToExcludes(((DeclaredType) ex).asElement());
                        results.add(itemFactory.createTypeItem(env.getController(), (TypeElement) ((DeclaredType) ex).asElement(), (DeclaredType) ex, anchorOffset, env.getReferencesCount(), elements.isDeprecated(((DeclaredType) ex).asElement()), false, false, false, true, false));
                    }
                }
            }
        }
        TypeElement te = controller.getElements().getTypeElement("java.lang.Throwable"); //NOI18N
        if (te != null) {
            addTypes(env, EnumSet.of(CLASS, INTERFACE, TYPE_PARAMETER), controller.getTypes().getDeclaredType(te));
        }
    }
}
 
Example 10
Project: incubator-netbeans   File: LazyJavaCompletionItem.java   View Source Code Vote up 5 votes
@Override
protected JavaCompletionItem getDelegate(CompilationInfo info, Scope scope, TypeElement te) {
    Elements elements = info.getElements();
    if (te != null && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(te)) && info.getTrees().isAccessible(scope, te)) {
        if (isOfKind(te, kinds) && (!afterExtends || !te.getModifiers().contains(Modifier.FINAL)) && (!isInDefaultPackage(te) || isInDefaultPackage(scope.getEnclosingClass())) && !Utilities.isExcluded(te.getQualifiedName())) {
            return createTypeItem(info, te, (DeclaredType) te.asType(), substitutionOffset, referencesCount, elements.isDeprecated(te), insideNew, addTypeVars, false, false, false, getWhiteList());
        }
    }
    return null;
}
 
Example 11
Project: incubator-netbeans   File: LazyJavaCompletionItem.java   View Source Code Vote up 5 votes
@Override
protected JavaCompletionItem getDelegate(CompilationInfo info, Scope scope, TypeElement te) {
    Elements elements = info.getElements();
    Trees trees = info.getTrees();
    if (te != null) {
        Element element = null;
        boolean multiVersion = false;
        for (Element e : te.getEnclosedElements()) {
            if ((e.getKind().isField() || e.getKind() == ElementKind.METHOD)
                    && name.contentEquals(Utilities.isCaseSensitive() ? e.getSimpleName() : e.getSimpleName().toString().toLowerCase())
                    && e.getModifiers().contains(Modifier.STATIC)
                    && (Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(e))
                    && trees.isAccessible(scope, e, (DeclaredType) te.asType())) {
                if (element != null) {
                    multiVersion = true;
                    break;
                }
                element = e;
            }
        }
        if (element != null) {
            name = element.getSimpleName().toString();
            return createStaticMemberItem(info, (DeclaredType) te.asType(), element, element.asType(), multiVersion, substitutionOffset, elements.isDeprecated(element), addSemicolon, getWhiteList());
        }
    }
    return null;
}
 
Example 12
Project: incubator-netbeans   File: JavaCompletionTask.java   View Source Code Vote up 4 votes
private void insideParens(Env env) throws IOException {
    TreePath path = env.getPath();
    ParenthesizedTree pa = (ParenthesizedTree) path.getLeaf();
    SourcePositions sourcePositions = env.getSourcePositions();
    CompilationUnitTree root = env.getRoot();
    Tree exp = unwrapErrTree(pa.getExpression());
    if (exp == null || env.getOffset() <= sourcePositions.getStartPosition(root, exp)) {
        if (!options.contains(Options.ALL_COMPLETION) && path.getParentPath().getLeaf().getKind() != Tree.Kind.SWITCH) {
            Set<? extends TypeMirror> smarts = getSmartTypes(env);
            if (smarts != null) {
                Elements elements = env.getController().getElements();
                for (TypeMirror smart : smarts) {
                    if (smart != null) {
                        if (smart.getKind() == TypeKind.DECLARED) {
                            for (DeclaredType subtype : getSubtypesOf(env, (DeclaredType) smart)) {
                                TypeElement elem = (TypeElement) subtype.asElement();
                                if ((Utilities.isShowDeprecatedMembers() || !elements.isDeprecated(elem)) && !Utilities.isExcluded(elem.getQualifiedName())) {
                                    results.add(itemFactory.createTypeItem(env.getController(), elem, subtype, anchorOffset, env.getReferencesCount(), elements.isDeprecated(elem), false, false, false, true, false));
                                }
                                env.addToExcludes(elem);
                            }
                        } else if (smart.getKind() == TypeKind.ARRAY) {
                            try {
                                TypeMirror tm = smart;
                                while (tm.getKind() == TypeKind.ARRAY) {
                                    tm = ((ArrayType) tm).getComponentType();
                                }
                                if (tm.getKind().isPrimitive() && startsWith(env, tm.toString())) {
                                    results.add(itemFactory.createArrayItem(env.getController(), (ArrayType) smart, anchorOffset, env.getReferencesCount(), env.getController().getElements()));
                                } else if ((tm.getKind() == TypeKind.DECLARED || tm.getKind() == TypeKind.ERROR) && startsWith(env, ((DeclaredType) tm).asElement().getSimpleName().toString())) {
                                    results.add(itemFactory.createArrayItem(env.getController(), (ArrayType) smart, anchorOffset, env.getReferencesCount(), env.getController().getElements()));
                                }
                            } catch (IllegalArgumentException iae) {
                            }
                        }
                    }
                }
            }
        }
        addLocalMembersAndVars(env);
        addTypes(env, EnumSet.of(CLASS, INTERFACE, ENUM, ANNOTATION_TYPE, TYPE_PARAMETER), null);
        addPrimitiveTypeKeywords(env);
        addValueKeywords(env);
    } else {
        insideExpression(env, new TreePath(path, exp));
    }
}