Java Code Examples for javax.lang.model.element.ElementKind.OTHER

The following are Jave code examples for showing how to use OTHER of the javax.lang.model.element.ElementKind 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: ReferencesCount.java   View Source Code Vote up 6 votes
/**
 * Returns an estimate of a number of classes on given source path (source root) which are
 * using given type.
 * @param type the type type to find the usage frequency for.
 * @return number of classes using the type.
 */
public int getTypeReferenceCount(@NonNull final ElementHandle<? extends TypeElement> type) {
    Parameters.notNull("binaryName", type);   //NOI18N
    if (!type.getKind().isClass() &&
        !type.getKind().isInterface() &&
         type.getKind() != ElementKind.OTHER) {
        throw new IllegalArgumentException(type.toString());
    }
    try {
        init();
        final Integer count = typeFreqs.get(SourceUtils.getJVMSignature(type)[0]);
        return count == null ? 0 : count;
    } catch (InterruptedException ie) {
        return 0;
    }
}
 
Example 2
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 6 votes
@CheckForNull
public static <T extends Element> ElementHandle<T> createElementHandle(@NonNull final T element) {
    //ElementKind OTHER represents errors <any>, <none>.
    //These are special errors which cannot be resolved
    if (element.getKind() == ElementKind.OTHER) {
        return null;
    }
    try {
        return ElementHandle.create(element);
    } catch (IllegalArgumentException e) {
        LOG.log(
                Level.INFO,
                "Unresolvable element: {0}, reason: {1}",    //NOI18N
                new Object[]{
                    element,
                    e.getMessage()
                });
        return null;
    }
}
 
Example 3
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 6 votes
public static boolean signatureEquals(
    @NonNull final ElementHandle<Element> handle,
    @NonNull final Element element) {
    if (handle == null) {
        return false;
    }
    //ElementKind OTHER represents errors <any>, <none>.
    //These are special errors which cannot be resolved
    if (element.getKind() == ElementKind.OTHER) {
        return false;
    }
    try {
        return handle.signatureEquals(element);
    } catch (IllegalArgumentException e) {
        LOG.log(
            Level.INFO,
            "Unresolvable element: {0}, reason: {1}",    //NOI18N
            new Object[]{
                element,
                e.getMessage()
            });
        return false;
    }
}
 
Example 4
Project: incubator-netbeans   File: ElementNode.java   View Source Code Vote up 6 votes
@NonNull
static Description directive(
        @NonNull final ClassMemberPanelUI ui,
        @NonNull final String name,
        @NonNull final TreePathHandle treePathHandle,
        @NonNull final ModuleElement.DirectiveKind kind,
        @NonNull final ClasspathInfo cpInfo,
        final long pos,
        @NonNull final Openable openable) {
    return new Description(
            ui,
            name,
            Union2.<ElementHandle<?>,TreePathHandle>createSecond(treePathHandle),
            ElementKind.OTHER,
            directivePosInKind(kind),
            cpInfo,
            EnumSet.of(Modifier.PUBLIC),
            pos,
            false,
            false,
            ()->ElementIcons.getModuleDirectiveIcon(kind),
            openable);
}
 
Example 5
Project: incubator-netbeans   File: ElementNode.java   View Source Code Vote up 6 votes
@NonNull
static Description directive(
        @NonNull final ClassMemberPanelUI ui,
        @NonNull final String name,
        @NonNull final ModuleElement.DirectiveKind kind,
        @NonNull final ClasspathInfo cpInfo,
        @NonNull final Openable openable) {
    return new Description(
            ui,
            name,
            null,
            ElementKind.OTHER,
            directivePosInKind(kind),
            cpInfo,
            EnumSet.of(Modifier.PUBLIC),
            -1,
            false,
            false,
            ()->ElementIcons.getModuleDirectiveIcon(kind),
            openable);
}
 
Example 6
Project: incubator-netbeans   File: ClassMemberPanelUI.java   View Source Code Vote up 6 votes
@CheckForNull
@Override
public Node findNode(@NonNull final Point loc) {
    final TreePath path = tree.getPathForLocation( loc.x, loc.y );
    if( null == path ) {
        return null;
    }
    final Node node = Visualizer.findNode( path.getLastPathComponent());
    if (!(node instanceof ElementNode)) {
        return null;
    }
    final ElementNode enode = (ElementNode) node;
    final ElementNode.Description desc = enode.getDescritption();
    //Other and module do not have javadoc
    return desc.kind != ElementKind.OTHER
        && desc.kind != ElementKind.MODULE ?
            node :
            null;
}
 
Example 7
Project: incubator-netbeans   File: ElementHandle.java   View Source Code Vote up 5 votes
private static boolean isSameKind (ElementKind k1, ElementKind k2) {
    if ((k1 == k2) ||
       (k1 == ElementKind.OTHER && (k2.isClass() || k2.isInterface())) ||     
       (k2 == ElementKind.OTHER && (k1.isClass() || k1.isInterface()))) {
        return true;
    }
    return false;
}
 
Example 8
Project: incubator-netbeans   File: ElementHandle.java   View Source Code Vote up 5 votes
/**
 * Returns a binary name of the {@link TypeElement} represented by this
 * {@link ElementHandle}. When the {@link ElementHandle} doesn't represent
 * a {@link TypeElement} it throws a {@link IllegalStateException}
 * @return the qualified name
 * @throws an {@link IllegalStateException} when this {@link ElementHandle} 
 * isn't created for the {@link TypeElement}.
 */
public @NonNull String getBinaryName () throws IllegalStateException {
    if ((this.kind.isClass() && !isArray(signatures[0])) ||
            this.kind.isInterface() ||
            this.kind == ElementKind.MODULE ||
            this.kind == ElementKind.OTHER) {
        return this.signatures[0];
    }
    else {
        throw new IllegalStateException ();
    }
}
 
Example 9
Project: incubator-netbeans   File: ElementHandle.java   View Source Code Vote up 5 votes
/**
 * Returns a qualified name of the {@link TypeElement} represented by this
 * {@link ElementHandle}. When the {@link ElementHandle} doesn't represent
 * a {@link TypeElement} it throws a {@link IllegalStateException}
 * @return the qualified name
 * @throws an {@link IllegalStateException} when this {@link ElementHandle} 
 * isn't creatred for the {@link TypeElement}.
 */
public @NonNull String getQualifiedName () throws IllegalStateException {
    if ((this.kind.isClass() && !isArray(signatures[0])) ||
            this.kind.isInterface() ||
            this.kind == ElementKind.MODULE ||
            this.kind == ElementKind.OTHER) {
        return this.signatures[0].replace (Target.DEFAULT.syntheticNameChar(),'.');    //NOI18N
    }
    else {
        throw new IllegalStateException ();
    }
}
 
Example 10
Project: incubator-netbeans   File: ElementHandle.java   View Source Code Vote up 5 votes
/**
 * Tests if the handle has this same signature as the parameter.
 * The handles has the same signatures if it is resolved into the same
 * element in the same {@link javax.tools.JavaCompiler} task, but may be resolved into
 * the different {@link Element} in the different {@link javax.tools.JavaCompiler} task.
 * @param element to be checked
 * @return true if this handle resolves into the same {@link Element}
 * in the same {@link javax.tools.JavaCompiler} task.
 */
public boolean signatureEquals (@NonNull final T element) {
    final ElementKind ek = element.getKind();
    final ElementKind thisKind = getKind();
    if ((ek != thisKind) && !(thisKind == ElementKind.OTHER && (ek.isClass() || ek.isInterface()))) {
        return false;
    }
    final ElementHandle<T> handle = create (element);
    return signatureEquals (handle);
}
 
Example 11
Project: incubator-netbeans   File: CodeStyle.java   View Source Code Vote up 5 votes
/**
 * Returns the group number of the class member. Elements with the same
 * number form a group. Groups with lower numbers should be positioned
 * higher in the class member list.
 * @param tree the member tree
 * @return the group number
 * @since 0.96
 */
public int getGroupId(Tree tree) {
    ElementKind kind = ElementKind.OTHER;
    Set<Modifier> modifiers = null;
    switch (tree.getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            kind = ElementKind.CLASS;
            modifiers = ((ClassTree)tree).getModifiers().getFlags();
            break;
        case METHOD:
            MethodTree mt = (MethodTree)tree;
            if (mt.getName().contentEquals("<init>")) { //NOI18N
                kind = ElementKind.CONSTRUCTOR;
            } else {
                kind = ElementKind.METHOD;
            }
            modifiers = mt.getModifiers().getFlags();
            break;
        case VARIABLE:
            kind = ElementKind.FIELD;
            modifiers = ((VariableTree)tree).getModifiers().getFlags();
            break;
        case BLOCK:
            kind = ((BlockTree)tree).isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
            break;
    }
    for (Info info : infos) {
        if (info.check(kind, modifiers))
            return info.groupId;
    }
    return infos.length;
}
 
Example 12
Project: incubator-netbeans   File: ElementNode.java   View Source Code Vote up 5 votes
@Override
public Action[] getActions( boolean context ) {
    if ( context || description.name == null ) {
        return description.ui.getActions();
    } else {
        final Action panelActions[] = description.ui.getActions();
        final List<? extends Action> standardActions;
        final List<? extends Action> additionalActions;
        if (description.kind == ElementKind.OTHER) {
            standardActions = Collections.singletonList(getOpenAction());
            additionalActions = Collections.<Action>emptyList();
        } else {
            standardActions = Arrays.asList(new Action[] {
                getOpenAction(),
                RefactoringActionsFactory.whereUsedAction(),
                RefactoringActionsFactory.popupSubmenuAction()
            });
            additionalActions = Utilities.actionsForPath(ACTION_FOLDER);
        }
        final int standardActionsSize = standardActions.isEmpty() ? 0 : standardActions.size() + 1;
        final int additionalActionSize = additionalActions.isEmpty() ? 0 : additionalActions.size() + 1;
        final List<Action> actions = new ArrayList<>(standardActionsSize + additionalActionSize + panelActions.length);
        if (standardActionsSize > 0) {
            actions.addAll(standardActions);
            actions.add(null);
        }
        if (additionalActionSize > 0) {
            actions.addAll(additionalActions);
            actions.add(null);
        }
        actions.addAll(Arrays.asList(panelActions));
        return actions.toArray(new Action[actions.size()]);
    }
}
 
Example 13
Project: incubator-netbeans   File: CaretListeningTask.java   View Source Code Vote up 5 votes
private void updateNavigatorSelection(CompilationInfo ci, TreePath tp) throws Exception {
    final ClassMemberPanel cmp = ClassMemberPanel.getInstance();
    if (cmp == null) {
        return;
    }
    final ClassMemberPanelUI cmpUi = cmp.getClassMemberPanelUI();
    if (!cmpUi.isAutomaticRefresh()) {
        cmpUi.getTask().runImpl(ci, false);
        lastEhForNavigator = null;
    }
    // Try to find the declaration we are in
    final Pair<Element,TreePath> p = outerElement(ci, tp);
    if (p != null) {
        final Element e = p.first();
        Runnable action = null;
        if (e == null) {
            //Directive
            lastEhForNavigator = null;
            action = () -> {
                cmp.selectTreePath(TreePathHandle.create(p.second(), ci));
            };
        } else if (e.getKind() != ElementKind.OTHER) {
            final ElementHandle<Element> eh = ElementHandle.create(e);
            if (lastEhForNavigator != null && eh.signatureEquals(lastEhForNavigator)) {
                return;
            }
            lastEhForNavigator = eh;
            action = () -> {
                cmp.selectElement(eh);
            };
        }
        if (action != null) {
            SwingUtilities.invokeLater(action);
        }
    }
}
 
Example 14
Project: incubator-netbeans   File: LayerBuilderTest.java   View Source Code Vote up 5 votes
public void testOriginatingElementComments() throws Exception {
    b = new LayerBuilder(doc, new Element() {
        public @Override ElementKind getKind() {
            return ElementKind.OTHER;
        }
        public @Override String toString() {
            return "originating.Type";
        }
        public @Override TypeMirror asType() {return null;}
        public @Override List<? extends AnnotationMirror> getAnnotationMirrors() {return null;}
        public @Override <A extends Annotation> A getAnnotation(Class<A> annotationType) {return null;}
        public @Override Set<Modifier> getModifiers() {return null;}
        public @Override Name getSimpleName() {return null;}
        public @Override Element getEnclosingElement() {return null;}
        public @Override List<? extends Element> getEnclosedElements() {return null;}
        public @Override <R, P> R accept(ElementVisitor<R, P> v, P p) {return null;}
        @Override
        public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
            return (A[]) Array.newInstance(annotationType, 0);
        }
    }, null);
    b.folder("f").write();
    assertEquals("<filesystem><folder name='f'><!--originating.Type--></folder></filesystem>", dump());
    // #180154: do not repeat after an incremental build
    b.folder("f").write();
    assertEquals("<filesystem><folder name='f'><!--originating.Type--></folder></filesystem>", dump());
}
 
Example 15
Project: openjdk-jdk10   File: Utils.java   View Source Code Vote up 5 votes
private DocCommentDuo getDocCommentTuple(Element element) {
    // prevent nasty things downstream with overview element
    if (element.getKind() != ElementKind.OTHER) {
        TreePath path = getTreePath(element);
        if (path != null) {
            DocCommentTree docCommentTree = docTrees.getDocCommentTree(path);
            return new DocCommentDuo(path, docCommentTree);
        }
    }
    return null;
}
 
Example 16
Project: incubator-netbeans   File: PersistentClassIndex.java   View Source Code Vote up 4 votes
@Override
public <T> void search (
        @NonNull final ElementHandle<?> element,
        @NonNull final Set<? extends UsageType> usageType,
        @NonNull final Set<? extends ClassIndex.SearchScopeType> scope,
        @NonNull final Convertor<? super Document, T> convertor,
        @NonNull final Set<? super T> result) throws InterruptedException, IOException {
    Parameters.notNull("element", element); //NOI18N
    Parameters.notNull("usageType", usageType); //NOI18N
    Parameters.notNull("scope", scope); //NOI18N
    Parameters.notNull("convertor", convertor); //NOI18N
    Parameters.notNull("result", result);   //NOI18N
    final Pair<Convertor<? super Document, T>,Index> ctu = indexPath.getPatch(convertor);
    try {
        final String binaryName = SourceUtils.getJVMSignature(element)[0];
        final ElementKind kind = element.getKind();
        if (kind == ElementKind.PACKAGE) {
            IndexManager.priorityAccess(() -> {
                final Query q = QueryUtil.scopeFilter(
                        QueryUtil.createPackageUsagesQuery(binaryName,usageType,Occur.SHOULD),
                        scope);
                if (q != null) {
                    index.query(result, ctu.first(), DocumentUtil.declaredTypesFieldSelector(false, false), cancel.get(), q);
                    if (ctu.second() != null) {
                        ctu.second().query(result, convertor, DocumentUtil.declaredTypesFieldSelector(false, false), cancel.get(), q);
                    }
                }
                return null;
            });
        } else if (kind.isClass() ||
                   kind.isInterface() ||
                   kind == ElementKind.OTHER) {
            if (BinaryAnalyser.OBJECT.equals(binaryName)) {
                getDeclaredElements(
                    "", //NOI18N
                    ClassIndex.NameKind.PREFIX,
                    scope,
                    DocumentUtil.declaredTypesFieldSelector(false, false),
                    convertor,
                    result);
            } else {
                IndexManager.priorityAccess(() -> {
                    final Query usagesQuery = QueryUtil.scopeFilter(
                            QueryUtil.createUsagesQuery(binaryName, usageType, Occur.SHOULD),
                            scope);
                    if (usagesQuery != null) {
                        index.query(result, ctu.first(), DocumentUtil.declaredTypesFieldSelector(false, false), cancel.get(), usagesQuery);
                        if (ctu.second() != null) {
                            ctu.second().query(result, convertor, DocumentUtil.declaredTypesFieldSelector(false, false), cancel.get(), usagesQuery);
                        }
                    }
                    return null;
                });
            }
        } else {
            throw new IllegalArgumentException(element.toString());
        }
    } catch (IOException ioe) {
        this.<Void,IOException>handleException(null, ioe, root);
    }
}
 
Example 17
Project: openjdk-jdk10   File: Symbol.java   View Source Code Vote up 4 votes
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.OTHER;       // most unkind
}
 
Example 18
Project: openjdk-jdk10   File: OverviewElement.java   View Source Code Vote up 4 votes
@Override
public ElementKind getKind() {
    return ElementKind.OTHER;
}
 
Example 19
Project: openjdk-jdk10   File: Utils.java   View Source Code Vote up 4 votes
public boolean isOverviewElement(Element e) {
    return e.getKind() == ElementKind.OTHER;
}
 
Example 20
Project: openjdk-jdk10   File: Utils.java   View Source Code Vote up 4 votes
/**
 * Retrieves the doc comments for a given element.
 * @param element
 * @return DocCommentTree for the Element
 */
public DocCommentTree getDocCommentTree0(Element element) {

    DocCommentDuo duo = null;

    ElementKind kind = element.getKind();
    if (kind == ElementKind.PACKAGE || kind == ElementKind.OTHER) {
        duo = dcTreeCache.get(element); // local cache
        if (!isValidDuo(duo) && kind == ElementKind.PACKAGE) {
            // package-info.java
            duo = getDocCommentTuple(element);
        }
        if (!isValidDuo(duo)) {
            // package.html or overview.html
            duo = configuration.cmtUtils.getHtmlCommentDuo(element); // html source
        }
    } else {
        duo = configuration.cmtUtils.getSyntheticCommentDuo(element);
        if (!isValidDuo(duo)) {
            duo = dcTreeCache.get(element); // local cache
        }
        if (!isValidDuo(duo)) {
            duo = getDocCommentTuple(element); // get the real mccoy
        }
    }

    DocCommentTree docCommentTree = isValidDuo(duo) ? duo.dcTree : null;
    TreePath path = isValidDuo(duo) ? duo.treePath : null;
    if (!dcTreeCache.containsKey(element)) {
        if (docCommentTree != null && path != null) {
            if (!configuration.isAllowScriptInComments()) {
                try {
                    javaScriptScanner.scan(docCommentTree, path, p -> {
                        throw new JavaScriptScanner.Fault();
                    });
                } catch (JavaScriptScanner.Fault jsf) {
                    String text = configuration.getText("doclet.JavaScript_in_comment");
                    throw new UncheckedDocletException(new SimpleDocletException(text, jsf));
                }
            }
            configuration.workArounds.runDocLint(path);
        }
        dcTreeCache.put(element, duo);
    }
    return docCommentTree;
}