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

The following examples show how to use javax.lang.model.element.ElementKind#MODULE . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: ElementJavadoc.java    License: 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 Project: netbeans   File: DocumentUtil.java    License: 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 3
Source Project: netbeans   File: ElementUtilities.java    License: 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 4
Source Project: netbeans   File: ClassMemberPanelUI.java    License: 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 5
Source Project: openjdk-jdk9   File: Env.java    License: 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 6
Source Project: netbeans   File: DocumentUtil.java    License: 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 Project: netbeans   File: BinaryAnalyser.java    License: 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 Project: netbeans   File: ElementHandle.java    License: 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 Project: netbeans   File: ElementHandle.java    License: 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 Project: netbeans   File: ElementHandle.java    License: 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
@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 Project: netbeans   File: UnusedImports.java    License: 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
@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
@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
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.MODULE;
}
 
Example 16
Source Project: netbeans   File: DocumentUtil.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static Convertor<Document,ElementHandle<ModuleElement>> moduleElementConvertor() {
    return new ElementHandleConvertor<>(ElementKind.MODULE);
}
 
Example 17
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public ElementKind getKind() {
    return ElementKind.MODULE;
}
 
Example 18
Source Project: openjdk-jdk9   File: Utils.java    License: GNU General Public License v2.0 4 votes vote down vote up
public boolean isModule(Element e) {
    return e.getKind() == ElementKind.MODULE;
}