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


Java Element.getModifiers方法代码示例

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


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

示例1: checkAnnotation

import javax.lang.model.element.Element; //导入方法依赖的package包/类
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
@Override
public void checkAnnotation(Element annotatedField) {
	checkEnvironment(annotatedField);

	if (annotatedField.getKind() != mValidKind) {
		mErrorBuilder.append("Field " + annotatedField + " of " + annotatedField.getEnclosingElement().getSimpleName() + " should be " + mValidKind.name() + ", or not mark it as @" + InjectPresenter.class.getSimpleName()).append("\n");
	}

	for (Modifier modifier : annotatedField.getModifiers()) {
		if (!mValidModifiers.contains(modifier)) {
			mErrorBuilder.append("Field " + annotatedField + " of " + annotatedField.getEnclosingElement().getSimpleName() + " can't be a " + modifier).append(". Use ").append(validModifiersToString()).append("\n");
		}
	}

	Element enclosingElement = annotatedField.getEnclosingElement();
	while (enclosingElement.getKind() == ElementKind.CLASS) {
		if (!enclosingElement.getModifiers().contains(Modifier.PUBLIC)) {
			mErrorBuilder.append(enclosingElement.getSimpleName() + " should be PUBLIC ");
			break;
		}

		enclosingElement = enclosingElement.getEnclosingElement();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:PresenterInjectorRules.java

示例2: addAllNonPrivateAccessors

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void addAllNonPrivateAccessors(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
    List<? extends Element> enclosedElements = element.getEnclosedElements();
    for (Element enclosedElement : enclosedElements) {
        ElementKind enclosedElementKind = enclosedElement.getKind();
        if (enclosedElementKind == ElementKind.FIELD) {
            Set<Modifier> modifiers = enclosedElement.getModifiers();

            if (modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.TRANSIENT) && !modifiers.contains(Modifier.STATIC)) {

                String getter = JsonFieldHolder.getGetter(enclosedElement, elements);
                String setter = JsonFieldHolder.getSetter(enclosedElement, elements);

                if (!TextUtils.isEmpty(getter) && !TextUtils.isEmpty(setter)) {
                    createOrUpdateFieldHolder(enclosedElement, elements, types, objectHolder);
                }
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:JsonObjectProcessor.java

示例3: isDeclaredAsJavaBean

import javax.lang.model.element.Element; //导入方法依赖的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

示例4: process

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
	Set<? extends Element> root = roundEnv.getElementsAnnotatedWith(APILevel.class);
	System.out.println("Processing ..");
	for (Element element : root) {
		for (Modifier modifier : element.getModifiers()) {
			if (modifier.equals(Modifier.ABSTRACT)
					|| modifier.equals(Modifier.PRIVATE)
					|| modifier.equals(Modifier.PUBLIC)
					|| modifier.equals(Modifier.PROTECTED)) {
				processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ERROR_MESSAGE, element);
				return false;
			}
		}
	}

	processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ERROR_MESSAGE, null);
	return true;
}
 
开发者ID:ThorbenKuck,项目名称:NetCom2,代码行数:23,代码来源:APILevelAnnotationProcessor.java

示例5: addModifiers

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * Add the modifier for the member. The modifiers are ordered as specified
 * by <em>The Java Language Specification</em>.
 *
 * @param member the member for which teh modifier will be added.
 * @param htmltree the content tree to which the modifier information will be added.
 */
protected void addModifiers(Element member, Content htmltree) {
    Set<Modifier> set = new TreeSet<>(member.getModifiers());

    // remove the ones we really don't need
    set.remove(NATIVE);
    set.remove(SYNCHRONIZED);
    set.remove(STRICTFP);

    // According to JLS, we should not be showing public modifier for
    // interface methods.
    if ((utils.isField(member) || utils.isMethod(member))
        && ((writer instanceof ClassWriterImpl
             && utils.isInterface(((ClassWriterImpl) writer).getTypeElement())  ||
             writer instanceof AnnotationTypeWriterImpl) )) {
        // Remove the implicit abstract and public modifiers
        if (utils.isMethod(member) &&
            (utils.isInterface(member.getEnclosingElement()) ||
             utils.isAnnotationType(member.getEnclosingElement()))) {
            set.remove(ABSTRACT);
            set.remove(PUBLIC);
        }
        if (!utils.isMethod(member)) {
            set.remove(PUBLIC);
        }
    }
    if (!set.isEmpty()) {
        String mods = set.stream().map(Modifier::toString).collect(Collectors.joining(" "));
        htmltree.addContent(mods);
        htmltree.addContent(Contents.SPACE);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AbstractMemberWriter.java

示例6: checkFieldModifier

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void checkFieldModifier(Element element) {
    Set<Modifier> modifiers = element.getModifiers();
    if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
        TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
        ProcessorUtils.printError(messager, element, "@%s %s must not be private or static. (%s.%s)",
                Autowired.class.getSimpleName(), "fields", enclosingElement.getQualifiedName(),
                element.getSimpleName());
    }
}
 
开发者ID:chiclaim,项目名称:MRouter,代码行数:10,代码来源:AutowireProcessor.java

示例7: addAllNonPrivateFields

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void addAllNonPrivateFields(Element element, Elements elements, Types types, JsonObjectHolder objectHolder) {
    List<? extends Element> enclosedElements = element.getEnclosedElements();
    for (Element enclosedElement : enclosedElements) {
        ElementKind enclosedElementKind = enclosedElement.getKind();
        if (enclosedElementKind == ElementKind.FIELD) {
            Set<Modifier> modifiers = enclosedElement.getModifiers();
            if (!modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.PROTECTED) && !modifiers.contains(Modifier.TRANSIENT) && !modifiers.contains(Modifier.STATIC)) {
                createOrUpdateFieldHolder(enclosedElement, elements, types, objectHolder);
            }
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:JsonObjectProcessor.java

示例8: getExtendedModifiers

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static String getExtendedModifiers(Elements elements, Element el) {
    StringBuilder sb = new StringBuilder();
    for (Modifier m : el.getModifiers())
        sb.append(m.name());
    if (elements.isDeprecated(el))
        sb.append(DEPRECATED);
    if (el.getKind() == ElementKind.FIELD) {
        Object v = ((VariableElement) el).getConstantValue();
        if (v != null) {
            sb.append(v.getClass().getName());
            sb.append(String.valueOf(v));
        }
    }
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CheckSums.java

示例9: hasStaticImportSimpleNameClash

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * @param info
 * @param simpleName of static method.
 * @return true if a static import exists with the same simple name.
 * Caveat, expect false positives on protected and default visibility methods from wildcard static imports.
 */
private static boolean hasStaticImportSimpleNameClash(CompilationInfo info, String simpleName) {
    for (ImportTree i : info.getCompilationUnit().getImports()) {
        if (!i.isStatic()) {
            continue;
        }
        String q = i.getQualifiedIdentifier().toString();
        if (q.endsWith(".*")) { //NOI18N
            TypeElement ie = info.getElements().getTypeElement(q.substring(0, q.length() - 2));
            if (ie == null) {
                continue;
            }
            for (Element enclosed : ie.getEnclosedElements()) {
                Set<Modifier> modifiers = enclosed.getModifiers();
                if (enclosed.getKind() != ElementKind.METHOD || !modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.PRIVATE)) {
                    continue;
                }
                String sn1 = enclosed.getSimpleName().toString();
                if (simpleName.equals(sn1)) {
                    return true;
                }
            }
        } else {
            int endIndex = q.lastIndexOf("."); //NOI18N
            if (endIndex == -1 || endIndex >= q.length() - 1) {
                continue;
            }
            if (q.substring(endIndex).equals(simpleName)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:StaticImport.java

示例10: checkModifier

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * Returns true if access is allowed.
 *
 * @param e the element in question
 * @return whether the modifiers pass this filter
 */
public boolean checkModifier(Element e) {
    Set<Modifier> modifiers = e.getModifiers();
    AccessKind fflag = AccessKind.PACKAGE;
    if (modifiers.contains(Modifier.PUBLIC)) {
        fflag = AccessKind.PUBLIC;
    } else if (modifiers.contains(Modifier.PROTECTED)) {
        fflag = AccessKind.PROTECTED;
    } else if (modifiers.contains(Modifier.PRIVATE)) {
        fflag = AccessKind.PRIVATE;
    }
    EnumSet<AccessKind> filterSet = filterMap.get(getAllowedKind(e.getKind()));
    return filterSet.contains(fflag);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ElementsTable.java

示例11: ElementDescription

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public ElementDescription(CompilationInfo info, Element element, boolean overriddenFlag) {
    this.originalCPInfo = info.getClasspathInfo();
    this.handle = ElementHandle.create(element);
    if (METHOD.equals(element.getKind()) && null != element.getEnclosingElement()) {
        //when showing the implementors/overriders of a method, show the type icon (not the method icon)
        this.imageKind = element.getEnclosingElement().getKind();
    } else {
        this.imageKind = this.handle.getKind();
    }
    this.outtermostElement = ElementHandle.create(SourceUtils.getOutermostEnclosingTypeElement(element));
    this.modifiers = element.getModifiers();
    this.displayName = overriddenFlag ? computeDisplayNameIsOverridden(element) : computeDisplayNameOverrides(element);
    this.overriddenFlag = overriddenFlag;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ElementDescription.java

示例12: create

import javax.lang.model.element.Element; //导入方法依赖的package包/类
public static Description create(CompilationInfo info, Element element, List<Description> subs, boolean isSelectable, boolean isSelected ) {
    boolean deprecated = info.getElements().isDeprecated(element);
    String htmlHeader = null;
    switch (element.getKind()) {
        case ANNOTATION_TYPE:
        case CLASS:
        case ENUM:
        case INTERFACE:
            htmlHeader = createHtmlHeader(deprecated, (TypeElement)element);
            break;
        case ENUM_CONSTANT:
        case FIELD:
            htmlHeader = createHtmlHeader(deprecated, (VariableElement)element);
            break;
        case CONSTRUCTOR:
        case METHOD:
            htmlHeader = createHtmlHeader(deprecated, (ExecutableElement)element);
            break;                    
    }
    return new Description(element.getSimpleName().toString(), 
                           ElementHandle.create(element), 
                           element.getModifiers(), 
                           subs, 
                           htmlHeader,
                           isSelectable,
                           isSelected);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ElementNode.java

示例13: getParamModels

import javax.lang.model.element.Element; //导入方法依赖的package包/类
private List<ActivityIntentModel.ParamModel> getParamModels(TypeElement typeElement) {
    List<ActivityIntentModel.ParamModel> paramModels = new ArrayList<>();

    List<? extends Element> list = typeElement.getEnclosedElements();
    if (list == null) {
        return paramModels;
    }
    for (Element paramElement : list) {
        IntentParam intentParam = paramElement.getAnnotation(IntentParam.class); //AnnotationMirror mirror = e.getAnnotationMirrors().get(0);
        if (intentParam != null) {
            if (paramElement.getKind() != ElementKind.FIELD || paramElement.getModifiers() == null || !paramElement.getModifiers().contains(Modifier.STATIC)) {
                messager.printMessage(Diagnostic.Kind.ERROR, "IntentParam can only be applied to STATIC FIELD");
                continue;
            }
            messager.printMessage(Diagnostic.Kind.NOTE, "   IntentParam annotated element:" + paramElement.getSimpleName());

            ActivityIntentModel.ParamModel paramModel = new ActivityIntentModel.ParamModel();
            paramModel.fieldName = paramElement.getSimpleName().toString();
            //TypeMirror fieldType = e.asType();
            //paramModel.type = fieldType;
            paramModel.type = intentParam.type();
            paramModel.generatedPropName = intentParam.name();
            paramModel.qualifiedClassName = typeElement.getQualifiedName().toString();
            paramModels.add(paramModel);

        }
    }

    return paramModels;

}
 
开发者ID:daawa,项目名称:auto-nav,代码行数:32,代码来源:NavProcessor.java

示例14: isValid

import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
 * 注解是否有效
 * @author leibing
 * @createTime 2017/3/2
 * @lastModify 2017/3/2
 * @param annotationClass
 * @param targetThing
 * @param element 元素
 * @return
 */
private boolean isValid(Class<? extends Annotation> annotationClass, String targetThing, Element element) {
    boolean isVaild = true;
    // 获取变量的所在的父元素,肯能是类、接口、枚举
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
    // 父元素的全限定名
    String qualifiedName = enclosingElement.getQualifiedName().toString();
    // 所在的类不能是private或static修饰
    Set<Modifier> modifiers = element.getModifiers();
    if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
        error(element, "@%s %s must not be private or static. (%s.%s)",
                annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
                element.getSimpleName());
        isVaild = false;
    }
    // 父元素必须是类,而不能是接口或枚举
    if (enclosingElement.getKind() != ElementKind.CLASS) {
        error(enclosingElement, "@%s %s may only be contained in classes. (%s.%s)",
                annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
                element.getSimpleName());
        isVaild = false;
    }
    // 不能在Android框架层注解
    if (qualifiedName.startsWith("android.")) {
        error(element, "@%s-annotated class incorrectly in Android framework package. (%s)",
                annotationClass.getSimpleName(), qualifiedName);
        return false;
    }
    // 不能在java框架层注解
    if (qualifiedName.startsWith("java.")) {
        error(element, "@%s-annotated class incorrectly in Java framework package. (%s)",
                annotationClass.getSimpleName(), qualifiedName);
        return false;
    }

    return isVaild;
}
 
开发者ID:leibing8912,项目名称:CustomAnnotation,代码行数:47,代码来源:ProxyToolProcessor.java

示例15: process

import javax.lang.model.element.Element; //导入方法依赖的package包/类
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment environment) {
    for(final Element element : environment.getElementsAnnotatedWith(PutMany.class)) {
        final PutMany annotation = element.getAnnotation(PutMany.class);

        if(ElementKind.METHOD != element.getKind()) {
            throw new DataSinkDefinitionException(
                "Must use @PutMany with methods only! Tried to use with " + element.getSimpleName()
                    + ", which is not a method.");
        }

        final Set<Modifier> modifiers = element.getModifiers();
        if(!modifiers.contains(Modifier.PUBLIC)) {
            throw new DataSinkDefinitionException(
                "Must use @PutMany with public methods only! Tried to use with " + element.getSimpleName()
                    + ", which is not public.");
        }
        if(modifiers.contains(Modifier.STATIC)) {
            throw new DataSinkDefinitionException(
                "Must use @PutMany with non-static methods only! Tried to use with " + element.getSimpleName()
                    + ", which is static.");
        }

        final ExecutableType method = (ExecutableType)element.asType();
        final Types types = processingEnv.getTypeUtils();
        final Elements elements = processingEnv.getElementUtils();

        // annotation.value() will throw the exception because it doesn't have compiled class information yet, and is of type Class<?>.
        TypeMirror annotatedType = null;
        try {
            annotation.value();
        } catch(final MirroredTypeException e) {
            annotatedType = e.getTypeMirror();
        }

        if(TypeKind.VOID != method.getReturnType().getKind()) {
            throw new DataSinkDefinitionException("@PutMany method must have void return! Tried to use with " + element.getSimpleName() + ", which returns "
                + method.getReturnType() + ".");
        }
        if(method.getParameterTypes().size() != 2) {
            throw new DataSinkDefinitionException("@PutMany methods must take 2 arguments: Iterable<T> items, PipelineContext context. Tried to use with "
                + element.getSimpleName() + ", which has a different signature.");
        }

        final TypeElement iterableType = elements.getTypeElement(Iterable.class.getName());
        final TypeMirror[] genericType = new TypeMirror[] {annotatedType};
        final DeclaredType itemsType = types.getDeclaredType(iterableType, genericType);
        final TypeMirror contextType = elements.getTypeElement(PipelineContext.class.getName()).asType();

        if(!types.isAssignable(itemsType, method.getParameterTypes().get(0))) {
            throw new DataSinkDefinitionException(
                "@PutMany method annotated value must be assignable from the generic type of the method's first argument . Tried to use with "
                    + element.getSimpleName() + ", which takes " + method.getParameterTypes().get(0) + ".");
        }
        if(!types.isAssignable(method.getParameterTypes().get(1), contextType)) {
            throw new DataSinkDefinitionException("@PutMany method second argument must be assignable from " + contextType + ". Tried to use with "
                + element.getSimpleName() + ", which takes " + method.getParameterTypes().get(1) + ".");
        }
    }

    return true;
}
 
开发者ID:meraki-analytics,项目名称:datapipelines-java,代码行数:63,代码来源:PutManyProcessor.java


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