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

The following examples show how to use javax.lang.model.util.Elements#isDeprecated() . 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: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 2
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 3
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 4
Source File: CheckSums.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 5
Source File: LazyJavaCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: LazyJavaCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
}