javax.lang.model.type.MirroredTypeException Java Examples
The following examples show how to use
javax.lang.model.type.MirroredTypeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArgumentAnnotatedField.java From fragmentargs with Apache License 2.0 | 6 votes |
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; try { Class<? extends ArgsBundler> clazz = annotation.bundler(); bundlerClass = getFullQualifiedNameByClass(clazz); } catch (MirroredTypeException mte) { TypeMirror baggerClass = mte.getTypeMirror(); bundlerClass = getFullQualifiedNameByTypeMirror(baggerClass); } }
Example #2
Source File: InjectViewStateProcessor.java From Moxy with MIT License | 6 votes |
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; }
Example #3
Source File: InjectViewStateProcessor.java From Moxy with MIT License | 6 votes |
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; }
Example #4
Source File: ServiceProviderProcessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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)) { String interfaceName = ex.getTypeMirror().toString(); createProviderFile(serviceProvider, interfaceName); } } } }
Example #5
Source File: EasyMVPProcessor.java From EasyMVP with Apache License 2.0 | 6 votes |
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); } }
Example #6
Source File: BuilderUtils.java From sundrio with Apache License 2.0 | 6 votes |
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); } }
Example #7
Source File: IntimateProcesser.java From Intimate with Apache License 2.0 | 6 votes |
private void processRefTarget(RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(RefTarget.class)) { if (this.element == null) { this.element = element; } TypeElement classElement = (TypeElement) element; RefTarget refTarget = classElement.getAnnotation(RefTarget.class); String interfaceFullName = classElement.getQualifiedName().toString(); String targetName; try { targetName = refTarget.clazz().getCanonicalName(); } catch (MirroredTypeException mte) { targetName = mte.getTypeMirror().toString(); } RefTargetModel model = new RefTargetModel(interfaceFullName, targetName, false, refTarget.optimizationRef()); targetModelMap.put(interfaceFullName, model); } }
Example #8
Source File: FactoryAnnotatedCls.java From ShapeView with Apache License 2.0 | 6 votes |
public FactoryAnnotatedCls(TypeElement classElement) throws ProcessingException { this.mAnnotatedClsElement = classElement; ShapeType annotation = classElement.getAnnotation(ShapeType.class); type = annotation.value(); try { mSupperClsSimpleName = annotation.superClass().getSimpleName(); mSupperClsQualifiedName = annotation.superClass().getCanonicalName(); } catch (MirroredTypeException mte) { DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror(); TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement(); mSupperClsQualifiedName = classTypeElement.getQualifiedName().toString(); mSupperClsSimpleName = classTypeElement.getSimpleName().toString(); } if (mSupperClsSimpleName == null || mSupperClsSimpleName.equals("")) { throw new ProcessingException(classElement, "superClass() in @%s for class %s is null or empty! that's not allowed", ShapeType.class.getSimpleName(), classElement.getQualifiedName().toString()); } }
Example #9
Source File: AutoParcelProcessor.java From auto-parcel with Apache License 2.0 | 6 votes |
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(); }
Example #10
Source File: LibraryConfigAnnotationParser.java From aircon with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Override public <T> T getAttribute(final String attr) { try { return (T) Objects.requireNonNull(mConfigAnnotation) .annotationType() .getMethod(attr) .invoke(mConfigAnnotation); } catch (Exception e) { if (e.getCause() instanceof MirroredTypeException) { return (T) ((MirroredTypeException) e.getCause()).getTypeMirror(); } } return null; }
Example #11
Source File: AndroidResourceSanner.java From convalida with Apache License 2.0 | 6 votes |
private static void parseRClass(String respectivePackageName, String rClass) { Element element; try { element = scanner.elementUtils.getTypeElement(rClass); } catch (MirroredTypeException mte) { element = scanner.typeUtils.asElement(mte.getTypeMirror()); } JCTree tree = (JCTree) scanner.trees.getTree(element); if (tree != null) { IdScanner idScanner = new IdScanner(scanner.symbols, scanner.elementUtils.getPackageOf(element) .getQualifiedName().toString(), respectivePackageName); tree.accept(idScanner); } else { parseCompiledR(respectivePackageName, (TypeElement) element); } }
Example #12
Source File: Field.java From kvs-schema with MIT License | 6 votes |
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(); }
Example #13
Source File: DataBeanModel.java From PowerfulRecyclerViewAdapter with Apache License 2.0 | 5 votes |
@Override public BeanInfo visitType(TypeElement element, Void aVoid) { //check element type if (!VALIDATED_CLASS_NAME.equals(getQualifiedName(element))) checkElementType(element, VALIDATED_CLASS_NAME); TypeMirror typeMirror = null; BeanInfo beanInfo = new BeanInfo(); //get annotated Element info. String annotatedElementPackage = getPackageName(element); beanInfo.holderName = getSimpleName(element); beanInfo.holderPackage = annotatedElementPackage; //get annotation info try { DataBean dataBean = element.getAnnotation(DataBean.class); beanInfo.dataBeanName = dataBean.beanName(); beanInfo.dataBeanPackage = annotatedElementPackage + ".databean"; beanInfo.layoutId = dataBean.layout(); //Get type of Data,may throw exception dataBean.data(); } catch (MirroredTypeException mte) { typeMirror = mte.getTypeMirror(); } if (typeMirror != null) { if (typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement dataBeanElement = (TypeElement) declaredType.asElement(); beanInfo.dataPackage = getPackageName(dataBeanElement); beanInfo.dataName = getSimpleName(dataBeanElement); } } //log logger.log(Diagnostic.Kind.NOTE, beanInfo.toString()); return beanInfo; }
Example #14
Source File: EasyMVPProcessor.java From EasyMVP with Apache License 2.0 | 5 votes |
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) { delegateClassGenerator.setViewType(ViewType.FRAGMENT); } else { delegateClassGenerator.setViewType(ViewType.SUPPORT_FRAGMENT); } FragmentView annotation = element.getAnnotation(FragmentView.class); try { annotation.presenter(); } catch (MirroredTypeException mte) { parsePresenter(delegateClassGenerator, mte); } }
Example #15
Source File: StarlarkMethodProcessor.java From bazel with Apache License 2.0 | 5 votes |
private static TypeMirror getParamType(Param param) { // See explanation of this hack at Element.getAnnotation // and at https://stackoverflow.com/a/10167558. try { param.type(); throw new IllegalStateException("unreachable"); } catch (MirroredTypeException ex) { return ex.getTypeMirror(); } }
Example #16
Source File: ScoopsProcesssor.java From Scoops with Apache License 2.0 | 5 votes |
private TypeMirror getAdapterTypeMirror(BindTopping annotation){ TypeMirror value = null; try { annotation.adapter(); }catch (MirroredTypeException e){ value = e.getTypeMirror(); } return value; }
Example #17
Source File: ScoopsProcesssor.java From Scoops with Apache License 2.0 | 5 votes |
private TypeMirror getInterpolatorTypeMirror(BindTopping annotation){ TypeMirror value = null; try{ annotation.interpolator(); }catch (MirroredTypeException e){ value = e.getTypeMirror(); } return value; }
Example #18
Source File: ScoopsProcesssor.java From Scoops with Apache License 2.0 | 5 votes |
private TypeMirror getInterpolatorTypeMirror(BindToppingStatus annotation){ TypeMirror value = null; try{ annotation.interpolator(); }catch (MirroredTypeException e){ value = e.getTypeMirror(); } return value; }
Example #19
Source File: ReduceAction.java From reductor with Apache License 2.0 | 5 votes |
private static TypeMirror getCreator(AutoReducer.Action action, Elements elements, Env env, ExecutableElement element) { TypeMirror typeMirror; try { Class<?> fromClass = action.from(); String className = fromClass.getCanonicalName(); typeMirror = elements.getTypeElement(className).asType(); } catch (MirroredTypeException mte) { typeMirror = mte.getTypeMirror(); } //Void is used by default meaning it's not linked to any action creator return env.getTypes().isSameType(typeMirror, env.asType(Void.class)) ? null : typeMirror; }
Example #20
Source File: VersionProviderMetaData.java From picocli with Apache License 2.0 | 5 votes |
/** * Sets the specified {@code CommandSpec}'s * {@linkplain CommandSpec#versionProvider(picocli.CommandLine.IVersionProvider)} version provider} * to an {@code VersionProviderMetaData} instance if the annotation attribute was present on the * specified {@code Command} annotation. * * @param result the command spec to initialize * @param cmd the {@code @Command} annotation to inspect */ public static void initVersionProvider(CommandSpec result, Command cmd) { try { // this is a hack to get access to the TypeMirror of the version provider class cmd.versionProvider(); } catch (MirroredTypeException ex) { VersionProviderMetaData provider = new VersionProviderMetaData(ex.getTypeMirror()); if (!provider.isDefault()) { result.versionProvider(provider); } } }
Example #21
Source File: EasyMVPProcessor.java From EasyMVP with Apache License 2.0 | 5 votes |
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) { delegateClassGenerator.setViewType(ViewType.SUPPORT_ACTIVITY); } else { delegateClassGenerator.setViewType(ViewType.ACTIVITY); } try { annotation.presenter(); } catch (MirroredTypeException mte) { parsePresenter(delegateClassGenerator, mte); } }
Example #22
Source File: ProcessorUtils.java From Akatsuki with Apache License 2.0 | 5 votes |
public DeclaredType getClassFromAnnotationMethod(Supplier<Class<?>> supplier) { // JDK suggested way of getting type mirrors, do not waste time here, // just move on try { return (DeclaredType) of(supplier.get()); } catch (MirroredTypeException e) { // types WILL be declared return (DeclaredType) e.getTypeMirror(); } }
Example #23
Source File: JServiceCodeGenerator.java From jackdaw with Apache License 2.0 | 5 votes |
private String getProviderClass(final JService annotation) { try { final Class<?> providerClass = annotation.value(); return providerClass.getCanonicalName(); } catch (final MirroredTypeException ex) { final TypeMirror typeMirror = ex.getTypeMirror(); return typeMirror.toString(); } }
Example #24
Source File: RegistrationAnnotatedClassCreator.java From Alligator with MIT License | 5 votes |
private String obtainScreenClassName(TypeElement classElement) { RegisterScreen annotation = classElement.getAnnotation(RegisterScreen.class); try { Class<?> clazz = annotation.value(); return clazz.getCanonicalName(); } catch (MirroredTypeException mte) { DeclaredType type = (DeclaredType) mte.getTypeMirror(); TypeElement typeElement = (TypeElement) type.asElement(); return typeElement.getQualifiedName().toString(); } }
Example #25
Source File: StarlarkMethodProcessor.java From bazel with Apache License 2.0 | 5 votes |
private static TypeMirror getParamTypeType(ParamType paramType) { // See explanation of this hack at Element.getAnnotation // and at https://stackoverflow.com/a/10167558. try { paramType.type(); throw new IllegalStateException("unreachable"); } catch (MirroredTypeException ex) { return ex.getTypeMirror(); } }
Example #26
Source File: VelocityTransformationProcessor.java From sundrio with Apache License 2.0 | 5 votes |
private TypeMirror annotationMirror(AnnotationSelector selector){ try { selector.value(); return null; } catch (MirroredTypeException m) { return m.getTypeMirror(); } }
Example #27
Source File: BuilderUtils.java From sundrio with Apache License 2.0 | 5 votes |
public static TypeDef getInlineType(BuilderContext context, Inline inline) { try { return ClassTo.TYPEDEF.apply(inline.type()); } catch (MirroredTypeException e) { Element element = context.getTypes().asElement(e.getTypeMirror()); return ElementTo.TYPEDEF.apply((TypeElement) element); } }
Example #28
Source File: ProcessorUtils.java From Witch-Android with Apache License 2.0 | 5 votes |
public static TypeName getBindDataViewTypeName(Element action) { TypeMirror bindClass; try { action.getAnnotation(BindData.class).view(); return null; } catch (MirroredTypeException mte) { bindClass = mte.getTypeMirror(); } return TypeName.get(bindClass); }
Example #29
Source File: AptDeserializerBuilder.java From domino-jackson with Apache License 2.0 | 5 votes |
private String getBuilderName() { JsonDeserialize jsonDeserialize = typeUtils.asElement(beanType).getAnnotation(JsonDeserialize.class); if (isNull(jsonDeserialize)) { return null; } String builderName; try { builderName = jsonDeserialize.builder().getName(); } catch (MirroredTypeException e) { TypeMirror typeMirror = e.getTypeMirror(); builderName = typeMirror.toString(); } return builderName; }
Example #30
Source File: DaggerAutoInjectProcessor.java From DaggerAutoInject with Apache License 2.0 | 5 votes |
private static TypeMirror getComponent(InjectApplication annotation) { try { annotation.component(); // this should throw } catch (MirroredTypeException mte) { return mte.getTypeMirror(); } return null; // can this ever happen ?? }