--- a/langtools/make/Makefile Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/make/Makefile Fri Jan 22 09:34:46 2010 -0800
@@ -144,8 +144,8 @@
ifdef ALT_JDK_TOPDIR
ANT_OPTIONS += -Dimport.jdk=$(ALT_JDK_TOPDIR)
else
- ifdef ALT_JDK_IMPORT_DIR
- ANT_OPTIONS += -Dimport.jdk=$(ALT_JDK_IMPORT_DIR)
+ ifdef ALT_JDK_IMPORT_PATH
+ ANT_OPTIONS += -Dimport.jdk=$(ALT_JDK_IMPORT_PATH)
endif
endif
endif
--- a/langtools/make/build.xml Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/make/build.xml Fri Jan 22 09:34:46 2010 -0800
@@ -107,14 +107,21 @@
ignoresystemclasses="true"
classpath="${import.jdk}/jre/lib/rt.jar" classname="java.nio.file.Path"/>
+ <!-- Set the default value of the sourcepath used for javac. -->
<condition property="javac.sourcepath" value="${build.genstubs.dir}" else="">
<isset property="import.jdk.src.dir"/>
</condition>
+ <!-- Set the default value of the classpath used for javac. -->
<property name="javac.classpath" value=""/>
+ <!-- Set the default bootclasspath option used for javac.
+ Note that different variants of the option are used, meaning we can't just
+ define the value for the option.
+ Note the explicit use of the standard property ${path.separator} in the following.
+ This is because Ant is not clever enough to handle direct use of : or ; -->
<condition property="javac.bootclasspath.opt"
- value="-Xbootclasspath:${build.classes.dir}:${import.jdk.jar}"
+ value="-Xbootclasspath:${build.classes.dir}${path.separator}${import.jdk.jar}"
else="-Xbootclasspath/p:${build.classes.dir}">
<isset property="import.jdk.jar"/>
</condition>
--- a/langtools/make/tools/CompileProperties/CompileProperties.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/make/tools/CompileProperties/CompileProperties.java Fri Jan 22 09:34:46 2010 -0800
@@ -101,7 +101,7 @@
boolean ok = true;
/* Original usage */
if (args.length == 2 && args[0].charAt(0) != '-' ) {
- ok = createFile(args[0], args[1], "ListResourceBundle");
+ ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
} else if (args.length == 3) {
ok = createFile(args[0], args[1], args[2]);
} else if (args.length == 0) {
@@ -285,9 +285,9 @@
log.info(" java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
log.info("");
log.info("Example:");
- log.info(" java CompileProperties -compile test.properties test.java ListResourceBundle");
+ log.info(" java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
log.info(" java CompileProperties -optionsfile option_file");
- log.info("option_file contains: -compile test.properties test.java ListResourceBundle");
+ log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
}
private static String escape(String theString) {
@@ -379,7 +379,6 @@
private static final String FORMAT =
"{0}" +
- "import java.util.ListResourceBundle;\n\n" +
"public final class {1} extends {2} '{'\n" +
" protected final Object[][] getContents() '{'\n" +
" return new Object[][] '{'\n" +
--- a/langtools/make/tools/CompileProperties/CompilePropertiesTask.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/make/tools/CompileProperties/CompilePropertiesTask.java Fri Jan 22 09:34:46 2010 -0800
@@ -45,6 +45,7 @@
this.superclass = superclass;
}
+ @Override
public void execute() {
CompileProperties.Log log = new CompileProperties.Log() {
public void error(String msg, Exception e) {
@@ -84,7 +85,7 @@
log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
CompileProperties cp = new CompileProperties();
cp.setLog(log);
- boolean ok = cp.run((String[])mainOpts.toArray(new String[mainOpts.size()]));
+ boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
if (!ok)
throw new BuildException("CompileProperties failed.");
}
--- a/langtools/make/tools/GenStubs/GenStubs.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/make/tools/GenStubs/GenStubs.java Fri Jan 22 09:34:46 2010 -0800
@@ -22,6 +22,7 @@
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
+
import java.io.*;
import java.util.*;
import javax.tools.JavaFileObject;
@@ -41,15 +42,22 @@
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.TypeTags;
import com.sun.tools.javac.tree.JCTree;
-import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
+import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
+import com.sun.tools.javac.tree.JCTree.JCIdent;
+import com.sun.tools.javac.tree.JCTree.JCImport;
import com.sun.tools.javac.tree.JCTree.JCLiteral;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
-import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.Pretty;
+import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.tree.TreeTranslator;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.ListBuffer;
+import com.sun.tools.javac.util.Name;
+import javax.tools.JavaFileManager;
/**
* Generate stub source files by removing implementation details from input files.
@@ -161,6 +169,7 @@
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
CompilationUnitTree tree2 = new StubMaker().translate(tree);
+ CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
@@ -168,7 +177,7 @@
// System.err.println("Writing " + className + " to " + fo.getName());
Writer out = fo.openWriter();
try {
- new Pretty(out, true).printExpr((JCTree) tree2);
+ new Pretty(out, true).printExpr((JCTree) tree3);
} finally {
out.close();
}
@@ -272,6 +281,53 @@
}
}
+ class ImportCleaner extends TreeScanner {
+ private Set<Name> names = new HashSet<Name>();
+ private TreeMaker m;
+
+ ImportCleaner(JavaFileManager fm) {
+ // ImportCleaner itself doesn't require a filemanager, but instantiating
+ // a TreeMaker does, indirectly (via ClassReader, sigh)
+ Context c = new Context();
+ c.put(JavaFileManager.class, fm);
+ m = TreeMaker.instance(c);
+ }
+
+ CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
+ JCCompilationUnit tree = (JCCompilationUnit) t;
+ tree.accept(this);
+ ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
+ for (JCTree def: tree.defs) {
+ if (def.getTag() == JCTree.IMPORT) {
+ JCImport imp = (JCImport) def;
+ if (imp.qualid.getTag() == JCTree.SELECT) {
+ JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
+ if (!qualid.name.toString().equals("*")
+ && !names.contains(qualid.name)) {
+ continue;
+ }
+ }
+ }
+ defs.add(def);
+ }
+ return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
+ }
+
+ @Override
+ public void visitImport(JCImport tree) { } // ignore names found in imports
+
+ @Override
+ public void visitIdent(JCIdent tree) {
+ names.add(tree.name);
+ }
+
+ @Override
+ public void visitSelect(JCFieldAccess tree) {
+ super.visitSelect(tree);
+ names.add(tree.name);
+ }
+ }
+
//---------- Ant Invocation ------------------------------------------------
public static class Ant extends MatchingTask {
--- a/langtools/src/share/bin/launcher.sh-template Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/bin/launcher.sh-template Fri Jan 22 09:34:46 2010 -0800
@@ -38,7 +38,7 @@
# dependent jar files for additional dependencies.
if [ "$LANGTOOLS_USE_BOOTCLASSPATH" != "no" ]; then
- cp=`unzip -c $mylib/#PROGRAM#.jar META-INF/MANIFEST.MF |
+ cp=`unzip -c "$mylib/#PROGRAM#.jar" META-INF/MANIFEST.MF |
grep "Class-Path:" |
sed -e 's|Class-Path: *||' -e 's|\([a-z]*\.jar\) *|'"$mylib"'/\1:|g'`
bcp="$mylib/#PROGRAM#.jar":$cp
--- a/langtools/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Fri Jan 22 09:34:46 2010 -0800
@@ -309,7 +309,7 @@
}
protected static String toBinaryName(String relativePath, String sep) {
- return removeExtension(relativePath).replaceAll(sep, ".");
+ return removeExtension(relativePath).replace(sep, ".");
}
protected static String removeExtension(String fileName) {
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jan 22 09:34:46 2010 -0800
@@ -2613,12 +2613,12 @@
body = toP(F.at(identPos).AnonymousClassDef(mods1, defs));
}
if (args.isEmpty() && body == null)
- createPos = Position.NOPOS;
- JCIdent ident = F.at(Position.NOPOS).Ident(enumName);
+ createPos = identPos;
+ JCIdent ident = F.at(identPos).Ident(enumName);
JCNewClass create = F.at(createPos).NewClass(null, typeArgs, ident, args, body);
- if (createPos != Position.NOPOS)
+ if (createPos != identPos)
storeEnd(create, S.prevEndPos());
- ident = F.at(Position.NOPOS).Ident(enumName);
+ ident = F.at(identPos).Ident(enumName);
JCTree result = toP(F.at(pos).VarDef(mods, name, ident, create));
attach(result, dc);
return result;
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/Keywords.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/Keywords.java Fri Jan 22 09:34:46 2010 -0800
@@ -51,12 +51,10 @@
return instance;
}
- private final Log log;
private final Names names;
protected Keywords(Context context) {
context.put(keywordsKey, this);
- log = Log.instance(context);
names = Names.instance(context);
for (Token t : Token.values()) {
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Jan 22 09:34:46 2010 -0800
@@ -704,7 +704,7 @@
{0}; overridden method is a bridge method
compiler.warn.pkg-info.already.seen=\
- [package-info] a package-info.java file has already been seen for package {0}
+ a package-info.java file has already been seen for package {0}
compiler.warn.path.element.not.found=\
[path] bad path element "{0}": no such file or directory
compiler.warn.possible.fall-through.into.case=\
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/Pretty.java Fri Jan 22 09:34:46 2010 -0800
@@ -468,6 +468,10 @@
print(" throws ");
printExprs(tree.thrown);
}
+ if (tree.defaultValue != null) {
+ print(" default ");
+ printExpr(tree.defaultValue);
+ }
if (tree.body != null) {
print(" ");
printStat(tree.body);
@@ -1148,20 +1152,7 @@
// Prints the inner element type of a nested array
private void printBaseElementType(JCTree tree) throws IOException {
- switch (tree.getTag()) {
- case JCTree.TYPEARRAY:
- printBaseElementType(((JCArrayTypeTree)tree).elemtype);
- return;
- case JCTree.WILDCARD:
- printBaseElementType(((JCWildcard)tree).inner);
- return;
- case JCTree.ANNOTATED_TYPE:
- printBaseElementType(((JCAnnotatedType)tree).underlyingType);
- return;
- default:
- printExpr(tree);
- return;
- }
+ printExpr(TreeInfo.innermostType(tree));
}
// prints the brackets of a nested array in reverse order
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Jan 22 09:34:46 2010 -0800
@@ -891,4 +891,17 @@
throw new AssertionError("Unexpected type tree: " + tree);
}
}
+
+ public static JCTree innermostType(JCTree type) {
+ switch (type.getTag()) {
+ case JCTree.TYPEARRAY:
+ return innermostType(((JCArrayTypeTree)type).elemtype);
+ case JCTree.WILDCARD:
+ return innermostType(((JCWildcard)type).inner);
+ case JCTree.ANNOTATED_TYPE:
+ return innermostType(((JCAnnotatedType)type).underlyingType);
+ default:
+ return type;
+ }
+ }
}
--- a/langtools/src/share/classes/com/sun/tools/javac/util/LayoutCharacters.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/LayoutCharacters.java Fri Jan 22 09:34:46 2010 -0800
@@ -49,7 +49,7 @@
/** Tabulator character.
*/
- final static byte TAB = 0x8;
+ final static byte TAB = 0x9;
/** Line feed character.
*/
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Log.java Fri Jan 22 09:34:46 2010 -0800
@@ -145,7 +145,10 @@
private int getIntOption(Options options, String optionName, int defaultValue) {
String s = options.get(optionName);
try {
- if (s != null) return Integer.parseInt(s);
+ if (s != null) {
+ int n = Integer.parseInt(s);
+ return (n <= 0 ? Integer.MAX_VALUE : n);
+ }
} catch (NumberFormatException e) {
// silently ignore ill-formed numbers
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6326754.java Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6326754
+ * @summary Compiler will fail to handle -Xmaxerrs with -ve numbers
+ *
+ * @compile/fail/ref=T6326754.out -XDrawDiagnostics -Xmaxerrs -1 T6326754.java
+ * @compile/fail/ref=T6326754.out -XDrawDiagnostics -Xmaxerrs 0 T6326754.java
+ * @compile/fail/ref=T6326754.out -XDrawDiagnostics -Xmaxerrs 10 T6326754.java
+ * @compile/fail/ref=T6326754.out -XDrawDiagnostics T6326754.java
+ */
+class TestConstructor<T,K>{
+ T t;
+ K k;
+ public TestConstructor(T t,K k){
+ this.t =t;
+ }
+ public TestConstructor(K k){
+ this.k = k;
+ this.t = null;
+ }
+ public TestConstructor(T t){
+ this.t=t;
+ this.k=null;
+ }
+ public void setT(T t){
+ this.t=t;
+ this.k=null;
+ }
+ public void setT(K k){
+ this.k = k;
+ this.t = null;
+ }
+ public void setT(T t,K k){
+ this.t = t;
+ this.k = k;
+ }
+}
+class TestC<T>{
+ T t;
+ public <T>void setT(T t){
+ this.t = t;
+ }
+}
+public class T6326754{
+ public static void main(String... arg){
+ TestC tC =new TestC();
+ tC.setT();
+ TestConstructor tc = new TestConstructor("saaa");
+ tc.setT("sasa");
+ TestC<Integer> tC1 = new TestC();
+ tC1.setT(545);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6326754.out Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,7 @@
+T6326754.java:44:12: compiler.err.name.clash.same.erasure: TestConstructor(T), TestConstructor(K)
+T6326754.java:52:17: compiler.err.name.clash.same.erasure: setT(K), setT(T)
+T6326754.java:64:18: compiler.err.prob.found.req: (compiler.misc.incompatible.types), T, T
+T6326754.java:70:11: compiler.err.cant.apply.symbol: kindname.method, setT, java.lang.Object, compiler.misc.no.args, kindname.class, TestC<T>, null
+- compiler.note.unchecked.filename: T6326754.java
+- compiler.note.unchecked.recompile
+4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6472751.java Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006-2010 Sun Microsystems, Inc. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6472751
+ * @summary SourcePositions.getStartPos returns incorrect value for enum constants
+ * @author Peter Ahe
+ */
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.SourcePositions;
+import com.sun.source.util.TreeScanner;
+import com.sun.source.util.Trees;
+import com.sun.tools.javac.util.List;
+import java.io.IOException;
+import java.net.URI;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+
+public class T6472751 {
+ static class MyFileObject extends SimpleJavaFileObject {
+ public MyFileObject() {
+ super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ }
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return "public enum Test { ABC, DEF; }";
+ }
+ }
+ static Trees trees;
+ static SourcePositions positions;
+ public static void main(String[] args) throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ JavacTask task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
+ trees = Trees.instance(task);
+ positions = trees.getSourcePositions();
+ Iterable<? extends CompilationUnitTree> asts = task.parse();
+ for (CompilationUnitTree ast : asts) {
+ new MyVisitor().scan(ast, null);
+ }
+ }
+
+ static class MyVisitor extends TreeScanner<Void,Void> {
+ @Override
+ public Void scan(Tree node, Void ignored) {
+ if (node == null)
+ return null;
+ Kind k = node.getKind();
+ long pos = positions.getStartPosition(null,node);
+ System.out.format("%s: %s%n", k, pos);
+ if (k != Kind.MODIFIERS && pos < 0)
+ throw new Error("unexpected position found");
+ return super.scan(node, ignored);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6567414.java Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,11 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 6567414
+ * @summary javac compiler reports no source file or line on enum constant declaration error
+ * @compile/fail/ref=T6567414.out -XDrawDiagnostics T6567414.java
+ */
+enum Test {
+ FOO;
+ Test() throws Exception {}
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6567414.out Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,2 @@
+T6567414.java:8:3: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
+1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6665791.java Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6665791
+ * @summary com.sun.source.tree.MethodTree.toString() does not output default values
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import com.sun.source.tree.ClassTree;
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.TreeScanner;
+import java.io.FileWriter;
+
+public class T6665791 {
+ static String test = "public @interface Annotation { boolean booleanProperty() default false; }";
+ static File test_java = new File("Test.java");
+
+ public static void main(String[] args) throws Exception {
+ 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);
+
+ 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");
+ }
+ }
+
+ static void write(File file, String body) throws IOException {
+ FileWriter out = new FileWriter(file);
+ out.write(body);
+ out.close();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/T6855236.java Fri Jan 22 09:34:46 2010 -0800
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc. 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6855236
+ * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator
+ * @compile T6855236.java
+ * @compile -processor T6855236 -proc:only T6855236.java
+ */
+
+import java.util.*;
+
+import javax.annotation.processing.*;
+import javax.lang.model.*;
+import javax.lang.model.element.*;
+
+import com.sun.source.tree.*;
+import com.sun.source.util.*;
+
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+@SupportedAnnotationTypes("*")
+public class T6855236 extends AbstractProcessor {
+
+ private Trees trees;
+
+ @Override
+ public void init(ProcessingEnvironment pe) {
+ super.init(pe);
+ trees = Trees.instance(pe);
+ }
+
+ @Override
+ public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) {
+ // Scanner class to scan through various component elements
+ CodeVisitor visitor = new CodeVisitor();
+
+ for (Element e : roundEnvironment.getRootElements()) {
+ TreePath tp = trees.getPath(e);
+ visitor.scan(tp, trees);
+ }
+
+ return true;
+ }
+
+ class CodeVisitor extends TreePathScanner<Object, Trees> {
+
+ @Override
+ public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
+ System.out.print("current path: ");
+ for (Tree t : getCurrentPath()) {
+ System.out.print('/');
+ System.out.print(t);
+ }
+ System.out.println();
+ System.out.println("parent path: " + getCurrentPath().getParentPath());
+ System.out.println("method select: " + node.getMethodSelect().toString());
+ for (ExpressionTree arg : node.getArguments()) {
+ System.out.println("argument: " + arg.toString());
+ }
+ return super.visitMethodInvocation(node, p);
+ }
+
+ @Override
+ public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
+ ExpressionTree t = node.getExpression();
+ System.out.println("expression statement: " + t.toString());
+ return super.visitExpressionStatement(node, p);
+ }
+
+ }
+
+}
+
+
--- a/langtools/test/tools/javac/nio/compileTest/CompileTest.java Thu Jan 21 11:12:47 2010 -0800
+++ b/langtools/test/tools/javac/nio/compileTest/CompileTest.java Fri Jan 22 09:34:46 2010 -0800
@@ -23,7 +23,9 @@
/**
* @test
- * @compile HelloPathWorld.java
+ * @bug 6906175 6915476 6915497
+ * @summary Path-based JavaFileManager
+ * @compile -g HelloPathWorld.java
* @run main CompileTest
*/
@@ -92,7 +94,8 @@
options.addAll(Arrays.asList(opts));
options.addAll(Arrays.asList(
"-verbose", "-XDverboseCompilePolicy",
- "-d", classes.toString()
+ "-d", classes.toString(),
+ "-g"
));
Iterable<? extends JavaFileObject> compilationUnits =
fm.getJavaFileObjects(testSrcDir.resolve(className + ".java"));
@@ -109,6 +112,8 @@
File expect = new File("classes." + count + "/" + className + ".class");
if (!expect.exists())
throw new Exception("expected file not found: " + expect);
+ // Note that we explicitly specify -g for compiling both the actual class and the expected class.
+ // This isolates the expected class from javac options that might be given to jtreg.
long expectedSize = new File(testClassesDir.toString(), className + ".class").length();
long actualSize = expect.length();
if (expectedSize != actualSize)