Created
August 13, 2014 21:46
-
-
Save hsestupin/135b6568df8bc64c278b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean process(Set elements, RoundEnvironment env) { | |
System.out.println("processor running"); | |
for (Element element: env.getElementsAnnotatedWith(Marker.class)) { | |
if (element.getKind() == ElementKind.METHOD) { | |
// Create an aspect targeting this method! | |
String methodName = element.getSimpleName().toString(); | |
String aspectText = | |
"public aspect Advise_"+methodName+" {\n"+ | |
" before(): execution(* "+methodName+"(..)) {\n"+ | |
" System.out.println(\""+methodName+" running\");\n"+ | |
" }\n"+ | |
"}\n"; | |
try { | |
FileObject file = filer.createResource( | |
StandardLocation.SOURCE_OUTPUT, | |
packageElement.getQualifiedName(), | |
"Advise_"+methodName + ".aj", | |
element); | |
file.openWriter().append(aspectText).close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Generated aspect to advise "+element.getSimpleName()); | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment