当前位置: 首页>>代码示例>>Java>>正文


Java MirroredTypeException.getTypeMirror方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:ViewStateProviderClassGenerator.java

示例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();
    }
}
 
开发者ID:jacklongway,项目名称:FactoryAnnotation,代码行数:24,代码来源:FactoryAnnotatedClass.java

示例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();
  }
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:22,代码来源:JsonProperty.java

示例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();
}
 
开发者ID:foodora,项目名称:android-auto-mapper,代码行数:22,代码来源:AutoMappperProcessor.java

示例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();
    }
}
 
开发者ID:CharonChui,项目名称:AnnotationDemo,代码行数:25,代码来源:FactoryAnnotatedClass.java

示例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);
}
 
开发者ID:kobakei,项目名称:spot,代码行数:17,代码来源:SpotCompiler.java

示例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);
}
 
开发者ID:AlbertoSH,项目名称:Swagplash,代码行数:20,代码来源:SPResponse.java

示例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();
}
 
开发者ID:aitorvs,项目名称:auto-parcel,代码行数:21,代码来源:AutoParcelProcessor.java

示例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};
}
 
开发者ID:blipinsk,项目名称:Android-ParseModel,代码行数:23,代码来源:AnnotatedWrapperClass.java

示例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();
    }
  }
}
 
开发者ID:rharter,项目名称:auto-value-parcel,代码行数:18,代码来源:AutoValueParcelExtension.java

示例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;
}
 
开发者ID:yongjhih,项目名称:retrofit2.bak,代码行数:21,代码来源:RetrofitProcessor.java

示例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();
}
 
开发者ID:doe300,项目名称:jactiverecord,代码行数:27,代码来源:ProcessorUtils.java

示例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();
}
 
开发者ID:rejasupotaro,项目名称:kvs-schema,代码行数:20,代码来源:Field.java

示例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);
  }
}
 
开发者ID:sockeqwe,项目名称:fragmentargs,代码行数:24,代码来源:ArgumentAnnotatedField.java

示例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);
    }
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:17,代码来源:MainProcessor.java


注:本文中的javax.lang.model.type.MirroredTypeException.getTypeMirror方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。