Java Code Examples for javax.lang.model.element.ElementKind#MODULE

The following examples show how to use javax.lang.model.element.ElementKind#MODULE . 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: ElementJavadoc.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private StringBuilder getContainingClassOrPackageHeader(Element el, Elements elements, ElementUtilities eu) {
    StringBuilder sb = new StringBuilder();
    if (el.getKind() != ElementKind.PACKAGE && el.getKind() != ElementKind.MODULE) {
        TypeElement cls = eu.enclosingTypeElement(el);
        if (cls != null) {
            switch(cls.getEnclosingElement().getKind()) {
                case ANNOTATION_TYPE:
                case CLASS:
                case ENUM:
                case INTERFACE:
                case PACKAGE:
                    sb.append("<font size='+0'><b>"); //NOI18N
                    createLink(sb, cls, makeNameLineBreakable(cls.getQualifiedName().toString()));
                    sb.append("</b></font>"); //NOI18N)
            }
        } else {
            PackageElement pkg = elements.getPackageOf(el);
            if (pkg != null) {
                sb.append("<font size='+0'><b>"); //NOI18N
                createLink(sb, pkg, makeNameLineBreakable(pkg.getQualifiedName().toString()));
                sb.append("</b></font>"); //NOI18N)
            }
        }
    }
    return sb;
}
 
Example 2
Source File: Env.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
    currPath = path;
    currDocComment = comment;
    currElement = trees.getElement(currPath);
    currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);

    AccessKind ak = AccessKind.PUBLIC;
    for (TreePath p = path; p != null; p = p.getParentPath()) {
        Element e = trees.getElement(p);
        if (e != null && e.getKind() != ElementKind.PACKAGE && e.getKind() != ElementKind.MODULE) {
            ak = min(ak, AccessKind.of(e.getModifiers()));
        }
    }
    currAccess = ak;
}
 
Example 3
Source File: ClassMemberPanelUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: ElementUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether 'e' contains error or is missing. If the passed element is null
 * it's assumed the element could not be resolved and this method returns true. Otherwise,
 * the element's type kind is checked against error constants and finally the erroneous
 * state of the element is checked. 
 * 
 * @param e Element to check or {@code null}
 * @return true, if the element is missing (is {@code null}) or contains errors.
 */
public boolean isErroneous(@NullAllowed Element e) {
    if (e == null) {
        return true;
    }
    if (e.getKind() == ElementKind.MODULE && ((Symbol)e).kind == Kinds.Kind.ERR) {
        return true;
    }
    final TypeMirror type = e.asType();
    if (type == null) {
        return false;
    }
    if (type.getKind() == TypeKind.ERROR || type.getKind() == TypeKind.OTHER) {
        return true;
    }
    if (type instanceof Type) {
        if (((Type)type).isErroneous()) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: DocumentUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
static ElementKind decodeKind (char kind) {
    switch (kind) {
        case EK_CLASS:
        case EK_LOCAL_CLASS:
            return ElementKind.CLASS;
        case EK_INTERFACE:
        case EK_LOCAL_INTERFACE:
            return ElementKind.INTERFACE;
        case EK_ENUM:
        case EK_LOCAL_ENUM:
            return ElementKind.ENUM;
        case EK_ANNOTATION:
        case EK_LOCAL_ANNOTATION:
            return ElementKind.ANNOTATION_TYPE;
        case EK_MODULE:
            return ElementKind.MODULE;
        case EK_RECORD:
        case EK_LOCAL_RECORD:
            return ElementKind.valueOf("RECORD");
        default:
            throw new IllegalArgumentException ();
    }
}
 
Example 6
Source File: DocumentUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public FileObject convert (final Document doc) {
    final String binaryName = getBinaryName(doc, kindHolder);            
    return binaryName == null ?
            null :
            kindHolder[0] == ElementKind.MODULE ?
                resolveFile(FileObjects.MODULE_INFO) :
                convertType(binaryName);
}
 
Example 7
Source File: BinaryAnalyser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ElementKind getElementKind(@NonNull final ClassFile cf) {
    if (cf.isEnum()) {
        return ElementKind.ENUM;
    } else if (cf.isAnnotation()) {
        return ElementKind.ANNOTATION_TYPE;
    } else if (cf.isModule()) {
        return ElementKind.MODULE;
    } else if ((cf.getAccess() & Access.INTERFACE) == Access.INTERFACE) {
        return ElementKind.INTERFACE;
    } else {
        return ElementKind.CLASS;
    }
}
 
Example 8
Source File: ElementHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: ElementHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: ElementHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@link ElementHandle} representing a {@link ModuleElement}.
 * @param moduleName the name of the module
 * @return the created {@link ElementHandle}
 * @since 2.26
 */
@NonNull
public static ElementHandle<ModuleElement> createModuleElementHandle(
        @NonNull final String moduleName) {
    Parameters.notNull("moduleName", moduleName); //NOI18N
    return new ElementHandle<>(ElementKind.MODULE, moduleName);
}
 
Example 11
Source File: SemanticHighlighterBase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitMemberSelect(MemberSelectTree tree, Void p) {
    if (info.getTreeUtilities().isSynthetic(getCurrentPath()))
        return null;

    long memberSelectBypassLoc = memberSelectBypass;
    
    memberSelectBypass = -1;
    
    Element el = info.getTrees().getElement(getCurrentPath());
    
    if (el != null && el.getKind() == ElementKind.MODULE) {
        //Xxx
        handlePossibleIdentifier(getCurrentPath(), false);
        tl.moduleNameHere(tree, tree2Tokens);
        return null;
    }

    super.visitMemberSelect(tree, p);
    
    tl.moveToEnd(tree.getExpression());
    
    if (memberSelectBypassLoc != (-1)) {
        tl.moveToOffset(memberSelectBypassLoc);
    }
    
    handlePossibleIdentifier(getCurrentPath(), false);
    firstIdentifier(tree.getIdentifier().toString());
    addParameterInlineHint(tree);
    return null;
}
 
Example 12
Source File: UnusedImports.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean isErroneous(@NullAllowed Element e) {
    if (e == null) {
        return true;
    }
    if (e.getKind() == ElementKind.MODULE) {
        return false;
    }
    final TypeMirror type = e.asType();
    if (type == null) {
        return false;
    }
    return type.getKind() == TypeKind.ERROR || type.getKind() == TypeKind.OTHER;
}
 
Example 13
Source File: Checker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitProvides(ProvidesTree tree, Void ignore) {
    Element e = env.trees.getElement(env.currPath);
    if (e.getKind() != ElementKind.MODULE) {
        env.messages.error(REFERENCE, tree, "dc.invalid.provides");
    }
    ReferenceTree serviceType = tree.getServiceType();
    Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
    if (se == null) {
        env.messages.error(REFERENCE, tree, "dc.service.not.found");
    }
    return super.visitProvides(tree, ignore);
}
 
Example 14
Source File: Checker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitUses(UsesTree tree, Void ignore) {
    Element e = env.trees.getElement(env.currPath);
    if (e.getKind() != ElementKind.MODULE) {
        env.messages.error(REFERENCE, tree, "dc.invalid.uses");
    }
    ReferenceTree serviceType = tree.getServiceType();
    Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
    if (se == null) {
        env.messages.error(REFERENCE, tree, "dc.service.not.found");
    }
    return super.visitUses(tree, ignore);
}
 
Example 15
Source File: DocumentUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
public static Convertor<Document,ElementHandle<ModuleElement>> moduleElementConvertor() {
    return new ElementHandleConvertor<>(ElementKind.MODULE);
}
 
Example 16
Source File: Symbol.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.MODULE;
}
 
Example 17
Source File: Symbol.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.MODULE;
}
 
Example 18
Source File: Utils.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isModule(Element e) {
    return e.getKind() == ElementKind.MODULE;
}