当前位置: 首页>>代码示例>>Java>>正文


Java TypeElement.getModifiers方法代码示例

本文整理汇总了Java中javax.lang.model.element.TypeElement.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getModifiers方法的具体用法?Java TypeElement.getModifiers怎么用?Java TypeElement.getModifiers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.TypeElement的用法示例。


在下文中一共展示了TypeElement.getModifiers方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isVisible

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private boolean isVisible(String myPackage, TypeElement typeElement) {
    Set<Modifier> modifiers = typeElement.getModifiers();
    boolean visible;
    if (modifiers.contains(Modifier.PUBLIC)) {
        visible = true;
    } else if (modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.PROTECTED)) {
        visible = false;
    } else {
        String subscriberPackage = getPackageElement(typeElement).getQualifiedName().toString();
        if (myPackage == null) {
            visible = subscriberPackage.length() == 0;
        } else {
            visible = myPackage.equals(subscriberPackage);
        }
    }
    return visible;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:EventBusAnnotationProcessor.java

示例2: isDeclaredAsJavaBean

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static String isDeclaredAsJavaBean(TypeElement clazz) {
    if (ElementKind.CLASS != clazz.getKind()) {
        return PaletteUtils.getBundleString("MSG_notAClass"); // NOI18N
    }

    Set<javax.lang.model.element.Modifier> mods = clazz.getModifiers();
    if (mods.contains(javax.lang.model.element.Modifier.ABSTRACT)) {
        return PaletteUtils.getBundleString("MSG_abstractClass"); // NOI18N
    }

    if (!mods.contains(javax.lang.model.element.Modifier.PUBLIC)) {
        return PaletteUtils.getBundleString("MSG_notPublic"); // NOI18N
    }
    
    for (Element member : clazz.getEnclosedElements()) {
        mods = member.getModifiers();
        if (ElementKind.CONSTRUCTOR == member.getKind() &&
                mods.contains(javax.lang.model.element.Modifier.PUBLIC) &&
                ((ExecutableElement) member).getParameters().isEmpty()) {
            return null;
        }
    }
    
    return PaletteUtils.getBundleString("MSG_noPublicConstructor"); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:BeanInstaller.java

示例3: ClassEntity

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * @param elementUtils
 * @param typeUtils
 * @param element      current anntated class
 */
public ClassEntity(Elements elementUtils, Types typeUtils, TypeElement element) {
    elementWeakCache = new WeakReference<TypeElement>(element);
    this.classPackageName = elementUtils.getPackageOf(element).getQualifiedName().toString();
    this.modifierSet = element.getModifiers();
    this.className = element.toString();
    annotationMirrors = element.getAnnotationMirrors();
    this.classSimpleName = element.getSimpleName();
    this.classQualifiedName = element.getQualifiedName();
    if ("java.lang.Object".equals(element.getSuperclass().toString())){
        this.superclass = null;
    }else{
        this.superclass = element.getSuperclass().toString();
    }
    List<? extends TypeMirror> interfaces = element.getInterfaces();

    for (TypeMirror anInterface : interfaces){
        this.interfaces.add(typeUtils.asElement(anInterface).toString());
    }
}
 
开发者ID:simplezhli,项目名称:RxPay,代码行数:25,代码来源:ClassEntity.java

示例4: visitType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Void visitType(TypeElement e, Void p) {
    if (isNonPrivate(e)) {
        PubApi prevApi = collectedApi;
        collectedApi = new PubApi();
        super.visitType(e, p);
        if (!isAnonymous(e)) {
            String name = ((ClassSymbol) e).flatname.toString();
            PubType t = new PubType(e.getModifiers(),
                                    name,
                                    //e.getQualifiedName().toString(),
                                    collectedApi);
            prevApi.types.put(t.fqName, t);
        }
        collectedApi = prevApi;
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PubapiVisitor.java

示例5: verify

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * 校验{@code moduleElement}的合法性
 *
 * @param moduleElement 携带@XModule的Element
 * @throws ProcessException
 */
private void verify(Element moduleElement) throws ProcessException {
    XModule XModule = moduleElement.getAnnotation(XModule.class);
    // 检验XModule注解
    if (XModule == null) {
        throw new ProcessException(
                String.format("当前的element(%s)未携带%s注解",
                        moduleElement.toString(),
                        XModule.class.getSimpleName()));
    } else if (XModule.name() == null || XModule.name().isEmpty()) {
        throw new ProcessException(String.format("%s的组件名不能为空", moduleElement.toString()));
    }

    // 检验被XModule注解的是否为class
    if (moduleElement.getKind() != ElementKind.CLASS) {
        throw new ProcessException(
                String.format("%s不是类,只有类才能使用%s",
                        moduleElement.toString(),
                        XModule.class.getSimpleName()));
    }

    TypeElement classElement = (TypeElement) moduleElement;

    // 检验类修饰符
    Set<Modifier> modifiers = classElement.getModifiers();
    if (!modifiers.contains(Modifier.PUBLIC)) {
        throw new ProcessException(
                String.format("被%s注解的%s的权限修饰符必须为public",
                        XModule.class.getSimpleName(),
                        classElement.getQualifiedName().toString()));
    }
    if (modifiers.contains(Modifier.ABSTRACT)) {
        throw new ProcessException(
                String.format("%s是抽象类,不能被%s注解",
                        classElement.getQualifiedName().toString(),
                        XModule.class.getSimpleName()));
    }
}
 
开发者ID:xpleemoon,项目名称:XModulable,代码行数:44,代码来源:XModuleProcessor.java

示例6: checkClassVisibility

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static void checkClassVisibility(Elements eles, TypeElement target, String fromPkg) {
    Set<Modifier> targetMods = target.getModifiers();
    if (!isNestedClass(target)) {
        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    } else {
        Element surround = target.getEnclosingElement();

        if (surround.getKind() != CLASS
                && surround.getKind() != INTERFACE
                // Not sure if that is allowed, but we include it anyways.
                && surround.getKind() != ENUM) {
            throw new IllegalStateException(
                    target.toString() + " is not nested? " + surround.toString());
        }

        TypeElement enclosingType = (TypeElement) surround;

        // The surrounding class must be visible for us to see the nested class
        if (!isElementVisibleFrom(eles, enclosingType, fromPkg)) {
            throw new EasyPluginException(enclosingType.toString()
                    + " is not visible from output package; need for access to " + target.toString());
        }
        // Nested class must be static since we don't have an enclosing instance
        if (!targetMods.contains(Modifier.STATIC)) {
            throw new EasyPluginException(target.toString() + " must be static.");
        }

        simpleVisibility(target.getModifiers(), eles.getPackageOf(target), fromPkg, target);
    }
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:31,代码来源:Util.java

示例7: getClassHeader

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private StringBuilder getClassHeader(TypeElement cdoc) {
    StringBuilder sb = new StringBuilder();
    sb.append("<pre>"); //NOI18N
    cdoc.getAnnotationMirrors().forEach((annotationDesc) -> {
        appendAnnotation(sb, annotationDesc, true);
    });
    for (Modifier modifier : cdoc.getModifiers()) {
        switch(cdoc.getKind()) {
            case ENUM:
                if (modifier == Modifier.FINAL)
                    continue;
                break;
            case INTERFACE:
            case ANNOTATION_TYPE:
                if (modifier == Modifier.ABSTRACT)
                    continue;
                break;                     
        }
        sb.append(modifier).append(' '); //NOI18N
    }
    switch (cdoc.getKind()) {
        case ANNOTATION_TYPE:
            sb.append("@interface "); //NOI18N
            break;
        case ENUM:
            sb.append("enum "); //NOI18N
            break;
        case INTERFACE:
            sb.append("interface "); //NOI18N
            break;
        default:
            sb.append("class "); //NOI18N            
    }
    sb.append("<b>").append(cdoc.getSimpleName()); //NOI18N
    List<? extends TypeParameterElement> typeParams = cdoc.getTypeParameters();
    if (!typeParams.isEmpty()) {
        sb.append("&lt;"); //NOI18N
        for (Iterator<? extends TypeParameterElement> it = typeParams.iterator(); it.hasNext();) {
            TypeParameterElement typeParam = it.next();
            appendType(sb, typeParam.asType(), false, true, false);
            if (it.hasNext())
                sb.append(","); //NOI18N
        }
        sb.append("&gt;"); //NOI18N
    }
    sb.append("</b>"); //NOi18N
    if (cdoc.getKind() != ElementKind.ANNOTATION_TYPE) {
        TypeMirror supercls = cdoc.getSuperclass();
        if (supercls != null && supercls.getKind() != TypeKind.NONE) {
            sb.append("<br>extends "); //NOI18N
            appendType(sb, supercls, false, false, false);            
        }
        List<? extends TypeMirror> ifaces = cdoc.getInterfaces();
        if (!ifaces.isEmpty()) {
            sb.append(cdoc.getKind().isInterface() ? "<br>extends " : "<br>implements "); //NOI18N
            for (Iterator<? extends TypeMirror> it = ifaces.iterator(); it.hasNext();) {
                TypeMirror iface = it.next();
                appendType(sb, iface, false, false, false);
                if (it.hasNext())
                    sb.append(", "); //NOI18N
            }            
        }
    }
    sb.append("</pre>"); //NOI18N
    return sb;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:ElementJavadoc.java

示例8: ClassValidator

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
ClassValidator(TypeElement annotatedClass) {
  this.annotatedClass = annotatedClass;
  this.modifiers = annotatedClass.getModifiers();
}
 
开发者ID:Comcast,项目名称:resourceprovider,代码行数:5,代码来源:ClassValidator.java

示例9: isLegalImplementation

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
protected boolean isLegalImplementation(WebService webService, TypeElement classElement) {
    boolean isStateful = isStateful(classElement);

    Collection<Modifier> modifiers = classElement.getModifiers();
    if (!modifiers.contains(Modifier.PUBLIC)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_NOT_PUBLIC(classElement.getQualifiedName()), classElement);
        return false;
    }
    if (modifiers.contains(Modifier.FINAL) && !isStateful) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_FINAL(classElement.getQualifiedName()), classElement);
        return false;
    }
    if (modifiers.contains(Modifier.ABSTRACT) && !isStateful) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_ABSTRACT(classElement.getQualifiedName()), classElement);
        return false;
    }
    boolean hasDefaultConstructor = false;
    for (ExecutableElement constructor : ElementFilter.constructorsIn(classElement.getEnclosedElements())) {
        if (constructor.getModifiers().contains(Modifier.PUBLIC) &&
                constructor.getParameters().isEmpty()) {
            hasDefaultConstructor = true;
            break;
        }
    }
    if (!hasDefaultConstructor && !isStateful) {
        if (classElement.getEnclosingElement() != null && !modifiers.contains(Modifier.STATIC)) {
            builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_CLASS_IS_INNERCLASS_NOT_STATIC(
                    classElement.getQualifiedName()), classElement);
            return false;
        }

        builder.processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_NO_DEFAULT_CONSTRUCTOR(
                classElement.getQualifiedName()), classElement);
        return false;
    }
    if (webService.endpointInterface().isEmpty()) {
        if (!methodsAreLegal(classElement))
            return false;
    } else {
        TypeElement interfaceElement = getEndpointInterfaceElement(webService.endpointInterface(), classElement);
        if (!classImplementsSei(classElement, interfaceElement))
            return false;
    }

    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:WebServiceVisitor.java

示例10: process

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        return false;
    }

    GraphNodeVerifier verifier = new GraphNodeVerifier(this);

    for (Element element : roundEnv.getElementsAnnotatedWith(NodeInfo.class)) {
        scope = element;
        try {
            if (!isNodeType(element)) {
                errorMessage(element, "%s can only be applied to Node subclasses", NodeInfo.class.getSimpleName());
                continue;
            }

            NodeInfo nodeInfo = element.getAnnotation(NodeInfo.class);
            if (nodeInfo == null) {
                errorMessage(element, "Cannot get %s annotation from annotated element", NodeInfo.class.getSimpleName());
                continue;
            }

            TypeElement typeElement = (TypeElement) element;

            Set<Modifier> modifiers = typeElement.getModifiers();
            if (!modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.ABSTRACT)) {
                // TODO(thomaswue): Reenable this check.
                // errorMessage(element, "%s annotated class must be either final or abstract",
                // NodeInfo.class.getSimpleName());
                // continue;
            }
            boolean found = false;
            for (Element e : typeElement.getEnclosedElements()) {
                if (e.getKind() == ElementKind.FIELD) {
                    if (e.getSimpleName().toString().equals("TYPE")) {
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                errorMessage(element, "%s annotated class must have a field named TYPE", NodeInfo.class.getSimpleName());
            }

            if (!typeElement.equals(verifier.Node) && !modifiers.contains(Modifier.ABSTRACT)) {
                verifier.verify(typeElement);
            }
        } catch (ElementException ee) {
            errorMessage(ee.element, ee.getMessage());
        } catch (Throwable t) {
            reportException(isBug367599(t) ? Kind.NOTE : Kind.ERROR, element, t);
        } finally {
            scope = null;
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:GraphNodeProcessor.java

示例11: checkConcreteType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
static void checkConcreteType(TypeElement e) {
    Set<Modifier> mods = e.getModifiers();
    if (mods.contains(Modifier.ABSTRACT) || e.getKind().isInterface()) {
        throw new EasyPluginException(e.toString() + " must be concrete to use as a service.");
    }
}
 
开发者ID:c0d3d,项目名称:easy-plugins,代码行数:7,代码来源:Util.java


注:本文中的javax.lang.model.element.TypeElement.getModifiers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。