本文整理汇总了Java中com.google.auto.common.MoreElements.isAnnotationPresent方法的典型用法代码示例。如果您正苦于以下问题:Java MoreElements.isAnnotationPresent方法的具体用法?Java MoreElements.isAnnotationPresent怎么用?Java MoreElements.isAnnotationPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.auto.common.MoreElements
的用法示例。
在下文中一共展示了MoreElements.isAnnotationPresent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateActionCreator
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static void validateActionCreator(ExecutableElement element,
String actionName,
TypeMirror actionCreator,
ArrayList<VariableElement> args,
Map<String, ActionCreatorElement> knownActionCreators,
Env env) throws ValidationException {
Element actionCreatorElement = MoreTypes.asElement(actionCreator);
if (!MoreElements.isAnnotationPresent(actionCreatorElement, ActionCreator.class)) {
throw new ValidationException(element, "Action creator %s should be annotated with @%s", actionCreator, ActionCreator.class.getSimpleName());
}
ActionCreatorElement creatorElement = knownActionCreators.get(env.getElements().getBinaryName((TypeElement) actionCreatorElement).toString());
if (creatorElement == null) {
throw new ElementNotReadyException();
}
if (!creatorElement.hasAction(actionName, args)) {
throw new ValidationException(element, "Cannot find action creator for action \"%s\" and args %s in interface %s", actionName, toString(args), creatorElement.getName(env));
}
}
示例2: findScope
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
* Find annotation that is itself annoted with @Scope
* If there is one, it will be later applied on the generated component
* Otherwise the component will be unscoped
* Throw error if more than one scope annotation found
*/
private AnnotationMirror findScope() {
AnnotationMirror annotationTypeMirror = null;
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
Element annotationElement = annotationMirror.getAnnotationType().asElement();
if (MoreElements.isAnnotationPresent(annotationElement, Scope.class)) {
// already found one scope
if (annotationTypeMirror != null) {
errors.addInvalid("Several dagger scopes on same element are not allowed");
continue;
}
annotationTypeMirror = annotationMirror;
}
}
return annotationTypeMirror;
}
示例3: processFields
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void processFields(TypeElement typeElement, FieldDataBuilder fdBuilder) {
for (VariableElement var : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (!SuperficialValidation.validateElement(var)) continue;
// Ignore if this isn't a field (it could be an enum constant).
if (var.getKind() != ElementKind.FIELD) continue;
// Ignore if it has Realm's @Ignore or our @Hide annotation.
if (MoreElements.isAnnotationPresent(var, Ignore.class) ||
MoreElements.isAnnotationPresent(var, Hide.class)) continue;
// Ignore static fields.
if (var.getModifiers().contains(Modifier.STATIC)) continue;
// Ignore if not a valid field.
TypeMirror varMirror = var.asType();
if (!isValidFieldType(varMirror)) continue;
// The field is valid! Start getting data about it; real name first.
String realFieldName = var.getSimpleName().toString();
// Check for @VisibleAs.
String visibleFieldName = null;
if (MoreElements.isAnnotationPresent(var, VisibleAs.class)) {
VisibleAs vaAnnot = var.getAnnotation(VisibleAs.class);
visibleFieldName = vaAnnot.string();
}
if (visibleFieldName == null || visibleFieldName.isEmpty()) // Generate a name from camelCase.
visibleFieldName = Utils.makeVisName(realFieldName);
// Field type.
TypeName fieldType = TypeName.get(varMirror);
// If field is a RealmList, we need to get the parameter's type too.
ClassName realmListType = null;
if (isRealmList(fieldType)) {
List<? extends TypeMirror> parameterTypes = MoreTypes.asDeclared(varMirror).getTypeArguments();
realmListType = ClassName.bestGuess(parameterTypes.get(0).toString());
}
// Add this field's data to the field data builder.
fdBuilder.addField(realFieldName, visibleFieldName, fieldType, realmListType);
}
}
示例4: validate
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validate(Element annotatedType, String errorMessage) {
Element container = annotatedType.getEnclosingElement();
if (!MoreElements.isAnnotationPresent(container, RetroFacebook.class)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, errorMessage, annotatedType);
}
}
示例5: validate
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validate(Element annotatedType, String errorMessage) {
Element container = annotatedType.getEnclosingElement();
if (!MoreElements.isAnnotationPresent(container, AutoCursor.class)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, errorMessage, annotatedType);
}
}
示例6: getSubcomponents
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private List<MethodSpec> getSubcomponents() {
if (extractor.getSubcomponentsTypeMirrors().isEmpty()) {
return Collections.emptyList();
}
List<MethodSpec> methodSpecs = new ArrayList<>(extractor.getSubcomponentsTypeMirrors().size());
for (TypeMirror typeMirror : extractor.getSubcomponentsTypeMirrors()) {
Element e = MoreTypes.asElement(typeMirror);
TypeName typeName;
String name;
if (MoreElements.isAnnotationPresent(e, AutoSubcomponent.class)) {
ClassName cls = AutoComponentClassNameUtil.getComponentClassName(e);
typeName = cls;
name = cls.simpleName();
} else {
typeName = TypeName.get(typeMirror);
name = e.getSimpleName().toString();
}
List<TypeMirror> modules = state.getSubcomponentModules(typeMirror);
List<ParameterSpec> parameterSpecs;
if(modules != null) {
parameterSpecs = new ArrayList<>(modules.size());
int count = 0;
for (TypeMirror moduleTypeMirror : modules) {
parameterSpecs.add(ParameterSpec.builder(TypeName.get(moduleTypeMirror), String.format("module%d", ++count)).build());
}
} else {
parameterSpecs = new ArrayList<>(0);
}
methodSpecs.add(MethodSpec.methodBuilder("plus" + name)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameters(parameterSpecs)
.returns(typeName)
.build());
}
return methodSpecs;
}
示例7: processElement
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
@Override
public boolean processElement(Element element, Errors.ElementErrors elementErrors) {
// @AutoX applied on annotation
if (element.getKind() == ElementKind.ANNOTATION_TYPE) {
// @AutoX is applied on another annotation, find out the targets of that annotation
Set<? extends Element> targetElements = roundEnvironment.getElementsAnnotatedWith(MoreElements.asType(element));
for (Element targetElement : targetElements) {
if (!process(targetElement, element)) {
return false;
}
}
return true;
}
// @AutoX applied on method
// only valid for @AutoExpose with @Provides
if (element.getKind() == ElementKind.METHOD) {
if (processedAnnotation.equals(AutoInjector.class)) {
errors.addInvalid(element, "@AutoInjector cannot be applied on the method %s", element.getSimpleName());
return false;
}
if (!MoreElements.isAnnotationPresent(element, Provides.class)) {
errors.addInvalid(element, "@AutoExpose can be applied on @Provides method only, %s is missing it", element.getSimpleName());
return false;
}
ExecutableElement executableElement = MoreElements.asExecutable(element);
Element returnElement = MoreTypes.asElement(executableElement.getReturnType());
return process(returnElement, element);
}
process(element, element);
return !errors.hasErrors();
}
示例8: extract
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
@Override
public void extract() {
modulesTypeMirrors = findTypeMirrors(element, AutoComponentExtractorUtil.ANNOTATION_MODULES);
if (!MoreElements.isAnnotationPresent(element, AutoSubcomponent.class)) {
return;
}
superinterfacesTypeMirrors = findTypeMirrors(element, AutoComponentExtractorUtil.ANNOTATION_SUPERINTERFACES);
scopeAnnotationTypeMirror = findScope();
}
示例9: findAnnotatedAnnotation
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static List<AnnotationMirror> findAnnotatedAnnotation(Element element, Class<? extends Annotation> annotationCls) {
List<AnnotationMirror> annotationMirrors = new ArrayList<>();
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
Element annotationElement = annotationMirror.getAnnotationType().asElement();
if (MoreElements.isAnnotationPresent(annotationElement, annotationCls)) {
annotationMirrors.add(annotationMirror);
}
}
return annotationMirrors;
}
示例10: validate
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validate(Element annotatedType, String errorMessage) {
Element container = annotatedType.getEnclosingElement();
if (!MoreElements.isAnnotationPresent(container, Retrofit.class)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, errorMessage, annotatedType);
}
}
示例11: validate
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validate(Element annotatedType, String errorMessage) {
Element container = annotatedType.getEnclosingElement();
if (!MoreElements.isAnnotationPresent(container, RetroWeibo.class)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, errorMessage, annotatedType);
}
}
示例12: validate
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private void validate(Element annotatedType, String errorMessage) {
Element container = annotatedType.getEnclosingElement();
if (!MoreElements.isAnnotationPresent(container, AutoJson.class)) {
processingEnv.getMessager().printMessage(
Diagnostic.Kind.ERROR, errorMessage, annotatedType);
}
}
示例13: hasShareProtectedAnnotation
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static boolean hasShareProtectedAnnotation(Element element) {
return MoreElements.isAnnotationPresent(element, ShareProtected.class);
}
示例14: hasUseInjectionAnnotation
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static boolean hasUseInjectionAnnotation(TypeElement element) {
return MoreElements.isAnnotationPresent(element, UseInjection.class);
}
示例15: buildClassAndFieldData
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
* Process all classes which are annotated with {@link RealmClass} and get information needed to generate the class
* data and various field data files.
*/
void buildClassAndFieldData(RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(RealmClass.class)) {
if (!SuperficialValidation.validateElement(element)) continue;
if (element.getKind() != ElementKind.CLASS) {
// Really this shouldn't be an issue since Realm's annotation processor will do real checks, but still.
error(element, "@RealmClass annotations can only be applied to classes!");
continue;
}
TypeElement typeElement = MoreElements.asType(element);
if (!isValidRealmClass(typeElement)) continue;
// Get ClassName object, we'll store this so that we can write out a real type later.
ClassName className = ClassName.get(typeElement);
// Get real class name.
String realName = className.simpleName();
// Check that the real name of the class isn't already in use.
if (realClassNames.contains(realName)) {
error(element, "Failed while processing \"%s\" because there is already a realm object class called " +
"\"%s\"; Ruqus currently cannot handle multiple classes with the same name.",
className.toString(), realName);
continue;
}
// Check class for queryable and visible name annotations to try and figure out visible name.
String visibleName = null;
boolean isQueryable = false;
if (MoreElements.isAnnotationPresent(typeElement, Queryable.class)) {
Queryable qAnnot = typeElement.getAnnotation(Queryable.class);
visibleName = qAnnot.name();
isQueryable = true;
}
if ((visibleName == null || visibleName.isEmpty()) &&
MoreElements.isAnnotationPresent(typeElement, VisibleAs.class)) {
VisibleAs vaAnnot = typeElement.getAnnotation(VisibleAs.class);
visibleName = vaAnnot.string();
}
if (visibleName == null || visibleName.isEmpty()) {
// Generate a name from TitleCase.
visibleName = Utils.makeVisName(realName);
}
// Check that visible name hasn't already been used.
if (visibleNames.values().contains(visibleName)) {
error(element, "Failed while processing \"%s\" because there is already a realm object class which " +
"has the visible name \"%s\"; Ruqus currently cannot handle having multiple classes with the " +
"same visible name.", className.toString(), visibleName);
continue;
}
// Get field information for all fields in this class.
FieldDataBuilder fdBuilder = new FieldDataBuilder(realName);
processFields(typeElement, fdBuilder);
// Store these locally until we write out the whole class data file.
realClassNames.add(realName);
if (isQueryable) queryable.add(realName);
classMap.put(realName, className);
visibleNames.put(realName, visibleName);
fieldData.put(realName, fdBuilder);
}
}