Java 类javax.lang.model.type.MirroredTypeException 实例源码

项目:GitHub    文件:ButterKnifeProcessor.java   
private void parseRClass(String respectivePackageName, String rClass) {
  Element element;

  try {
    element = elementUtils.getTypeElement(rClass);
  } catch (MirroredTypeException mte) {
    element = typeUtils.asElement(mte.getTypeMirror());
  }

  JCTree tree = (JCTree) trees.getTree(element);
  if (tree != null) { // tree can be null if the references are compiled types and not source
    IdScanner idScanner = new IdScanner(symbols, elementUtils.getPackageOf(element)
        .getQualifiedName().toString(), respectivePackageName);
    tree.accept(idScanner);
  } else {
    parseCompiledR(respectivePackageName, (TypeElement) element);
  }
}
项目:GitHub    文件:ViewStateProviderClassGenerator.java   
private String getViewClassFromAnnotationParams(TypeElement typeElement) {
    InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
    String mvpViewClassName = "";

    if (annotation != null) {
        TypeMirror value = null;
        try {
            annotation.view();
        } catch (MirroredTypeException mte) {
            value = mte.getTypeMirror();
        }

        mvpViewClassName = Util.getFullClassName(value);
    }

    if (mvpViewClassName.isEmpty() || DefaultView.class.getName().equals(mvpViewClassName)) {
        return null;
    }

    return mvpViewClassName;
}
项目:GitHub    文件:ViewStateProviderClassGenerator.java   
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;
}
项目:FactoryAnnotation    文件:FactoryAnnotatedClass.java   
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();
    }
}
项目:auto-value-json    文件:JsonProperty.java   
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();
  }
}
项目:convalida    文件:ConvalidaProcessor.java   
private void parseRClass(String respectivePackageName, String rClass) {
    Element element;

    try {
        element = elementUtils.getTypeElement(rClass);
    } catch (MirroredTypeException mte) {
        element = typeUtils.asElement(mte.getTypeMirror());
    }

    JCTree tree = (JCTree) trees.getTree(element);
    if (tree != null) {
        IdScanner idScanner = new IdScanner(symbols, elementUtils.getPackageOf(element)
                .getQualifiedName().toString(), respectivePackageName);
        tree.accept(idScanner);
    } else {
        parseCompiledR(respectivePackageName, (TypeElement) element);
    }
}
项目:android-auto-mapper    文件:AutoMappperProcessor.java   
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();
}
项目:butterknife-parent    文件:ButterKnifeProcessor.java   
private void parseRClass(String respectivePackageName, String rClass) {
  Element element;

  try {
    element = elementUtils.getTypeElement(rClass);
  } catch (MirroredTypeException mte) {
    element = typeUtils.asElement(mte.getTypeMirror());
  }

  JCTree tree = (JCTree) trees.getTree(element);
  if (tree != null) { // tree can be null if the references are compiled types and not source
    IdScanner idScanner = new IdScanner(symbols, elementUtils.getPackageOf(element)
        .getQualifiedName().toString(), respectivePackageName);
    tree.accept(idScanner);
  } else {
    parseCompiledR(respectivePackageName, (TypeElement) element);
  }
}
项目:AnnotationDemo    文件:FactoryAnnotatedClass.java   
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();
    }
}
项目:spot    文件:SpotCompiler.java   
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);
}
项目:Android-ButterKinfe    文件:ButterKnifeProcessor.java   
private void parseRClass(String rClass) {
  Element element;

  try {
    element = elementUtils.getTypeElement(rClass);
  } catch (MirroredTypeException mte) {
    element = typeUtils.asElement(mte.getTypeMirror());
  }

  JCTree tree = (JCTree) trees.getTree(element);
  if (tree != null) { // tree can be null if the references are compiled types and not source
    IdScanner idScanner =
        new IdScanner(symbols, elementUtils.getPackageOf(element).getQualifiedName().toString());
    tree.accept(idScanner);
  } else {
    parseCompiledR((TypeElement) element);
  }
}
项目:EasyMVP    文件:EasyMVPProcessor.java   
private void parseConductorController(Element element,
                                      Map<TypeElement, DelegateClassGenerator> delegateClassMap) {
    if (!SuperficialValidation.validateElement(element)) {
        error("Superficial validation error for %s", element.getSimpleName());
        return;
    }
    if (!Validator.isNotAbstractClass(element)) {
        error("%s is abstract", element.getSimpleName());
        return;
    }
    if (!Validator.isSubType(element, CONDUCTOR_CONTROLLER_CLASS_NAME, processingEnv)) {
        error("%s must extend View", element.getSimpleName());
        return;
    }
    //getEnclosing for class type will returns its package/
    TypeElement enclosingElement = (TypeElement) element;
    DelegateClassGenerator delegateClassGenerator =
            getDelegate(enclosingElement, delegateClassMap);
    delegateClassGenerator.setViewType(ViewType.CONDUCTOR_CONTROLLER);
    ConductorController annotation = element.getAnnotation(ConductorController.class);
    try {
        annotation.presenter();
    } catch (MirroredTypeException mte) {
        parsePresenter(delegateClassGenerator, mte);
    }
}
项目:Swagplash    文件:SPResponse.java   
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);
}
项目:Mockery    文件:GetTestClass.java   
private Mockery.Behaviour getBehaviourMockery(Mockery mockery) {
  try {
    mockery.value();
  } catch (MirroredTypeException e) {
    TypeElement typeElement = (TypeElement) types.asElement(e.getTypeMirror());
    try {
      String className = typeElement.getQualifiedName().toString();
      Class<?> behaviourClass = Class.forName(className);
      Mockery.Behaviour behaviour = (Mockery.Behaviour) instantiateInterface.from(behaviourClass);
      return behaviour;
    } catch (ClassNotFoundException e1) {
      e1.printStackTrace();
    }
  }
  return null;
}
项目:auto-parcel    文件:AutoParcelProcessor.java   
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();
}
项目:bridje-framework    文件:ComponentProcessor.java   
@Override
public void processElement(Element element) throws IOException
{
    //Get the @Component annotation for the current element.
    Component annot = element.getAnnotation(Component.class);
    String clsName = element.toString();
    String scope = "";
    try
    {
        annot.scope();
    }
    catch (MirroredTypeException e)
    {
        scope = e.getTypeMirror().toString();
    }
    appendProperty(clsName, scope);
}
项目:Android-ParseModel    文件:AnnotatedWrapperClass.java   
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};
}
项目:AndroidLife    文件:ButterKnifeProcessor.java   
/**
 * 1.获取 该 R class 在 scanForRClasses(...) 时,生辰生成的那棵树
 * - 如果存在树,就解析编译好的 R class
 * - 不存在的话,创建一个 Id 扫描类,扫描 R class 内的所有 Id
 * 2.Id 扫描类,内还会让树调用 Var 扫描类,扫描全部 int 变量
 *
 * @param respectivePackageName R class package name
 * @param rClass R class
 */
private void parseRClass(String respectivePackageName, String rClass) {
    Element element;

    try {
        element = elementUtils.getTypeElement(rClass);
    } catch (MirroredTypeException mte) {
        element = typeUtils.asElement(mte.getTypeMirror());
    }

    JCTree tree = (JCTree) trees.getTree(element);
    if (tree != null) { // tree can be null if the references are compiled types and not source
        IdScanner idScanner = new IdScanner(symbols, elementUtils.getPackageOf(element)
            .getQualifiedName().toString(), respectivePackageName);
        tree.accept(idScanner);
    } else {
        parseCompiledR(respectivePackageName, (TypeElement) element);
    }
}
项目:AndroidLife    文件:ScannerManager.java   
/**
 * 1.获取 该 R class 在 scanForRClasses(...) 时,生辰生成的那棵树
 * - 如果存在树,就解析编译好的 R class
 * - 不存在的话,创建一个 Id 扫描类,扫描 R class 内的所有 Id
 * 2.Id 扫描类,内还会让树调用 Var 扫描类,扫描全部 int 变量
 *
 * @param respectivePackageName R class package name
 * @param rClass R class
 */
private void parseRClass(String respectivePackageName, String rClass) {
    Element element;

    try {
        element = elementUtils.getTypeElement(rClass);
    } catch (MirroredTypeException mte) {
        element = typeUtils.asElement(mte.getTypeMirror());
    }

    JCTree tree = (JCTree) trees.getTree(element);
    if (tree != null) { // tree can be null if the references are compiled types and not source
        IdScanner idScanner = new IdScanner(this.symbols,
            this.elementUtils.getPackageOf(element)
                .getQualifiedName().toString(), respectivePackageName);
        tree.accept(idScanner);
    } else {
        parseCompiledR(respectivePackageName, (TypeElement) element);
    }
}
项目:auto-value-parcel    文件:AutoValueParcelExtension.java   
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();
    }
  }
}
项目:sundrio    文件:BuilderUtils.java   
public static TypeDef getInlineReturnType(BuilderContext context, Inline inline, TypeDef fallback) {
    try {
        Class returnType = inline.returnType();
        if (returnType == null) {
            return fallback;
        }
        return ClassTo.TYPEDEF.apply(inline.returnType());
    } catch (MirroredTypeException e) {
        if (None.FQN.equals(e.getTypeMirror().toString())) {
            return fallback;
        }

        Element element = context.getTypes().asElement(e.getTypeMirror());
        return ElementTo.TYPEDEF.apply((TypeElement) element);
    }
}
项目:retrofit2.bak    文件:RetrofitProcessor.java   
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;
}
项目:jactiverecord    文件:ProcessorUtils.java   
/**
 * 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();
}
项目:kvs-schema    文件:Field.java   
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();
}
项目:fragmentargs    文件:ArgumentAnnotatedField.java   
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);
  }
}
项目:kie-wb-common    文件:MainProcessor.java   
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);
    }
}
项目:kie-wb-common    文件:MainProcessor.java   
private void processDefinitionSetModelBuilder(final Element e,
                                              final String className,
                                              final Map<String, String> processingContextMap) {
    DefinitionSet definitionAnn = e.getAnnotation(DefinitionSet.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);
    }
}
项目:butterknife    文件:ButterKnifeProcessor.java   
private void parseRClass(PackageElement respectivePackageName, Symbol.ClassSymbol rClass,
    Set<String> referenced) {
  TypeElement element;

  try {
    element = rClass;
  } catch (MirroredTypeException mte) {
    element = (TypeElement) typeUtils.asElement(mte.getTypeMirror());
  }

  JCTree tree = (JCTree) trees.getTree(element);
  if (tree != null) { // tree can be null if the references are compiled types and not source
    IdScanner idScanner =
        new IdScanner(symbols, elementUtils.getPackageOf(element), respectivePackageName,
            referenced);
    tree.accept(idScanner);
  } else {
    parseCompiledR(respectivePackageName, element, referenced);
  }
}
项目:GitHub    文件:EasyMVPProcessor.java   
private void parseActivityView(Element element,
                               Map<TypeElement, DelegateClassGenerator> delegateClassMap) {
    //TODO print errors
    if (!SuperficialValidation.validateElement(element)) {
        error("Superficial validation error for %s", element.getSimpleName());
        return;
    }
    if (!Validator.isNotAbstractClass(element)) {
        error("%s is abstract", element.getSimpleName());
        return;
    }
    boolean isActivity =
            Validator.isSubType(element, ANDROID_ACTIVITY_CLASS_NAME, processingEnv);
    boolean isSupportActivity =
            Validator.isSubType(element, ANDROID_SUPPORT_ACTIVITY_CLASS_NAME, processingEnv);
    if (!isActivity && !isSupportActivity) {
        error("%s must extend Activity or AppCompatActivity", element.getSimpleName());
        return;
    }
    //getEnclosing for class type will returns its package/
    TypeElement enclosingElement = (TypeElement) element;
    DelegateClassGenerator delegateClassGenerator =
            getDelegate(enclosingElement, delegateClassMap);
    ActivityView annotation = element.getAnnotation(ActivityView.class);
    delegateClassGenerator.setResourceID(annotation.layout());
    if (isSupportActivity) {
        needSupportLoader = true;
        delegateClassGenerator.setViewType(ViewType.SUPPORT_ACTIVITY);
    } else {
        needLoader = true;
        delegateClassGenerator.setViewType(ViewType.ACTIVITY);
    }
    try {
        annotation.presenter();
    } catch (MirroredTypeException mte) {
        parsePresenter(delegateClassGenerator, mte);
    }
}
项目:GitHub    文件:EasyMVPProcessor.java   
private void parseFragmentView(Element element,
                               Map<TypeElement, DelegateClassGenerator> delegateClassMap) {
    //TODO print errors
    if (!SuperficialValidation.validateElement(element)) {
        error("Superficial validation error for %s", element.getSimpleName());
        return;
    }
    if (!Validator.isNotAbstractClass(element)) {
        error("%s is abstract", element.getSimpleName());
        return;
    }
    boolean isFragment =
            Validator.isSubType(element, ANDROID_FRAGMENT_CLASS_NAME, processingEnv);
    boolean isSupportFragment =
            Validator.isSubType(element, ANDROID_SUPPORT_FRAGMENT_CLASS_NAME, processingEnv);
    if (!isFragment && !isSupportFragment) {
        error("%s must extend Fragment or support Fragment", element.getSimpleName());
        return;
    }
    //getEnclosing for class type will returns its package/
    TypeElement enclosingElement = (TypeElement) element;
    DelegateClassGenerator delegateClassGenerator =
            getDelegate(enclosingElement, delegateClassMap);
    if (isFragment) {
        needLoader = true;
        delegateClassGenerator.setViewType(ViewType.FRAGMENT);
    } else {
        needSupportLoader = true;
        delegateClassGenerator.setViewType(ViewType.SUPPORT_FRAGMENT);
    }
    FragmentView annotation = element.getAnnotation(FragmentView.class);
    try {
        annotation.presenter();
    } catch (MirroredTypeException mte) {
        parsePresenter(delegateClassGenerator, mte);
    }
}
项目:GitHub    文件:EasyMVPProcessor.java   
private void parseCustomView(Element element,
                             Map<TypeElement, DelegateClassGenerator> delegateClassMap) {
    //TODO print errors
    if (!SuperficialValidation.validateElement(element)) {
        error("Superficial validation error for %s", element.getSimpleName());
        return;
    }
    if (!Validator.isNotAbstractClass(element)) {
        error("%s is abstract", element.getSimpleName());
        return;
    }
    if (!Validator.isSubType(element, ANDROID_CUSTOM_VIEW_CLASS_NAME, processingEnv)) {
        error("%s must extend View", element.getSimpleName());
        return;
    }

    //getEnclosing for class type will returns its package/
    TypeElement enclosingElement = (TypeElement) element;
    DelegateClassGenerator delegateClassGenerator =
            getDelegate(enclosingElement, delegateClassMap);
    delegateClassGenerator.setViewType(ViewType.CUSTOM_VIEW);

    CustomView annotation = element.getAnnotation(CustomView.class);
    try {
        annotation.presenter();
    } catch (MirroredTypeException mte) {
        parsePresenter(delegateClassGenerator, mte);
    }
}
项目:GitHub    文件:EasyMVPProcessor.java   
private void parsePresenter(DelegateClassGenerator delegateClassGenerator,
                            MirroredTypeException mte) {
    TypeElement presenterElement = getTypeElement(mte);
    delegateClassGenerator.setPresenter(getClassName(presenterElement));
    String presenterView = findViewTypeOfPresenter(presenterElement);
    delegateClassGenerator.setPresenterViewQualifiedName(presenterView);
}
项目:GitHub    文件:JsonFieldProcessor.java   
private void processJsonFieldAnnotation(Element element, Map<String, JsonObjectHolder> jsonObjectMap, Elements elements, Types types) {
    if (!isJsonFieldFieldAnnotationValid(element, elements)) {
        return;
    }

    TypeElement enclosingElement = (TypeElement)element.getEnclosingElement();

    JsonObjectHolder objectHolder = jsonObjectMap.get(TypeUtils.getInjectedFQCN(enclosingElement, elements));
    JsonFieldHolder fieldHolder = objectHolder.fieldMap.get(element.getSimpleName().toString());

    if (fieldHolder == null) {
        fieldHolder = new JsonFieldHolder();
        objectHolder.fieldMap.put(element.getSimpleName().toString(), fieldHolder);
    }

    JsonField annotation = element.getAnnotation(JsonField.class);

    TypeMirror typeConverterType;
    try {
        typeConverterType = mProcessingEnv.getElementUtils().getTypeElement(annotation.typeConverter().getCanonicalName()).asType();
    } catch (MirroredTypeException mte) {
        typeConverterType = mte.getTypeMirror();
    }

    String[] fieldName = annotation.name();

    JsonIgnore ignoreAnnotation = element.getAnnotation(JsonIgnore.class);
    boolean shouldParse = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.SERIALIZE_ONLY;
    boolean shouldSerialize = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.PARSE_ONLY;

    String error = fieldHolder.fill(element, elements, types, fieldName, typeConverterType, objectHolder, shouldParse, shouldSerialize);
    if (!TextUtils.isEmpty(error)) {
        error(element, error);
    }

    ensureTypeConverterClassValid(typeConverterType, elements, types);
}
项目:DaggerAutoInject    文件:DaggerAutoInjectProcessor.java   
private static TypeMirror getComponent(InjectApplication annotation) {
    try {
        annotation.component(); // this should throw
    } catch (MirroredTypeException mte) {
        return mte.getTypeMirror();
    }
    return null; // can this ever happen ??
}
项目:Witch-Android    文件:AnnotationUtils.java   
public static TypeName getOnBindToRecyclerViewAdapterClass(Element bindAction) {
    TypeMirror bindClass;
    try {
        bindAction.getAnnotation(se.snylt.witch.annotations.BindToRecyclerView.class).adapter();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return TypeName.get(bindClass);
}
项目:Witch-Android    文件:AnnotationUtils.java   
public static TypeName getOnBindToViewPagerAdapterClass(Element bindAction) {
    TypeMirror bindClass;
    try {
        bindAction.getAnnotation(se.snylt.witch.annotations.BindToViewPager.class).adapter();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return TypeName.get(bindClass);
}
项目:Witch-Android    文件:AnnotationUtils.java   
public static TypeMirror getOnBindTypeMirror(Element action) {
    TypeMirror bindClass;
    try {
        action.getAnnotation(se.snylt.witch.annotations.OnBind.class).value();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return bindClass;
}
项目:Witch-Android    文件:AnnotationUtils.java   
public static TypeName getOnBindToViewClass(Element action) {
    TypeMirror bindClass;
    try {
        action.getAnnotation(se.snylt.witch.annotations.BindToView.class).view();
        return null;
    } catch (MirroredTypeException mte) {
        bindClass = mte.getTypeMirror();
    }
    return TypeName.get(bindClass);
}
项目:DUnit    文件:DUnitModelUtil.java   
/**
 * 获取DUnitGroup的group字段的TypeMirror
 */
public TypeMirror getUnitGroupModelGroupTypeMirror(DUnitGroup dUnitGroup){
    try {
        dUnitGroup.group();
    }catch (MirroredTypeException e){
        TypeMirror typeMirror = e.getTypeMirror();
        return typeMirror;
    }
    return null;
}
项目:DUnit    文件:DUnitModelUtil.java   
/**
 * 获取DUnit的group字段的TypeMirror
 */
public TypeMirror getUnitModelGroupTypeMirror(DUnit dUnit){
    try {
        dUnit.group();
    }catch (MirroredTypeException e){
        TypeMirror typeMirror = e.getTypeMirror();
        return typeMirror;
    }
    return null;
}