@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // check if process was done on previous round if (OcelotProcessor.isDone() || roundEnv.processingOver()) { // Returns true if types generated by this round will not be subject to a subsequent round of annotation processing; returns false otherwise. return true; //if is it : stop } writeCoreInClassesOutput(); writeCoreInDirectory(jsdir, jsfwk); // one core.js in same time for (Element element : roundEnv.getElementsAnnotatedWith(DataService.class)) { processElement(element); } ElementVisitor visitor = new JsCacheRemoveVisitor(processingEnv); Set<TypeElement> elements = getTypeElementContainsJsRemoveAnno(roundEnv); for (TypeElement te : elements) { createPropertiesFile(te, visitor); } OcelotProcessor.setDone(true); return true; }
/** * Test of process method, of class OcelotProcessor. * * @throws java.io.IOException */ @Test public void processJsCacheRemoveTest() throws IOException { System.out.println("process"); OcelotProcessor.setDone(Boolean.FALSE); RoundEnvironment roundEnv = mock(RoundEnvironment.class); Set<? extends TypeElement> annotations = mock(Set.class); Set elements = new HashSet<>(); elements.add(mock(TypeElement.class)); elements.add(mock(TypeElement.class)); when(roundEnv.processingOver()).thenReturn(Boolean.FALSE); doNothing().when(instance).writeCoreInClassesOutput(); doNothing().when(instance).writeCoreInDirectory(anyString(), anyString()); doNothing().when(instance).createPropertiesFile(any(TypeElement.class), any(ElementVisitor.class)); doReturn(elements).when(instance).getTypeElementContainsJsRemoveAnno(any(RoundEnvironment.class)); when(roundEnv.getElementsAnnotatedWith(eq(DataService.class))).thenReturn(Collections.EMPTY_SET); boolean result = instance.process(annotations, roundEnv); assertThat(result).isTrue(); verify(instance, times(2)).createPropertiesFile(any(TypeElement.class), any(ElementVisitor.class)); }
/** * Test of createPropertiesFile method, of class. * @throws java.io.IOException */ @Test public void createPropertiesFileTest() throws IOException { System.out.println("createPropertiesFile"); TypeElement te = mock(TypeElement.class); Name name = mock(Name.class); ElementVisitor visitor = mock(ElementVisitor.class); Writer writer = mock(Writer.class); when(te.getSimpleName()).thenReturn(name); when(name.toString()).thenReturn("ClassName"); when(fws.getFileObjectWriterInClassOutput(eq("package"), eq("ClassName.properties"))).thenReturn(writer).thenThrow(IOException.class); doReturn("package").when(instance).getPackagePath(eq(te)); instance.createPropertiesFile(te, visitor); instance.createPropertiesFile(te, visitor); verify(te).accept(eq(visitor), eq(writer)); }
private void collectPlugins(final Iterable<? extends Element> elements) { final Elements elementUtils = processingEnv.getElementUtils(); final ElementVisitor<PluginEntry, Plugin> pluginVisitor = new PluginElementVisitor(elementUtils); final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor = new PluginAliasesElementVisitor( elementUtils); for (final Element element : elements) { final Plugin plugin = element.getAnnotation(Plugin.class); if (plugin == null) { continue; } final PluginEntry entry = element.accept(pluginVisitor, plugin); final Map<String, PluginEntry> category = pluginCache.getCategory(entry.getCategory()); category.put(entry.getKey(), entry); final Collection<PluginEntry> entries = element.accept(pluginAliasesVisitor, plugin); for (final PluginEntry pluginEntry : entries) { category.put(pluginEntry.getKey(), pluginEntry); } } }
public void testOriginatingElementComments() throws Exception { b = new LayerBuilder(doc, new Element() { public @Override ElementKind getKind() { return ElementKind.OTHER; } public @Override String toString() { return "originating.Type"; } public @Override TypeMirror asType() {return null;} public @Override List<? extends AnnotationMirror> getAnnotationMirrors() {return null;} public @Override <A extends Annotation> A getAnnotation(Class<A> annotationType) {return null;} public @Override Set<Modifier> getModifiers() {return null;} public @Override Name getSimpleName() {return null;} public @Override Element getEnclosingElement() {return null;} public @Override List<? extends Element> getEnclosedElements() {return null;} public @Override <R, P> R accept(ElementVisitor<R, P> v, P p) {return null;} @Override public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) { return (A[]) Array.newInstance(annotationType, 0); } }, null); b.folder("f").write(); assertEquals("<filesystem><folder name='f'><!--originating.Type--></folder></filesystem>", dump()); // #180154: do not repeat after an incremental build b.folder("f").write(); assertEquals("<filesystem><folder name='f'><!--originating.Type--></folder></filesystem>", dump()); }
public DsvSerializer( Elements elements, ElementVisitor<TypeElement,Void> enclosingTypeVisitor, MessagePrinter messagePrinter ) { this.elements = elements; this.enclosingTypeVisitor = enclosingTypeVisitor; this.messagePrinter = messagePrinter; this.fieldExporter = new DsvFieldExporter( elements ); }
void createPropertiesFile(TypeElement te, ElementVisitor visitor) { try (Writer w = fws.getFileObjectWriterInClassOutput(getPackagePath(te), te.getSimpleName().toString()+".properties")) { te.accept(visitor, w); } catch(IOException ioe) { messager.printMessage(Diagnostic.Kind.ERROR, " properties generation class : " + te); } }
/** * generate js service in packagePath.fn in classes directory/packagePath * * @param element * @param visitor * @param packagePath * @param fn */ void writeJsFileToJsDir(TypeElement element, ElementVisitor visitor, String packagePath, String fn, String dir) { if (null != dir) { try (Writer w = fws.getFileObjectWriter(dir + File.separatorChar + "srvs", packagePath + "." + fn)) { messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " javascript generation class : " + element + " to : " + dir); element.accept(visitor, w); } catch (IOException ioe) { messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " FAILED TO CREATE : " + packagePath + "." + fn); } } }
/** * Test of writeJsFile method, of class. * * @throws java.io.IOException */ @Test public void test_writeJsFile() throws IOException { System.out.println("writeJsFile"); TypeElement element = mock(TypeElement.class); ElementVisitor visitor = mock(ElementVisitor.class); Writer writer = mock(Writer.class); when(fws.getFileObjectWriterInClassOutput(eq("packagePath"), eq("fn"))).thenReturn(writer).thenThrow(IOException.class); instance.writeJsFile(element, visitor, "packagePath", "fn"); instance.writeJsFile(element, visitor, "packagePath", "fn"); verify(element).accept(eq(visitor), eq(writer)); }
/** * Test of writeJsFileToJsDir method, of class. * * @throws java.io.IOException */ @Test public void test_writeJsFileToJsDir() throws IOException { System.out.println("writeJsFileToJsDir"); TypeElement element = mock(TypeElement.class); ElementVisitor visitor = mock(ElementVisitor.class); Writer writer = mock(Writer.class); when(fws.getFileObjectWriter(eq("dir"+File.separatorChar+"srvs"), eq("packagePath.fn"))).thenReturn(writer).thenThrow(IOException.class); instance.writeJsFileToJsDir(element, visitor, "packagePath", "fn", "dir"); instance.writeJsFileToJsDir(element, visitor, "packagePath", "fn", "dir"); verify(element).accept(eq(visitor), eq(writer)); }
public ReferenceScanResult scan(TypeElement typeElement) throws IOException { ElementImports imports = processingEnvironment.getElementUtils().findImports(typeElement); ReferenceScanResult scanResult = new ReferenceScanResult(imports); ElementVisitor<Void, ReferenceScanResult> visitor = instanceVisitor(imports); typeElement.accept(visitor, scanResult); return scanResult; }
@Override public <R, P> R accept(ElementVisitor<R, P> v, P p) { return delegate.accept(v, p); }
@Override public <R, P> R accept(ElementVisitor<R, P> v, P p) { throw new UnsupportedOperationException("Not supported yet."); }
@Override public <R, P> R accept(ElementVisitor<R, P> v, P p) { throw new AssertionError(); }
@DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return other.accept(v, p); }
@Override @DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitTypeParameter(this, p); }
@Override @DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitModule(this, p); }
@DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitPackage(this, p); }
@DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitType(this, p); }
@DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitVariable(this, p); }
@DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitExecutable(this, p); }
@Override @DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { throw new AssertionError(); }
@Override public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitUnknown(this, p); }
@Override @DefinedBy(Api.LANGUAGE_MODEL) public <R, P> R accept(ElementVisitor<R, P> v, P p) { return v.visitUnknown(this, p); }
@Override public <R, P> R accept( ElementVisitor<R,P> v, P p ) { return null; }
@Override public <R, P> R accept(ElementVisitor<R, P> visitor, @Nullable P parameter) { return visitor.visitTypeParameter(this, parameter); }
@Override @Nullable public <T, P> T accept(ElementVisitor<T, P> visitor, @Nullable P parameter) { return visitor.visitType(this, parameter); }