javax.lang.model.element.ElementKind#OTHER源码实例Demo

下面列出了javax.lang.model.element.ElementKind#OTHER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ReferencesCount.java
/**
 * 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;
    }
}
 
源代码2 项目: netbeans   文件: Utils.java
@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;
    }
}
 
源代码3 项目: netbeans   文件: Utils.java
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;
    }
}
 
源代码4 项目: netbeans   文件: ElementNode.java
@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);
}
 
源代码5 项目: netbeans   文件: ElementNode.java
@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);
}
 
源代码6 项目: netbeans   文件: ClassMemberPanelUI.java
@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;
}
 
源代码7 项目: netbeans   文件: ElementHandle.java
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;
}
 
源代码8 项目: netbeans   文件: ElementHandle.java
/**
 * 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 ();
    }
}
 
源代码9 项目: netbeans   文件: ElementHandle.java
/**
 * 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 ();
    }
}
 
源代码10 项目: netbeans   文件: ElementHandle.java
/**
 * 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);
}
 
源代码11 项目: netbeans   文件: CodeStyle.java
/**
 * 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;
}
 
源代码12 项目: netbeans   文件: ElementNode.java
@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()]);
    }
}
 
源代码13 项目: netbeans   文件: CaretListeningTask.java
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);
        }
    }
}
 
源代码14 项目: openjdk-jdk9   文件: Utils.java
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;
}
 
源代码15 项目: lua-for-android   文件: Symbol.java
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.OTHER;       // most unkind
}
 
源代码16 项目: netbeans   文件: PersistentClassIndex.java
@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);
    }
}
 
源代码17 项目: openjdk-jdk9   文件: Symbol.java
@DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.OTHER;       // most unkind
}
 
源代码18 项目: openjdk-jdk9   文件: OverviewElement.java
@Override
public ElementKind getKind() {
    return ElementKind.OTHER;
}
 
源代码19 项目: openjdk-jdk9   文件: Utils.java
public boolean isOverviewElement(Element e) {
    return e.getKind() == ElementKind.OTHER;
}
 
源代码20 项目: openjdk-jdk9   文件: Utils.java
/**
 * 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;
}