Java Code Examples for javax.lang.model.type.MirroredTypesException#getTypeMirrors()

The following examples show how to use javax.lang.model.type.MirroredTypesException#getTypeMirrors() . 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: LibraryConfigAnnotationParser.java    From aircon with MIT License 5 votes vote down vote up
private List<? extends TypeMirror> getJsonGenericTypes() {
	try {
		((JsonConfig) mConfigAnnotation).genericTypes();
	} catch (MirroredTypesException e) {
		return e.getTypeMirrors();
	}

	return null;
}
 
Example 2
Source File: ServiceAnnotationProcessor.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> getInterface(RouterService service) {
    try {
        service.interfaces();
    } catch (MirroredTypesException mte) {
        return mte.getTypeMirrors();
    }
    return null;
}
 
Example 3
Source File: PageAnnotationProcessor.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> getInterceptors(RouterPage page) {
    try {
        page.interceptors();
    } catch (MirroredTypesException mte) {
        return mte.getTypeMirrors();
    }
    return null;
}
 
Example 4
Source File: UriAnnotationProcessor.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> getInterceptors(RouterUri scheme) {
    try {
        scheme.interceptors();
    } catch (MirroredTypesException mte) {
        return mte.getTypeMirrors();
    }
    return null;
}
 
Example 5
Source File: RegexAnnotationProcessor.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
private static List<? extends TypeMirror> getInterceptors(RouterRegex regex) {
    try {
        regex.interceptors();
    } catch (MirroredTypesException mte) {
        return mte.getTypeMirrors();
    }
    return null;
}
 
Example 6
Source File: DataBindingParser.java    From data-mediator with Apache License 2.0 5 votes vote down vote up
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 7
Source File: TypeUtils.java    From data-mediator with Apache License 2.0 5 votes vote down vote up
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 8
Source File: RouteProcessor.java    From Naviganto with MIT License 5 votes vote down vote up
@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 9
Source File: RouteProcessor.java    From Naviganto with MIT License 5 votes vote down vote up
@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 10
Source File: ProcessorUtils.java    From Akatsuki with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: TypeProcessor.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: AutoCodecUtil.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: ReactModuleSpecProcessor.java    From react-native-GPay with MIT License 4 votes vote down vote up
@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;
}