javax.lang.model.type.MirroredTypesException Java Examples
The following examples show how to use
javax.lang.model.type.MirroredTypesException.
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: AutoCodecUtil.java From bazel with Apache License 2.0 | 5 votes |
/** * Initializes the deserialize method. * * @param encodedType type being serialized */ static MethodSpec.Builder initializeSerializeMethodBuilder( TypeElement encodedType, AutoCodec annotation, ProcessingEnvironment env) { MethodSpec.Builder builder = MethodSpec.methodBuilder("serialize") .addModifiers(Modifier.PUBLIC) .returns(void.class) .addAnnotation(Override.class) .addAnnotation( AnnotationSpec.builder(ClassName.get(SuppressWarnings.class)) .addMember("value", "$S", "unchecked") .build()) .addException(SerializationException.class) .addException(IOException.class) .addParameter(SerializationContext.class, "context") .addParameter(TypeName.get(env.getTypeUtils().erasure(encodedType.asType())), "input") .addParameter(CodedOutputStream.class, "codedOut"); if (annotation.checkClassExplicitlyAllowed()) { builder.addStatement("context.checkClassExplicitlyAllowed(getEncodedClass(), input)"); } List<? extends TypeMirror> explicitlyAllowedClasses; try { explicitlyAllowedClasses = Arrays.stream(annotation.explicitlyAllowClass()) .map((clazz) -> getType(clazz, env)) .collect(Collectors.toList()); } catch (MirroredTypesException e) { explicitlyAllowedClasses = e.getTypeMirrors(); } for (TypeMirror explicitlyAllowedClass : explicitlyAllowedClasses) { builder.addStatement("context.addExplicitlyAllowedClass($T.class)", explicitlyAllowedClass); } return builder; }
Example #2
Source File: TypeProcessor.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void createElement(final StringBuilder sb, final ProcessorContext context, final Element e, final type t) { List<? extends TypeMirror> types = Collections.EMPTY_LIST; // Trick to obtain the names of the classes... try { t.wraps(); } catch (final MirroredTypesException ex) { try { types = ex.getTypeMirrors(); } catch (final MirroredTypeException ex2) { types = Arrays.asList(ex2.getTypeMirror()); } } verifyDoc(context, e, "type " + t.name(), t); for (final Element m : e.getEnclosedElements()) { if (m.getKind() == ElementKind.METHOD && m.getSimpleName().contentEquals("cast")) { final ExecutableElement ee = (ExecutableElement) m; if (ee.getParameters().size() == 4) { verifyDoc(context, m, "the casting operator of " + t.name(), null); } } } sb.append(in).append("_type(").append(toJavaString(t.name())).append(",new ") .append(rawNameOf(context, e.asType())).append("(),").append(t.id()).append(',').append(t.kind()); types.stream().map((ty) -> rawNameOf(context, ty)).forEach(s -> { sb.append(',').append(toClassObject(s)); TypeConverter.registerType(s, t.name(), t.id()); }); sb.append(");"); }
Example #3
Source File: ServiceAnnotationProcessor.java From WMRouter with Apache License 2.0 | 5 votes |
private static List<? extends TypeMirror> getInterface(RouterService service) { try { service.interfaces(); } catch (MirroredTypesException mte) { return mte.getTypeMirrors(); } return null; }
Example #4
Source File: PageAnnotationProcessor.java From WMRouter with Apache License 2.0 | 5 votes |
private static List<? extends TypeMirror> getInterceptors(RouterPage page) { try { page.interceptors(); } catch (MirroredTypesException mte) { return mte.getTypeMirrors(); } return null; }
Example #5
Source File: UriAnnotationProcessor.java From WMRouter with Apache License 2.0 | 5 votes |
private static List<? extends TypeMirror> getInterceptors(RouterUri scheme) { try { scheme.interceptors(); } catch (MirroredTypesException mte) { return mte.getTypeMirrors(); } return null; }
Example #6
Source File: RegexAnnotationProcessor.java From WMRouter with Apache License 2.0 | 5 votes |
private static List<? extends TypeMirror> getInterceptors(RouterRegex regex) { try { regex.interceptors(); } catch (MirroredTypesException mte) { return mte.getTypeMirrors(); } return null; }
Example #7
Source File: ProcessorUtils.java From Akatsuki with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public List<DeclaredType> getClassArrayFromAnnotationMethod(Supplier<Class<?>[]> supplier) { // JDK suggested way of getting type mirrors, do not waste time here, // just move on try { supplier.get(); } catch (MirroredTypesException e) { // types WILL be declared return (List<DeclaredType>) e.getTypeMirrors(); } return Collections.emptyList(); }
Example #8
Source File: RouteProcessor.java From Naviganto with MIT License | 5 votes |
@SuppressWarnings("unchecked") private List<TypeMirror> getParameters(RoutableView annotation) { try { annotation.params(); // TODO get forResult } catch (MirroredTypesException e) { return (List<TypeMirror>) e.getTypeMirrors(); } return null; }
Example #9
Source File: RouteProcessor.java From Naviganto with MIT License | 5 votes |
@SuppressWarnings("unchecked") private List<TypeMirror> getParameters(RoutableActivity annotation) { try { annotation.params(); // TODO get forResult } catch (MirroredTypesException e) { return (List<TypeMirror>) e.getTypeMirrors(); } return null; }
Example #10
Source File: LibraryConfigAnnotationParser.java From aircon with MIT License | 5 votes |
private List<? extends TypeMirror> getJsonGenericTypes() { try { ((JsonConfig) mConfigAnnotation).genericTypes(); } catch (MirroredTypesException e) { return e.getTypeMirrors(); } return null; }
Example #11
Source File: DataBindingParser.java From data-mediator with Apache License 2.0 | 5 votes |
private boolean parseBindsInternal(DataBindingInfo info, String varName, int index,String[] props, BindMethod[] methods) { final ProcessorPrinter pp = mContext.getProcessorPrinter(); if(props.length == 0){ pp.error(TAG, "parseBindsProperty", "props.length must > 0"); return false; } if(props.length > methods.length){ pp.error(TAG, "parseBindsProperty", "props.length can't > methods.length"); return false; } //truncate if props.length < methods.length if(props.length < methods.length){ methods = truncate(methods, props.length); } for(int i =0 ; i < props.length ; i ++){ final String prop = props[i]; if(prop == null || prop.isEmpty()){ continue; } List<String> types = null; //read Class<?> in compile time is wrong. see https://area-51.blog/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/. try { methods[i].paramTypes(); }catch (MirroredTypesException mte){ List<? extends TypeMirror> mirrors = mte.getTypeMirrors(); types = TypeUtils.convertToClassname(mirrors, null); } info.addBindInfo(new DataBindingInfo.BindInfo(varName, prop, index, methods[i].value(), types)); } return true; }
Example #12
Source File: TypeUtils.java From data-mediator with Apache License 2.0 | 5 votes |
public static List<String> classesToClassNames(ImportDesc desc){ List<String> types = null; //read Class<?> in compile time is wrong. see https://area-51.blog/2009/02/13/getting-class-values-from-annotations-in-an-annotationprocessor/. try { desc.classes(); }catch (MirroredTypesException mte){ List<? extends TypeMirror> mirrors = mte.getTypeMirrors(); types = convertToClassname(mirrors, null); } return types; }
Example #13
Source File: AnnotationProxyMaker.java From javaide with GNU General Public License v3.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #14
Source File: AnnotationMirrorImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Convert an annotation member value from JDT into Reflection, and from whatever its actual type * is into whatever type the reflective invoker of a method is expecting. * <p> * Only certain types are permitted as member values. Specifically, a member must be a constant, * and must be either a primitive type, String, Class, an enum constant, an annotation, or an * array of any of those. Multidimensional arrays are not permitted. * * @param actualValue the value as represented by {@link ElementValuePair#getValue()} * @param actualType the return type of the corresponding {@link MethodBinding} * @param expectedType the type that the reflective method invoker is expecting * @return an object of the expected type representing the annotation member value, * or an appropriate dummy value (such as null) if no value is available */ private Object getReflectionValue(Object actualValue, TypeBinding actualType, Class<?> expectedType) { if (null == expectedType) { // With no expected type, we can't even guess at a conversion return null; } if (null == actualValue) { // Return a type-appropriate equivalent of null return Factory.getMatchingDummyValue(expectedType); } if (expectedType.isArray()) { if (Class.class.equals(expectedType.getComponentType())) { // package Class[]-valued return as a MirroredTypesException if (actualType.isArrayType() && actualValue instanceof Object[] && ((ArrayBinding)actualType).leafComponentType.erasure().id == TypeIds.T_JavaLangClass) { Object[] bindings = (Object[])actualValue; List<TypeMirror> mirrors = new ArrayList<TypeMirror>(bindings.length); for (int i = 0; i < bindings.length; ++i) { if (bindings[i] instanceof TypeBinding) { mirrors.add(_env.getFactory().newTypeMirror((TypeBinding)bindings[i])); } } throw new MirroredTypesException(mirrors); } // TODO: actual value is not a TypeBinding[]. Should we return a TypeMirror[] around an ErrorType? return null; } // Handle arrays of types other than Class, e.g., int[], MyEnum[], ... return convertJDTArrayToReflectionArray(actualValue, actualType, expectedType); } else if (Class.class.equals(expectedType)) { // package the Class-valued return as a MirroredTypeException if (actualValue instanceof TypeBinding) { TypeMirror mirror = _env.getFactory().newTypeMirror((TypeBinding)actualValue); throw new MirroredTypeException(mirror); } else { // TODO: actual value is not a TypeBinding. Should we return a TypeMirror around an ErrorType? return null; } } else { // Handle unitary values of type other than Class, e.g., int, MyEnum, ... return convertJDTValueToReflectionType(actualValue, actualType, expectedType); } }
Example #15
Source File: AnnotationProxyMaker.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #16
Source File: AnnotationProxyMaker.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #17
Source File: AnnotationProxyMaker.java From hottub with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #18
Source File: AnnotationProxyMaker.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #19
Source File: AnnotationProxyMaker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #20
Source File: AnnotationProxyMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #21
Source File: AnnotationProxyMaker.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #22
Source File: ReactModuleSpecProcessor.java From react-native-GPay with MIT License | 4 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Set<? extends Element> reactModuleListElements = roundEnv.getElementsAnnotatedWith( ReactModuleList.class); for (Element reactModuleListElement : reactModuleListElements) { if (!(reactModuleListElement instanceof TypeElement)) { continue; } TypeElement typeElement = (TypeElement) reactModuleListElement; ReactModuleList reactModuleList = typeElement.getAnnotation(ReactModuleList.class); if (reactModuleList == null) { continue; } ClassName className = ClassName.get(typeElement); String packageName = ClassName.get(typeElement).packageName(); String fileName = className.simpleName(); List<String> nativeModules = new ArrayList<>(); try { reactModuleList.nativeModules(); // throws MirroredTypesException } catch (MirroredTypesException mirroredTypesException) { List<? extends TypeMirror> typeMirrors = mirroredTypesException.getTypeMirrors(); for (TypeMirror typeMirror : typeMirrors) { nativeModules.add(typeMirror.toString()); } } MethodSpec getReactModuleInfosMethod; try { getReactModuleInfosMethod = MethodSpec.methodBuilder("getReactModuleInfos") .addAnnotation(Override.class) .addModifiers(PUBLIC) .addCode(getCodeBlockForReactModuleInfos(nativeModules)) .returns(MAP_TYPE) .build(); } catch (ReactModuleSpecException reactModuleSpecException) { mMessager.printMessage(ERROR, reactModuleSpecException.mMessage); return false; } TypeSpec reactModulesInfosTypeSpec = TypeSpec.classBuilder( fileName + "$$ReactModuleInfoProvider") .addModifiers(Modifier.PUBLIC) .addMethod(getReactModuleInfosMethod) .addSuperinterface(ReactModuleInfoProvider.class) .build(); JavaFile javaFile = JavaFile.builder(packageName, reactModulesInfosTypeSpec) .addFileComment("Generated by " + getClass().getName()) .build(); try { javaFile.writeTo(mFiler); } catch (IOException e) { e.printStackTrace(); } } return true; }
Example #23
Source File: AnnotationProxyMaker.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #24
Source File: AnnotationProxyMaker.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }
Example #25
Source File: AnnotationProxyMaker.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected RuntimeException generateException() { return new MirroredTypesException(types); }