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 error-prone by google.
the class AbstractUTreeTest method createContext.
@Before
public void createContext() {
context = new Context();
JavacFileManager.preRegister(context);
unifier = new Unifier(context);
inliner = unifier.createInliner();
}
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 T6889255 method test.
void test(String testName, boolean expectNames, String... opts) throws Exception {
System.err.println("Test " + testName + ": expectNames:" + expectNames + " javacOpts:" + Arrays.asList(opts));
File outDir = new File(testName);
outDir.mkdirs();
compile(outDir, opts);
Context ctx = new Context();
JavacFileManager fm = new JavacFileManager(ctx, true, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir));
ClassReader cr = ClassReader.instance(ctx);
cr.saveParameterNames = true;
Names names = Names.instance(ctx);
Set<String> classes = getTopLevelClasses(outDir);
Deque<String> work = new LinkedList<String>(classes);
String classname;
while ((classname = work.poll()) != null) {
System.err.println("Checking class " + classname);
ClassSymbol sym = cr.enterClass(names.table.fromString(classname));
sym.complete();
if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces)
continue;
for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) {
System.err.println("Checking member " + e.sym);
switch(e.sym.kind) {
case Kinds.TYP:
{
String name = e.sym.flatName().toString();
if (!classes.contains(name)) {
classes.add(name);
work.add(name);
}
break;
}
case Kinds.MTH:
verify((MethodSymbol) e.sym, expectNames);
break;
}
}
}
}
use of com.sun.tools.javac.util.Context in project ceylon-compiler by ceylon.
the class GetDeps method run.
void run(PrintWriter out, String... args) throws IOException, ClassFileNotFoundException {
decodeArgs(args);
final StandardJavaFileManager fm = new JavacFileManager(new Context(), false, null);
if (classpath != null)
fm.setLocation(StandardLocation.CLASS_PATH, classpath);
ClassFileReader reader = new ClassFileReader(fm);
Dependencies d = new Dependencies();
if (regex != null)
d.setFilter(Dependencies.getRegexFilter(Pattern.compile(regex)));
if (packageNames.size() > 0)
d.setFilter(Dependencies.getPackageFilter(packageNames, false));
SortedRecorder r = new SortedRecorder(reverse);
d.findAllDependencies(reader, rootClassNames, transitiveClosure, r);
SortedMap<Location, SortedSet<Dependency>> deps = r.getMap();
for (Map.Entry<Location, SortedSet<Dependency>> e : deps.entrySet()) {
out.println(e.getKey());
for (Dependency dep : e.getValue()) {
out.println(" " + dep.getTarget());
}
}
}
Aggregations