本文整理汇总了Java中javax.lang.model.type.MirroredTypeException.getTypeMirror方法的典型用法代码示例。如果您正苦于以下问题:Java MirroredTypeException.getTypeMirror方法的具体用法?Java MirroredTypeException.getTypeMirror怎么用?Java MirroredTypeException.getTypeMirror使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.MirroredTypeException
的用法示例。
在下文中一共展示了MirroredTypeException.getTypeMirror方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getViewStateClassFromAnnotationParams
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的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.type.MirroredTypeException; //导入方法依赖的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: JsonProperty
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public JsonProperty(String humanName, ExecutableElement element) {
this.methodName = element.getSimpleName().toString();
this.humanName = humanName;
this.element = element;
this.type = TypeName.get(element.getReturnType());
this.annotations = buildAnnotations(element);
JsonAdapter jsonAdapter = element.getAnnotation(JsonAdapter.class);
if (jsonAdapter != null) {
try {
jsonAdapter.value();
} catch (MirroredTypeException e) {
typeAdapter = e.getTypeMirror();
}
}
DefaultValue defaultValue = element.getAnnotation(DefaultValue.class);
if (defaultValue != null) {
this.defaultValue = defaultValue.value();
}
}
示例4: Property
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
Property(String fieldName, TypeName typeName, VariableElement element, boolean isMapped) {
this.fieldName = fieldName;
this.element = element;
this.typeName = typeName;
this.annotations = getAnnotations(element);
this.isMapped = isMapped;
// 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();
}
示例5: FactoryAnnotatedClass
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public FactoryAnnotatedClass(TypeElement classElement) throws IllegalArgumentException {
this.annotatedClassElement = classElement;
Factory annotation = classElement.getAnnotation(Factory.class);
id = annotation.id();
if ("".equalsIgnoreCase(id) || id == null) {
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();
// 返回底层阶级Java语言规范中定义的标准名称。
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();
}
}
示例6: getConvertClass
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
private TypeName getConvertClass(PrefField prefField) {
TypeElement typeElement = null;
try {
prefField.converter();
} catch (MirroredTypeException e) {
DeclaredType typeMirror = (DeclaredType) e.getTypeMirror();
typeElement = (TypeElement) typeMirror.asElement();
}
if (typeElement == null) {
throw new IllegalArgumentException("TypeConverter may be wrong");
}
TypeMirror superType = typeElement.getSuperclass();
TypeMirror arg = ((DeclaredType) superType).getTypeArguments().get(1);
return ClassName.get(arg);
}
示例7: SPResponse
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public SPResponse(ApiResponse apiResponse, ExecutableElement element) {
int intCode = apiResponse.code();
if (intCode != -1) {
code = String.valueOf(apiResponse.code());
} else {
code = "default";
}
description = apiResponse.message();
TypeMirror tm = null;
try {
// Force exception
apiResponse.response().toString();
} catch (MirroredTypeException e) {
tm = e.getTypeMirror();
}
schema = SPSchema.fromTypeMirrorAndContainer(tm, apiResponse.responseContainer(), element);
}
示例8: Property
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
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();
}
示例9: validateAnnotation
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
private static String[] validateAnnotation(TypeElement annotatedElement) {
final ParseWrapperClass annotation =
annotatedElement.getAnnotation(ParseWrapperClass.class);
String canonicalName;
String shortName;
try {
Class<?> clazz = annotation.value();
canonicalName = clazz.getCanonicalName();
shortName = clazz.getSimpleName();
} catch (MirroredTypeException mte) {
DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
canonicalName = classTypeElement.getQualifiedName().toString();
shortName = classTypeElement.getSimpleName().toString();
}
if (!contains(WrapperElementCodeGenerator.ALLOWED_CLASSES, canonicalName)) {
Logger.getInstance().error("You cannot create a WrapperModel with " + canonicalName +
". See allowed classes in " + WrapperElementCodeGenerator.class.getSimpleName() + ".ALLOWED_CLASSES");
}
final String packageName = canonicalName.substring(0, canonicalName.length() - shortName.length() - 1);
return new String[]{packageName, shortName};
}
示例10: Property
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public Property(String humanName, ExecutableElement element) {
this.methodName = element.getSimpleName().toString();
this.humanName = humanName;
this.element = element;
type = TypeName.get(element.getReturnType());
annotations = buildAnnotations(element);
nullable = nullableAnnotation() != null;
ParcelAdapter parcelAdapter = element.getAnnotation(ParcelAdapter.class);
if (parcelAdapter != null) {
try {
parcelAdapter.value();
} catch (MirroredTypeException e) {
typeAdapter = e.getTypeMirror();
}
}
}
示例11: buildConverter
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
private String buildConverter(ExecutableElement method) {
String converterName = "";
Retrofit.Converter converterAnnotation = method.getAnnotation(Retrofit.Converter.class);
if (converterAnnotation != null) {
TypeMirror converter = null;
try {
converter = getTypeMirror(processingEnv, converterAnnotation.value());
} catch (MirroredTypeException mte) {
// http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/
converter = mte.getTypeMirror();
}
converterName = typeSimplifier.simplify(converter);
TypeMirror gsonConverterType = getTypeMirror(processingEnv, retrofit.converter.GsonConverter.class);
Types typeUtils = processingEnv.getTypeUtils();
if (typeUtils.isSubtype(gsonConverterType, converter)) {
this.gsonConverter = converterName;
}
}
return converterName;
}
示例12: getTypeMirror
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
/**
* Uses a neat trick to get a useful TypeMirror from an unusable Class
*
* @param processingEnv
* @param type
* @return the type-mirror for this type
* @since 0.4
* @see "http://blog.retep.org/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/"
*/
@Nullable
public static DeclaredType getTypeMirror(@Nullable final ProcessingEnvironment processingEnv, @Nonnull final Supplier<Class<?>> type)
{
try{
type.get().getCanonicalName();
}
catch(MirroredTypeException mte)
{
return ( DeclaredType ) mte.getTypeMirror();
}
//fall back to default behavior
if(processingEnv == null)
{
return null;
}
return ( DeclaredType )processingEnv.getElementUtils().getTypeElement( type.get().getCanonicalName()).asType();
}
示例13: Field
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public Field(Element element, Key key) {
this.prefKeyName = key.name();
try {
Class clazz = key.serializer();
serializerType = TypeName.get(clazz);
serializeType = detectSerializeTypeNameByClass(clazz);
} catch (MirroredTypeException mte) {
DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
serializerType = TypeName.get(classTypeMirror);
serializeType = detectSerializeTypeByTypeElement(classTypeElement);
}
VariableElement variable = (VariableElement) element;
this.fieldType = TypeName.get(element.asType());
this.name = element.getSimpleName().toString();
this.value = variable.getConstantValue();
}
示例14: ArgumentAnnotatedField
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
public ArgumentAnnotatedField(Element element, TypeElement classElement, Arg annotation)
throws ProcessingException {
this.name = element.getSimpleName().toString();
this.key = getKey(element, annotation);
this.type = element.asType().toString();
this.element = element;
this.required = annotation.required();
this.classElement = classElement;
// Private or protected fields need a setter method
useSetterMethod = element.getModifiers().contains(javax.lang.model.element.Modifier.PRIVATE)
|| element.getModifiers().contains(javax.lang.model.element.Modifier.PROTECTED);
try {
Class<? extends ArgsBundler> clazz = annotation.bundler();
bundlerClass = getFullQualifiedNameByClass(clazz);
} catch (MirroredTypeException mte) {
TypeMirror baggerClass = mte.getTypeMirror();
bundlerClass = getFullQualifiedNameByTypeMirror(baggerClass);
}
}
示例15: processDefinitionModelBuilder
import javax.lang.model.type.MirroredTypeException; //导入方法依赖的package包/类
private void processDefinitionModelBuilder(final Element e,
final String className,
final Map<String, String> processingContextMap) {
Definition definitionAnn = e.getAnnotation(Definition.class);
TypeMirror bMirror = null;
try {
Class<?> builderClass = definitionAnn.builder();
} catch (MirroredTypeException mte) {
bMirror = mte.getTypeMirror();
}
if (null != bMirror && !VoidBuilder.class.getName().equals(bMirror.toString())) {
String fqcn = bMirror.toString();
processingContextMap.put(className,
fqcn);
}
}