javax.lang.model.element.VariableElement#getModifiers ( )源码实例Demo

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

源代码1 项目: TencentKona-8   文件: PubapiVisitor.java
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
源代码2 项目: openjdk-jdk8u   文件: PubapiVisitor.java
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
源代码3 项目: dagger2-sample   文件: InjectFieldValidator.java
@Override
public ValidationReport<VariableElement> validate(VariableElement fieldElement) {
  ValidationReport.Builder<VariableElement> builder =
      ValidationReport.Builder.about(fieldElement);
  Set<Modifier> modifiers = fieldElement.getModifiers();
  if (modifiers.contains(FINAL)) {
    builder.addItem(FINAL_INJECT_FIELD, fieldElement);
  }

  if (modifiers.contains(PRIVATE)) {
    builder.addItem(PRIVATE_INJECT_FIELD, fieldElement);
  }

  ImmutableSet<? extends AnnotationMirror> qualifiers = getQualifiers(fieldElement);
  if (qualifiers.size() > 1) {
    for (AnnotationMirror qualifier : qualifiers) {
      builder.addItem(MULTIPLE_QUALIFIERS, fieldElement, qualifier);
    }
  }

  return builder.build();
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: PubapiVisitor.java
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
源代码5 项目: sqlitemagic   文件: Environment.java
private static void getLocalAndInheritedColumnFields(PackageElement pkg,
                                                     TypeElement type,
                                                     SetMultimap<String, VariableElement> fields) {
  for (TypeMirror superInterface : type.getInterfaces()) {
    getLocalAndInheritedColumnFields(pkg, asTypeElement(superInterface), fields);
  }
  if (type.getSuperclass().getKind() != TypeKind.NONE) {
    // Visit the superclass after superinterfaces so we will always see the implementation of a
    // method after any interfaces that declared it.
    getLocalAndInheritedColumnFields(pkg, asTypeElement(type.getSuperclass()), fields);
  }
  for (VariableElement field : ElementFilter.fieldsIn(type.getEnclosedElements())) {
    final Set<Modifier> modifiers = field.getModifiers();
    if (!modifiers.contains(Modifier.STATIC)) {
      fields.put(field.getSimpleName().toString(), field);
    }
  }
}
 
源代码6 项目: openjdk-8-source   文件: PubapiVisitor.java
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
源代码7 项目: netbeans   文件: EntityClassInfo.java
protected void extractFields(DeclaredType originalEntity, TypeElement typeElement, 
        CompilationController controller) 
{
    List<VariableElement> fields = ElementFilter.fieldsIn(typeElement.getEnclosedElements());

    for (VariableElement field : fields) {
        Set<Modifier> modifiers = field.getModifiers();
        if (modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.TRANSIENT) || modifiers.contains(Modifier.VOLATILE) || modifiers.contains(Modifier.FINAL)) {
            continue;
        }

        FieldInfo fieldInfo = new FieldInfo();

        fieldInfo.parseAnnotations(field.getAnnotationMirrors());

        if (!fieldInfo.isPersistent()) {
            continue;
        }

        fieldInfos.add(fieldInfo);
        fieldInfo.setName(field.getSimpleName().toString());
        fieldInfo.setType(controller.getTypes().
                asMemberOf(originalEntity, field), controller);

        if (fieldInfo.isId() && idFieldInfo == null ) {
            idFieldInfo = fieldInfo;
        }
    }
    TypeElement superClass = getJPASuperClass(typeElement, controller);
    if ( superClass == null ){
        return;
    }
    extractFields(originalEntity , superClass , controller );
}
 
源代码8 项目: Freezer   文件: ProcessUtils.java
public static List<VariableElement> filterStaticFinal(List<VariableElement> elements) {
    List<VariableElement> filtered = new ArrayList<>();
    for (VariableElement variableElement : elements) {
        final Set<Modifier> modifiers = variableElement.getModifiers();
        if (!modifiers.containsAll(Arrays.asList(Modifier.FINAL, Modifier.STATIC))) {
            filtered.add(variableElement);
        }
    } return filtered;
}
 
源代码9 项目: netbeans   文件: EntityClassInfo.java
private boolean useFieldAccess(TypeElement typeElement, 
        CompilationController controller) 
{
    List<VariableElement> fields = ElementFilter.fieldsIn(typeElement.getEnclosedElements());

    for (VariableElement field : fields) {
        Set<Modifier> modifiers = field.getModifiers();
        if (modifiers.contains(Modifier.STATIC) || modifiers.contains(Modifier.TRANSIENT) || modifiers.contains(Modifier.VOLATILE) || modifiers.contains(Modifier.FINAL)) {
            continue;
        }

        FieldInfo fieldInfo = new FieldInfo();

        fieldInfo.parseAnnotations(field.getAnnotationMirrors());

        if (fieldInfo.isPersistent() && fieldInfo.hasPersistenceAnnotation()) {
            return true;
        }
    }
    
    TypeElement superClass = getJPASuperClass(typeElement, controller);
    if ( superClass != null ){
            return useFieldAccess(superClass, controller);
    }

    return false;
}
 
源代码10 项目: netbeans   文件: ProducerFieldAnalyzer.java
private void checkSessionBean( VariableElement element, TypeElement parent,
        CdiAnalysisResult result  )
{
    if ( !AnnotationUtil.isSessionBean( parent , result.getInfo())) {
        return;
    }
    Set<Modifier> modifiers = element.getModifiers();
    if ( !modifiers.contains(Modifier.STATIC)){
        result.addError( element,  NbBundle.getMessage(
                ProducerFieldAnalyzer.class, 
                "ERR_NonStaticProducerSessionBean"));    // NOI18N
    }
}
 
源代码11 项目: netbeans   文件: FieldInjectionPointLogic.java
private void checkInjectionPoint( VariableElement element ) 
    throws InjectionPointDefinitionError
{
    CompilationController compilationController = getModel().getHelper().
        getCompilationController();
    Tree tree = compilationController.getTrees().getTree( element );
    if ( tree instanceof VariableTree ){
        VariableTree varTree = (VariableTree)tree;
        ExpressionTree initializer = varTree.getInitializer();
        if ( initializer != null ){
            throw new InjectionPointDefinitionError(NbBundle.getMessage( 
                    FieldInjectionPointLogic.class, 
                    "ERR_InitializedInjectionPoint"));      // NOI18N
        }
    }
    Set<Modifier> modifiers = element.getModifiers();
    if ( modifiers.contains(Modifier.STATIC)){
        throw new InjectionPointDefinitionError(NbBundle.getMessage( 
                FieldInjectionPointLogic.class, 
                "ERR_StaticInjectionPoint"));      // NOI18N
    }
    if ( modifiers.contains(Modifier.FINAL)){
        throw new InjectionPointDefinitionError(NbBundle.getMessage( 
                FieldInjectionPointLogic.class, 
                "ERR_FinalInjectionPoint"));      // NOI18N
    }
}
 
源代码12 项目: netbeans   文件: BeanModelBuilder.java
private void addConstant(VariableElement v) {
    Set<Modifier> mods = v.getModifiers();
    if (!(mods.contains(Modifier.FINAL) && mods.contains(Modifier.STATIC))) {
        return;
    }
    
    boolean ok = false;
    
    // check that the return type is the same as this class' type
    if (!compilationInfo.getTypes().isSameType(
            v.asType(), classElement.asType())) {
        // the constant may be primitive & our type the wrapper
        TypeMirror t = v.asType();
        if (t instanceof PrimitiveType) {
            PrimitiveType p = (PrimitiveType)t;
            if (compilationInfo.getTypes().isSameType(
                    compilationInfo.getTypes().boxedClass(p).asType(),
                    classElement.asType())) {
                ok = true;
            }
        } 
        if (!ok) {
            return;
        }
    }
    
    addConstant(v.getSimpleName().toString());
}
 
源代码13 项目: AutoBundle   文件: Validator.java
static void checkAutoBundleFieldModifier(VariableElement element, boolean hasGetterSetter) {
    Set<Modifier> modifiers = element.getModifiers();
    if (modifiers.contains(Modifier.PRIVATE) && !hasGetterSetter) {
        throw new ProcessingException(
                AutoBundleField.class + " does not support private field without setter/getter.");
    }
}
 
源代码14 项目: openjdk-jdk9   文件: PubapiVisitor.java
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Void visitVariable(VariableElement e, Void p) {
    if (isNonPrivate(e)) {
        Object constVal = e.getConstantValue();
        String constValStr = null;
        // TODO: This doesn't seem to be entirely accurate. What if I change
        // from, say, 0 to 0L? (And the field is public final static so that
        // it could get inlined.)
        if (constVal != null) {
            if (e.asType().toString().equals("char")) {
                // What type is 'value'? Is it already a char?
                char c = constVal.toString().charAt(0);
                constValStr = "'" + encodeChar(c) + "'";
            } else {
                constValStr = constVal.toString()
                                      .chars()
                                      .mapToObj(PubapiVisitor::encodeChar)
                                      .collect(Collectors.joining("", "\"", "\""));
            }
        }

        PubVar v = new PubVar(e.getModifiers(),
                              TypeDesc.fromType(e.asType()),
                              e.toString(),
                              constValStr);
        collectedApi.variables.put(v.identifier, v);
    }

    // Safe to not recurse here, because the only thing
    // to visit here is the constructor of a variable declaration.
    // If it happens to contain an anonymous inner class (which it might)
    // then this class is never visible outside of the package anyway, so
    // we are allowed to ignore it here.
    return null;
}
 
源代码15 项目: toothpick   文件: ToothpickProcessor.java
protected boolean isValidInjectAnnotatedFieldOrParameter(VariableElement variableElement) {
  TypeElement enclosingElement = (TypeElement) variableElement.getEnclosingElement();

  // Verify modifiers.
  Set<Modifier> modifiers = variableElement.getModifiers();
  if (modifiers.contains(PRIVATE)) {
    error(
        variableElement,
        "@Inject annotated fields must be non private : %s#%s",
        enclosingElement.getQualifiedName(),
        variableElement.getSimpleName());
    return false;
  }

  // Verify parentScope modifiers.
  Set<Modifier> parentModifiers = enclosingElement.getModifiers();
  if (parentModifiers.contains(PRIVATE)) {
    error(
        variableElement,
        "@Injected fields in class %s. The class must be non private.",
        enclosingElement.getSimpleName());
    return false;
  }

  if (!isValidInjectedType(variableElement)) {
    return false;
  }
  return true;
}
 
源代码16 项目: AirData   文件: Utils.java
public static boolean isValid(VariableElement element) {
    Set<Modifier> modifiers = element.getModifiers();
    return !modifiers.contains(Modifier.STATIC)
            && !modifiers.contains(Modifier.FINAL)
            && !modifiers.contains(Modifier.TRANSIENT)
            && element.getAnnotation(ColumnIgnore.class) == null;
}
 
源代码17 项目: paperparcel   文件: PaperParcelDescriptor.java
private static boolean isWritableDirectly(VariableElement field) {
  Set<Modifier> fieldModifiers = field.getModifiers();
  return !fieldModifiers.contains(Modifier.PRIVATE)
      && !fieldModifiers.contains(Modifier.FINAL);
}
 
源代码18 项目: openjdk-jdk9   文件: GraphNodeVerifier.java
private void scanFields(TypeElement node) {
    TypeElement currentClazz = node;
    do {
        for (VariableElement field : ElementFilter.fieldsIn(currentClazz.getEnclosedElements())) {
            Set<Modifier> modifiers = field.getModifiers();
            if (modifiers.contains(STATIC) || modifiers.contains(TRANSIENT)) {
                continue;
            }

            List<? extends AnnotationMirror> annotations = field.getAnnotationMirrors();

            boolean isNonOptionalInput = findAnnotationMirror(annotations, Input) != null;
            boolean isOptionalInput = findAnnotationMirror(annotations, OptionalInput) != null;
            boolean isSuccessor = findAnnotationMirror(annotations, Successor) != null;

            if (isNonOptionalInput || isOptionalInput) {
                if (findAnnotationMirror(annotations, Successor) != null) {
                    throw new ElementException(field, "Field cannot be both input and successor");
                } else if (isNonOptionalInput && isOptionalInput) {
                    throw new ElementException(field, "Inputs must be either optional or non-optional");
                } else if (isAssignableWithErasure(field, NodeInputList)) {
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Input list field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Input list field must not be public");
                    }
                } else {
                    if (!isAssignableWithErasure(field, Node) && field.getKind() == ElementKind.INTERFACE) {
                        throw new ElementException(field, "Input field type must be an interface or assignable to Node");
                    }
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Input field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Input field must not be public");
                    }
                }
            } else if (isSuccessor) {
                if (isAssignableWithErasure(field, NodeSuccessorList)) {
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Successor list field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Successor list field must not be public");
                    }
                } else {
                    if (!isAssignableWithErasure(field, Node)) {
                        throw new ElementException(field, "Successor field must be a Node type");
                    }
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Successor field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Successor field must not be public");
                    }
                }

            } else {
                if (isAssignableWithErasure(field, Node) && !field.getSimpleName().contentEquals("Null")) {
                    throw new ElementException(field, "Node field must be annotated with @" + Input.getSimpleName() + ", @" + OptionalInput.getSimpleName() + " or @" + Successor.getSimpleName());
                }
                if (isAssignableWithErasure(field, NodeInputList)) {
                    throw new ElementException(field, "NodeInputList field must be annotated with @" + Input.getSimpleName() + " or @" + OptionalInput.getSimpleName());
                }
                if (isAssignableWithErasure(field, NodeSuccessorList)) {
                    throw new ElementException(field, "NodeSuccessorList field must be annotated with @" + Successor.getSimpleName());
                }
                if (modifiers.contains(PUBLIC) && !modifiers.contains(FINAL)) {
                    throw new ElementException(field, "Data field must be final if public");
                }
            }
        }
        currentClazz = getSuperType(currentClazz);
    } while (!isObject(getSuperType(currentClazz).asType()));
}
 
源代码19 项目: paperparcel   文件: PaperParcelDescriptor.java
private static boolean isReadableDirectly(VariableElement field) {
  Set<Modifier> fieldModifiers = field.getModifiers();
  return !fieldModifiers.contains(Modifier.PRIVATE);
}
 
源代码20 项目: jasperreports   文件: PropertyProcessor.java
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
{
	CompiledPropertiesMetadata props = new CompiledPropertiesMetadata();
	String messagesName = processingEnv.getOptions().get(OPTION_MESSAGES_NAME);
	props.setMessagesName(messagesName);
	
	for (TypeElement annotation : annotations)
	{
		Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
		for (Element element : elements)
		{
			if (element.getKind() != ElementKind.FIELD)
			{
				processingEnv.getMessager().printMessage(Kind.WARNING, 
						"Annotation " + annotation + " can only be applied to static fields", 
						element);
				continue;
			}
			
			VariableElement varElement = (VariableElement) element;
			Set<Modifier> modifiers = varElement.getModifiers();
			if (!modifiers.contains(Modifier.STATIC) || !modifiers.contains(Modifier.PUBLIC)
					|| !modifiers.contains(Modifier.FINAL))
			{
				processingEnv.getMessager().printMessage(Kind.WARNING, 
						"Annotation " + annotation + " can only be applied to public static final fields", 
						element);
				continue;
			}
			
			TypeMirror varType = varElement.asType();
			if (!varType.toString().equals(String.class.getCanonicalName()))
			{
				processingEnv.getMessager().printMessage(Kind.WARNING, 
						"Annotation " + annotation + " can only be applied to String fields", 
						element);
				continue;
			}
			
			AnnotationMirror propertyAnnotation = findPropertyAnnotation(varElement);
			if (propertyAnnotation == null)
			{
				//should not happen
				continue;
			}
			
			CompiledPropertyMetadata property = toPropertyMetadata(varElement, propertyAnnotation);
			if (property != null)
			{
				props.addProperty(property);
			}
		}
	}
	
	if (!props.getProperties().isEmpty())
	{
		writePropertiesMetadata(props);
		
		String propertiesDoc = processingEnv.getOptions().get(OPTION_PROPERTIES_DOC);
		if (propertiesDoc != null)
		{
			PropertiesDocReader docReader = new PropertiesDocReader(processingEnv, props);
			docReader.readPropertiesDoc(propertiesDoc);
			docReader.writeDefaultMessages();
			
			String referenceOut = processingEnv.getOptions().get(OPTION_CONFIG_REFERENCE_OUT);
			if (referenceOut != null)
			{
				docReader.writeConfigReference(referenceOut);
			}
		}
	}
	
	return true;
}