use of com.sun.tools.javac.main.JavaCompiler in project checker-framework by typetools.
the class StubGenerator method main.
/**
* The main entry point to StubGenerator.
*
* @param args command-line arguments
*/
// User-supplied arguments to main
@SuppressWarnings("signature")
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage:");
System.out.println(" java StubGenerator [class or package name]");
return;
}
Context context = new Context();
Options options = Options.instance(context);
if (SystemUtil.getJreVersion() == 8) {
options.put(Option.SOURCE, "8");
options.put(Option.TARGET, "8");
}
JavaCompiler javac = JavaCompiler.instance(context);
javac.initModules(com.sun.tools.javac.util.List.nil());
javac.enterDone();
ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
StubGenerator generator = new StubGenerator();
if (env.getElementUtils().getPackageElement(args[0]) != null) {
generator.stubFromPackage(env.getElementUtils().getPackageElement(args[0]));
} else if (env.getElementUtils().getTypeElement(args[0]) != null) {
generator.stubFromType(env.getElementUtils().getTypeElement(args[0]));
} else {
error("Couldn't find a package or a class named " + args[0]);
}
}
use of com.sun.tools.javac.main.JavaCompiler in project checker-framework by typetools.
the class AbstractTypeProcessor method init.
/**
* {@inheritDoc}
*
* <p>Register a TaskListener that will get called after FLOW.
*/
@Override
public synchronized void init(ProcessingEnvironment env) {
super.init(env);
JavacTask.instance(env).addTaskListener(listener);
Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext();
JavaCompiler compiler = JavaCompiler.instance(ctx);
compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError, CompileState.FLOW);
compiler.shouldStopPolicyIfError = CompileState.max(compiler.shouldStopPolicyIfError, CompileState.FLOW);
}
use of com.sun.tools.javac.main.JavaCompiler in project error-prone by google.
the class VisitorState method getTypeFromStringInternal.
private Type getTypeFromStringInternal(String typeStr) {
validateTypeStr(typeStr);
if (isPrimitiveType(typeStr)) {
return getPrimitiveType(typeStr);
}
if (isVoidType(typeStr)) {
return getVoidType();
}
Name typeName = getName(typeStr);
try {
ClassSymbol typeSymbol = getSymtab().getClass(inferModule(typeName), typeName);
if (typeSymbol == null) {
JavaCompiler compiler = JavaCompiler.instance(context);
Symbol sym = compiler.resolveIdent(inferModule(typeName), typeStr);
if (!(sym instanceof ClassSymbol)) {
return null;
}
typeSymbol = (ClassSymbol) sym;
}
Type type = typeSymbol.asType();
// Throws CompletionFailure if the source/class file for this type is not available.
// This is hacky but the best way I can think of to handle this case.
type.complete();
if (type.isErroneous()) {
return null;
}
return type;
} catch (CompletionFailure failure) {
// during the compilation.
return null;
}
}
use of com.sun.tools.javac.main.JavaCompiler in project ceylon by eclipse.
the class T6400303 method main.
public static void main(String... args) {
javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, null, null, null, null, null);
JavaCompiler compiler = JavaCompiler.instance(task.getContext());
try {
compiler.resolveIdent("Test$1").complete();
} catch (CompletionFailure ex) {
System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
return;
}
throw new AssertionError("No error reported");
}
use of com.sun.tools.javac.main.JavaCompiler in project ceylon by eclipse.
the class T6358168 method testNoAnnotationProcessing.
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
Context context = new Context();
fm.setContext(context);
Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
compilerMain.setOptions(Options.instance(context));
compilerMain.filenames = new ListBuffer<File>();
compilerMain.processArgs(new String[] { "-d", "." });
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.compile(List.of(f));
try {
compiler.compile(List.of(f));
throw new Error("Error: AssertionError not thrown after second call of compile");
} catch (AssertionError e) {
System.err.println("Exception from compiler (expected): " + e);
}
}
Aggregations