use of com.sun.tools.javac.util.Context in project error-prone by google.
the class UMatches method makeVisitorState.
static VisitorState makeVisitorState(Tree target, Unifier unifier) {
Context context = unifier.getContext();
TreePath path = TreePath.getPath(context.get(JCCompilationUnit.class), target);
return new VisitorState(context).withPath(path);
}
use of com.sun.tools.javac.util.Context in project error-prone by google.
the class SubContextTest method testOverlay.
@Test
public void testOverlay() {
Context base = new Context();
base.put(KEY1, "key1");
base.put(Enum1.class, Enum1.VALUE1);
Context overlay = new SubContext(base);
overlay.put(KEY2, "key2");
overlay.put(Enum2.class, Enum2.VALUE);
assertEquals("key1", overlay.get(KEY1));
assertEquals(Enum1.VALUE1, overlay.get(Enum1.class));
assertEquals("key2", overlay.get(KEY2));
assertEquals(Enum2.VALUE, overlay.get(Enum2.class));
assertEquals(null, base.get(KEY2));
assertEquals(null, base.get(Enum2.class));
}
use of com.sun.tools.javac.util.Context in project error-prone by google.
the class BugCheckerRefactoringTestHelper method doCompile.
private JCCompilationUnit doCompile(final JavaFileObject input, Iterable<JavaFileObject> files, Context context) throws IOException {
JavacTool tool = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>();
context.put(ErrorProneOptions.class, ErrorProneOptions.empty());
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(CharStreams.nullWriter(), fileManager, diagnosticsCollector, options, /*classes=*/
null, files, context);
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
JCCompilationUnit tree = Iterables.getOnlyElement(Iterables.filter(Iterables.filter(trees, JCCompilationUnit.class), compilationUnit -> compilationUnit.getSourceFile() == input));
Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables.filter(diagnosticsCollector.getDiagnostics(), d -> d.getKind() == Diagnostic.Kind.ERROR);
if (!Iterables.isEmpty(errorDiagnostics)) {
fail("compilation failed unexpectedly: " + errorDiagnostics);
}
return tree;
}
use of com.sun.tools.javac.util.Context in project lombok by rzwitserloot.
the class JavacHandlerUtil method copyTypeParams.
public static List<JCTypeParameter> copyTypeParams(JavacNode source, List<JCTypeParameter> params) {
if (params == null || params.isEmpty())
return params;
ListBuffer<JCTypeParameter> out = new ListBuffer<JCTypeParameter>();
JavacTreeMaker maker = source.getTreeMaker();
Context context = source.getContext();
for (JCTypeParameter tp : params) {
List<JCExpression> bounds = tp.bounds;
if (bounds != null && !bounds.isEmpty()) {
ListBuffer<JCExpression> boundsCopy = new ListBuffer<JCExpression>();
for (JCExpression expr : tp.bounds) {
boundsCopy.append(cloneType(maker, expr, source.get(), context));
}
bounds = boundsCopy.toList();
}
out.append(maker.TypeParameter(tp.name, bounds));
}
return out.toList();
}
use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.
the class JavacTool method getTask.
public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits) {
try {
Context context = new Context();
ClientCodeWrapper ccw = ClientCodeWrapper.instance(context);
final String kindMsg = "All compilation units must be of SOURCE kind";
if (options != null)
for (String option : options) // null check
option.getClass();
if (classes != null) {
for (String cls : classes) if (// implicit null check
!SourceVersion.isName(cls))
throw new IllegalArgumentException("Not a valid class name: " + cls);
}
if (compilationUnits != null) {
// implicit null check
compilationUnits = ccw.wrapJavaFileObjects(compilationUnits);
for (JavaFileObject cu : compilationUnits) {
if (cu.getKind() != JavaFileObject.Kind.SOURCE)
throw new IllegalArgumentException(kindMsg);
}
}
if (diagnosticListener != null)
context.put(DiagnosticListener.class, ccw.wrap(diagnosticListener));
if (out == null)
context.put(Log.outKey, new PrintWriter(System.err, true));
else
context.put(Log.outKey, new PrintWriter(out, true));
if (fileManager == null)
fileManager = getStandardFileManager(diagnosticListener, null, null);
fileManager = ccw.wrap(fileManager);
context.put(JavaFileManager.class, fileManager);
processOptions(context, fileManager, options);
Main compiler = new Main("javacTask", context.get(Log.outKey));
return new JavacTaskImpl(compiler, options, context, classes, compilationUnits);
} catch (ClientCodeException ex) {
throw new RuntimeException(ex.getCause());
}
}
Aggregations