本文整理汇总了Java中javax.lang.model.element.TypeElement.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getAnnotation方法的具体用法?Java TypeElement.getAnnotation怎么用?Java TypeElement.getAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.TypeElement
的用法示例。
在下文中一共展示了TypeElement.getAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getViewStateClassFromAnnotationParams
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getViewStateClassFromAnnotationParams(TypeElement typeElement) {
InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
String mvpViewStateClassName = "";
if (annotation != null) {
TypeMirror value;
try {
annotation.value();
} catch (MirroredTypeException mte) {
value = mte.getTypeMirror();
mvpViewStateClassName = value.toString();
}
}
if (mvpViewStateClassName.isEmpty() || DefaultViewState.class.getName().equals(mvpViewStateClassName)) {
return null;
}
return mvpViewStateClassName;
}
示例2: FactoryAnnotatedClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public FactoryAnnotatedClass(TypeElement classElement) throws IllegalArgumentException {
this.annotatedClassElement = classElement;
Factory annotation = classElement.getAnnotation(Factory.class);
id = annotation.id();
if (id == null || id.length() == 0) {
throw new IllegalArgumentException(
String.format("id() in @%s for class %s is null or empty! that's not allowed",
Factory.class.getSimpleName(), classElement.getQualifiedName().toString()));
}
// Get the full QualifiedTypeName
try {
Class<?> clazz = annotation.type();
qualifiedSuperClassName = clazz.getCanonicalName();
simpleTypeName = clazz.getSimpleName();
} catch (MirroredTypeException mte) {
DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
qualifiedSuperClassName = classTypeElement.getQualifiedName().toString();
simpleTypeName = classTypeElement.getSimpleName().toString();
}
}
示例3: ModuleModel
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Creates a new module class model.
* @param ctx
* @param moduleElement type element representing the class of the module.
* @throws ModelException
*/
ModuleModel(ModelContext ctx, TypeElement moduleElement) throws ModelException {
if (!ctx.isModuleBase(moduleElement.asType()))
throw new ModelException("module must inherit from " + ModuleBase.class + ": " + moduleElement.getQualifiedName());
if (!moduleElement.getTypeParameters().isEmpty())
throw new ModelException("module cannot be generic: " + moduleElement.getQualifiedName());
element = moduleElement;
dataClass = ctx.getModuleDataClass(moduleElement);
simpleName = moduleElement.getSimpleName().toString();
fullName = moduleElement.getQualifiedName().toString();
packageName = fullName.substring(0, fullName.lastIndexOf('.'));
annotation = moduleElement.getAnnotation(AlvisNLPModule.class);
bundleName = annotation.docResourceBundle().isEmpty() ? fullName + "Doc" : annotation.docResourceBundle();
Map<String,ExecutableElement> methods = ctx.getMethodsByName(moduleElement);
for (ExecutableElement method : methods.values()) {
Param paramAnnotation = method.getAnnotation(Param.class);
if (paramAnnotation != null) {
params.add(new ParamModel(methods, method, paramAnnotation));
continue;
}
TimeThis timeAnnotation = method.getAnnotation(TimeThis.class);
if (timeAnnotation != null) {
timedMethods.add(new TimedMethodModel(ctx, method, timeAnnotation));
}
}
}
示例4: getMirrorModelIfAnnotation
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Nullable
private MirrorModel getMirrorModelIfAnnotation() {
if (this.kind == AttributeTypeKind.ANNOTATION) {
TypeElement element = toElement(this.type);
if (element.getAnnotation(Mirror.Annotation.class) != null) {
return new MirrorModel(element);
}
}
return null;
}
示例5: isCallbackMethodAnnotationValid
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public boolean isCallbackMethodAnnotationValid(Element element, String annotationName) {
TypeElement enclosingElement = (TypeElement)element.getEnclosingElement();
if (enclosingElement.getAnnotation(JsonObject.class) == null) {
error(enclosingElement, "%s: @%s methods can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), annotationName, JsonObject.class.getSimpleName());
return false;
}
ExecutableElement executableElement = (ExecutableElement)element;
if (executableElement.getParameters().size() > 0) {
error(element, "%s: @%s methods must not take any parameters.", enclosingElement.getQualifiedName(), annotationName);
return false;
}
List<? extends Element> allElements = enclosingElement.getEnclosedElements();
int methodInstances = 0;
for (Element enclosedElement : allElements) {
for (AnnotationMirror am : enclosedElement.getAnnotationMirrors()) {
if (am.getAnnotationType().asElement().getSimpleName().toString().equals(annotationName)) {
methodInstances++;
}
}
}
if (methodInstances != 1) {
error(element, "%s: There can only be one @%s method per class.", enclosingElement.getQualifiedName(), annotationName);
return false;
}
return true;
}
示例6: process
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (context.getRound() != 1) {
return true;
}
context.incrementRound();
WebService webService;
WebServiceProvider webServiceProvider;
WebServiceVisitor webServiceVisitor = new WebServiceWrapperGenerator(this, context);
boolean processedEndpoint = false;
Collection<TypeElement> classes = new ArrayList<TypeElement>();
filterClasses(classes, roundEnv.getRootElements());
for (TypeElement element : classes) {
webServiceProvider = element.getAnnotation(WebServiceProvider.class);
webService = element.getAnnotation(WebService.class);
if (webServiceProvider != null) {
if (webService != null) {
processError(WebserviceapMessages.WEBSERVICEAP_WEBSERVICE_AND_WEBSERVICEPROVIDER(element.getQualifiedName()));
}
processedEndpoint = true;
}
if (webService == null) {
continue;
}
element.accept(webServiceVisitor, null);
processedEndpoint = true;
}
if (!processedEndpoint) {
if (isCommandLineInvocation) {
if (!ignoreNoWebServiceFoundWarning) {
processWarning(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
}
} else {
processError(WebserviceapMessages.WEBSERVICEAP_NO_WEBSERVICE_ENDPOINT_FOUND());
}
}
return true;
}
示例7: ConverterModel
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Creates a new converter model.
* @param ctx
* @param converterElement type element representing the converter class declaration
* @throws ModelException
*/
ConverterModel(ModelContext ctx, TypeElement converterElement) throws ModelException {
fullName = converterElement.getQualifiedName().toString();
targetType = ctx.getTargetType(converterElement);
Converter annotation = converterElement.getAnnotation(Converter.class);
bundleName = annotation.docResourceBundle().isEmpty() ? fullName + "Doc" : annotation.docResourceBundle();
}
示例8: processElement
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void processElement(TypeElement serviceProvider) {
if (processed.contains(serviceProvider)) {
return;
}
processed.add(serviceProvider);
ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class);
if (annotation != null) {
try {
annotation.value();
} catch (MirroredTypeException ex) {
TypeMirror serviceInterface = ex.getTypeMirror();
if (verifyAnnotation(serviceInterface, serviceProvider)) {
if (serviceProvider.getNestingKind().isNested()) {
/*
* This is a simplifying constraint that means we don't have to process the
* qualified name to insert '$' characters at the relevant positions.
*/
String msg = String.format("Service provider class %s must be a top level class", serviceProvider.getSimpleName());
processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider);
} else {
serviceProviders.put(serviceProvider, ex.getTypeMirror().toString());
}
}
}
}
}
示例9: processType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void processType(TypeElement type, Map<TypeElement, String> elementTargetNames) {
TypeElement mapFrom = getClassToMapFrom(type);
AutoMapper autoMapper = type.getAnnotation(AutoMapper.class);
if (autoMapper == null) {
mErrorReporter.abortWithError(
"annotation processor for @AutoParcel was invoked with a type annotated differently; compiler bug? O_o",
type
);
}
if (type.getKind() != ElementKind.CLASS) {
mErrorReporter.abortWithError("@" + AutoMapper.class.getName() + " only applies to classes", type);
}
if (ancestorIsAutoParcel(type)) {
mErrorReporter.abortWithError("One @AutoParcel class shall not extend another", type);
}
checkModifiersIfNested(type);
// get the fully-qualified class name
String fqClassName = generatedSubclassName(type, 0);
// class name
String className = TypeUtil.simpleNameOf(fqClassName);
String source = generateClass(type, className, type.getSimpleName().toString(), mapFrom, elementTargetNames);
source = Reformatter.fixup(source);
writeSourceFile(fqClassName, source, type);
}
示例10: preProcessWebService
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
protected void preProcessWebService(WebService webService, TypeElement element) {
processedMethods = new HashSet<String>();
seiContext = context.getSeiContext(element);
String targetNamespace = null;
if (webService != null)
targetNamespace = webService.targetNamespace();
PackageElement packageElement = builder.getProcessingEnvironment().getElementUtils().getPackageOf(element);
if (targetNamespace == null || targetNamespace.length() == 0) {
String packageName = packageElement.getQualifiedName().toString();
if (packageName == null || packageName.length() == 0) {
builder.processError(WebserviceapMessages.WEBSERVICEAP_NO_PACKAGE_CLASS_MUST_HAVE_TARGETNAMESPACE(
element.getQualifiedName()), element);
}
targetNamespace = RuntimeModeler.getNamespace(packageName);
}
seiContext.setNamespaceUri(targetNamespace);
if (serviceImplName == null)
serviceImplName = seiContext.getSeiImplName();
if (serviceImplName != null) {
seiContext.setSeiImplName(serviceImplName);
context.addSeiContext(serviceImplName, seiContext);
}
portName = ClassNameInfo.getName(element.getSimpleName().toString().replace('$', '_'));
packageName = packageElement.getQualifiedName();
portName = webService != null && webService.name() != null && webService.name().length() > 0 ?
webService.name() : portName;
serviceName = ClassNameInfo.getName(element.getQualifiedName().toString()) + WebServiceConstants.SERVICE.getValue();
serviceName = webService != null && webService.serviceName() != null && webService.serviceName().length() > 0 ?
webService.serviceName() : serviceName;
wsdlNamespace = seiContext.getNamespaceUri();
typeNamespace = wsdlNamespace;
SOAPBinding soapBinding = element.getAnnotation(SOAPBinding.class);
if (soapBinding != null) {
pushedSoapBinding = pushSoapBinding(soapBinding, element, element);
} else if (element.equals(typeElement)) {
pushedSoapBinding = pushSoapBinding(new MySoapBinding(), element, element);
}
}
示例11: AdapterAnnotatedClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public AdapterAnnotatedClass(TypeElement typeElement) {
annotatedClassName = typeElement.getQualifiedName().toString();
RecyclerAdapter annotation = typeElement.getAnnotation(RecyclerAdapter.class);
try {
Class<?> clazz = annotation.itemType();
adapterItemType = clazz.getCanonicalName();
} catch (MirroredTypeException e) {
DeclaredType classTypeMirror = (DeclaredType) e.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
adapterItemType = classTypeElement.getQualifiedName().toString();
}
}
示例12: getBuilderForParam
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Returns the {@link ParamBuilder} that knows how to generate code for the given type of parameter
*/
ParamBuilder getBuilderForParam(TypeMirror typeMirror) {
ParamBuilder paramBuilder = typeBuilderMap.get(typeMirror);
if (paramBuilder == null) {
switch (typeMirror.getKind()) {
case BOOLEAN:
paramBuilder = new BooleanParamBuilder(messager, null);
break;
case BYTE:
paramBuilder = new ByteParamBuilder(messager, null);
break;
case CHAR:
paramBuilder = new CharParamBuilder(messager, null);
break;
case DOUBLE:
paramBuilder = new DoubleParamBuilder(messager, null);
break;
case FLOAT:
paramBuilder = new FloatParamBuilder(messager, null);
break;
case INT:
paramBuilder = new IntParamBuilder(messager, null);
break;
case LONG:
paramBuilder = new LongParamBuilder(messager, null);
break;
case SHORT:
paramBuilder = new ShortParamBuilder(messager, null);
break;
case ARRAY:
paramBuilder = getBuilderForParam(((ArrayType) typeMirror).getComponentType());
break;
case DECLARED:
TypeElement genericList = getGenericType(typeMirror);
if (genericList != null) {
paramBuilder = new ListOfParcelerParamBuilder(messager, null, genericList);
} else if (typeUtils.isAssignable(typeMirror, stringTypeMirror)) {
paramBuilder = new StringParamBuilder(messager, null);
} else if (typeUtils.isAssignable(typeMirror, charSequenceTypeMirror)) {
paramBuilder = new CharSequenceParamBuilder(messager, null);
} else if (typeUtils.isAssignable(typeMirror, listTypeMirror) || typeMirror.toString().equals("java.util.List<java.lang.String>")) {
paramBuilder = new ListParamBuilder(messager, null);
} else if (typeUtils.isAssignable(typeMirror, mapTypeMirror)) {
paramBuilder = new MapParamBuilder(messager, null);
} else if (typeUtils.isAssignable(typeMirror, parcellableTypeMirror)) {
paramBuilder = new ParcellableParamBuilder(messager, null);
} else {
String typeName = typeMirror.toString();
int templateStart = typeName.indexOf('<');
if (templateStart != -1) {
typeName = typeName.substring(0, templateStart).trim();
}
TypeElement typeElement = elementUtils.getTypeElement(typeName);
if (typeElement != null) {
if (typeElement.getKind() == ElementKind.INTERFACE && typeElement.getAnnotation(Remoter.class) != null) {
paramBuilder = new BinderParamBuilder(messager, null);
} else if (parcelClass != null && typeElement.getAnnotation(parcelClass) != null) {
paramBuilder = new ParcelerParamBuilder(messager, null);
}
}
}
break;
}
if (paramBuilder != null) {
paramBuilder.setBindingManager(this);
typeBuilderMap.put(typeMirror, paramBuilder);
} else {
paramBuilder = new GenericParamBuilder(messager, null);
paramBuilder.setBindingManager(this);
typeBuilderMap.put(typeMirror, paramBuilder);
}
}
return paramBuilder;
}
示例13: isAnnotatedWithClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private boolean isAnnotatedWithClass(RoundEnvironment roundEnvironment,
Class<? extends Annotation> clazz) {
Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(clazz);
for (Element element : elements) {
if (isValid(element)) {
return false;
}
if (!element.getKind().isClass()) {
return false;
}
TypeElement typeElement = (TypeElement) element;
String fullPackageName = typeElement.getQualifiedName().toString();
String packageName = mElementUtils.getPackageOf(element).getQualifiedName().toString();
String className = typeElement.getSimpleName().toString();
Annotation annotation = typeElement.getAnnotation(clazz);
ProxyInfo proxyInfo = mInfoMap.get(fullPackageName);
if (proxyInfo == null) {
proxyInfo = new ProxyInfo();
mInfoMap.put(fullPackageName, proxyInfo);
}
proxyInfo.fullPackageName = fullPackageName;
proxyInfo.className = className;
proxyInfo.packageName = packageName;
proxyInfo.typeElement = typeElement;
if (fullPackageName != null && fullPackageName.length() > 0) {
String outClassFullName;
try {
outClassFullName = fullPackageName.substring(0, fullPackageName.length() - className.length() - 1);
if (outClassFullName.equals(packageName)) {
outClassFullName = fullPackageName;
}
} catch (Exception e) {
outClassFullName = "";
}
proxyInfo.outClassFullPackageName = outClassFullName;
}
if (annotation instanceof AutoNetPatternAnontation) {
autoNetPatternProc(proxyInfo, (AutoNetPatternAnontation) annotation);
} else if (annotation instanceof AutoNetEncryptionAnontation) {
autoNetEncryptionProc(proxyInfo, (AutoNetEncryptionAnontation) annotation);
} else if (annotation instanceof AutoNetBaseUrlKeyAnontation) {
autoNetBaseUrlKeyProc(proxyInfo, (AutoNetBaseUrlKeyAnontation) annotation);
} else if (annotation instanceof AutoNetAnontation) {
autoNetProc(proxyInfo, (AutoNetAnontation) annotation);
} else if (annotation instanceof AutoNetResponseEntityClass) {
autoNetResponseEntityClassProc(proxyInfo, (AutoNetResponseEntityClass) annotation, element);
} else if (annotation instanceof AutoNetTypeAnontation) {
autoNetReqTypeProc(proxyInfo, (AutoNetTypeAnontation) annotation);
} else if (annotation instanceof AutoNetMediaTypeAnontation) {
autoNetMediaTypeProc(proxyInfo, (AutoNetMediaTypeAnontation) annotation);
} else {
return false;
}
}
return true;
}
示例14: isExtension
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
boolean isExtension(TypeElement element) {
return element.getAnnotation(GlideExtension.class) != null;
}
示例15: ActivityInfo
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public ActivityInfo(Element element) {
TypeElement typeElement = (TypeElement) element;
Router router = typeElement.getAnnotation(Router.class);
url = router.value();
className = ClassName.bestGuess(typeElement.getQualifiedName().toString());
}