當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。