Skip to content

Instantly share code, notes, and snippets.

@jasmo2
Created September 15, 2015 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasmo2/6fd43f2be1666b04ef1f to your computer and use it in GitHub Desktop.
Save jasmo2/6fd43f2be1666b04ef1f to your computer and use it in GitHub Desktop.
package processor;
import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtAnnotation;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.reference.CtTypeReference;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import annotation.FeatureAnnotation;
public class Processor extends AbstractProcessor {
List<CtAnnotation<? extends Annotation>> codeAnnotations;
@Override
public void init() {
System.out.println("Empieza procesamiento");
codeAnnotations = new ArrayList<CtAnnotation<? extends Annotation>>();
super.init();
}
/*
@Override
public void process(CtAnnotation<FeatureAnnotation> annotation) {
boolean mandatory = annotation.getActualAnnotation().Mandatory();
String name = annotation.getActualAnnotation().Name();
System.out.println("Anotacion encontrada, Name: "+name);
System.out.println("Mandatorio: "+mandatory);
System.out.println("\t usada en: "+annotation.getParent().getSignature());
}
*/
@Override
public void processingDone() {
System.out.println("Termina procesamiento");
super.processingDone();
FeatureIdeWriter featureIdeWriter = new FeatureIdeWriter(codeAnnotations);
featureIdeWriter.WriteFeatureIdeFile();
}
@Override
public void process(CtElement element) {
List<CtAnnotation<? extends Annotation>> annotations = element.getAnnotations();
for (CtAnnotation<? extends Annotation> annotation : annotations)
{
codeAnnotations.add(annotation);
CtTypeReference<? extends Annotation> annotationType = annotation.getAnnotationType();
System.out.println("Anotacion encontrada, tipo: "+annotationType );
System.out.println("\t usada en: "+annotation.getParent().getSignature());
if (annotationType.getActualClass() == FeatureAnnotation.class)
{
FeatureAnnotation actualAnnotation = (FeatureAnnotation)annotation.getActualAnnotation();
System.out.println("\t FeatureAnnotation encontrada, atributo: "+actualAnnotation.Name());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment