List of usage examples for javax.annotation.processing RoundEnvironment getElementsAnnotatedWith
Set<? extends Element> getElementsAnnotatedWith(Class<? extends Annotation> a);
From source file:Main.java
/** * Returns only the elements that are annotated with the given class. For some reason * RoundEnvironment is returning elements annotated by other annotations. *//* w ww .ja v a 2 s .c om*/ static List<Element> getElementsAnnotatedWith(RoundEnvironment roundEnv, Class<? extends Annotation> annotationClass) { ArrayList<Element> elements = new ArrayList<Element>(); for (Element element : roundEnv.getElementsAnnotatedWith(annotationClass)) { if (element.getAnnotation(annotationClass) != null) { elements.add(element); } } return elements; }
From source file:org.mule.module.extension.internal.capability.xml.schema.AnnotationProcessorUtils.java
/** * Returns the {@link TypeElement}s in the * {@code roundEnvironment} which are annotated * with {@code annotationType}/* w w w . j a v a 2 s . co m*/ * * @param annotationType the type of the {@link Annotation} * @param roundEnvironment the current {@link RoundEnvironment} * @return a {@link Set} with the {@link TypeElement}s annotated with {@code annotationType} */ public static Set<TypeElement> getTypeElementsAnnotatedWith(Class<? extends Annotation> annotationType, RoundEnvironment roundEnvironment) { return ElementFilter.typesIn(roundEnvironment.getElementsAnnotatedWith(annotationType)); }
From source file:cat.ogasoft.protocolizer.processor.CompilerPhase.java
public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException { try {/*from w w w .j a v a2s. c om*/ String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft" + File.separatorChar + "protocolizer" + File.separatorChar + "protoc"; DefaultExecutor de = new DefaultExecutor(); for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) { ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class); if (compiler.compile()) { String base = protocPath.replace('.', File.separatorChar); File dst = new File(base); if (!dst.exists() && !dst.mkdirs()) { throw new Exception("Cann not be created directory " + dst.getAbsolutePath()); } File rootDirectori = new File(base); //Compile all the files in compiler.protoFilePaths() FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".proto"); } }; for (File protoc : rootDirectori.listFiles(filter)) { String target = base + File.separatorChar + protoc.getName(); LOG.info("\tCompiling " + target + "..."); CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " " + compiler.language().option + "=src " + target); int result = de.execute(cmd); if (result != 0) { throw new CompilerException("HO ho... somthing went wrong, code: " + result); } LOG.info("\t" + target + " compiled"); } } } } catch (Exception e) { //Any exception is a CompilerException. throw new CompilerException(e.getMessage()); } }
From source file:org.drombler.acp.core.action.impl.ActionAnnotationProcessor.java
@Override protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(Action.class)) { Action actionAnnotation = element.getAnnotation(Action.class); if (actionAnnotation != null) { registerAction(element, actionAnnotation); }//from w w w. ja v a2 s . co m } for (Element element : roundEnv.getElementsAnnotatedWith(ToggleAction.class)) { ToggleAction actionAnnotation = element.getAnnotation(ToggleAction.class); if (actionAnnotation != null) { registerToggleAction(element, actionAnnotation); } } return false; }
From source file:org.drombler.acp.core.docking.impl.DockingAreaAnnotationProcessor.java
@Override protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(DockingAreas.class)) { DockingAreas dockingAreasAnnotation = element.getAnnotation(DockingAreas.class); if (dockingAreasAnnotation != null) { for (DockingArea dockingAreaAnnotation : dockingAreasAnnotation.value()) { registerDockingArea(dockingAreaAnnotation, element); }/*w w w. ja v a2 s .c o m*/ } } for (Element element : roundEnv.getElementsAnnotatedWith(DockingArea.class)) { DockingArea dockingAreaAnnotation = element.getAnnotation(DockingArea.class); if (dockingAreaAnnotation != null) { registerDockingArea(dockingAreaAnnotation, element); } } return false; }
From source file:org.drombler.acp.core.docking.impl.DockingAnnotationProcessor.java
@Override protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(ViewDocking.class)) { ViewDocking dockingAnnotation = element.getAnnotation(ViewDocking.class); if (dockingAnnotation != null) { registerViewDocking(dockingAnnotation, element); }//from www . ja v a 2 s. co m } for (Element element : roundEnv.getElementsAnnotatedWith(EditorDocking.class)) { EditorDocking dockingAnnotation = element.getAnnotation(EditorDocking.class); if (dockingAnnotation != null) { registerEditorDocking(dockingAnnotation, element); } } return false; }
From source file:com.github.cchacin.JsonSchemaProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (final Element element : roundEnv.getElementsAnnotatedWith(JsonSchema.class)) { final TypeElement classElement = (TypeElement) element; final PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "annotated class: " + classElement.getQualifiedName(), element); final String fqClassName = classElement.getQualifiedName().toString(); final String className = classElement.getSimpleName().toString(); final String packageName = packageElement.getQualifiedName().toString(); final JsonSchema jsonSchema = element.getAnnotation(JsonSchema.class); try {/*from w ww .ja v a 2 s. co m*/ final JsonNode node = new ObjectMapper().readTree( Thread.currentThread().getContextClassLoader().getResourceAsStream(jsonSchema.path())); vc.put("display", new DisplayTool()); vc.put("json", node); vc.put("className", className); vc.put("packageName", packageName); final JavaFileObject jfo = filer.createSourceFile(fqClassName + "JsonSchema"); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "creating source file: " + jfo.toUri()); final Writer writer = jfo.openWriter(); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "applying velocity template: " + vt.getName()); vt.merge(vc, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:org.drombler.acp.core.action.impl.ToolBarAnnotationProcessor.java
@Override protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(ToolBars.class)) { ToolBars toolBarsAnnotation = element.getAnnotation(ToolBars.class); if (toolBarsAnnotation != null) { for (ToolBar toolBarAnnotation : toolBarsAnnotation.value()) { registerToolBar(toolBarAnnotation, element); }//from w w w . j ava 2s . c o m } } for (Element element : roundEnv.getElementsAnnotatedWith(ToolBar.class)) { ToolBar toolBarAnnotation = element.getAnnotation(ToolBar.class); if (toolBarAnnotation != null) { registerToolBar(toolBarAnnotation, element); } } for (Element element : roundEnv.getElementsAnnotatedWith(ToolBarEntry.class)) { ToolBarEntry toolBarEntryAnnotation = element.getAnnotation(ToolBarEntry.class); if (toolBarEntryAnnotation != null) { Action actionAnnotation = element.getAnnotation(Action.class); registerToolBarEntry(toolBarEntryAnnotation, actionAnnotation, element); } } for (Element element : roundEnv.getElementsAnnotatedWith(ToolBarToggleEntry.class)) { ToolBarToggleEntry toolBarEntryAnnotation = element.getAnnotation(ToolBarToggleEntry.class); if (toolBarEntryAnnotation != null) { ToggleAction actionAnnotation = element.getAnnotation(ToggleAction.class); registerToolBarToggleEntry(toolBarEntryAnnotation, actionAnnotation, element); } } return false; }
From source file:org.drombler.acp.core.action.impl.MenuAnnotationProcessor.java
@Override protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(Menus.class)) { Menus menusAnnotation = element.getAnnotation(Menus.class); if (menusAnnotation != null) { for (Menu menuAnnotation : menusAnnotation.value()) { registerMenu(menuAnnotation, element); }/*from w w w.j ava 2 s .c om*/ } } for (Element element : roundEnv.getElementsAnnotatedWith(Menu.class)) { Menu menuAnnotation = element.getAnnotation(Menu.class); if (menuAnnotation != null) { registerMenu(menuAnnotation, element); } } for (Element element : roundEnv.getElementsAnnotatedWith(MenuEntry.class)) { MenuEntry menuEntryAnnotation = element.getAnnotation(MenuEntry.class); if (menuEntryAnnotation != null) { Action actionAnnotation = element.getAnnotation(Action.class); registerMenuEntry(menuEntryAnnotation, actionAnnotation, element); } } for (Element element : roundEnv.getElementsAnnotatedWith(ToggleMenuEntry.class)) { ToggleMenuEntry toggleMenuEntryAnnotation = element.getAnnotation(ToggleMenuEntry.class); if (toggleMenuEntryAnnotation != null) { ToggleAction actionAnnotation = element.getAnnotation(ToggleAction.class); registerToggleMenuEntry(toggleMenuEntryAnnotation, actionAnnotation, element); } } return false; }
From source file:com.ym.easyipc.processor.AnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { jobs = new HashMap<TypeElement, List<ExecutableElement>>(); try {//from www . j av a2s. co m for (Element elem : roundEnv.getElementsAnnotatedWith(EasyIPCMethod.class)) { if (elem.getKind() != ElementKind.METHOD) throw new Exception("only methods can be marked by EasyIPCMethod"); ExecutableElement methodElem = (ExecutableElement) elem; TypeElement classElem = (TypeElement) methodElem.getEnclosingElement(); if (jobs.get(classElem) == null) { jobs.put(classElem, new ArrayList<ExecutableElement>()); } jobs.get(classElem).add(methodElem); } boolean hasListenerJobs = false; for (Element elem : roundEnv.getElementsAnnotatedWith(EasyIPCListener.class)) { hasListenerJobs = true; new ListenerGenerator(processingEnv, roundEnv, (TypeElement) elem).generateClass(); } if (hasListenerJobs || !jobs.isEmpty()) { new Generator(processingEnv, roundEnv, jobs).generate(); return true; } } catch (Exception e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "failed to generate EasyIPC classes:\n " + ExceptionUtils.getFullStackTrace(e)); } return false; }