use of com.sun.tools.javac.util.Context in project error-prone by google.
the class ErrorProneJavacPluginTest method hello.
@Test
public void hello() throws IOException {
FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
Path source = fileSystem.getPath("Test.java");
Files.write(source, ImmutableList.of("import java.util.HashSet;", "import java.util.Set;", "class Test {", " public static void main(String[] args) {", " Set<Short> s = new HashSet<>();", " for (short i = 0; i < 100; i++) {", " s.add(i);", " s.remove(i - 1);", " }", " System.out.println(s.size());", " }", "}"), UTF_8);
JavacFileManager fileManager = new JavacFileManager(new Context(), false, UTF_8);
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
JavacTask task = JavacTool.create().getTask(null, fileManager, diagnosticCollector, ImmutableList.of("-Xplugin:ErrorProne"), ImmutableList.of(), fileManager.getJavaFileObjects(source));
assertThat(task.call()).isFalse();
Diagnostic<? extends JavaFileObject> diagnostic = diagnosticCollector.getDiagnostics().stream().filter(d -> d.getKind() == Diagnostic.Kind.ERROR).collect(onlyElement());
assertThat(diagnostic.getMessage(ENGLISH)).contains("[CollectionIncompatibleType]");
}
use of com.sun.tools.javac.util.Context in project error-prone by google.
the class SubContextTest method testOverride.
@Test
public void testOverride() {
Context base = new Context();
base.put(KEY1, "key1");
base.put(Enum1.class, Enum1.VALUE1);
Context overlay = new SubContext(base);
overlay.put(KEY1, "key2");
overlay.put(Enum1.class, Enum1.VALUE2);
assertEquals("key2", overlay.get(KEY1));
assertEquals(Enum1.VALUE2, overlay.get(Enum1.class));
assertEquals("key1", base.get(KEY1));
assertEquals(Enum1.VALUE1, base.get(Enum1.class));
}
use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.
the class T6725036 method run.
void run() throws Exception {
RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class");
File f = new File(System.getProperty("java.home"));
if (!f.getName().equals("jre"))
f = new File(f, "jre");
File rt_jar = new File(new File(f, "lib"), "rt.jar");
JarFile j = new JarFile(rt_jar);
JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath());
long jarEntryTime = je.getTime();
ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance();
ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false);
long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME);
check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime);
Context context = new Context();
JavacFileManager fm = new JavacFileManager(context, false, null);
ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi);
JavaFileObject jfo = zfia.getFileObject(TEST_ENTRY_NAME.dirname(), TEST_ENTRY_NAME.basename());
long jfoTime = jfo.getLastModified();
check(je, jarEntryTime, jfo, jfoTime);
if (errors > 0)
throw new Exception(errors + " occurred");
}
use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.
the class JavacTool method getStandardFileManager.
public JavacFileManager getStandardFileManager(DiagnosticListener<? super JavaFileObject> diagnosticListener, Locale locale, Charset charset) {
Context context = new Context();
context.put(Locale.class, locale);
if (diagnosticListener != null)
context.put(DiagnosticListener.class, diagnosticListener);
PrintWriter pw = (charset == null) ? new PrintWriter(System.err, true) : new PrintWriter(new OutputStreamWriter(System.err, charset), true);
context.put(Log.outKey, pw);
return new JavacFileManager(context, true, charset);
}
use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.
the class JavapFileManager method create.
public static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log) {
Context javac_context = new Context();
if (dl != null)
javac_context.put(DiagnosticListener.class, dl);
javac_context.put(com.sun.tools.javac.util.Log.outKey, log);
return new JavapFileManager(javac_context, null);
}
Aggregations