mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-04 07:28:22 +00:00
Merge
This commit is contained in:
commit
c7ec9afee6
@ -76,6 +76,7 @@ import static javax.tools.StandardLocation.*;
|
||||
*/
|
||||
public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager {
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
public static char[] toArray(CharBuffer buffer) {
|
||||
if (buffer.hasArray())
|
||||
return ((CharBuffer)buffer.compact().flip()).array();
|
||||
@ -129,6 +130,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
if (register)
|
||||
context.put(JavaFileManager.class, this);
|
||||
setContext(context);
|
||||
if (System.getProperty("show.fm.open.close") != null)
|
||||
System.err.println("JavacFileManager.open " + this.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -570,6 +573,8 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
||||
*/
|
||||
@DefinedBy(Api.COMPILER)
|
||||
public void close() {
|
||||
if (System.getProperty("show.fm.open.close") != null)
|
||||
System.err.println("JavacFileManager.close " + this.hashCode());
|
||||
for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) {
|
||||
Archive a = i.next();
|
||||
i.remove();
|
||||
|
||||
@ -517,6 +517,13 @@ implements CRTFlags {
|
||||
result = sr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeUnion(JCTypeUnion tree) {
|
||||
SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
|
||||
sr.mergeWith(csp(tree.alternatives));
|
||||
result = sr;
|
||||
}
|
||||
|
||||
public void visitWildcard(JCWildcard tree) {
|
||||
result = null;
|
||||
}
|
||||
|
||||
@ -235,6 +235,7 @@ public abstract class BaseFileManager implements JavaFileManager {
|
||||
return encName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
public CharBuffer decode(ByteBuffer inbuf, boolean ignoreEncodingErrors) {
|
||||
String encodingName = getEncodingName();
|
||||
CharsetDecoder decoder;
|
||||
@ -315,6 +316,7 @@ public abstract class BaseFileManager implements JavaFileManager {
|
||||
* @return a byte buffer containing the contents of the stream
|
||||
* @throws IOException if an error occurred while reading the stream
|
||||
*/
|
||||
@SuppressWarnings("cast")
|
||||
public ByteBuffer makeByteBuffer(InputStream in)
|
||||
throws IOException {
|
||||
int limit = in.available();
|
||||
@ -343,6 +345,7 @@ public abstract class BaseFileManager implements JavaFileManager {
|
||||
/**
|
||||
* A single-element cache of direct byte buffers.
|
||||
*/
|
||||
@SuppressWarnings("cast")
|
||||
private static class ByteBufferCache {
|
||||
private ByteBuffer cached;
|
||||
ByteBuffer get(int capacity) {
|
||||
|
||||
@ -88,6 +88,9 @@ public class Start extends ToolOption.Helper {
|
||||
*/
|
||||
private boolean apiMode;
|
||||
|
||||
private JavaFileManager fileManager;
|
||||
private boolean closeFileManagerOnExit;
|
||||
|
||||
Start(String programName,
|
||||
PrintWriter errWriter,
|
||||
PrintWriter warnWriter,
|
||||
@ -239,6 +242,12 @@ public class Start extends ToolOption.Helper {
|
||||
messager.error(Messager.NOPOS, "main.fatal.exception");
|
||||
failed = true;
|
||||
} finally {
|
||||
if (fileManager != null && closeFileManagerOnExit) {
|
||||
try {
|
||||
fileManager.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
messager.exitNotice();
|
||||
messager.flush();
|
||||
}
|
||||
@ -270,7 +279,8 @@ public class Start extends ToolOption.Helper {
|
||||
}
|
||||
|
||||
|
||||
JavaFileManager fileManager = context.get(JavaFileManager.class);
|
||||
fileManager = context.get(JavaFileManager.class);
|
||||
|
||||
setDocletInvoker(docletClass, fileManager, argv);
|
||||
|
||||
compOpts = Options.instance(context);
|
||||
@ -333,6 +343,7 @@ public class Start extends ToolOption.Helper {
|
||||
if (fileManager == null) {
|
||||
JavacFileManager.preRegister(context);
|
||||
fileManager = context.get(JavaFileManager.class);
|
||||
closeFileManagerOnExit = true;
|
||||
}
|
||||
if (fileManager instanceof BaseFileManager) {
|
||||
((BaseFileManager) fileManager).handleOptions(fileManagerOpts);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, 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
|
||||
@ -106,6 +106,8 @@ public class T6406133 extends ToolTester {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new T6406133().test();
|
||||
try (T6406133 t = new T6406133()) {
|
||||
t.test();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
* @run main T6410643
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.tools.JavaFileObject;
|
||||
import static java.util.Collections.singleton;
|
||||
|
||||
@ -68,7 +69,10 @@ public class T6410643 extends ToolTester {
|
||||
testGetTask(s, s, f);
|
||||
System.err.println("Test result: PASSED");
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6410643().test(args);
|
||||
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6410643 t = new T6410643()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -54,6 +54,8 @@ public class T6411310 extends ToolTester {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws IOException {
|
||||
new T6411310().test(args);
|
||||
try (T6411310 t = new T6411310()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -82,7 +82,10 @@ public class T6411333 extends ToolTester {
|
||||
testRelativeUri("util/List.java", false);
|
||||
testRelativeUri("/util/List.java", true);
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6411333().test(args);
|
||||
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6411333 t = new T6411333()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -31,6 +31,7 @@
|
||||
* @run main T6412656
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@ -52,8 +53,10 @@ public class T6412656 extends ToolTester {
|
||||
System.out.println("OK");
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
new T6412656().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6412656 t = new T6412656()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes("*")
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -32,6 +32,7 @@
|
||||
* @run main T6415780
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import static javax.tools.StandardLocation.CLASS_PATH;
|
||||
|
||||
public class T6415780 extends ToolTester {
|
||||
@ -39,8 +40,9 @@ public class T6415780 extends ToolTester {
|
||||
System.out.println(fm.getClassLoader(CLASS_PATH).toString()); // null-check
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
T6415780 tester = new T6415780();
|
||||
tester.test();
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6415780 tester = new T6415780()) {
|
||||
tester.test();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -32,6 +32,7 @@
|
||||
* @run main T6418694
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
public class T6418694 extends ToolTester {
|
||||
@ -52,7 +53,9 @@ public class T6418694 extends ToolTester {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6418694().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6418694 t = new T6418694()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -101,8 +102,10 @@ public class T6421111 extends ToolTester {
|
||||
return SourceVersion.latest();
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6421111().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6421111 t = new T6421111()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
public static AssertionError error(String format, Object... args) {
|
||||
return new AssertionError(String.format(format, args));
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -32,6 +32,7 @@
|
||||
* @run main T6421756
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
public class T6421756 extends ToolTester {
|
||||
@ -44,7 +45,9 @@ public class T6421756 extends ToolTester {
|
||||
System.out.println("OK: got expected error " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6421756().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6421756 t = new T6421756()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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,7 +46,9 @@ public class T6422215 extends ToolTester {
|
||||
System.out.println("OK: caught expected exception: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6422215().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6422215 t = new T6422215()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class T6422327 extends ToolTester {
|
||||
void test(String... args) {
|
||||
@ -43,7 +44,9 @@ public class T6422327 extends ToolTester {
|
||||
System.err.println("OK, got expected exception: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6422327().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6422327 t = new T6422327()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -32,6 +32,7 @@
|
||||
* @run main T6423003
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class T6423003 extends ToolTester {
|
||||
@ -44,7 +45,9 @@ public class T6423003 extends ToolTester {
|
||||
}
|
||||
throw new AssertionError("Expected IllegalStateException not thrown");
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6423003().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6423003 t = new T6423003()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -67,6 +67,8 @@ public class T6431257 extends ToolTester {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws IOException {
|
||||
new T6431257().test(args);
|
||||
try (T6431257 t = new T6431257()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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,6 +51,8 @@ public class T6437349 extends ToolTester {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static void main(String... args) throws IOException {
|
||||
new T6437349().test(args);
|
||||
try (T6437349 t = new T6437349()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -86,6 +86,8 @@ public class T6437999 extends ToolTester {
|
||||
throw new AssertionError("Error in UTF-8 mode");
|
||||
}
|
||||
public static void main(String... args) throws IOException {
|
||||
new T6437999().test(args);
|
||||
try (T6437999 t = new T6437999()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -50,6 +50,8 @@ public class T6440333 extends ToolTester {
|
||||
}
|
||||
}
|
||||
public static void main(String... args) throws IOException {
|
||||
new T6440333().test(args);
|
||||
try (T6440333 t = new T6440333()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -66,6 +66,8 @@ public class T6440528 extends ToolTester {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new T6440528().test(args);
|
||||
try (T6440528 t = new T6440528()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, 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
|
||||
@ -88,8 +88,10 @@ public class T6468404 extends ToolTester {
|
||||
if (!task.call())
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static void main(String... args) {
|
||||
new T6468404().test(args);
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6468404 t = new T6468404()) {
|
||||
t.test(args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, 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
|
||||
@ -106,6 +106,8 @@ public class T6731573 extends ToolTester {
|
||||
}
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new T6731573().test();
|
||||
try (T6731573 t = new T6731573()) {
|
||||
t.test();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, 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
|
||||
@ -31,6 +31,7 @@
|
||||
* @run main T6733837
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URI;
|
||||
@ -43,8 +44,10 @@ import com.sun.source.util.JavacTask;
|
||||
|
||||
public class T6733837 extends ToolTester {
|
||||
|
||||
public static void main(String... args) {
|
||||
new T6733837().exec();
|
||||
public static void main(String... args) throws IOException {
|
||||
try (T6733837 t = new T6733837()) {
|
||||
t.exec();
|
||||
}
|
||||
}
|
||||
|
||||
public void exec() {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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> {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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. */
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,7 +115,9 @@ public class TestJavacTaskScanner extends ToolTester {
|
||||
|
||||
public static void main(String... args) throws IOException {
|
||||
String srcdir = System.getProperty("test.src");
|
||||
new TestJavacTaskScanner(new File(srcdir, args[0])).run();
|
||||
try (TestJavacTaskScanner t = new TestJavacTaskScanner(new File(srcdir, args[0]))) {
|
||||
t.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void testGetAllMembers(TypeElement clazz) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,9 @@ import com.sun.tools.javac.api.JavacTaskImpl;
|
||||
*/
|
||||
public class TestResolveError extends ToolTester {
|
||||
public static void main(String... args) throws Exception {
|
||||
new TestResolveError().run();
|
||||
try (TestResolveError t = new TestResolveError()) {
|
||||
t.run();
|
||||
}
|
||||
}
|
||||
|
||||
void run() throws Exception {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user