示例#1
0
  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Processing @Implemented...");
    for (TypeElement annotation : annotations) {
      for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
        TypeElement serviceElement = (TypeElement) element;
        PackageElement packageElement = getPackage(serviceElement);
        final String packageName =
            packageElement == null ? "" : packageElement.getQualifiedName().toString();
        Implemented implemented = serviceElement.getAnnotation(Implemented.class);
        final String implName =
            "".equals(implemented.value())
                ? serviceElement.getSimpleName().toString() + "Impl"
                : implemented.value();
        final List<FieldDescriptor> fields = createFieldList(serviceElement);
        final String localName = determineLocalName(serviceElement);
        final boolean isPublic = serviceElement.getModifiers().contains(Modifier.PUBLIC);
        ImplementedDescriptor annotationDescriptor =
            new ImplementedDescriptor(isPublic, packageName, implName, localName, fields);
        createImplSourceFile(annotationDescriptor, serviceElement, packageName + "." + implName);
      }
    }

    return true;
  }
 @Override
 public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
     elements.add(elem.getQualifiedName());
   }
   return false;
 }
示例#3
0
 @Override
 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   for (TypeElement te : ElementFilter.typesIn(roundEnv.getRootElements())) {
     if (isSimpleName(te, "InvalidSource")) {
       for (Element c : te.getEnclosedElements()) {
         for (AnnotationMirror am : c.getAnnotationMirrors()) {
           Element ate = am.getAnnotationType().asElement();
           if (isSimpleName(ate, "ExpectInterfaces")) {
             checkInterfaces((TypeElement) c, getValue(am));
           } else if (isSimpleName(ate, "ExpectSupertype")) {
             checkSupertype((TypeElement) c, getValue(am));
           }
         }
       }
     }
   }
   return true;
 }
示例#4
0
 private List<FieldDescriptor> createFieldList(TypeElement serviceElement) {
   return ListUtils.unmodifiableList(
       CollectionUtils.collect(
           serviceElement.getEnclosedElements(),
           new Transformer<Element, FieldDescriptor>() {
             @Override
             public FieldDescriptor transform(Element enclosed) {
               FieldDescriptor fieldDescriptor =
                   enclosed.accept(AnnotationFieldVisitor.INSTANCE, utils);
               return fieldDescriptor;
             }
           },
           new ArrayList<FieldDescriptor>()));
 }
示例#5
0
 private void checkSupertype(TypeElement te, String expect) {
   System.err.println("check supertype: " + te + " -- " + expect);
   String found = asString(te.getSuperclass());
   checkEqual("supertype", te, found, expect);
 }
示例#6
0
 private void checkInterfaces(TypeElement te, String expect) {
   System.err.println("check interfaces: " + te + " -- " + expect);
   String found = asString(te.getInterfaces(), ", ");
   checkEqual("interfaces", te, found, expect);
 }
示例#7
0
 private String determineLocalName(final TypeElement serviceElement) {
   return serviceElement.getQualifiedName().toString();
 }