List of usage examples for javax.tools JavaFileObject getKind
Kind getKind();
From source file:adalid.util.meta.MetaJavaCompiler.java
private static void scanGeneratedFiles(Iterable<? extends JavaFileObject> files) { // logger.info("files" + EQ + files); logger.info("files"); for (JavaFileObject file : files) { // logger.info("file" + CL + file); // logger.info("kind" + CL + file.getKind()); logger.info("file" + CL + file + CM + file.getKind() + CM + file.getName()); }/*from w ww.j av a2 s . c om*/ }
From source file:org.cloudfoundry.tools.io.compiler.ResourceJavaFileManager.java
@Override public String inferBinaryName(Location location, JavaFileObject file) { String name = getNameWithoutExtension(file.getName()); ResourceJavaFileObject javaFileObject = getJavaFile(location, name, file.getKind(), true); if (javaFileObject != null) { String binaryName = javaFileObject.getFile().toString(); while (binaryName.startsWith("/")) { binaryName = binaryName.substring(1); }//from ww w . ja v a2 s . c o m binaryName = getNameWithoutExtension(binaryName); binaryName = binaryName.replace("/", "."); return binaryName; } return super.inferBinaryName(location, file); }
From source file:org.cloudfoundry.tools.compiler.CloudFoundryJavaCompilerTest.java
@Test public void shouldCompileVirtualFile() throws Exception { JavaFileObject sourceFile = mock(JavaFileObject.class); given(sourceFile.getKind()).willReturn(Kind.SOURCE); given(sourceFile.getName()).willReturn("Example.java"); given(sourceFile.getCharContent(anyBoolean())).willReturn(getExampleJavaContent()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JavaFileObject classFile = mock(JavaFileObject.class); given(classFile.openOutputStream()).willReturn(outputStream); JavaFileManager fileManager = mock(JavaFileManager.class); given(fileManager.getJavaFileForOutput(Matchers.any(Location.class), anyString(), eq(Kind.CLASS), eq(sourceFile))).willReturn(classFile); Iterable<? extends JavaFileObject> compilationUnits = Collections.singleton(sourceFile); CompilationTask task = this.javaCompiler.getTask(null, fileManager, null, standardCompilerOptions(), null, compilationUnits);/* w ww . j a v a 2s. co m*/ assertThat(task.call(), is(Boolean.TRUE)); assertThat(outputStream.toByteArray().length, is(greaterThan(0))); }