示例#1
0
  private Set<TypeElement> getMappers(
      final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) {
    Set<TypeElement> mapperTypes = new HashSet<TypeElement>();

    for (TypeElement annotation : annotations) {
      // Indicates that the annotation's type isn't on the class path of the compiled
      // project. Let the compiler deal with that and print an appropriate error.
      if (annotation.getKind() != ElementKind.ANNOTATION_TYPE) {
        continue;
      }

      try {
        Set<? extends Element> annotatedMappers =
            roundEnvironment.getElementsAnnotatedWith(annotation);
        for (Element mapperElement : annotatedMappers) {
          TypeElement mapperTypeElement = asTypeElement(mapperElement);

          // on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with
          // annotations unknown to the compiler, even though they are not declared Mappers
          if (mapperTypeElement != null && MapperPrism.getInstanceOn(mapperTypeElement) != null) {
            mapperTypes.add(mapperTypeElement);
          }
        }
      } catch (Throwable t) { // whenever that may happen, but just to stay on the save side
        handleUncaughtError(annotation, t);
        continue;
      }
    }
    return mapperTypes;
  }
  private List<MapperReference> initReferencedMappers(
      TypeElement element, MapperConfiguration mapperConfig) {
    List<MapperReference> result = new LinkedList<MapperReference>();
    List<String> variableNames = new LinkedList<String>();

    for (TypeMirror usedMapper : mapperConfig.uses()) {
      DefaultMapperReference mapperReference =
          DefaultMapperReference.getInstance(
              typeFactory.getType(usedMapper),
              MapperPrism.getInstanceOn(typeUtils.asElement(usedMapper)) != null,
              typeFactory,
              variableNames);

      result.add(mapperReference);
      variableNames.add(mapperReference.getVariableName());
    }

    return result;
  }
 public static MapperConfiguration getInstanceOn(Element e) {
   return new MapperConfiguration(MapperPrism.getInstanceOn(e));
 }