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

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

源代码1 项目: doma   文件: EntityMetaFactory.java
public void doFieldElements(TypeElement classElement, EntityMeta entityMeta) {
  for (VariableElement fieldElement : getFieldElements(classElement)) {
    try {
      if (fieldElement.getAnnotation(Transient.class) != null) {
        continue;
      } else if (fieldElement.getModifiers().contains(Modifier.STATIC)) {
        continue;
      } else if (fieldElement.getAnnotation(OriginalStates.class) != null) {
        doOriginalStatesField(classElement, fieldElement, entityMeta);
      } else {
        doEntityPropertyMeta(classElement, fieldElement, entityMeta);
      }
    } catch (AptException e) {
      ctx.getReporter().report(e);
      entityMeta.setError(true);
    }
  }
}
 
源代码2 项目: auto-parcel   文件: AutoParcelProcessor.java
Property(String fieldName, VariableElement element) {
    this.fieldName = fieldName;
    this.element = element;
    this.typeName = TypeName.get(element.asType());
    this.annotations = getAnnotations(element);

    // get the parcel adapter if any
    ParcelAdapter parcelAdapter = element.getAnnotation(ParcelAdapter.class);
    if (parcelAdapter != null) {
        try {
            parcelAdapter.value();
        } catch (MirroredTypeException e) {
            this.typeAdapter = e.getTypeMirror();
        }
    }

    // get the element version, default 0
    ParcelVersion parcelVersion = element.getAnnotation(ParcelVersion.class);
    this.version = parcelVersion == null ? 0 : parcelVersion.from();
}
 
源代码3 项目: WandFix   文件: InjectObjectField.java
public InjectObjectField(Element element) throws IllegalArgumentException {
    if (element.getKind() != ElementKind.FIELD) {
        throw new IllegalArgumentException(String.format("Only fields can be annotated with @%s",
                InjectObject.class.getSimpleName()));
    }
    mVariableElement = (VariableElement) element;

    InjectObject injectOvject = mVariableElement.getAnnotation(InjectObject.class);
    mClassName = injectOvject.className();
    mLevel = injectOvject.level();
    if (mClassName == null) {
        throw new IllegalArgumentException(
                String.format("value() in %s for field %s is not valid !", InjectObject.class.getSimpleName(),
                        mVariableElement.getSimpleName()));
    }
}
 
源代码4 项目: RetroFacebook   文件: RetroFacebookProcessor.java
public String buildBody(ExecutableElement method) {
  String body = "";

  // TODO duplicated routine
  retrofacebook.RetroFacebook.POST post = method.getAnnotation(retrofacebook.RetroFacebook.POST.class);
  if (post == null) return body;

  // TODO duplicated code
  List<? extends VariableElement> parameters = method.getParameters();
  for (VariableElement parameter : parameters) {
    if (parameter.getAnnotation(retrofacebook.RetroFacebook.Body.class) != null) {
      body = parameter.getSimpleName().toString();
    }
  }
  return body;
}
 
源代码5 项目: simple-preferences   文件: KeyAnnotatedField.java
public KeyAnnotatedField(VariableElement element) throws ProcessingException {
  if (element.getModifiers().contains(Modifier.PRIVATE)) {
    throw new ProcessingException(element,
        "Field %s is private, must be accessible from inherited class", element.getSimpleName());
  }
  annotatedElement = element;

  type = TypeName.get(element.asType());

  Key annotation = element.getAnnotation(Key.class);
  name = element.getSimpleName().toString();
  preferenceKey = Strings.isNullOrEmpty(annotation.name()) ? Utils.lowerCamelToLowerSnake(name)
      : annotation.name();
  omitGetterPrefix = annotation.omitGetterPrefix();
  needCommitMethod = annotation.needCommitMethod();
}
 
源代码6 项目: RxAndroidOrm   文件: ProcessUtils.java
public static List<VariableElement> filterIgnore(List<VariableElement> elements) {
    List<VariableElement> filtered = new ArrayList<>();
    for (VariableElement variableElement : elements) {
        if (variableElement.getAnnotation(Ignore.class) == null && !Constants.PARCEL_CREATOR.equals(
            ProcessUtils.getObjectName(variableElement)) || ProcessUtils.isNotVariable(variableElement)) {
            filtered.add(variableElement);
        }
    }
    return filterStaticFinal(filtered);
}
 
源代码7 项目: Ollie   文件: ColumnElement.java
public ColumnElement(Registry registry, TypeElement enclosingType, VariableElement element) {
	this.element = element;
	this.column = element.getAnnotation(Column.class);
	this.enclosingType = enclosingType;
	this.deserializedType = registry.getElements().getTypeElement(element.asType().toString());

	final TypeAdapterElement typeAdapterElement = registry.getTypeAdapterElement(deserializedType);
	final TypeElement modelElement = registry.getElements().getTypeElement("ollie.Model");
	final DeclaredType modelType = registry.getTypes().getDeclaredType(modelElement);
	isModel = registry.getTypes().isAssignable(element.asType(), modelType);

	if (isModel) {
		final Table table = deserializedType.getAnnotation(Table.class);
		serializedType = registry.getElements().getTypeElement(Long.class.getName());
		modelTableName = table.value();
	} else if (typeAdapterElement != null) {
		serializedType = typeAdapterElement.getSerializedType();
	} else {
		serializedType = deserializedType;
	}

	this.sqlType = SQL_TYPE_MAP.get(getSerializedQualifiedName());

	List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
	for (AnnotationMirror annotationMirror : annotationMirrors) {
		try {
			Class annotationClass = Class.forName(annotationMirror.getAnnotationType().toString());
			annotations.put(annotationClass, element.getAnnotation(annotationClass));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
 
源代码8 项目: doma   文件: MoreElements.java
public String getParameterName(VariableElement variableElement) {
  assertNotNull(variableElement);
  ParameterName parameterName = variableElement.getAnnotation(ParameterName.class);
  if (parameterName != null && !parameterName.value().isEmpty()) {
    return parameterName.value();
  }
  return variableElement.getSimpleName().toString();
}
 
源代码9 项目: AirData   文件: ColumnInfo.java
private String getColumnName(VariableElement element) {
    Column c = element.getAnnotation(Column.class);
    if (c != null) {
        String columnName = c.name();
        if (columnName != null && columnName.length() > 0) {
            return columnName;
        }
    }
    return element.getSimpleName().toString();
}
 
源代码10 项目: squidb   文件: FieldReferencePlugin.java
@Override
public boolean processVariableElement(VariableElement field, DeclaredTypeName fieldType) {
    if (field.getAnnotation(Deprecated.class) != null) {
        return false;
    }
    if (field.getAnnotation(ColumnSpec.class) != null) {
        utils.getMessager().printMessage(Diagnostic.Kind.WARNING,
                "ColumnSpec is ignored outside of table models", field);
    }
    return super.processVariableElement(field, fieldType);
}
 
源代码11 项目: RetroFacebook   文件: RetroFacebookProcessor.java
public List<String> buildQueryBundles(ExecutableElement method) {
  List<String> queryBundles = new ArrayList<String>();
  List<? extends VariableElement> parameters = method.getParameters();
  for (VariableElement parameter : parameters) {
    retrofacebook.RetroFacebook.QueryBundle queryBundle = parameter
        .getAnnotation(retrofacebook.RetroFacebook.QueryBundle.class);
    if (queryBundle == null) {
      continue;
    }

    queryBundles.add(parameter.getSimpleName().toString());
  }
  return queryBundles;
}
 
源代码12 项目: ParcelablePlease   文件: ParcelableField.java
public ParcelableField(VariableElement element, Elements elementUtils, Types typeUtils) {

    this.element = element;
    fieldName = element.getSimpleName().toString();
    type = element.asType().toString();

    // Check for Bagger
    Bagger baggerAnnotation = element.getAnnotation(Bagger.class);
    if (baggerAnnotation != null) {
      // has a bagger annotation
      try {
        Class<? extends ParcelBagger> clazz = baggerAnnotation.value();
        baggerFullyQualifiedName = getFullQualifiedNameByClass(clazz);
      } catch (MirroredTypeException mte) {
        TypeMirror baggerClass = mte.getTypeMirror();
        baggerFullyQualifiedName = getFullQualifiedNameByTypeMirror(baggerClass);
      }

      // Everything is fine, so use the bagger
      codeGenerator = new BaggerCodeGen();
    } else {
      // Not using Bagger
      CodeGenInfo res = SupportedTypes.getCodeGenInfo(element, elementUtils, typeUtils);
      codeGenerator = res.getCodeGenerator();
      genericsTypeArgument = res.getGenericsType();

      // Check if type is supported
      if (codeGenerator == null) {
        ProcessorMessage.error(element,
            "Unsupported type %s for field %s. You could use @%s to provide your own serialization mechanism",
            element.asType().toString(), element.getSimpleName(), Bagger.class.getSimpleName());
      }
    }
  }
 
源代码13 项目: SimpleWeibo   文件: RetroWeiboProcessor.java
public List<String> buildQueryBundles(ExecutableElement method) {
  List<String> queryBundles = new ArrayList<String>();
  List<? extends VariableElement> parameters = method.getParameters();
  for (VariableElement parameter : parameters) {
    retroweibo.RetroWeibo.QueryBundle queryBundle = parameter
        .getAnnotation(retroweibo.RetroWeibo.QueryBundle.class);
    if (queryBundle == null) {
      continue;
    }

    queryBundles.add(parameter.getSimpleName().toString());
  }
  return queryBundles;
}
 
源代码14 项目: openjdk-jdk9   文件: WebServiceVisitor.java
protected boolean isLegalParameter(VariableElement param,
                                   ExecutableElement method,
                                   TypeElement typeElement,
                                   int paramIndex) {
    if (!isLegalType(param.asType())) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_PARAMETER_TYPES_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(),
                method.getSimpleName(),
                param.getSimpleName(),
                param.asType().toString()), param);
        return false;
    }
    TypeMirror holderType;
    holderType = builder.getHolderValueType(param.asType());
    WebParam webParam = param.getAnnotation(WebParam.class);
    WebParam.Mode mode = null;
    if (webParam != null)
        mode = webParam.mode();

    if (holderType != null) {
        if (mode != null && mode == WebParam.Mode.IN)
            builder.processError(WebserviceapMessages.WEBSERVICEAP_HOLDER_PARAMETERS_MUST_NOT_BE_IN_ONLY(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    } else if (mode != null && mode != WebParam.Mode.IN) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_NON_IN_PARAMETERS_MUST_BE_HOLDER(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    }

    return true;
}
 
源代码15 项目: squidb   文件: JSONFieldPlugin.java
@Override
protected boolean hasPropertyGeneratorForField(VariableElement field, DeclaredTypeName fieldType) {
    if (field.getAnnotation(JSONColumn.class) == null) {
        return false;
    }
    if (field.getModifiers().containsAll(TypeConstants.PUBLIC_STATIC_FINAL)) {
        // Might be a constant, ignore
        return false;
    }

    // Check that all type args are concrete types
    return recursivelyCheckTypes(field, fieldType, new AtomicBoolean(false));
}
 
源代码16 项目: openjdk-8   文件: WebServiceVisitor.java
protected boolean isLegalParameter(VariableElement param,
                                   ExecutableElement method,
                                   TypeElement typeElement,
                                   int paramIndex) {
    if (!isLegalType(param.asType())) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_PARAMETER_TYPES_CANNOT_IMPLEMENT_REMOTE(typeElement.getQualifiedName(),
                method.getSimpleName(),
                param.getSimpleName(),
                param.asType().toString()), param);
        return false;
    }
    TypeMirror holderType;
    holderType = builder.getHolderValueType(param.asType());
    WebParam webParam = param.getAnnotation(WebParam.class);
    WebParam.Mode mode = null;
    if (webParam != null)
        mode = webParam.mode();

    if (holderType != null) {
        if (mode != null && mode == WebParam.Mode.IN)
            builder.processError(WebserviceapMessages.WEBSERVICEAP_HOLDER_PARAMETERS_MUST_NOT_BE_IN_ONLY(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    } else if (mode != null && mode != WebParam.Mode.IN) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_NON_IN_PARAMETERS_MUST_BE_HOLDER(typeElement.getQualifiedName(), method.toString(), paramIndex), param);
    }

    return true;
}
 
源代码17 项目: droitatedDB   文件: ColumnReader.java
private boolean isAutoIncrementAnnotated(final VariableElement variableElement) {
    return variableElement.getAnnotation(AutoIncrement.class) != null;
}
 
public boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, VariableElement f) {
    return f.getAnnotation(annotationType)!=null;
}
 
源代码19 项目: hottub   文件: InlineAnnotationReaderImpl.java
public boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, VariableElement f) {
    return f.getAnnotation(annotationType)!=null;
}
 
源代码20 项目: AirData   文件: ColumnInfo.java
public ColumnInfo(VariableElement columnElement) {

        typeMirror = columnElement.asType();

        LogUtils.debug("" + typeMirror);

        setType(DataType.getTypeString(typeMirror));

        String simpleName = columnElement.getSimpleName().toString();
        if (Utils.isPublic(columnElement)) {
            setGetter(simpleName);
            setSetter(simpleName + " = $L");
        } else {
            if (DataType.isBoolean(typeMirror)) {
                setGetter("is" + new String(new char[]{simpleName.charAt(0)}).toString().toUpperCase() + simpleName.substring(1) + "()");
            } else {
                setGetter("get" + new String(new char[]{simpleName.charAt(0)}).toString().toUpperCase() + simpleName.substring(1) + "()");
            }
            setSetter("set" + new String(new char[]{simpleName.charAt(0)}).toString().toUpperCase() + simpleName.substring(1) + "($L)");
        }

        setPrimaryKey(columnElement.getAnnotation(PrimaryKey.class) != null);

        setName(getColumnName(columnElement));

        // generate column definition
        StringBuilder sb = new StringBuilder();
        sb.append(name).append(" ").append(type);
        if (isPrimaryKey()) {
            sb.append(" PRIMARY KEY AUTOINCREMENT");
        }

        Column annotation = columnElement.getAnnotation(Column.class);
        if (annotation != null) {
            if (annotation.notNull()) {
                sb.append(" NOT NULL ON CONFLICT ");
                sb.append(annotation.onNullConflict().toString());
            }

            if (annotation.unique()) {
                sb.append(" UNIQUE ON CONFLICT ");
                sb.append(annotation.onUniqueConflict().toString());
            }
        }
        definition = sb.toString();
    }