8062348: langtools tests should close file manager (group 1)

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2014-10-29 17:25:23 -07:00
parent b587478f7c
commit 8bd23f1681
145 changed files with 2701 additions and 2452 deletions

View file

@ -77,41 +77,42 @@ public class RunCodingRules {
}
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null);
DiagnosticListener<JavaFileObject> noErrors = diagnostic -> {
Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString());
};
try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
DiagnosticListener<JavaFileObject> noErrors = diagnostic -> {
Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString());
};
List<File> crulesFiles = Files.walk(crulesDir)
.filter(entry -> entry.getFileName().toString().endsWith(".java"))
.filter(entry -> entry.getParent().endsWith("crules"))
.map(entry -> entry.toFile())
.collect(Collectors.toList());
List<File> crulesFiles = Files.walk(crulesDir)
.filter(entry -> entry.getFileName().toString().endsWith(".java"))
.filter(entry -> entry.getParent().endsWith("crules"))
.map(entry -> entry.toFile())
.collect(Collectors.toList());
Path crulesTarget = targetDir.resolve("crules");
Files.createDirectories(crulesTarget);
List<String> crulesOptions = Arrays.asList("-d", crulesTarget.toString());
javaCompiler.getTask(null, fm, noErrors, crulesOptions, null,
fm.getJavaFileObjectsFromFiles(crulesFiles)).call();
Path registration = crulesTarget.resolve("META-INF/services/com.sun.source.util.Plugin");
Files.createDirectories(registration.getParent());
try (Writer metaInfServices = Files.newBufferedWriter(registration, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
metaInfServices.write("crules.CodingRulesAnalyzerPlugin\n");
Path crulesTarget = targetDir.resolve("crules");
Files.createDirectories(crulesTarget);
List<String> crulesOptions = Arrays.asList("-d", crulesTarget.toString());
javaCompiler.getTask(null, fm, noErrors, crulesOptions, null,
fm.getJavaFileObjectsFromFiles(crulesFiles)).call();
Path registration = crulesTarget.resolve("META-INF/services/com.sun.source.util.Plugin");
Files.createDirectories(registration.getParent());
try (Writer metaInfServices = Files.newBufferedWriter(registration, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
metaInfServices.write("crules.CodingRulesAnalyzerPlugin\n");
}
List<File> sources = sourceDirs.stream()
.flatMap(dir -> silentFilesWalk(dir))
.filter(entry -> entry.getFileName().toString().endsWith(".java"))
.map(p -> p.toFile())
.collect(Collectors.toList());
Path sourceTarget = targetDir.resolve("classes");
Files.createDirectories(sourceTarget);
String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString();
List<String> options = Arrays.asList("-d", sourceTarget.toString(),
"-processorpath", processorPath, "-Xplugin:coding_rules");
javaCompiler.getTask(null, fm, noErrors, options, null,
fm.getJavaFileObjectsFromFiles(sources)).call();
}
List<File> sources = sourceDirs.stream()
.flatMap(dir -> silentFilesWalk(dir))
.filter(entry -> entry.getFileName().toString().endsWith(".java"))
.map(p -> p.toFile())
.collect(Collectors.toList());
Path sourceTarget = targetDir.resolve("classes");
Files.createDirectories(sourceTarget);
String processorPath = crulesTarget.toString() + File.pathSeparator + crulesDir.toString();
List<String> options = Arrays.asList("-d", sourceTarget.toString(),
"-processorpath", processorPath, "-Xplugin:coding_rules");
javaCompiler.getTask(null, fm, noErrors, options, null,
fm.getJavaFileObjectsFromFiles(sources)).call();
}
Stream<Path> silentFilesWalk(Path dir) throws IllegalStateException {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -113,58 +113,59 @@ public class T6341866 {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
MyDiagListener dl = new MyDiagListener();
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
// Note: class A references class B, so compile A if we want implicit compilation
File file = (implicitType != ImplicitType.NONE) ? a_java : b_java;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
// Note: class A references class B, so compile A if we want implicit compilation
File file = (implicitType != ImplicitType.NONE) ? a_java : b_java;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
//System.err.println("compile: " + opts + " " + files);
//System.err.println("compile: " + opts + " " + files);
boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
if (!ok) {
error("compilation failed");
return false;
}
// check implicit compilation results if necessary
if (implicitType != ImplicitType.NONE) {
boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
if (b_class.exists() != expectClass) {
if (b_class.exists())
error("B implicitly compiled unexpectedly");
else
error("B not impliictly compiled");
boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
if (!ok) {
error("compilation failed");
return false;
}
}
// check message key results
String expectKey = null;
if (implicitType == ImplicitType.OPT_UNSET) {
switch (annoType) {
case SERVICE:
expectKey = "compiler.warn.proc.use.proc.or.implicit";
break;
case SPECIFY:
expectKey = "compiler.warn.proc.use.implicit";
break;
// check implicit compilation results if necessary
if (implicitType != ImplicitType.NONE) {
boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
if (b_class.exists() != expectClass) {
if (b_class.exists())
error("B implicitly compiled unexpectedly");
else
error("B not impliictly compiled");
return false;
}
}
}
if (expectKey == null) {
if (dl.diagCodes.size() != 0) {
error("no diagnostics expected");
return false;
// check message key results
String expectKey = null;
if (implicitType == ImplicitType.OPT_UNSET) {
switch (annoType) {
case SERVICE:
expectKey = "compiler.warn.proc.use.proc.or.implicit";
break;
case SPECIFY:
expectKey = "compiler.warn.proc.use.implicit";
break;
}
}
} else {
if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
error("unexpected diagnostics generated");
return false;
}
}
return true;
if (expectKey == null) {
if (dl.diagCodes.size() != 0) {
error("no diagnostics expected");
return false;
}
} else {
if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
error("unexpected diagnostics generated");
return false;
}
}
return true;
}
}
static void createProcessorServices(String name) throws IOException {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,8 +58,7 @@ public class T6400872 {
throws IOException {
System.err.println("compile...");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
try {
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fileObjects =
fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
@ -78,8 +77,6 @@ public class T6400872 {
compiler.getTask(null, fm, null, options, null, fileObjects);
if (!task.call())
throw new AssertionError("compilation failed");
} finally {
fm.close();
}
}

View file

@ -54,25 +54,26 @@ abstract class Checker {
};
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames));
task = tool.getTask(null, fm, dl, null, null, files);
Iterable<? extends CompilationUnitTree> units = task.parse();
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(getFiles(testSrc, fileNames));
task = tool.getTask(null, fm, dl, null, null, files);
Iterable<? extends CompilationUnitTree> units = task.parse();
if (errors)
throw new AssertionError("errors occurred creating trees");
if (errors)
throw new AssertionError("errors occurred creating trees");
ScopeScanner s = new ScopeScanner();
for (CompilationUnitTree unit: units) {
TreePath p = new TreePath(unit);
s.scan(p, getTrees());
additionalChecks(getTrees(), unit);
ScopeScanner s = new ScopeScanner();
for (CompilationUnitTree unit: units) {
TreePath p = new TreePath(unit);
s.scan(p, getTrees());
additionalChecks(getTrees(), unit);
}
task = null;
if (errors)
throw new AssertionError("errors occurred checking scopes");
}
task = null;
if (errors)
throw new AssertionError("errors occurred checking scopes");
}
// default impl: split ref at ";" and call checkLocal(scope, ref_segment) on scope and its enclosing scopes

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,30 +40,31 @@ public class T6440583 {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends Tree> trees = task.parse();
Iterable<? extends Tree> trees = task.parse();
TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {
public Boolean visitErroneous(ErroneousTree tree, Void ignore) {
JCErroneous etree = (JCErroneous) tree;
List<? extends Tree> errs = etree.getErrorTrees();
System.err.println("errs: " + errs);
if (errs == null || errs.size() == 0)
throw new AssertionError("no error trees found");
found = true;
return true;
}
};
TreeScanner<Boolean,Void> checker = new TreeScanner<Boolean,Void>() {
public Boolean visitErroneous(ErroneousTree tree, Void ignore) {
JCErroneous etree = (JCErroneous) tree;
List<? extends Tree> errs = etree.getErrorTrees();
System.err.println("errs: " + errs);
if (errs == null || errs.size() == 0)
throw new AssertionError("no error trees found");
found = true;
return true;
}
};
for (Tree tree: trees)
checker.scan(tree, null);
for (Tree tree: trees)
checker.scan(tree, null);
if (!found)
throw new AssertionError("no ErroneousTree nodes found");
if (!found)
throw new AssertionError("no ErroneousTree nodes found");
}
}
private static boolean found;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,38 +54,39 @@ public class Test {
void test(File test) throws Exception {
JavacTool tool1 = JavacTool.create();
StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(test);
try (StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(test);
// parse test file into a tree, and write it out to a stringbuffer using Pretty
JavacTask t1 = tool1.getTask(null, fm, null, null, null, files);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends CompilationUnitTree> trees = t1.parse();
for (CompilationUnitTree tree: trees) {
new Pretty(pw, true).printExpr((JCTree) tree);
}
pw.close();
final String out = sw.toString();
System.err.println("generated code:\n" + out + "\n");
// verify the generated code is valid Java by compiling it
JavacTool tool2 = JavacTool.create();
JavaFileObject fo = new SimpleJavaFileObject(URI.create("output"), JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return out;
// parse test file into a tree, and write it out to a stringbuffer using Pretty
JavacTask t1 = tool1.getTask(null, fm, null, null, null, files);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends CompilationUnitTree> trees = t1.parse();
for (CompilationUnitTree tree: trees) {
new Pretty(pw, true).printExpr((JCTree) tree);
}
};
JavacTask t2 = tool2.getTask(null, fm, null, null, null, Collections.singleton(fo));
boolean ok = t2.call();
if (!ok)
throw new Exception("compilation of generated code failed");
pw.close();
File expectedClass = new File(test.getName().replace(".java", ".class"));
if (!expectedClass.exists())
throw new Exception(expectedClass + " not found");
final String out = sw.toString();
System.err.println("generated code:\n" + out + "\n");
// verify the generated code is valid Java by compiling it
JavacTool tool2 = JavacTool.create();
JavaFileObject fo = new SimpleJavaFileObject(URI.create("output"), JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return out;
}
};
JavacTask t2 = tool2.getTask(null, fm, null, null, null, Collections.singleton(fo));
boolean ok = t2.call();
if (!ok)
throw new Exception("compilation of generated code failed");
File expectedClass = new File(test.getName().replace(".java", ".class"));
if (!expectedClass.exists())
throw new Exception(expectedClass + " not found");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -49,9 +49,6 @@ public class T7003595 {
/** global decls ***/
// Create a single file manager and reuse it for each compile to save time.
static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
//statistics
static int checkCount = 0;
@ -112,15 +109,18 @@ public class T7003595 {
}
public static void main(String... args) throws Exception {
for (ClassKind ck1 : ClassKind.values()) {
String cname1 = "C1";
for (ClassKind ck2 : ClassKind.values()) {
if (!ck1.isAllowed(ck2)) continue;
String cname2 = "C2";
for (ClassKind ck3 : ClassKind.values()) {
if (!ck2.isAllowed(ck3)) continue;
String cname3 = "C3";
new T7003595(new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck();
// Create a single file manager and reuse it for each compile to save time.
try (StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
for (ClassKind ck1 : ClassKind.values()) {
String cname1 = "C1";
for (ClassKind ck2 : ClassKind.values()) {
if (!ck1.isAllowed(ck2)) continue;
String cname2 = "C2";
for (ClassKind ck3 : ClassKind.values()) {
if (!ck2.isAllowed(ck3)) continue;
String cname3 = "C3";
new T7003595(fm, new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck();
}
}
}
}
@ -132,8 +132,10 @@ public class T7003595 {
ClassKind[] cks;
String[] cnames;
StandardJavaFileManager fm;
T7003595(ClassKind[] cks, String[] cnames) {
T7003595(StandardJavaFileManager fm, ClassKind[] cks, String[] cnames) {
this.fm = fm;
this.cks = cks;
this.cnames = cnames;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -100,13 +100,14 @@ public class TestCircularClassfile {
public static void main(String... args) throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
int count = 0;
for (SourceKind sk1 : SourceKind.values()) {
for (SourceKind sk2 : SourceKind.values()) {
for (TestKind tk : TestKind.values()) {
for (ClientKind ck : ClientKind.values()) {
new TestCircularClassfile("sub_"+count++, sk1, sk2, tk, ck).check(comp, fm);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
int count = 0;
for (SourceKind sk1 : SourceKind.values()) {
for (SourceKind sk2 : SourceKind.values()) {
for (TestKind tk : TestKind.values()) {
for (ClientKind ck : ClientKind.values()) {
new TestCircularClassfile("sub_"+count++, sk1, sk2, tk, ck).check(comp, fm);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -96,10 +96,11 @@ public class T7142086 {
void run(List<JavaFileObject> sources) throws Exception {
DiagnosticChecker dc = new DiagnosticChecker();
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
null, null, sources);
ct.analyze();
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
JavacTask ct = (JavacTask)comp.getTask(null, fm, dc,
null, null, sources);
ct.analyze();
}
}
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,31 +54,32 @@ public class NoStringToLower {
*/
boolean run(String... args) throws Exception {
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
JavaFileManager fm = c.getStandardFileManager(null, null, null);
JavaFileManager.Location javacLoc = findJavacLocation(fm);
String[] pkgs = {
"javax.annotation.processing",
"javax.lang.model",
"javax.tools",
"com.sun.source",
"com.sun.tools.classfile",
"com.sun.tools.doclet",
"com.sun.tools.doclint",
"com.sun.tools.javac",
"com.sun.tools.javadoc",
"com.sun.tools.javah",
"com.sun.tools.javap",
"com.sun.tools.jdeps",
"com.sun.tools.sjavac"
};
for (String pkg: pkgs) {
for (JavaFileObject fo: fm.list(javacLoc,
pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
scan(fo);
try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
JavaFileManager.Location javacLoc = findJavacLocation(fm);
String[] pkgs = {
"javax.annotation.processing",
"javax.lang.model",
"javax.tools",
"com.sun.source",
"com.sun.tools.classfile",
"com.sun.tools.doclet",
"com.sun.tools.doclint",
"com.sun.tools.javac",
"com.sun.tools.javadoc",
"com.sun.tools.javah",
"com.sun.tools.javap",
"com.sun.tools.jdeps",
"com.sun.tools.sjavac"
};
for (String pkg: pkgs) {
for (JavaFileObject fo: fm.list(javacLoc,
pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
scan(fo);
}
}
}
return (errors == 0);
return (errors == 0);
}
}
// depending on how the test is run, javac may be on bootclasspath or classpath

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -71,28 +71,29 @@ public class JarFromManifestFailure {
}
}
static void compile(File classOutDir, Iterable<File> classPath, File... files) {
static void compile(File classOutDir, Iterable<File> classPath, File... files) throws IOException {
System.err.println("compile...");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fileObjects =
fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fileObjects =
fm.getJavaFileObjectsFromFiles(Arrays.asList(files));
List<String> options = new ArrayList<String>();
if (classOutDir != null) {
options.add("-d");
options.add(classOutDir.getPath());
}
if (classPath != null) {
options.add("-classpath");
options.add(join(classPath, File.pathSeparator));
}
options.add("-verbose");
List<String> options = new ArrayList<String>();
if (classOutDir != null) {
options.add("-d");
options.add(classOutDir.getPath());
}
if (classPath != null) {
options.add("-classpath");
options.add(join(classPath, File.pathSeparator));
}
options.add("-verbose");
JavaCompiler.CompilationTask task =
compiler.getTask(null, fm, null, options, null, fileObjects);
if (!task.call())
throw new AssertionError("compilation failed");
JavaCompiler.CompilationTask task =
compiler.getTask(null, fm, null, options, null, fileObjects);
if (!task.call())
throw new AssertionError("compilation failed");
}
}
static void jar(File jar, Iterable<File> classPath, File base, File... files)

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -116,17 +116,18 @@ public class TestCompileJARInClassPath {
javax.tools.JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null);
try (StandardJavaFileManager stdFileManager = javac.getStandardFileManager(diagnostics, null, null)) {
List<File> files = new ArrayList<>();
files.add(clientJarFile);
List<File> files = new ArrayList<>();
files.add(clientJarFile);
stdFileManager.setLocation(StandardLocation.CLASS_PATH, files);
stdFileManager.setLocation(StandardLocation.CLASS_PATH, files);
Iterable<? extends JavaFileObject> sourceFiles = stdFileManager.getJavaFileObjects(sourceFileToCompile);
Iterable<? extends JavaFileObject> sourceFiles = stdFileManager.getJavaFileObjects(sourceFileToCompile);
if (!javac.getTask(null, stdFileManager, diagnostics, null, null, sourceFiles).call()) {
throw new AssertionError("compilation failed");
if (!javac.getTask(null, stdFileManager, diagnostics, null, null, sourceFiles).call()) {
throw new AssertionError("compilation failed");
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,10 +44,11 @@ public class T6265400 {
throw new NullPointerException(SILLY_BILLY);
}
};
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java"));
javac.getTask(null, fm, dl, null, null, files).call();
try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromStrings(Arrays.asList("badfile.java"));
javac.getTask(null, fm, dl, null, null, files).call();
}
}
catch (RuntimeException e) {
Throwable cause = e.getCause();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,13 +44,14 @@ public class T6340549 {
try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
jfm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
try (StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
jfm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(new File(".")));
for (JavaFileObject jfo : jfm.list(StandardLocation.CLASS_PATH,
"", EnumSet.of(Kind.OTHER), false)) {
if (new File(jfo.getName()).isDirectory()) {
throw new AssertionError("Found directory: " + jfo);
for (JavaFileObject jfo : jfm.list(StandardLocation.CLASS_PATH,
"", EnumSet.of(Kind.OTHER), false)) {
if (new File(jfo.getName()).isDirectory()) {
throw new AssertionError("Found directory: " + jfo);
}
}
}
} finally {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,52 +38,52 @@ public class T6351767 {
public static void main(String... args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
try (JavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
// test null
try {
jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
error("NPE not thrown");
}
catch (NullPointerException e) {
// expected
}
// test null
try {
jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
error("NPE not thrown");
}
catch (NullPointerException e) {
// expected
}
// test null fileKinds
try {
jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
error("NPE not thrown");
}
catch (NullPointerException e) {
// expected
}
// test null fileKinds
try {
jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
error("NPE not thrown");
}
catch (NullPointerException e) {
// expected
}
// test good package
boolean found = false;
for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java.lang",
EnumSet.of(Kind.CLASS),
false)) {
System.err.println("found " + jfo.toUri());
if (jfo.isNameCompatible("Object", Kind.CLASS))
found = true;
}
if (!found)
error("expected file, java/lang/Object.class, not found");
// test good package
boolean found = false;
for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java.lang",
EnumSet.of(Kind.CLASS),
false)) {
System.err.println("found " + jfo.toUri());
if (jfo.isNameCompatible("Object", Kind.CLASS))
found = true;
}
if (!found)
error("expected file, java/lang/Object.class, not found");
found = false;
// test good package (VM name)
for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java/lang",
EnumSet.of(Kind.CLASS),
false)) {
System.err.println("found " + jfo.toUri());
if (jfo.isNameCompatible("Object", Kind.CLASS))
found = true;
found = false;
// test good package (VM name)
for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java/lang",
EnumSet.of(Kind.CLASS),
false)) {
System.err.println("found " + jfo.toUri());
if (jfo.isNameCompatible("Object", Kind.CLASS))
found = true;
}
if (!found)
error("expected file, java/lang/Object.class, not found");
}
if (!found)
error("expected file, java/lang/Object.class, not found");
}
static void error(String msg) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -57,17 +57,18 @@ public class T6361619 extends AbstractProcessor {
}
};
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir,
self + ".java")));
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir,
self + ".java")));
JavacTask task = tool.getTask(out, fm, dl, flags, null, f);
MyTaskListener tl = new MyTaskListener(task);
task.setTaskListener(tl);
JavacTask task = tool.getTask(out, fm, dl, flags, null, f);
MyTaskListener tl = new MyTaskListener(task);
task.setTaskListener(tl);
// should complete, without exceptions
task.call();
// should complete, without exceptions
task.call();
}
}
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) {

View file

@ -44,24 +44,25 @@ public class T6395974 {
String testSrc = System.getProperty("test.src");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<?extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self + ".java")));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<?extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self + ".java")));
PrintWriter out = new PrintWriter(System.err, true);
PrintWriter out = new PrintWriter(System.err, true);
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
fm,
null,
Arrays.asList("-processor",
"Foo.java"),
null,
f);
JavacTaskImpl task = (JavacTaskImpl) tool.getTask(out,
fm,
null,
Arrays.asList("-processor",
"Foo.java"),
null,
f);
MyTaskListener tl = new MyTaskListener();
task.setTaskListener(tl);
MyTaskListener tl = new MyTaskListener();
task.setTaskListener(tl);
task.call();
task.call();
}
}
static class MyTaskListener implements TaskListener {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,14 +42,15 @@ public abstract class T6397044 {
String srcDir = System.getProperty("test.src", ".");
String self = T6397044.class.getName();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files
= fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
Checker checker = new Checker();
for (CompilationUnitTree tree: trees)
checker.check(tree);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files
= fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
Checker checker = new Checker();
for (CompilationUnitTree tree: trees)
checker.check(tree);
}
}
public int x_public;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,29 +40,30 @@ public class T6397286 {
String self = T6397286.class.getName();
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
throw new TaskEventError(e);
}
public void finished(TaskEvent e) {
}
});
JavacTask task = tool.getTask(null, fm, null, null, null, files);
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
throw new TaskEventError(e);
}
public void finished(TaskEvent e) {
}
});
try {
task.call();
throw new AssertionError("no exception thrown");
} catch (RuntimeException e) {
if (e.getCause() instanceof TaskEventError) {
TaskEventError tee = (TaskEventError) e.getCause();
System.err.println("Exception thrown for " + tee.event + " as expected");
} else {
e.printStackTrace();
throw new AssertionError("TaskEventError not thrown");
try {
task.call();
throw new AssertionError("no exception thrown");
} catch (RuntimeException e) {
if (e.getCause() instanceof TaskEventError) {
TaskEventError tee = (TaskEventError) e.getCause();
System.err.println("Exception thrown for " + tee.event + " as expected");
} else {
e.printStackTrace();
throw new AssertionError("TaskEventError not thrown");
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -51,24 +51,25 @@ public class T6403466 extends AbstractProcessor {
public static void main(String[] args) throws IOException {
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
"-processor", self,
"-s", ".",
"-d", ".");
JavacTask task = tool.getTask(out, fm, null, options, null, files);
Iterable<String> options = Arrays.asList("-processorpath", testClassDir,
"-processor", self,
"-s", ".",
"-d", ".");
JavacTask task = tool.getTask(out, fm, null, options, null, files);
VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
task.setTaskListener(vtl);
VerifyingTaskListener vtl = new VerifyingTaskListener(new File(testSrcDir, self + ".out"));
task.setTaskListener(vtl);
if (!task.call())
throw new AssertionError("compilation failed");
if (!task.call())
throw new AssertionError("compilation failed");
if (vtl.iter.hasNext() || vtl.errors)
throw new AssertionError("comparison against golden file failed.");
if (vtl.iter.hasNext() || vtl.errors)
throw new AssertionError("comparison against golden file failed.");
}
}
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {

View file

@ -33,21 +33,22 @@ public class T6406771 extends AbstractProcessor {
// White-space after this point does not matter
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
String self = T6406771.class.getName();
String testSrc = System.getProperty("test.src");
String testClasses = System.getProperty("test.classes");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next();
List<String> opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only");
List<String> opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only");
JavacTask task = tool.getTask(null, fm, null, opts, null, Arrays.asList(f));
JavacTask task = tool.getTask(null, fm, null, opts, null, Arrays.asList(f));
if (!task.call())
throw new AssertionError("failed");
if (!task.call())
throw new AssertionError("failed");
}
}
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment rEnv) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,20 +37,21 @@ public class T6407066 {
String testClasses = System.getProperty("test.classes", ".");
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = tool.getStandardFileManager(null, null, null);
try (StandardJavaFileManager jfm = tool.getStandardFileManager(null, null, null)) {
List<File> path = new ArrayList<File>();
path.add(new File("BadDirectory"));
path.add(new File(testSrc));
path.add(new File("BadFile.jar"));
List<File> path = new ArrayList<File>();
path.add(new File("BadDirectory"));
path.add(new File(testSrc));
path.add(new File("BadFile.jar"));
jfm.setLocation(StandardLocation.SOURCE_PATH, path);
jfm.setLocation(StandardLocation.SOURCE_PATH, path);
List<File> path2 = new ArrayList<File>();
for (File f: jfm.getLocation(StandardLocation.SOURCE_PATH))
path2.add(f);
List<File> path2 = new ArrayList<File>();
for (File f: jfm.getLocation(StandardLocation.SOURCE_PATH))
path2.add(f);
if (!path.equals(path2))
throw new AssertionError("path not preserved");
if (!path.equals(path2))
throw new AssertionError("path not preserved");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,21 +44,22 @@ public class T6410706 {
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
MyDiagListener dl = new MyDiagListener();
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, dl, null, null, files);
task.parse();
task.analyze();
task.generate();
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, dl, null, null, files);
task.parse();
task.analyze();
task.generate();
// expect 2 notes:
// Note: T6410706.java uses or overrides a deprecated API.
// Note: Recompile with -Xlint:deprecation for details.
// expect 2 notes:
// Note: T6410706.java uses or overrides a deprecated API.
// Note: Recompile with -Xlint:deprecation for details.
if (dl.notes != 2)
throw new AssertionError(dl.notes + " notes given");
if (dl.notes != 2)
throw new AssertionError(dl.notes + " notes given");
}
}
private static class MyDiagListener implements DiagnosticListener<JavaFileObject>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,33 +55,34 @@ public class T6458823 {
}
DiagnosticCollector<JavaFileObject> diagColl =
new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
List<String> options = new ArrayList<String>();
options.add("-processor");
options.add("MyProcessor");
options.add("-proc:only");
List<File> files = new ArrayList<File>();
files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl,
options, null, fm.getJavaFileObjectsFromFiles(files));
task.call();
int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
throw new AssertionError("Only warnings expected");
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
List<String> options = new ArrayList<String>();
options.add("-processor");
options.add("MyProcessor");
options.add("-proc:only");
List<File> files = new ArrayList<File>();
files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl,
options, null, fm.getJavaFileObjectsFromFiles(files));
task.call();
int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
throw new AssertionError("Only warnings expected");
}
System.out.println(diag);
if (diag.getPosition() == Diagnostic.NOPOS) {
throw new AssertionError("No position info in message");
}
if (diag.getSource() == null) {
throw new AssertionError("No source info in message");
}
diagCount++;
}
System.out.println(diag);
if (diag.getPosition() == Diagnostic.NOPOS) {
throw new AssertionError("No position info in message");
if (diagCount != 2) {
throw new AssertionError("unexpected number of warnings: " +
diagCount + ", expected: 2");
}
if (diag.getSource() == null) {
throw new AssertionError("No source info in message");
}
diagCount++;
}
if (diagCount != 2) {
throw new AssertionError("unexpected number of warnings: " +
diagCount + ", expected: 2");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,29 +47,30 @@ public class T6665791 {
write(test_java, test);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager manager =
compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
final StringWriter sw = new StringWriter();
JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
null, units);
try (StandardJavaFileManager manager =
compiler.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
final StringWriter sw = new StringWriter();
JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
null, units);
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitClass(ClassTree arg0, Void arg1) {
sw.write(arg0.toString());
return super.visitClass(arg0, arg1);
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitClass(ClassTree arg0, Void arg1) {
sw.write(arg0.toString());
return super.visitClass(arg0, arg1);
}
}.scan(task.parse(), null);
System.out.println("output:");
System.out.println(sw.toString());
String found = sw.toString().replaceAll("\\s+", " ").trim();
String expect = test.replaceAll("\\s+", " ").trim();
if (!expect.equals(found)) {
System.out.println("expect: " + expect);
System.out.println("found: " + found);
throw new Exception("unexpected output");
}
}.scan(task.parse(), null);
System.out.println("output:");
System.out.println(sw.toString());
String found = sw.toString().replaceAll("\\s+", " ").trim();
String expect = test.replaceAll("\\s+", " ").trim();
if (!expect.equals(found)) {
System.out.println("expect: " + expect);
System.out.println("found: " + found);
throw new Exception("unexpected output");
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,46 +45,47 @@ public class T6705935 {
java_home = java_home.getParentFile();
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
//System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
//System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)));
for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java.lang",
Collections.singleton(JavaFileObject.Kind.CLASS),
false)) {
test++;
for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH,
"java.lang",
Collections.singleton(JavaFileObject.Kind.CLASS),
false)) {
test++;
if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
skip++;
continue;
}
//System.err.println(fo.getName());
String p = fo.getName();
int bra = p.indexOf("(");
int ket = p.indexOf(")");
//System.err.println(bra + "," + ket + "," + p.length());
if (bra == -1 || ket != p.length() -1)
throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
String part1 = p.substring(0, bra);
String part2 = p.substring(bra + 1, ket);
//System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
throw new Exception("bad path: " + p);
if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) {
System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName());
skip++;
continue;
}
//System.err.println(fo.getName());
String p = fo.getName();
int bra = p.indexOf("(");
int ket = p.indexOf(")");
//System.err.println(bra + "," + ket + "," + p.length());
if (bra == -1 || ket != p.length() -1)
throw new Exception("unexpected path: " + p + "[" + bra + "," + ket + "," + p.length());
String part1 = p.substring(0, bra);
String part2 = p.substring(bra + 1, ket);
//System.err.println("[" + part1 + "|" + part2 + "]" + " " + java_home);
if (part1.equals(part2) || !part1.startsWith(java_home.getPath()))
throw new Exception("bad path: " + p);
if (test == 0)
throw new Exception("no files found");
if (skip == 0)
System.out.println(test + " files found");
else
System.out.println(test + " files found, " + skip + " files skipped");
if (test == skip)
System.out.println("Warning: all files skipped; no platform classes found in zip files.");
}
if (test == 0)
throw new Exception("no files found");
if (skip == 0)
System.out.println(test + " files found");
else
System.out.println(test + " files found, " + skip + " files skipped");
if (test == skip)
System.out.println("Warning: all files skipped; no platform classes found in zip files.");
}
private <T> List<T> asList(Iterable<? extends T> items) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,14 +37,15 @@ public class T6900149 {
DiagnosticCollector<JavaFileObject> diag =
new DiagnosticCollector<JavaFileObject>();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm =
compiler.getStandardFileManager(null, null, null);
File emptyFile = createTempFile("Empty.java");
File[] files = new File[] { emptyFile, emptyFile };
CompilationTask task = compiler.getTask(null, fm, diag,
null, null, fm.getJavaFileObjects(files));
if (! task.call()) {
throw new AssertionError("compilation failed");
try (StandardJavaFileManager fm =
compiler.getStandardFileManager(null, null, null)) {
File emptyFile = createTempFile("Empty.java");
File[] files = new File[] { emptyFile, emptyFile };
CompilationTask task = compiler.getTask(null, fm, diag,
null, null, fm.getJavaFileObjects(files));
if (! task.call()) {
throw new AssertionError("compilation failed");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,14 +44,15 @@ public class T6956462 {
if (compiler == null) {
throw new RuntimeException("can't get javax.tools.JavaCompiler!");
}
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
List<File> files = new ArrayList<File>();
files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, null,
null, null, fm.getJavaFileObjectsFromFiles(files));
JavacTask javacTask = (JavacTask) task;
for (CompilationUnitTree cu : javacTask.parse()) {
cu.accept(new MyVisitor(javacTask), null);
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
List<File> files = new ArrayList<File>();
files.add(new File(T6956462.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, null,
null, null, fm.getJavaFileObjectsFromFiles(files));
JavacTask javacTask = (JavacTask) task;
for (CompilationUnitTree cu : javacTask.parse()) {
cu.accept(new MyVisitor(javacTask), null);
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -96,34 +96,35 @@ public class T6956638 {
List<String> compileOptions = Arrays.asList("-d", classesDir.getPath());
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null);
Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjects(sourceFiles);
System.err.println("1- javac given java source JavaFileObjects " + sourceFileObjects);
JavaCompiler.CompilationTask task = compiler.getTask(compilerOutputStream, fileManager, null, compileOptions, null, sourceFileObjects);
JavacTask javacTask = (JavacTask) task;
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null)) {
Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjects(sourceFiles);
System.err.println("1- javac given java source JavaFileObjects " + sourceFileObjects);
JavaCompiler.CompilationTask task = compiler.getTask(compilerOutputStream, fileManager, null, compileOptions, null, sourceFileObjects);
JavacTask javacTask = (JavacTask) task;
Iterable<? extends CompilationUnitTree> parsedTrees = javacTask.parse();
Iterable<? extends Element> analyzedTrees = javacTask.analyze();
Iterable<? extends JavaFileObject> generatedFiles = javacTask.generate();
Iterable<? extends CompilationUnitTree> parsedTrees = javacTask.parse();
Iterable<? extends Element> analyzedTrees = javacTask.analyze();
Iterable<? extends JavaFileObject> generatedFiles = javacTask.generate();
System.err.println("2- parsed:" + size(parsedTrees) + " analysed:" + size(analyzedTrees) + " generated:" + size(generatedFiles));
System.err.println("2- parsed:" + size(parsedTrees) + " analysed:" + size(analyzedTrees) + " generated:" + size(generatedFiles));
System.err.print("3-");
for (JavaFileObject f : generatedFiles)
System.err.print(" " + f);
System.err.println("");
System.err.print("3-");
for (JavaFileObject f : generatedFiles)
System.err.print(" " + f);
System.err.println("");
System.err.print("5-");
for (File f : classesDir.listFiles())
System.err.print(" " + f);
System.err.println("");
System.err.print("5-");
for (File f : classesDir.listFiles())
System.err.print(" " + f);
System.err.println("");
System.err.println("----");
System.err.println(compilerOutputStream.toString());
System.err.println("----");
System.err.println(compilerOutputStream.toString());
if (size(generatedFiles) != size(parsedTrees)) {
throw new Exception("wrong number of files generated: " + size(generatedFiles)
+ " expected: " + size(parsedTrees));
if (size(generatedFiles) != size(parsedTrees)) {
throw new Exception("wrong number of files generated: " + size(generatedFiles)
+ " expected: " + size(parsedTrees));
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,28 +58,29 @@ public class Bug {
}
};
StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null);
try (StandardJavaFileManager sjfm = javac.getStandardFileManager(dl,null,null)) {
List<String> opts = new ArrayList<String>();
opts.add("-proc:only");
opts.add("-processor");
opts.add("AnnoProcessor");
List<String> opts = new ArrayList<String>();
opts.add("-proc:only");
opts.add("-processor");
opts.add("AnnoProcessor");
boolean xxx;
boolean xxx;
System.err.println("\n-- " + name);
task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null);
xxx = task2.call();
System.err.println("\n-- " + name);
task2 = javac.getTask(pw, sjfm, dl, opts, Arrays.asList(name), null);
xxx = task2.call();
String out = sw.toString();
System.err.println(out);
if (out.contains("Assert")) {
System.err.println("--Failed: Assertion failure");
System.exit(1);
}
if (!out.contains(expectedMsg)) {
System.err.println("--Failed: Expected diagnostic not found");
System.exit(1);
String out = sw.toString();
System.err.println(out);
if (out.contains("Assert")) {
System.err.println("--Failed: Assertion failure");
System.exit(1);
}
if (!out.contains(expectedMsg)) {
System.err.println("--Failed: Expected diagnostic not found");
System.exit(1);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,7 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class T7159016 {
@ -58,11 +59,13 @@ public class T7159016 {
w.close();
}
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
JavaCompiler.CompilationTask task = jc.getTask(null, null, null, null, null,
jc.getStandardFileManager(null, null, null).getJavaFileObjects(src));
task.setProcessors(Collections.singleton(new Proc()));
if (!task.call()) {
throw new Error("Test failed");
try (StandardJavaFileManager fm = jc.getStandardFileManager(null, null, null)) {
JavaCompiler.CompilationTask task = jc.getTask(null, fm, null, null, null,
fm.getJavaFileObjects(src));
task.setProcessors(Collections.singleton(new Proc()));
if (!task.call()) {
throw new Error("Test failed");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -179,18 +179,19 @@ public class DetectMutableStaticFields {
ConstantPoolException,
InvalidDescriptor {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
JavaFileManager.Location location =
StandardLocation.locationFor(resource.getPath());
fm.setLocation(location, com.sun.tools.javac.util.List.of(
new File(resource.getPath())));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
JavaFileManager.Location location =
StandardLocation.locationFor(resource.getPath());
fm.setLocation(location, com.sun.tools.javac.util.List.of(
new File(resource.getPath())));
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
String className = fm.inferBinaryName(location, file);
int index = className.lastIndexOf('.');
String pckName = index == -1 ? "" : className.substring(0, index);
if (shouldAnalyzePackage(pckName)) {
analyzeClassFile(ClassFile.read(file.openInputStream()));
for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) {
String className = fm.inferBinaryName(location, file);
int index = className.lastIndexOf('.');
String pckName = index == -1 ? "" : className.substring(0, index);
if (shouldAnalyzePackage(pckName)) {
analyzeClassFile(ClassFile.read(file.openInputStream()));
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -132,73 +132,74 @@ public class ParameterNamesAreNotCopiedToAnonymousInitTest {
throws IOException {
Assert.checkNonNull(paramsToCheck, nonNullParamPositionsMsg);
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fos =
fm.getJavaFileObjectsFromFiles(
Arrays.asList(new File(System.getProperty("test.src"),
this.getClass().getName() + ".java")));
JavacTask task = (JavacTask) c.getTask(null, fm, null,
Arrays.asList("-d", System.getProperty("user.dir")), null, fos);
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fos =
fm.getJavaFileObjectsFromFiles(
Arrays.asList(new File(System.getProperty("test.src"),
this.getClass().getName() + ".java")));
JavacTask task = (JavacTask) c.getTask(null, fm, null,
Arrays.asList("-d", System.getProperty("user.dir")), null, fos);
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
final Names names = Names.instance(context);
BasicJavacTask impl = (BasicJavacTask)task;
Context context = impl.getContext();
final Names names = Names.instance(context);
task.addTaskListener(new TaskListener() {
task.addTaskListener(new TaskListener() {
@Override
public void started(TaskEvent e) {}
@Override
public void started(TaskEvent e) {}
@Override
public void finished(TaskEvent e) {
class TheTreeScanner extends TreeScanner {
boolean foundAndCorrect = false;
@Override
public void finished(TaskEvent e) {
class TheTreeScanner extends TreeScanner {
boolean foundAndCorrect = false;
@Override
public void visitMethodDef(JCTree.JCMethodDecl tree) {
ClassSymbol clazz = (ClassSymbol)tree.sym.owner;
if (clazz.owner.name.toString().equals(classOwnerName) &&
tree.sym.name == names.init) {
@Override
public void visitMethodDef(JCTree.JCMethodDecl tree) {
ClassSymbol clazz = (ClassSymbol)tree.sym.owner;
if (clazz.owner.name.toString().equals(classOwnerName) &&
tree.sym.name == names.init) {
int currentParamPos = 0;
int paramArrayIndex = 0;
int currentParamPos = 0;
int paramArrayIndex = 0;
List<VarSymbol> params = tree.sym.params;
while (params.nonEmpty() && paramArrayIndex < paramsToCheck.size()) {
VarSymbol param = params.head;
if (currentParamPos == paramsToCheck.get(paramArrayIndex)) {
if (!param.name.toString()
.equals(paramNames.get(paramArrayIndex))) {
error(paramNameNotCopiedAssertionMsg);
List<VarSymbol> params = tree.sym.params;
while (params.nonEmpty() && paramArrayIndex < paramsToCheck.size()) {
VarSymbol param = params.head;
if (currentParamPos == paramsToCheck.get(paramArrayIndex)) {
if (!param.name.toString()
.equals(paramNames.get(paramArrayIndex))) {
error(paramNameNotCopiedAssertionMsg);
}
paramArrayIndex++;
}
paramArrayIndex++;
currentParamPos++;
params = params.tail;
}
currentParamPos++;
params = params.tail;
foundAndCorrect = paramArrayIndex >= paramsToCheck.size();
}
foundAndCorrect = paramArrayIndex >= paramsToCheck.size();
super.visitMethodDef(tree);
}
super.visitMethodDef(tree);
}
}
if (e.getKind() == TaskEvent.Kind.ANALYZE) {
CompilationUnitTree compUnitTree = e.getCompilationUnit();
boolean foundAndCorrect = false;
for (Tree tree : compUnitTree.getTypeDecls()) {
TheTreeScanner scanner = new TheTreeScanner();
scanner.scan((JCTree) tree);
foundAndCorrect = foundAndCorrect | scanner.foundAndCorrect;
}
if (!foundAndCorrect) {
error(seekMethodNotFound);
if (e.getKind() == TaskEvent.Kind.ANALYZE) {
CompilationUnitTree compUnitTree = e.getCompilationUnit();
boolean foundAndCorrect = false;
for (Tree tree : compUnitTree.getTypeDecls()) {
TheTreeScanner scanner = new TheTreeScanner();
scanner.scan((JCTree) tree);
foundAndCorrect = foundAndCorrect | scanner.foundAndCorrect;
}
if (!foundAndCorrect) {
error(seekMethodNotFound);
}
}
}
});
if (!task.call()) {
error(compilationFailed);
}
});
if (!task.call()) {
error(compilationFailed);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -117,16 +117,17 @@ public class InterruptedExceptionTest {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppress_decl : SuppressLevel.values()) {
for (SuppressLevel suppress_use : SuppressLevel.values()) {
for (ClassKind ck : ClassKind.values()) {
for (ExceptionKind ek_decl : ExceptionKind.values()) {
for (ExceptionKind ek_use : ExceptionKind.values()) {
new InterruptedExceptionTest(xlint, suppress_decl,
suppress_use, ck, ek_decl, ek_use).run(comp, fm);
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppress_decl : SuppressLevel.values()) {
for (SuppressLevel suppress_use : SuppressLevel.values()) {
for (ClassKind ck : ClassKind.values()) {
for (ExceptionKind ek_decl : ExceptionKind.values()) {
for (ExceptionKind ek_use : ExceptionKind.values()) {
new InterruptedExceptionTest(xlint, suppress_decl,
suppress_use, ck, ek_decl, ek_use).run(comp, fm);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -161,20 +161,24 @@ public class UnusedResourcesTest {
}
public static void main(String... args) throws Exception {
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppressLevel : SuppressLevel.values()) {
for (ResourceUsage usage1 : ResourceUsage.values()) {
for (ResourceUsage usage2 : ResourceUsage.values()) {
for (ResourceUsage usage3 : ResourceUsage.values()) {
test(xlint,
suppressLevel,
usage1,
usage2,
usage3);
try {
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppressLevel : SuppressLevel.values()) {
for (ResourceUsage usage1 : ResourceUsage.values()) {
for (ResourceUsage usage2 : ResourceUsage.values()) {
for (ResourceUsage usage3 : ResourceUsage.values()) {
test(xlint,
suppressLevel,
usage1,
usage2,
usage3);
}
}
}
}
}
} finally {
fm.close();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -41,38 +41,39 @@ public class VerifyAnnotationsAttributed {
File testSrc = new File(System.getProperty("test.src"));
File testFile = new File(testSrc, args[0]);
if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
JavacTask task = JavacTool.create().getTask(null,
fm,
null,
Collections.<String>emptyList(),
null,
fm.getJavaFileObjects(testFile));
final Trees trees = Trees.instance(task);
final CompilationUnitTree cut = task.parse().iterator().next();
task.analyze();
try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
JavacTask task = JavacTool.create().getTask(null,
fm,
null,
Collections.<String>emptyList(),
null,
fm.getJavaFileObjects(testFile));
final Trees trees = Trees.instance(task);
final CompilationUnitTree cut = task.parse().iterator().next();
task.analyze();
//ensure all the annotation attributes are annotated meaningfully
//all the attributes in the test file should contain either an identifier
//or a select, so only checking those for a reasonable Element/Symbol.
new TreePathScanner<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
verifyAttributedMeaningfully();
return super.visitIdentifier(node, p);
}
@Override
public Void visitMemberSelect(MemberSelectTree node, Void p) {
verifyAttributedMeaningfully();
return super.visitMemberSelect(node, p);
}
private void verifyAttributedMeaningfully() {
Element el = trees.getElement(getCurrentPath());
if (el == null || el.getKind() == ElementKind.OTHER) {
throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
//ensure all the annotation attributes are annotated meaningfully
//all the attributes in the test file should contain either an identifier
//or a select, so only checking those for a reasonable Element/Symbol.
new TreePathScanner<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
verifyAttributedMeaningfully();
return super.visitIdentifier(node, p);
}
}
}.scan(cut, null);
@Override
public Void visitMemberSelect(MemberSelectTree node, Void p) {
verifyAttributedMeaningfully();
return super.visitMemberSelect(node, p);
}
private void verifyAttributedMeaningfully() {
Element el = trees.getElement(getCurrentPath());
if (el == null || el.getKind() == ElementKind.OTHER) {
throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
}
}
}.scan(cut, null);
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -102,29 +102,31 @@ public class Helper {
throw new RuntimeException("can't get javax.tools.JavaCompiler!");
}
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
// Assuming filesCount can maximum be 2 and if true, one file is package-info.java
if (isPkgInfoPresent(files)) {
JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files);
try {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
task.generate();
} catch (IOException ioe) {
throw new RuntimeException("Compilation failed for package level tests", ioe);
}
int err = 0;
for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
if(d.getKind() == Diagnostic.Kind.ERROR) {
err++;
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
// Assuming filesCount can maximum be 2 and if true, one file is package-info.java
if (isPkgInfoPresent(files)) {
JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, null, null, files);
try {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
task.generate();
} catch (IOException ioe) {
throw new RuntimeException("Compilation failed for package level tests", ioe);
}
int err = 0;
for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
if(d.getKind() == Diagnostic.Kind.ERROR) {
err++;
}
}
ok = (err == 0);
} else {
CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files);
ok = task.call();
}
ok = (err == 0);
} else {
CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, files);
ok = task.call();
return ok;
} catch (IOException e) {
throw new Error(e);
}
return ok;
}
static private boolean isPkgInfoPresent(Iterable<? extends JavaFileObject> files) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,18 +46,18 @@ public class AnnotatedArrayOrder {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
private static class Scanner extends TreeScanner<Void,Void> {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -48,18 +48,18 @@ public class ArrayCreationTree {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
private static class Scanner extends TreeScanner<Void,Void> {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,18 +47,18 @@ public class ArrayPositionConsistency {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayPositionConsistency.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
private static class Scanner extends TreeScanner<Void,Void> {

View file

@ -72,77 +72,78 @@ public class CheckErrorsForSource7 {
File testSrc = new File(System.getProperty("test.src"));
File testFile = new File(testSrc, args[0]);
if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
//gather spans of the @TA annotations into typeAnnotationSpans:
JavacTask task = JavacTool.create().getTask(null,
fm,
null,
Collections.<String>emptyList(),
null,
fm.getJavaFileObjects(testFile));
final Trees trees = Trees.instance(task);
final CompilationUnitTree cut = task.parse().iterator().next();
final List<int[]> typeAnnotationSpans = new ArrayList<>();
//gather spans of the @TA annotations into typeAnnotationSpans:
JavacTask task = JavacTool.create().getTask(null,
fm,
null,
Collections.<String>emptyList(),
null,
fm.getJavaFileObjects(testFile));
final Trees trees = Trees.instance(task);
final CompilationUnitTree cut = task.parse().iterator().next();
final List<int[]> typeAnnotationSpans = new ArrayList<>();
new TreePathScanner<Void, Void>() {
@Override
public Void visitAnnotation(AnnotationTree node, Void p) {
if (node.getAnnotationType().getKind() == Kind.IDENTIFIER &&
((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) {
int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
int end = (int) trees.getSourcePositions().getEndPosition(cut, node);
typeAnnotationSpans.add(new int[] {start, end});
}
return null;
}
}.scan(cut, null);
//sort the spans in the reverse order, to simplify removing them from the source:
Collections.sort(typeAnnotationSpans, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o2[0] - o1[0];
}
});
//verify the errors are produce correctly:
String originalSource = cut.getSourceFile().getCharContent(false).toString();
for (int[] toKeep : typeAnnotationSpans) {
//prepare updated source code by removing all the annotations except the toKeep one:
String updated = originalSource;
for (int[] span : typeAnnotationSpans) {
if (span == toKeep) continue;
updated = updated.substring(0, span[0]) + updated.substring(span[1]);
}
//parse and verify:
JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated);
DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>();
JavacTask task2 = JavacTool.create().getTask(null,
fm,
errors,
Arrays.asList("-source", "7"),
null,
Arrays.asList(updatedFile));
task2.parse();
boolean found = false;
for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
if (found) {
throw new IllegalStateException("More than one expected error found.");
new TreePathScanner<Void, Void>() {
@Override
public Void visitAnnotation(AnnotationTree node, Void p) {
if (node.getAnnotationType().getKind() == Kind.IDENTIFIER &&
((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) {
int start = (int) trees.getSourcePositions().getStartPosition(cut, node);
int end = (int) trees.getSourcePositions().getEndPosition(cut, node);
typeAnnotationSpans.add(new int[] {start, end});
}
found = true;
return null;
}
}
}.scan(cut, null);
if (!found)
throw new IllegalStateException("Did not produce proper errors for: " + updated);
//sort the spans in the reverse order, to simplify removing them from the source:
Collections.sort(typeAnnotationSpans, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o2[0] - o1[0];
}
});
//verify the errors are produce correctly:
String originalSource = cut.getSourceFile().getCharContent(false).toString();
for (int[] toKeep : typeAnnotationSpans) {
//prepare updated source code by removing all the annotations except the toKeep one:
String updated = originalSource;
for (int[] span : typeAnnotationSpans) {
if (span == toKeep) continue;
updated = updated.substring(0, span[0]) + updated.substring(span[1]);
}
//parse and verify:
JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated);
DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>();
JavacTask task2 = JavacTool.create().getTask(null,
fm,
errors,
Arrays.asList("-source", "7"),
null,
Arrays.asList(updatedFile));
task2.parse();
boolean found = false;
for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) {
if (found) {
throw new IllegalStateException("More than one expected error found.");
}
found = true;
}
}
if (!found)
throw new IllegalStateException("Did not produce proper errors for: " + updated);
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,21 +46,22 @@ public class T6420409 {
public static void main(String... args) throws IOException {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
final StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(SOURCE_PATH, Arrays.asList(test_classes)); // switcheroo !!!
fm.setLocation(CLASS_PATH, Arrays.asList(test_src));
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(test_src, "T6420409.java")));
tool.getTask(null,
fm,
null,
Arrays.asList("-proc:none"),
null,
compilationUnits).call();
test(fm.getLocation(CLASS_PATH), test_src, CLASS_PATH);
test(fm.getLocation(SOURCE_PATH), test_classes, SOURCE_PATH);
test(fm.getLocation(CLASS_OUTPUT), test_classes, CLASS_OUTPUT);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
fm.setLocation(SOURCE_PATH, Arrays.asList(test_classes)); // switcheroo !!!
fm.setLocation(CLASS_PATH, Arrays.asList(test_src));
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
final Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(test_src, "T6420409.java")));
tool.getTask(null,
fm,
null,
Arrays.asList("-proc:none"),
null,
compilationUnits).call();
test(fm.getLocation(CLASS_PATH), test_src, CLASS_PATH);
test(fm.getLocation(SOURCE_PATH), test_classes, SOURCE_PATH);
test(fm.getLocation(CLASS_OUTPUT), test_classes, CLASS_OUTPUT);
}
}
static void test(Iterable<? extends File> path, File file, Location location) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,15 +38,16 @@ public class T6420464 {
public static void main(String... args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null);
mgr.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(test_src));
JavaFileObject f = mgr.getJavaFileForInput(StandardLocation.SOURCE_PATH,
"T6420464",
JavaFileObject.Kind.SOURCE);
if (!f.isNameCompatible("T6420464", JavaFileObject.Kind.SOURCE))
throw new AssertionError("isNameCompatible(SOURCE) fails on " + f.toUri());
if (f.isNameCompatible("T6420464", JavaFileObject.Kind.OTHER))
throw new AssertionError("isNameCompatible(OTHER) fails on " + f.toUri());
System.out.println("OK");
try (StandardJavaFileManager mgr = compiler.getStandardFileManager(null, null, null)) {
mgr.setLocation(StandardLocation.SOURCE_PATH, Collections.singleton(test_src));
JavaFileObject f = mgr.getJavaFileForInput(StandardLocation.SOURCE_PATH,
"T6420464",
JavaFileObject.Kind.SOURCE);
if (!f.isNameCompatible("T6420464", JavaFileObject.Kind.SOURCE))
throw new AssertionError("isNameCompatible(SOURCE) fails on " + f.toUri());
if (f.isNameCompatible("T6420464", JavaFileObject.Kind.OTHER))
throw new AssertionError("isNameCompatible(OTHER) fails on " + f.toUri());
System.out.println("OK");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,18 +39,19 @@ public class T6431435 {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
fm.setLocation(StandardLocation.SOURCE_PATH, Arrays.asList(new File(testSrc)));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
new File(testSrc, "A.java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
boolean ok = true;
ok &= check("parse", task.parse(), 1); // A.java
ok &= check("analyze", task.analyze(), 3); // A, Foo, p.B
ok &= check("generate", task.generate(), 5); // A, Foo, Foo$Baz, Foo$1, p.B
if (!ok)
throw new AssertionError("Test failed");
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
fm.setLocation(StandardLocation.SOURCE_PATH, Arrays.asList(new File(testSrc)));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(
new File(testSrc, "A.java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
boolean ok = true;
ok &= check("parse", task.parse(), 1); // A.java
ok &= check("analyze", task.analyze(), 3); // A, Foo, p.B
ok &= check("generate", task.generate(), 5); // A, Foo, Foo$Baz, Foo$1, p.B
if (!ok)
throw new AssertionError("Test failed");
}
}
private static boolean check(String name, Iterable<?> iter, int expect) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -66,10 +66,11 @@ public class T7086261 {
void test() throws Throwable {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
JavaFileManager jfm = javac.getStandardFileManager(null, null, null);
JavaCompiler.CompilationTask task =
javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
task.call();
try (JavaFileManager jfm = javac.getStandardFileManager(null, null, null)) {
JavaCompiler.CompilationTask task =
javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource()));
task.call();
}
}
public static void main(String[] args) throws Throwable {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -83,14 +83,15 @@ public class Test {
File testSrc = new File(System.getProperty("test.src"));
File thisFile = new File(testSrc, getClass().getName() + ".java");
JavacTool javac = JavacTool.create();
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
testAnnoProcessor(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
testTaskListener(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile);
testAnnoProcessor(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
testTaskListener(javac, fm, fos, out, EXPECT_DOC_COMMENTS);
if (errors > 0)
throw new Exception(errors + " errors occurred");
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
}
void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,17 +39,18 @@ import static javax.tools.JavaFileObject.Kind.CLASS;
public class Sibling {
public static void main(String... args) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
JavaFileObject sibling =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
.iterator().next();
JavaFileObject classFile = fm.getJavaFileForOutput(CLASS_OUTPUT,
"foo.bar.baz.Test",
CLASS,
sibling);
File file = new File("Test.class").getAbsoluteFile();
if (!classFile.toUri().equals(file.toURI()))
throw new AssertionError("Expected " + file.toURI() + ", got " +
classFile.toUri());
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
JavaFileObject sibling =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File("Test.java")))
.iterator().next();
JavaFileObject classFile = fm.getJavaFileForOutput(CLASS_OUTPUT,
"foo.bar.baz.Test",
CLASS,
sibling);
File file = new File("Test.class").getAbsoluteFile();
if (!classFile.toUri().equals(file.toURI()))
throw new AssertionError("Expected " + file.toURI() + ", got " +
classFile.toUri());
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,7 +33,7 @@ import java.util.Arrays;
import javax.tools.*;
public class T6258271 {
public static void main(String... args) {
public static void main(String... args) throws IOException {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> message) {
@ -43,9 +43,10 @@ public class T6258271 {
System.out.println(message);
}
};
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java"));
javac.getTask(null, fm, dl, null, null, files).call();
try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromStrings(Arrays.asList("nofile.java"));
javac.getTask(null, fm, dl, null, null, files).call();
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,11 +29,12 @@
*/
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.tools.*;
public class T6265137 {
public static void main(String... args) {
public static void main(String... args) throws IOException {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() {
public void report(Diagnostic<? extends JavaFileObject> message) {
@ -45,10 +46,11 @@ public class T6265137 {
System.out.flush();
}
};
StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
String srcdir = System.getProperty("test.src");
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call();
try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
String srcdir = System.getProperty("test.src");
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6265137a.java")));
javac.getTask(null, fm, dl, Arrays.asList("-target","9"), null, files).call();
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -87,10 +87,18 @@ public class T6306137 {
}
}
void close() throws IOException {
fm.close();
}
public static void main(String[] args) throws IOException {
T6306137 self = new T6306137();
self.test("utf-8", true);
self.test("ascii", false);
self.test("utf-8", true);
try {
self.test("utf-8", true);
self.test("ascii", false);
self.test("utf-8", true);
} finally {
self.close();
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,17 +45,18 @@ public class T6345974 {
public static void main(String[] args) throws Exception {
PrintWriter out = new PrintWriter(System.out, true);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File testSrc = new File(System.getProperty("test.src"));
Iterable<? extends JavaFileObject> f =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "T6345974.java")));
JavacTask task = tool.getTask(out, fm, null, null, null, f);
Iterable<? extends CompilationUnitTree> trees = task.parse();
out.flush();
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
Scanner s = new Scanner();
for (CompilationUnitTree t: trees)
s.scan(t, null);
}
}
private static class Scanner extends TreeScanner<Void,Void> {

View file

@ -33,42 +33,43 @@ import com.sun.source.util.*;
public class T6357331
{
public static void main(String... args) {
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
PrintWriter out = new PrintWriter(new StringWriter());
List<String> opts = Arrays.asList("-d", ".");
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File thisFile = new File(System.getProperty("test.src"), "T6357331.java");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
final JavacTask task = (JavacTask) (tool.getTask(out, fm, null, opts, null, files));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File thisFile = new File(System.getProperty("test.src"), "T6357331.java");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
final JavacTask task = (JavacTask) (tool.getTask(out, fm, null, opts, null, files));
// set a listener to verify that IllegalStateException is not thrown
// during the compilation
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
task.getElements();
task.getTypes();
}
public void finished(TaskEvent e) { }
});
// set a listener to verify that IllegalStateException is not thrown
// during the compilation
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
task.getElements();
task.getTypes();
}
public void finished(TaskEvent e) { }
});
task.call();
task.call();
// now the compilation is over, we expect IllegalStateException (not NPE)
try {
task.getElements();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
}
// now the compilation is over, we expect IllegalStateException (not NPE)
try {
task.getElements();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
}
try {
task.getTypes();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
try {
task.getTypes();
throw new AssertionError("IllegalStateException not thrown");
}
catch (IllegalStateException e) {
// expected
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,16 +44,17 @@ import javax.tools.*;
public class T6358786 {
public static void main(String... args) throws IOException {
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
Elements elements = task.getElements();
for (TypeElement clazz : task.enter(task.parse())) {
String doc = elements.getDocComment(clazz);
if (doc == null)
throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
String srcdir = System.getProperty("test.src");
File file = new File(srcdir, args[0]);
JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
Elements elements = task.getElements();
for (TypeElement clazz : task.enter(task.parse())) {
String doc = elements.getDocComment(clazz);
if (doc == null)
throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -36,34 +36,35 @@ import static javax.tools.JavaFileObject.Kind.*;
public class T6358955 {
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
try (StandardJavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
File dir = new File("temp" + args.hashCode());
if (!dir.exists())
dir.mkdir();
if (!dir.isDirectory())
throw new AssertionError("Not a directory " + dir);
File dir = new File("temp" + args.hashCode());
if (!dir.exists())
dir.mkdir();
if (!dir.isDirectory())
throw new AssertionError("Not a directory " + dir);
try {
jfm.setLocation(StandardLocation.CLASS_OUTPUT,
Arrays.asList(dir.getCanonicalFile().getParentFile()));
try {
jfm.getFileForInput(StandardLocation.CLASS_OUTPUT, "", dir.getPath());
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
try {
jfm.getJavaFileObjectsFromFiles(Arrays.asList(dir));
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
} finally {
try {
dir.delete(); // cleanup
} catch (Throwable t) {
t.printStackTrace();
jfm.setLocation(StandardLocation.CLASS_OUTPUT,
Arrays.asList(dir.getCanonicalFile().getParentFile()));
try {
jfm.getFileForInput(StandardLocation.CLASS_OUTPUT, "", dir.getPath());
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
try {
jfm.getJavaFileObjectsFromFiles(Arrays.asList(dir));
throw new AssertionError("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
System.out.println("OK: " + e.getLocalizedMessage());
}
} finally {
try {
dir.delete(); // cleanup
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -38,21 +38,22 @@ public class T6392782 {
public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends Tree> trees = task.parse();
TreeScanner<Integer,Void> scanner = new MyScanner();
check(scanner, 6, scanner.scan(trees, null));
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends Tree> trees = task.parse();
TreeScanner<Integer,Void> scanner = new MyScanner();
check(scanner, 6, scanner.scan(trees, null));
CountNodes nodeCounter = new CountNodes();
// 359 nodes with the regular parser; 360 nodes with EndPosParser
// We automatically switch to EndPosParser when calling JavacTask.parse()
check(nodeCounter, 360, nodeCounter.scan(trees, null));
CountNodes nodeCounter = new CountNodes();
// 359 nodes with the regular parser; 360 nodes with EndPosParser
// We automatically switch to EndPosParser when calling JavacTask.parse()
check(nodeCounter, 362, nodeCounter.scan(trees, null));
CountIdentifiers idCounter = new CountIdentifiers();
check(idCounter, 107, idCounter.scan(trees, null));
CountIdentifiers idCounter = new CountIdentifiers();
check(idCounter, 107, idCounter.scan(trees, null));
}
}
private static void check(TreeScanner<?,?> scanner, int expect, int found) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,16 +65,15 @@ public class T6397104 {
void test(boolean hasLocation, File siblingFile, String relName, String expectedPath)
throws Exception
{
StandardJavaFileManager fm;
if (hasLocation) {
for (Location location : StandardLocation.values()) {
fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
if (hasLocation) {
for (Location location : StandardLocation.values()) {
fm.setLocation(location, Arrays.asList(new File(".")));
test(fm, location, siblingFile, relName, expectedPath);
}
} else {
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
} else {
fm = tool.getStandardFileManager(null, null, null);
test(fm, CLASS_OUTPUT, siblingFile, relName, expectedPath);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,22 +28,24 @@
* @author Peter von der Ah\u00e9
*/
import java.io.IOException;
import javax.tools.*;
import static javax.tools.StandardLocation.*;
public class T6400205 {
public static void main(String... args) {
JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
try {
fm.getClassLoader(null);
throw new AssertionError("NullPointerException not thrown");
} catch (NullPointerException e) {
// expected result
public static void main(String... args) throws IOException {
try (JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
try {
fm.getClassLoader(null);
throw new AssertionError("NullPointerException not thrown");
} catch (NullPointerException e) {
// expected result
}
ClassLoader cl = fm.getClassLoader(locationFor("bogus"));
if (cl != null)
throw new AssertionError("non-null class loader for bogus location");
System.err.println("Test PASSED.");
}
ClassLoader cl = fm.getClassLoader(locationFor("bogus"));
if (cl != null)
throw new AssertionError("non-null class loader for bogus location");
System.err.println("Test PASSED.");
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -61,28 +61,29 @@ public class T6400207 {
}
public static void main(String... args) throws Exception {
JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
JavaFileManager.Location bogusLocation = locationFor("bogus");
JavaFileManager.Location knownLocation = CLASS_PATH;
String packageName = "java.lang";
Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS);
try (JavaFileManager fm =
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
JavaFileManager.Location bogusLocation = locationFor("bogus");
JavaFileManager.Location knownLocation = CLASS_PATH;
String packageName = "java.lang";
Set<JavaFileObject.Kind> kinds = EnumSet.of(CLASS);
for (StandardLocation location : StandardLocation.values()) {
if (location != locationFor(location.getName()))
throw new AssertionError(location + " != locationFor(" +
location.getName() + ")");
for (StandardLocation location : StandardLocation.values()) {
if (location != locationFor(location.getName()))
throw new AssertionError(location + " != locationFor(" +
location.getName() + ")");
}
testList(fm, null, null, null);
testList(fm, bogusLocation, packageName, kinds);
testList(fm, knownLocation, packageName, kinds);
testList(fm, null, packageName, kinds);
testList(fm, knownLocation, null, kinds);
testList(fm, knownLocation, packageName, null);
testList(fm, bogusLocation, null, kinds);
testList(fm, bogusLocation, packageName, null);
System.err.println("Test PASSED.");
}
testList(fm, null, null, null);
testList(fm, bogusLocation, packageName, kinds);
testList(fm, knownLocation, packageName, kinds);
testList(fm, null, packageName, kinds);
testList(fm, knownLocation, null, kinds);
testList(fm, knownLocation, packageName, null);
testList(fm, bogusLocation, null, kinds);
testList(fm, bogusLocation, packageName, null);
System.err.println("Test PASSED.");
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -64,22 +64,23 @@ public class T6412669 extends AbstractProcessor {
//System.err.println("toolsClasses: " + toolsClasses);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java")));
String[] opts = { "-proc:only", "-processor", T6412669.class.getName()};
StringWriter sw = new StringWriter();
JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files);
boolean ok = task.call();
String out = sw.toString();
if (!out.isEmpty())
System.err.println(out);
if (!ok)
throw new AssertionError("compilation of test program failed");
// verify we found an annotated element to exercise the SourcePositions API
if (!out.contains("processing element"))
throw new AssertionError("expected text not found in compilation output");
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses));
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java")));
String[] opts = { "-proc:only", "-processor", T6412669.class.getName()};
StringWriter sw = new StringWriter();
JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files);
boolean ok = task.call();
String out = sw.toString();
if (!out.isEmpty())
System.err.println(out);
if (!ok)
throw new AssertionError("compilation of test program failed");
// verify we found an annotated element to exercise the SourcePositions API
if (!out.contains("processing element"))
throw new AssertionError("expected text not found in compilation output");
}
}
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,17 +35,18 @@ import javax.tools.*;
public class T6419926 {
public static void main(String[] argv) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null);
System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
mgr.setLocation(StandardLocation.CLASS_OUTPUT,
Collections.singleton(new File(".")));
try (StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null)) {
System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
mgr.setLocation(StandardLocation.CLASS_OUTPUT,
Collections.singleton(new File(".")));
FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT,
"", "file.to.delete", null);
URI uri = fo.toUri();
System.out.println( uri );
FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT,
"", "file.to.delete", null);
URI uri = fo.toUri();
System.out.println( uri );
if (!"file".equals(uri.getScheme()))
throw new Exception("unexpected scheme for uri: " + uri.getScheme());
if (!"file".equals(uri.getScheme()))
throw new Exception("unexpected scheme for uri: " + uri.getScheme());
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -134,21 +134,22 @@
System.err.println("test task API: " + pcp);
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
if (pcp != null)
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
if (pcp != null)
fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, null, null, files);
boolean ok = task.call();
String out = showOutput(sw.toString());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavacTask task = tool.getTask(pw, fm, null, null, null, files);
boolean ok = task.call();
String out = showOutput(sw.toString());
checkCompilationOK(ok);
checkOutput(out, expectWarnings);
checkCompilationOK(ok);
checkOutput(out, expectWarnings);
}
}
//----- utility methods

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,18 +39,18 @@ public class T6431879 {
String testSrc = System.getProperty("test.src", ".");
String testClasses = System.getProperty("test.classes", ".");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
TreeScanner<Void,Trees> dependencyScanner = new DependencyScanner();
Trees treeUtil = Trees.instance(task);
for (CompilationUnitTree unit : trees) {
//System.err.println("scan " + unit);
dependencyScanner.scan(unit, treeUtil);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6431879.class.getName()+".java")));
JavacTask task = tool.getTask(null, fm, null, null, null, files);
Iterable<? extends CompilationUnitTree> trees = task.parse();
TreeScanner<Void,Trees> dependencyScanner = new DependencyScanner();
Trees treeUtil = Trees.instance(task);
for (CompilationUnitTree unit : trees) {
//System.err.println("scan " + unit);
dependencyScanner.scan(unit, treeUtil);
}
}
}
private static class DependencyScanner<R,P> extends TreePathScanner<R,P> {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -42,14 +42,15 @@ public class T6483788 {
void run() throws Exception {
File jar = createJar();
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
System.err.println("file: " + fo);
URI uri = fo.toUri();
System.err.println("uri: " + uri);
if (uri.toString().contains(" "))
throw new Exception("unexpected space character found");
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
System.err.println("file: " + fo);
URI uri = fo.toUri();
System.err.println("uri: " + uri);
if (uri.toString().contains(" "))
throw new Exception("unexpected space character found");
}
}
File createJar() throws IOException {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -46,16 +46,18 @@ public class T6501502 {
// we test a number of platform-independent paths.
void run() throws Exception {
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
fm = c.getStandardFileManager(null, null, null);
System.err.println(System.getProperties());
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File testSrcDir = new File(System.getProperty("test.src"));
File testClassesDir = new File(System.getProperty("test.classes"));
test(new File("abc.tmp"));
test(new File(tmpDir, "bad.file"));
test(new File(testSrcDir, "T6501501.java"));
test(new File(testClassesDir, "T6501501.class"));
test(new File("a b"));
try (StandardJavaFileManager sfm = c.getStandardFileManager(null, null, null)) {
fm = sfm;
System.err.println(System.getProperties());
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File testSrcDir = new File(System.getProperty("test.src"));
File testClassesDir = new File(System.getProperty("test.classes"));
test(new File("abc.tmp"));
test(new File(tmpDir, "bad.file"));
test(new File(testSrcDir, "T6501501.java"));
test(new File(testClassesDir, "T6501501.class"));
test(new File("a b"));
}
}
void test(File f) throws Exception {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -56,34 +56,36 @@ public class TestClientCodeWrapper extends JavacTestingAbstractProcessor {
*/
void run() throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
defaultFileManager = compiler.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
defaultFileManager = fm;
for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
test(m);
for (Method m: getMethodsExcept(JavaFileManager.class, "close", "getJavaFileForInput")) {
test(m);
}
for (Method m: getMethodsExcept(FileObject.class, "delete")) {
test(m);
}
for (Method m: getMethods(JavaFileObject.class)) {
test(m);
}
for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
test(m);
}
for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
test(m);
}
for (Method m: TaskListener.class.getDeclaredMethods()) {
test(m);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
for (Method m: getMethodsExcept(FileObject.class, "delete")) {
test(m);
}
for (Method m: getMethods(JavaFileObject.class)) {
test(m);
}
for (Method m: getMethodsExcept(Processor.class, "getCompletions")) {
test(m);
}
for (Method m: DiagnosticListener.class.getDeclaredMethods()) {
test(m);
}
for (Method m: TaskListener.class.getDeclaredMethods()) {
test(m);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
/** Get a sorted set of the methods declared on a class. */

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -52,23 +52,23 @@ public class TestDocComments {
File file = new File(testSrc, "TestDocComments.java");
JavacTool tool = JavacTool.create();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
Iterable<? extends CompilationUnitTree> units = task.parse();
Trees trees = Trees.instance(task);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file);
JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects);
Iterable<? extends CompilationUnitTree> units = task.parse();
Trees trees = Trees.instance(task);
CommentScanner s = new CommentScanner();
int n = s.scan(units, trees);
CommentScanner s = new CommentScanner();
int n = s.scan(units, trees);
if (n != 12)
error("Unexpected number of doc comments found: " + n);
if (n != 12)
error("Unexpected number of doc comments found: " + n);
if (errors > 0)
throw new Exception(errors + " errors occurred");
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
}
/**

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,31 +50,32 @@ public class TestGetElementReference {
public static void main(String... args) throws IOException {
File source = new File(System.getProperty("test.src", "."), "TestGetElementReferenceData.java").getAbsoluteFile();
StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavacTask ct = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, diagnostics, Arrays.asList("-Xjcov"), null, fm.getJavaFileObjects(source));
Trees trees = Trees.instance(ct);
CompilationUnitTree cut = ct.parse().iterator().next();
try (StandardJavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavacTask ct = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, diagnostics, Arrays.asList("-Xjcov"), null, fm.getJavaFileObjects(source));
Trees trees = Trees.instance(ct);
CompilationUnitTree cut = ct.parse().iterator().next();
ct.analyze();
ct.analyze();
for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR) {
throw new IllegalStateException("Should have been attributed without errors: " + diagnostics.getDiagnostics());
for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR) {
throw new IllegalStateException("Should have been attributed without errors: " + diagnostics.getDiagnostics());
}
}
}
Pattern p = Pattern.compile("/\\*getElement:(.*?)\\*/");
Matcher m = p.matcher(cut.getSourceFile().getCharContent(false));
Pattern p = Pattern.compile("/\\*getElement:(.*?)\\*/");
Matcher m = p.matcher(cut.getSourceFile().getCharContent(false));
while (m.find()) {
TreePath tp = pathFor(trees, cut, m.start() - 1);
Element found = trees.getElement(tp);
String expected = m.group(1);
String actual = found != null ? found.getKind() + ":" + symbolToString(found) : "<null>";
while (m.find()) {
TreePath tp = pathFor(trees, cut, m.start() - 1);
Element found = trees.getElement(tp);
String expected = m.group(1);
String actual = found != null ? found.getKind() + ":" + symbolToString(found) : "<null>";
if (!expected.equals(actual)) {
throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
if (!expected.equals(actual)) {
throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@
import com.sun.source.tree.IdentifierTree;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -51,24 +52,25 @@ import javax.lang.model.SourceVersion;
@SupportedAnnotationTypes("*")
public class TestGetScope extends AbstractProcessor {
public static void main(String... args) {
public static void main(String... args) throws IOException {
new TestGetScope().run();
}
public void run() {
public void run() throws IOException {
File srcDir = new File(System.getProperty("test.src"));
File thisFile = new File(srcDir, getClass().getName() + ".java");
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
List<String> opts = Arrays.asList("-proc:only", "-doe");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
t.setProcessors(Collections.singleton(this));
boolean ok = t.call();
if (!ok)
throw new Error("compilation failed");
List<String> opts = Arrays.asList("-proc:only", "-doe");
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
t.setProcessors(Collections.singleton(this));
boolean ok = t.call();
if (!ok)
throw new Error("compilation failed");
}
}
@Override

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -41,8 +41,8 @@ import javax.tools.ToolProvider;
public class TestJavacTask {
static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
static final StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
static JavacTaskImpl getTask(File... file) {
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
return (JavacTaskImpl)compiler.getTask(null, fm, null, null, null, files);
@ -69,7 +69,11 @@ public class TestJavacTask {
}
public static void main(String... args) throws IOException {
basicTest(args);
checkKindError();
try {
basicTest(args);
checkKindError();
} finally {
fm.close();
}
}
}

View file

@ -67,15 +67,18 @@ public class TestJavacTask_Lock {
void run() throws Exception {
comp = ToolProvider.getSystemJavaCompiler();
fm = comp.getStandardFileManager(null, null, null);
for (MethodKind first: MethodKind.values()) {
for (MethodKind second: MethodKind.values()) {
test(first, second);
try {
for (MethodKind first: MethodKind.values()) {
for (MethodKind second: MethodKind.values()) {
test(first, second);
}
}
}
if (errors > 0)
throw new Exception(errors + " errors found");
if (errors > 0)
throw new Exception(errors + " errors found");
} finally {
fm.close();
}
}
void test(MethodKind first, MethodKind second) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -68,16 +68,19 @@ public class TestJavacTask_Multiple {
void run() throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (TestKind tk: TestKind.values()) {
test(comp, fm, tk);
}
try {
for (TestKind tk: TestKind.values()) {
test(comp, fm, tk);
}
int expect = TestKind.values().length * MAX_TASKS;
if (count != expect) {
throw new Exception("Unexpected number of tests completed: " + count
+ ", expected: " + expect);
int expect = TestKind.values().length * MAX_TASKS;
if (count != expect) {
throw new Exception("Unexpected number of tests completed: " + count
+ ", expected: " + expect);
}
} finally {
fm.close();
}
}
void test(JavaCompiler comp, StandardJavaFileManager fm, TestKind tk) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,14 +45,17 @@ public class TestJavacTask_ParseAttrGen {
void run() throws Exception {
comp = ToolProvider.getSystemJavaCompiler();
fm = comp.getStandardFileManager(null, null, null);
final boolean[] booleanValues = { false, true };
for (boolean pk: booleanValues) {
for (boolean ak: booleanValues) {
for (boolean gk: booleanValues) {
test(pk, ak, gk);
try {
final boolean[] booleanValues = { false, true };
for (boolean pk: booleanValues) {
for (boolean ak: booleanValues) {
for (boolean gk: booleanValues) {
test(pk, ak, gk);
}
}
}
} finally {
fm.close();
}
}

View file

@ -76,30 +76,33 @@ public class TestSearchPaths {
void run() throws Exception {
compiler = ToolProvider.getSystemJavaCompiler();
fileManager = compiler.getStandardFileManager(null, null, null);
try {
// basic output path
testClassOutput();
// basic output path
testClassOutput();
// basic search paths
testClassPath();
testSourcePath();
testPlatformClassPath();
// basic search paths
testClassPath();
testSourcePath();
testPlatformClassPath();
// annotation processing
testAnnotationProcessorPath();
testSourceOutput();
// annotation processing
testAnnotationProcessorPath();
testSourceOutput();
// javah equivalent
testNativeHeaderOutput();
// javah equivalent
testNativeHeaderOutput();
// future-proof: guard against new StandardLocations being added
if (!tested.equals(EnumSet.allOf(StandardLocation.class))) {
error("not all standard locations have been tested");
out.println("not yet tested: " + EnumSet.complementOf(tested));
}
// future-proof: guard against new StandardLocations being added
if (!tested.equals(EnumSet.allOf(StandardLocation.class))) {
error("not all standard locations have been tested");
out.println("not yet tested: " + EnumSet.complementOf(tested));
}
if (errors > 0) {
throw new Exception(errors + " errors occurred");
if (errors > 0) {
throw new Exception(errors + " errors occurred");
}
} finally {
fileManager.close();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -105,17 +105,18 @@ public class TestTreePath extends AbstractProcessor {
public void run() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager
= compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> tests
= fileManager.getJavaFileObjects(writeTestFile());
try (StandardJavaFileManager fileManager
= compiler.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> tests
= fileManager.getJavaFileObjects(writeTestFile());
JavaCompiler.CompilationTask task =
ToolProvider.getSystemJavaCompiler().getTask(
null, null, null,
Arrays.asList("-processor", this.getClass().getName()), null,
tests);
task.call();
JavaCompiler.CompilationTask task =
ToolProvider.getSystemJavaCompiler().getTask(
null, null, null,
Arrays.asList("-processor", this.getClass().getName()), null,
tests);
task.call();
}
}
public static void main(String[] args) throws IOException {

View file

@ -74,29 +74,30 @@ public class TestTrees extends AbstractProcessor {
}
};
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
Iterable<? extends JavaFileObject> files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java")));
Iterable<String> opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple");
Iterable<String> opts = Arrays.asList("-d", ".", "-XDcompilePolicy=simple");
System.err.println("simple compilation, no processing");
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.setTaskListener(new MyTaskListener(task));
if (!task.call())
throw new AssertionError("compilation failed");
System.err.println("simple compilation, no processing");
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
task.setTaskListener(new MyTaskListener(task));
if (!task.call())
throw new AssertionError("compilation failed");
opts = Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self,
"-XDcompilePolicy=simple");
opts = Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self,
"-XDcompilePolicy=simple");
System.err.println();
System.err.println("compilation with processing");
task = tool.getTask(out, fm, dl,opts, null, files);
if (!task.call())
throw new AssertionError("compilation failed");
System.err.println();
System.err.println("compilation with processing");
task = tool.getTask(out, fm, dl,opts, null, files);
if (!task.call())
throw new AssertionError("compilation failed");
if (errors > 0)
throw new AssertionError(errors + " errors occurred");
if (errors > 0)
throw new AssertionError(errors + " errors occurred");
}
}
void testElement(Trees trees, Element e) {

View file

@ -73,18 +73,19 @@ public class CompileEvent {
assertOutput(out.toString());
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> testFileObjects = fm.getJavaFileObjects(test);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> testFileObjects = fm.getJavaFileObjects(test);
//test events fired to listeners registered from plugins
//when starting compiler using JavaCompiler.getTask(...).call
List<String> options =
Arrays.asList("-Xplugin:compile-event", "-processorpath", testClasses);
out = new StringWriter();
boolean compResult = comp.getTask(out, null, null, options, null, testFileObjects).call();
if (!compResult)
throw new AssertionError("Compilation failed unexpectedly.");
assertOutput(out.toString());
//test events fired to listeners registered from plugins
//when starting compiler using JavaCompiler.getTask(...).call
List<String> options =
Arrays.asList("-Xplugin:compile-event", "-processorpath", testClasses);
out = new StringWriter();
boolean compResult = comp.getTask(out, null, null, options, null, testFileObjects).call();
if (!compResult)
throw new AssertionError("Compilation failed unexpectedly.");
assertOutput(out.toString());
}
}
void assertOutput(String found) {

View file

@ -44,7 +44,12 @@ public class EventsBalancedTest {
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
public static void main(String... args) throws IOException {
new EventsBalancedTest().test();
EventsBalancedTest t = new EventsBalancedTest();
try {
t.test();
} finally {
t.fm.close();
}
}
void test() throws IOException {

View file

@ -203,7 +203,12 @@ public class TestSimpleAddRemove {
}
public static void main(String... args) throws Exception {
new TestSimpleAddRemove().run();
TestSimpleAddRemove t = new TestSimpleAddRemove();
try {
t.run();
} finally {
t.fm.close();
}
}
JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -104,35 +104,36 @@ public class IntersectionTypeParserTest {
public static void main(String... args) throws Exception {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (CastKind ck : CastKind.values()) {
for (TypeKind t1 : TypeKind.values()) {
for (ArrayKind ak1 : ArrayKind.values()) {
Type typ1 = new Type(t1, ak1);
if (ck.nBounds == 1) {
new IntersectionTypeParserTest(ck, typ1).run(comp, fm);
continue;
}
for (TypeKind t2 : TypeKind.values()) {
for (ArrayKind ak2 : ArrayKind.values()) {
Type typ2 = new Type(t2, ak2);
if (ck.nBounds == 2) {
new IntersectionTypeParserTest(ck, typ1, typ2).run(comp, fm);
continue;
}
for (TypeKind t3 : TypeKind.values()) {
for (ArrayKind ak3 : ArrayKind.values()) {
Type typ3 = new Type(t3, ak3);
new IntersectionTypeParserTest(ck, typ1, typ2, typ3).run(comp, fm);
for (CastKind ck : CastKind.values()) {
for (TypeKind t1 : TypeKind.values()) {
for (ArrayKind ak1 : ArrayKind.values()) {
Type typ1 = new Type(t1, ak1);
if (ck.nBounds == 1) {
new IntersectionTypeParserTest(ck, typ1).run(comp, fm);
continue;
}
for (TypeKind t2 : TypeKind.values()) {
for (ArrayKind ak2 : ArrayKind.values()) {
Type typ2 = new Type(t2, ak2);
if (ck.nBounds == 2) {
new IntersectionTypeParserTest(ck, typ1, typ2).run(comp, fm);
continue;
}
for (TypeKind t3 : TypeKind.values()) {
for (ArrayKind ak3 : ArrayKind.values()) {
Type typ3 = new Type(t3, ak3);
new IntersectionTypeParserTest(ck, typ1, typ2, typ3).run(comp, fm);
}
}
}
}
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
CastKind ck;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -68,39 +68,40 @@ public class T7031108 extends JavacTestingAbstractProcessor {
void run() throws Exception {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
// step 1: compile test classes
File cwd = new File(".");
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
compile(comp, fm, null, null, pC);
// step 1: compile test classes
File cwd = new File(".");
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(cwd));
compile(comp, fm, null, null, pC);
// step 2: verify functioning of processor
fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
fm.getLocation(StandardLocation.CLASS_PATH));
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
compile(comp, fm, null, getClass().getName(), dummy);
// step 2: verify functioning of processor
fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
fm.getLocation(StandardLocation.CLASS_PATH));
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(cwd));
compile(comp, fm, null, getClass().getName(), dummy);
File pC_class = new File(new File("p"), "C.class");
pC_class.delete();
File pC_class = new File(new File("p"), "C.class");
pC_class.delete();
DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
compile(comp, fm, dc, getClass().getName(), dummy);
List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
compile(comp, fm, dc, getClass().getName(), dummy);
List<Diagnostic<? extends JavaFileObject>> diags =dc.getDiagnostics();
System.err.println(diags);
switch (diags.size()) {
case 0:
throw new Exception("no diagnostics received");
case 1:
String code = diags.get(0).getCode();
String expect = "compiler.err.proc.cant.access.1";
if (!expect.equals(code))
throw new Exception("unexpected diag code: " + code
+ ", expected: " + expect);
break;
default:
throw new Exception("unexpected diags received");
System.err.println(diags);
switch (diags.size()) {
case 0:
throw new Exception("no diagnostics received");
case 1:
String code = diags.get(0).getCode();
String expect = "compiler.err.proc.cant.access.1";
if (!expect.equals(code))
throw new Exception("unexpected diag code: " + code
+ ", expected: " + expect);
break;
default:
throw new Exception("unexpected diags received");
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,31 +54,32 @@ public class DefaultMethodFlags {
void checkDefaultMethodFlags() throws IOException {
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> fos =
fm.getJavaFileObjectsFromFiles(
Arrays.asList(new File(
System.getProperty("test.src"),
this.getClass().getSimpleName() + ".java")));
JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos);
try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fos =
fm.getJavaFileObjectsFromFiles(
Arrays.asList(new File(
System.getProperty("test.src"),
this.getClass().getSimpleName() + ".java")));
JavacTask task = (JavacTask) c.getTask(null, fm, null, null, null, fos);
task.addTaskListener(new TaskListener() {
task.addTaskListener(new TaskListener() {
@Override
public void started(TaskEvent e) {}
@Override
public void started(TaskEvent e) {}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ANALYZE) {
TypeElement te = e.getTypeElement();
if (te.getSimpleName().toString().equals("I")) {
checkDefaultInterface(te);
@Override
public void finished(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ANALYZE) {
TypeElement te = e.getTypeElement();
if (te.getSimpleName().toString().equals("I")) {
checkDefaultInterface(te);
}
}
}
}
});
});
task.analyze();
task.analyze();
}
}
void checkDefaultInterface(TypeElement te) {

View file

@ -123,18 +123,19 @@ public class InterfaceMethodHidingTest {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (MethodKind mk1 : MethodKind.values()) {
for (SignatureKind sk1 : SignatureKind.values()) {
for (BodyExpr be1 : BodyExpr.values()) {
for (MethodKind mk2 : MethodKind.values()) {
for (SignatureKind sk2 : SignatureKind.values()) {
for (BodyExpr be2 : BodyExpr.values()) {
for (MethodKind mk3 : MethodKind.values()) {
for (SignatureKind sk3 : SignatureKind.values()) {
for (BodyExpr be3 : BodyExpr.values()) {
new InterfaceMethodHidingTest(mk1, mk2, mk3, sk1, sk2, sk3, be1, be2, be3).run(comp, fm);
for (MethodKind mk1 : MethodKind.values()) {
for (SignatureKind sk1 : SignatureKind.values()) {
for (BodyExpr be1 : BodyExpr.values()) {
for (MethodKind mk2 : MethodKind.values()) {
for (SignatureKind sk2 : SignatureKind.values()) {
for (BodyExpr be2 : BodyExpr.values()) {
for (MethodKind mk3 : MethodKind.values()) {
for (SignatureKind sk3 : SignatureKind.values()) {
for (BodyExpr be3 : BodyExpr.values()) {
new InterfaceMethodHidingTest(mk1, mk2, mk3, sk1, sk2, sk3, be1, be2, be3).run(comp, fm);
}
}
}
}
@ -143,8 +144,8 @@ public class InterfaceMethodHidingTest {
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
MethodKind mk1, mk2, mk3;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -188,20 +188,21 @@ public class TestDefaultMethodsSyntax {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (VersionKind vk : VersionKind.values()) {
for (EnclosingKind ek : EnclosingKind.values()) {
for (MethodKind mk : MethodKind.values()) {
for (ModifierKind modk1 : ModifierKind.values()) {
for (ModifierKind modk2 : ModifierKind.values()) {
new TestDefaultMethodsSyntax(vk, ek, mk, modk1, modk2).run(comp, fm);
for (VersionKind vk : VersionKind.values()) {
for (EnclosingKind ek : EnclosingKind.values()) {
for (MethodKind mk : MethodKind.values()) {
for (ModifierKind modk1 : ModifierKind.values()) {
for (ModifierKind modk2 : ModifierKind.values()) {
new TestDefaultMethodsSyntax(vk, ek, mk, modk1, modk2).run(comp, fm);
}
}
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
VersionKind vk;

View file

@ -313,27 +313,28 @@ public class CheckResourceKeys {
Set<String> getCodeStrings() throws IOException {
Set<String> results = new TreeSet<String>();
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
JavaFileManager fm = c.getStandardFileManager(null, null, null);
JavaFileManager.Location javacLoc = findJavacLocation(fm);
String[] pkgs = {
"javax.annotation.processing",
"javax.lang.model",
"javax.tools",
"com.sun.source",
"com.sun.tools.javac"
};
for (String pkg: pkgs) {
for (JavaFileObject fo: fm.list(javacLoc,
pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
String name = fo.getName();
// ignore resource files, and files which are not really part of javac
if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*")
|| name.matches(".*CreateSymbols\\.class.*"))
continue;
scan(fo, results);
try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) {
JavaFileManager.Location javacLoc = findJavacLocation(fm);
String[] pkgs = {
"javax.annotation.processing",
"javax.lang.model",
"javax.tools",
"com.sun.source",
"com.sun.tools.javac"
};
for (String pkg: pkgs) {
for (JavaFileObject fo: fm.list(javacLoc,
pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
String name = fo.getName();
// ignore resource files, and files which are not really part of javac
if (name.matches(".*resources.[A-Za-z_0-9]+\\.class.*")
|| name.matches(".*CreateSymbols\\.class.*"))
continue;
scan(fo, results);
}
}
return results;
}
return results;
}
// depending on how the test is run, javac may be on bootclasspath or classpath

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -109,44 +109,48 @@ public class DocLintTest {
void run() throws Exception {
javac = ToolProvider.getSystemJavaCompiler();
fm = javac.getStandardFileManager(null, null, null);
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncoding) {
return code;
}
};
try {
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
file = new SimpleJavaFileObject(URI.create("Test.java"), JavaFileObject.Kind.SOURCE) {
@Override
public CharSequence getCharContent(boolean ignoreEncoding) {
return code;
}
};
test(Collections.<String>emptyList(),
Main.Result.OK,
EnumSet.noneOf(Message.class));
test(Collections.<String>emptyList(),
Main.Result.OK,
EnumSet.noneOf(Message.class));
test(Arrays.asList("-Xdoclint:none"),
Main.Result.OK,
EnumSet.noneOf(Message.class));
test(Arrays.asList("-Xdoclint:none"),
Main.Result.OK,
EnumSet.noneOf(Message.class));
test(Arrays.asList(rawDiags, "-Xdoclint"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR6, Message.DL_ERR9, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
Main.Result.OK,
EnumSet.of(Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:all/public"),
Main.Result.OK,
EnumSet.of(Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:syntax"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR6, Message.DL_WRN12));
test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9));
test(Arrays.asList(rawDiags, "-Xdoclint:reference"),
Main.Result.ERROR,
EnumSet.of(Message.DL_ERR9));
test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
Main.Result.CMDERR,
EnumSet.of(Message.OPT_BADARG));
test(Arrays.asList(rawDiags, "-Xdoclint:badarg"),
Main.Result.CMDERR,
EnumSet.of(Message.OPT_BADARG));
if (errors > 0)
throw new Exception(errors + " errors occurred");
if (errors > 0)
throw new Exception(errors + " errors occurred");
} finally {
fm.close();
}
}
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -66,22 +66,23 @@ public class DocTreePathScannerTest {
}
JavacTool javac = JavacTool.create();
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
Iterable<? extends CompilationUnitTree> units = t.parse();
Iterable<? extends CompilationUnitTree> units = t.parse();
DeclScanner ds = new DeclScanner(trees);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
DeclScanner ds = new DeclScanner(trees);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void error(String msg) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -66,28 +66,29 @@ public class SimpleDocTreeVisitorTest {
}
JavacTool javac = JavacTool.create();
StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
JavacTask t = javac.getTask(null, fm, null, null, null, fos);
DocTrees trees = DocTrees.instance(t);
Iterable<? extends CompilationUnitTree> units = t.parse();
Iterable<? extends CompilationUnitTree> units = t.parse();
Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
DeclScanner ds = new DeclScanner(trees, found);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
DeclScanner ds = new DeclScanner(trees, found);
for (CompilationUnitTree unit: units) {
ds.scan(unit, null);
}
for (DocTree.Kind k: DocTree.Kind.values()) {
if (!found.contains(k) && k != DocTree.Kind.OTHER)
error("not found: " + k);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
for (DocTree.Kind k: DocTree.Kind.values()) {
if (!found.contains(k) && k != DocTree.Kind.OTHER)
error("not found: " + k);
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
void error(String msg) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -47,6 +47,7 @@ import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
@ -75,34 +76,36 @@ public class T7068451 {
System.err.println("FIRST compilation");
System.err.println();
CompilationTask task = compiler.getTask(null, null, null, opts, null,
compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("first")));
check("compilation", task.call());
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
CompilationTask task = compiler.getTask(null, fm, null, opts, null,
fm.getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("first")));
check("compilation", task.call());
writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }");
writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }");
//Thread.sleep(2000);
//Thread.sleep(2000);
System.err.println();
System.err.println("SECOND compilation");
System.err.println();
System.err.println();
System.err.println("SECOND compilation");
System.err.println();
task = compiler.getTask(null, null, null, opts, null,
compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("second")));
check("compilation", task.call());
task = compiler.getTask(null, fm, null, opts, null,
fm.getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("second")));
check("compilation", task.call());
//Thread.sleep(2000);
//Thread.sleep(2000);
System.err.println();
System.err.println("SECOND compilation, REPEATED");
System.err.println();
System.err.println();
System.err.println("SECOND compilation, REPEATED");
System.err.println();
task = compiler.getTask(null, null, null, opts, null,
compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("second")));
check("compilation", task.call());
task = compiler.getTask(null, fm, null, opts, null,
fm.getJavaFileObjects(input));
task.setProcessors(Collections.singleton(new Proc("second")));
check("compilation", task.call());
}
}
void check(String msg, boolean ok) {

View file

@ -76,18 +76,21 @@ public class LVTHarness {
static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
public static void main(String[] args) throws Exception {
try {
String testDir = System.getProperty("test.src");
fm.setLocation(SOURCE_PATH, Arrays.asList(new File(testDir, "tests")));
String testDir = System.getProperty("test.src");
fm.setLocation(SOURCE_PATH, Arrays.asList(new File(testDir, "tests")));
// Make sure classes are written to scratch dir.
fm.setLocation(CLASS_OUTPUT, Arrays.asList(new File(".")));
// Make sure classes are written to scratch dir.
fm.setLocation(CLASS_OUTPUT, Arrays.asList(new File(".")));
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(SOURCE), true)) {
new LVTHarness(jfo).check();
}
if (nerrors > 0) {
throw new AssertionError("Errors were found");
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(SOURCE), true)) {
new LVTHarness(jfo).check();
}
if (nerrors > 0) {
throw new AssertionError("Errors were found");
}
} finally {
fm.close();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -70,19 +70,23 @@ public class BridgeHarness {
static final StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
public static void main(String[] args) throws Exception {
//set sourcepath
fm.setLocation(SOURCE_PATH,
Arrays.asList(new File(System.getProperty("test.src"), "tests")));
//set output (-d)
fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
Arrays.asList(new File(System.getProperty("user.dir"))));
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
//for each source, compile and check against annotations
new BridgeHarness(jfo).compileAndCheck();
}
//if there were errors, fail
if (nerrors > 0) {
throw new AssertionError("Errors were found");
try {
//set sourcepath
fm.setLocation(SOURCE_PATH,
Arrays.asList(new File(System.getProperty("test.src"), "tests")));
//set output (-d)
fm.setLocation(javax.tools.StandardLocation.CLASS_OUTPUT,
Arrays.asList(new File(System.getProperty("user.dir"))));
for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
//for each source, compile and check against annotations
new BridgeHarness(jfo).compileAndCheck();
}
//if there were errors, fail
if (nerrors > 0) {
throw new AssertionError("Errors were found");
}
} finally {
fm.close();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -150,17 +150,17 @@ public class GenericConstructorAndDiamondTest {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
for (BoundKind boundKind : BoundKind.values()) {
for (ConstructorKind constructorKind : ConstructorKind.values()) {
for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
for (TypeArgArity arity : TypeArgArity.values()) {
for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
for (ArgumentKind argKind : ArgumentKind.values()) {
new GenericConstructorAndDiamondTest(boundKind, constructorKind,
declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (BoundKind boundKind : BoundKind.values()) {
for (ConstructorKind constructorKind : ConstructorKind.values()) {
for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
for (TypeArgArity arity : TypeArgArity.values()) {
for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
for (ArgumentKind argKind : ArgumentKind.values()) {
new GenericConstructorAndDiamondTest(boundKind, constructorKind,
declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -78,26 +78,27 @@ public class ParserTest {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (TypeQualifierArity arity : TypeQualifierArity.values()) {
for (TypeArgumentKind tak1 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.ONE) {
new ParserTest(arity, tak1).run(comp, fm);
continue;
}
for (TypeArgumentKind tak2 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.TWO) {
new ParserTest(arity, tak1, tak2).run(comp, fm);
for (TypeQualifierArity arity : TypeQualifierArity.values()) {
for (TypeArgumentKind tak1 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.ONE) {
new ParserTest(arity, tak1).run(comp, fm);
continue;
}
for (TypeArgumentKind tak3 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.THREE) {
new ParserTest(arity, tak1, tak2, tak3).run(comp, fm);
for (TypeArgumentKind tak2 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.TWO) {
new ParserTest(arity, tak1, tak2).run(comp, fm);
continue;
}
for (TypeArgumentKind tak4 : TypeArgumentKind.values()) {
new ParserTest(arity, tak1, tak2, tak3, tak4).run(comp, fm);
for (TypeArgumentKind tak3 : TypeArgumentKind.values()) {
if (arity == TypeQualifierArity.THREE) {
new ParserTest(arity, tak1, tak2, tak3).run(comp, fm);
continue;
}
for (TypeArgumentKind tak4 : TypeArgumentKind.values()) {
new ParserTest(arity, tak1, tak2, tak3, tak4).run(comp, fm);
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -86,18 +86,19 @@ public class T7086601b {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (TypeKind a1 : TypeKind.values()) {
for (TypeKind a2 : TypeKind.values()) {
for (TypeKind a3 : TypeKind.values()) {
for (MethodCallKind mck : MethodCallKind.values()) {
new T7086601b(a1, a2, a3, mck).run(comp, fm);
for (TypeKind a1 : TypeKind.values()) {
for (TypeKind a2 : TypeKind.values()) {
for (TypeKind a3 : TypeKind.values()) {
for (MethodCallKind mck : MethodCallKind.values()) {
new T7086601b(a1, a2, a3, mck).run(comp, fm);
}
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
TypeKind a1;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -105,18 +105,19 @@ public class BadLambdaExpr {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (ParameterListKind plk : ParameterListKind.values()) {
for (ParameterKind pk : ParameterKind.values()) {
for (ArrowKind ak : ArrowKind.values()) {
for (ExprKind ek : ExprKind.values()) {
new BadLambdaExpr(plk, pk, ak, ek).run(comp, fm);
for (ParameterListKind plk : ParameterListKind.values()) {
for (ParameterKind pk : ParameterKind.values()) {
for (ArrowKind ak : ArrowKind.values()) {
for (ExprKind ek : ExprKind.values()) {
new BadLambdaExpr(plk, pk, ak, ek).run(comp, fm);
}
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
ParameterListKind plk;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -114,22 +114,23 @@ public class TestSelfRef {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (EnclosingKind ek : EnclosingKind.values()) {
for (SiteKind sk : SiteKind.values()) {
if (sk == SiteKind.STATIC_INIT && ek == EnclosingKind.MEMBER_INNER)
continue;
for (InnerKind ik : InnerKind.values()) {
if (ik != InnerKind.NONE && sk == SiteKind.NONE)
break;
for (RefKind rk : RefKind.values()) {
new TestSelfRef(ek, sk, ik, rk).run(comp, fm);
for (EnclosingKind ek : EnclosingKind.values()) {
for (SiteKind sk : SiteKind.values()) {
if (sk == SiteKind.STATIC_INIT && ek == EnclosingKind.MEMBER_INNER)
continue;
for (InnerKind ik : InnerKind.values()) {
if (ik != InnerKind.NONE && sk == SiteKind.NONE)
break;
for (RefKind rk : RefKind.values()) {
new TestSelfRef(ek, sk, ik, rk).run(comp, fm);
}
}
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
EnclosingKind ek;

View file

@ -185,14 +185,15 @@ public class IntersectionTargetTypeTest {
public static void main(String... args) throws Exception {
//create default shared JavaCompiler - reused across multiple compilations
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
for (CastInfo cInfo : allCastInfo()) {
for (ExpressionKind ek : ExpressionKind.values()) {
new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm);
for (CastInfo cInfo : allCastInfo()) {
for (ExpressionKind ek : ExpressionKind.values()) {
new IntersectionTargetTypeTest(cInfo, ek).run(comp, fm);
}
}
System.out.println("Total check executed: " + checkCount);
}
System.out.println("Total check executed: " + checkCount);
}
static List<CastInfo> allCastInfo() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -250,13 +250,17 @@ public class SamConversionComboTest {
}
public static void main(String[] args) throws Exception {
for(Context ct : Context.values()) {
for (FInterface fi : FInterface.values()) {
for (MethodDef md: MethodDef.values()) {
new SamConversionComboTest(fi, ct, md).test();
try {
for(Context ct : Context.values()) {
for (FInterface fi : FInterface.values()) {
for (MethodDef md: MethodDef.values()) {
new SamConversionComboTest(fi, ct, md).test();
}
}
}
System.out.println("total tests: " + count);
} finally {
fm.close();
}
System.out.println("total tests: " + count);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ import org.openjdk.tests.shapegen.*;
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.util.Pair;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.ArrayList;
@ -41,6 +42,7 @@ import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
@ -70,12 +72,19 @@ public class FDTest {
fm = comp.getStandardFileManager(null, null, null);
}
@AfterSuite
static void teardown() throws IOException {
fm.close();
}
public static void main(String[] args) throws Exception {
init();
for (Pair<TestKind,Hierarchy> fdtest : generateCases()) {
runTest(fdtest.fst, fdtest.snd, comp, fm);
}
teardown();
}
@Test(dataProvider = "fdCases")

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -193,27 +193,30 @@ public class NativeHeaderTest {
void run() throws Exception {
javac = JavacTool.create();
fm = javac.getStandardFileManager(null, null, null);
for (RunKind rk: RunKind.values()) {
for (GenKind gk: GenKind.values()) {
for (Method m: getClass().getDeclaredMethods()) {
Annotation a = m.getAnnotation(Test.class);
if (a != null) {
init(rk, gk, m.getName());
try {
m.invoke(this, new Object[] { rk, gk });
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
throw (cause instanceof Exception) ? ((Exception) cause) : e;
try {
for (RunKind rk: RunKind.values()) {
for (GenKind gk: GenKind.values()) {
for (Method m: getClass().getDeclaredMethods()) {
Annotation a = m.getAnnotation(Test.class);
if (a != null) {
init(rk, gk, m.getName());
try {
m.invoke(this, new Object[] { rk, gk });
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
throw (cause instanceof Exception) ? ((Exception) cause) : e;
}
System.err.println();
}
System.err.println();
}
}
}
System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
if (errorCount > 0)
throw new Exception(errorCount + " errors found");
} finally {
fm.close();
}
System.err.println(testCount + " tests" + ((errorCount == 0) ? "" : ", " + errorCount + " errors"));
if (errorCount > 0)
throw new Exception(errorCount + " errors found");
}
/**

View file

@ -45,6 +45,7 @@ import java.util.regex.Pattern;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
@ -73,27 +74,31 @@ public class XPreferTest {
}
final static JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
final static StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
final static File OUTPUT_DIR = new File("out");
public static void main(String... args) throws Exception {
try {
// Initialize test-directories
OUTPUT_DIR.mkdir();
for (Dir dir : Dir.values())
dir.file.mkdir();
// Initialize test-directories
OUTPUT_DIR.mkdir();
for (Dir dir : Dir.values())
dir.file.mkdir();
int testCaseCounter = 0;
int testCaseCounter = 0;
for (List<Dir> dirSubset : SubseqIter.subseqsOf(Dir.values())) {
for (List<Dir> dirSubset : SubseqIter.subseqsOf(Dir.values())) {
if (dirSubset.isEmpty())
continue;
if (dirSubset.isEmpty())
continue;
for (ImplicitOption policy : ImplicitOption.values()) {
for (List<Dir> dirOrder : PermutationIterator.permutationsOf(dirSubset)) {
new TestCase(dirOrder, policy, testCaseCounter++).run();
for (ImplicitOption policy : ImplicitOption.values()) {
for (List<Dir> dirOrder : PermutationIterator.permutationsOf(dirSubset)) {
new TestCase(dirOrder, policy, testCaseCounter++).run();
}
}
}
} finally {
fm.close();
}
}
@ -234,8 +239,8 @@ public class XPreferTest {
if(dir == Dir.SOURCE_PATH)
return src;
// ...otherwise compile into a ".class".
CompilationTask task = comp.getTask(null, null, null, null, null,
comp.getStandardFileManager(null, null, null).getJavaFileObjects(src));
CompilationTask task = comp.getTask(null, fm, null, null, null,
fm.getJavaFileObjects(src));
File dest = new File(dir.file, classId + ".class");
if(!task.call() || !dest.exists())
throw new RuntimeException("Compilation failure.");

Some files were not shown because too many files have changed in this diff Show more