use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class Main method main.
public static void main(String[] args) throws Exception {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(CLASS_PATH, Collections.<File>emptyList());
JavacTask javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
Elements elements = javac.getElements();
final Set<String> packages = new LinkedHashSet<String>();
int nestedClasses = 0;
int classes = 0;
for (JavaFileObject file : fm.list(PLATFORM_CLASS_PATH, "", EnumSet.of(CLASS), true)) {
String type = fm.inferBinaryName(PLATFORM_CLASS_PATH, file);
if (type.endsWith("package-info"))
continue;
try {
TypeElement elem = elements.getTypeElement(type);
if (elem == null && type.indexOf('$') > 0) {
nestedClasses++;
type = null;
continue;
}
classes++;
packages.add(getPackage(elem).getQualifiedName().toString());
// force completion
elements.getTypeElement(type).getKind();
type = null;
} finally {
if (type != null)
System.err.println("Looking at " + type);
}
}
javac = null;
elements = null;
javac = (JavacTask) tool.getTask(null, fm, null, null, null, null);
elements = javac.getElements();
for (String name : packages) {
PackageElement pe = elements.getPackageElement(name);
for (Element e : pe.getEnclosedElements()) {
e.getSimpleName().getClass();
}
}
/*
* A few sanity checks based on current values:
*
* packages: 775, classes: 12429 + 5917
*
* As the platform evolves the numbers are likely to grow
* monotonically but in case somebody gets a clever idea for
* limiting the number of packages exposed, this number might
* drop. So we test low values.
*/
System.out.format("packages: %s, classes: %s + %s%n", packages.size(), classes, nestedClasses);
if (classes < 9000)
throw new AssertionError("Too few classes in PLATFORM_CLASS_PATH ;-)");
if (packages.size() < 530)
throw new AssertionError("Too few packages in PLATFORM_CLASS_PATH ;-)");
if (nestedClasses < 3000)
throw new AssertionError("Too few nested classes in PLATFORM_CLASS_PATH ;-)");
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6993305 method run.
void run() throws Exception {
File testSrc = new File(System.getProperty("test.src"));
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
JavacTask task = tool.getTask(null, fm, null, null, null, fos);
Iterable<? extends CompilationUnitTree> cus = task.parse();
TestScanner s = new TestScanner();
s.scan(cus, task);
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T6199075 method compileAndCheck.
void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(m1, m2, actual, argsArity);
ErrorChecker ec = new ErrorChecker();
JavacTask ct = (JavacTask) tool.getTask(null, fm, ec, null, null, Arrays.asList(source));
ct.generate();
check(source, ec, m1, m2, actual, argsArity);
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T7042566 method compileAndCheck.
void compileAndCheck() throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource();
ErrorChecker ec = new ErrorChecker();
JavacTask ct = (JavacTask) tool.getTask(null, fm, ec, null, null, Arrays.asList(source));
ct.call();
check(source, ec);
}
use of com.sun.source.util.JavacTask in project ceylon-compiler by ceylon.
the class T7043922 method compileAndCheck.
void compileAndCheck() throws Exception {
JavaSource source = new JavaSource();
ErrorChecker ec = new ErrorChecker();
JavacTask ct = (JavacTask) tool.getTask(null, fm, ec, null, null, Arrays.asList(source));
ct.analyze();
if (ec.errorFound) {
throw new Error("invalid diagnostics for source:\n" + source.getCharContent(true) + "\nCompiler diagnostics:\n" + ec.printDiags());
}
}
Aggregations