Mon, 25 Jun 2012 21:39:16 -0700
Merge
src/share/classes/com/sun/tools/javac/parser/EndPosTable.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Jun 21 17:08:31 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Jun 25 21:39:16 2012 -0700 1.3 @@ -60,7 +60,7 @@ 1.4 import com.sun.tools.javac.comp.MemberEnter; 1.5 import com.sun.tools.javac.comp.Resolve; 1.6 import com.sun.tools.javac.model.JavacElements; 1.7 -import com.sun.tools.javac.parser.EndPosTable; 1.8 +import com.sun.tools.javac.tree.EndPosTable; 1.9 import com.sun.tools.javac.processing.JavacProcessingEnvironment; 1.10 import com.sun.tools.javac.tree.JCTree; 1.11 import com.sun.tools.javac.tree.JCTree.*; 1.12 @@ -240,10 +240,11 @@ 1.13 1.14 public String getDocComment(TreePath path) { 1.15 CompilationUnitTree t = path.getCompilationUnit(); 1.16 - if (t instanceof JCTree.JCCompilationUnit) { 1.17 + Tree leaf = path.getLeaf(); 1.18 + if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { 1.19 JCCompilationUnit cu = (JCCompilationUnit) t; 1.20 if (cu.docComments != null) { 1.21 - return cu.docComments.get(path.getLeaf()); 1.22 + return cu.docComments.getCommentText((JCTree) leaf); 1.23 } 1.24 } 1.25 return null;
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Thu Jun 21 17:08:31 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Mon Jun 25 21:39:16 2012 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -312,7 +312,7 @@ 2.11 tree.packge); 2.12 if (addEnv || (tree0.packageAnnotations.isEmpty() && 2.13 tree.docComments != null && 2.14 - tree.docComments.get(tree) != null)) { 2.15 + tree.docComments.hasComment(tree))) { 2.16 typeEnvs.put(tree.packge, topEnv); 2.17 } 2.18 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Jun 21 17:08:31 2012 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Jun 25 21:39:16 2012 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -40,7 +40,7 @@ 3.11 import com.sun.tools.javac.code.Type.*; 3.12 3.13 import com.sun.tools.javac.jvm.Target; 3.14 -import com.sun.tools.javac.parser.EndPosTable; 3.15 +import com.sun.tools.javac.tree.EndPosTable; 3.16 3.17 import static com.sun.tools.javac.code.Flags.*; 3.18 import static com.sun.tools.javac.code.Flags.BLOCK;
4.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Thu Jun 21 17:08:31 2012 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Mon Jun 25 21:39:16 2012 -0700 4.3 @@ -36,6 +36,7 @@ 4.4 import java.util.Arrays; 4.5 import java.util.Calendar; 4.6 import java.util.Collections; 4.7 +import java.util.LinkedHashMap; 4.8 import java.util.HashMap; 4.9 import java.util.HashSet; 4.10 import java.util.List; 4.11 @@ -284,7 +285,7 @@ 4.12 try { 4.13 checkIndex(); 4.14 if (allDirs == Collections.EMPTY_SET) { 4.15 - allDirs = new HashSet<RelativeDirectory>(directories.keySet()); 4.16 + allDirs = new java.util.LinkedHashSet<RelativeDirectory>(directories.keySet()); 4.17 } 4.18 4.19 return allDirs; 4.20 @@ -572,7 +573,7 @@ 4.21 4.22 // Add each of the files 4.23 if (entryCount > 0) { 4.24 - directories = new HashMap<RelativeDirectory, DirectoryEntry>(); 4.25 + directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>(); 4.26 ArrayList<Entry> entryList = new ArrayList<Entry>(); 4.27 int pos = 2; 4.28 for (int i = 0; i < entryCount; i++) { 4.29 @@ -867,7 +868,7 @@ 4.30 if (zipFile.lastModified() != fileStamp) { 4.31 ret = false; 4.32 } else { 4.33 - directories = new HashMap<RelativeDirectory, DirectoryEntry>(); 4.34 + directories = new LinkedHashMap<RelativeDirectory, DirectoryEntry>(); 4.35 int numDirs = raf.readInt(); 4.36 for (int nDirs = 0; nDirs < numDirs; nDirs++) { 4.37 int dirNameBytesLen = raf.readInt();
5.1 --- a/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Thu Jun 21 17:08:31 2012 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/CRTable.java Mon Jun 25 21:39:16 2012 -0700 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -31,7 +31,7 @@ 5.11 import com.sun.tools.javac.util.*; 5.12 import com.sun.tools.javac.util.List; 5.13 import com.sun.tools.javac.tree.JCTree.*; 5.14 -import com.sun.tools.javac.parser.EndPosTable; 5.15 +import com.sun.tools.javac.tree.EndPosTable; 5.16 5.17 /** This class contains the CharacterRangeTable for some method 5.18 * and the hashtable for mapping trees or lists of trees to their
6.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Jun 21 17:08:31 2012 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Jun 25 21:39:16 2012 -0700 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -37,7 +37,7 @@ 6.11 import com.sun.tools.javac.code.Type.*; 6.12 import com.sun.tools.javac.jvm.Code.*; 6.13 import com.sun.tools.javac.jvm.Items.*; 6.14 -import com.sun.tools.javac.parser.EndPosTable; 6.15 +import com.sun.tools.javac.tree.EndPosTable; 6.16 import com.sun.tools.javac.tree.JCTree.*; 6.17 6.18 import static com.sun.tools.javac.code.Flags.*;
7.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacElements.java Thu Jun 21 17:08:31 2012 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacElements.java Mon Jun 25 21:39:16 2012 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -28,11 +28,14 @@ 7.11 import java.lang.annotation.Annotation; 7.12 import java.lang.annotation.Inherited; 7.13 import java.util.Map; 7.14 + 7.15 import javax.lang.model.SourceVersion; 7.16 import javax.lang.model.element.*; 7.17 import javax.lang.model.type.DeclaredType; 7.18 import javax.lang.model.util.Elements; 7.19 import javax.tools.JavaFileObject; 7.20 +import static javax.lang.model.util.ElementFilter.methodsIn; 7.21 + 7.22 import com.sun.tools.javac.code.*; 7.23 import com.sun.tools.javac.code.Symbol.*; 7.24 import com.sun.tools.javac.code.TypeTags; 7.25 @@ -47,9 +50,7 @@ 7.26 import com.sun.tools.javac.tree.TreeScanner; 7.27 import com.sun.tools.javac.util.*; 7.28 import com.sun.tools.javac.util.Name; 7.29 - 7.30 import static com.sun.tools.javac.tree.JCTree.Tag.*; 7.31 -import static javax.lang.model.util.ElementFilter.methodsIn; 7.32 7.33 /** 7.34 * Utility methods for operating on program elements. 7.35 @@ -361,7 +362,7 @@ 7.36 JCCompilationUnit toplevel = treeTop.snd; 7.37 if (toplevel.docComments == null) 7.38 return null; 7.39 - return toplevel.docComments.get(tree); 7.40 + return toplevel.docComments.getCommentText(tree); 7.41 } 7.42 7.43 public PackageElement getPackageOf(Element e) {
8.1 --- a/src/share/classes/com/sun/tools/javac/parser/EndPosTable.java Thu Jun 21 17:08:31 2012 -0700 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,56 +0,0 @@ 8.4 -/* 8.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 8.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 - * 8.8 - * This code is free software; you can redistribute it and/or modify it 8.9 - * under the terms of the GNU General Public License version 2 only, as 8.10 - * published by the Free Software Foundation. Oracle designates this 8.11 - * particular file as subject to the "Classpath" exception as provided 8.12 - * by Oracle in the LICENSE file that accompanied this code. 8.13 - * 8.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 - * version 2 for more details (a copy is included in the LICENSE file that 8.18 - * accompanied this code). 8.19 - * 8.20 - * You should have received a copy of the GNU General Public License version 8.21 - * 2 along with this work; if not, write to the Free Software Foundation, 8.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 - * 8.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.25 - * or visit www.oracle.com if you need additional information or have any 8.26 - * questions. 8.27 - */ 8.28 -package com.sun.tools.javac.parser; 8.29 - 8.30 -import com.sun.tools.javac.tree.JCTree; 8.31 - 8.32 -/** 8.33 - * Specifies the methods to access a mappings of syntax trees to end positions. 8.34 - * <p><b>This is NOT part of any supported API. 8.35 - * If you write code that depends on this, you do so at your own 8.36 - * risk. This code and its internal interfaces are subject to change 8.37 - * or deletion without notice.</b></p> 8.38 - */ 8.39 -public interface EndPosTable { 8.40 - 8.41 - /** 8.42 - * This method will return the end position of a given tree, otherwise a 8.43 - * Positions.NOPOS will be returned. 8.44 - * @param tree JCTree 8.45 - * @return position of the source tree or Positions.NOPOS for non-existent mapping 8.46 - */ 8.47 - public int getEndPos(JCTree tree); 8.48 - 8.49 - /** 8.50 - * Give an old tree and a new tree, the old tree will be replaced with 8.51 - * the new tree, the position of the new tree will be that of the old 8.52 - * tree. 8.53 - * not exist. 8.54 - * @param oldtree a JCTree to be replaced 8.55 - * @param newtree a JCTree to be replaced with 8.56 - * @return position of the old tree or Positions.NOPOS for non-existent mapping 8.57 - */ 8.58 - public int replaceTree(JCTree oldtree, JCTree newtree); 8.59 -}
9.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Thu Jun 21 17:08:31 2012 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java Mon Jun 25 21:39:16 2012 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -571,7 +571,7 @@ 9.11 reader.scanCommentChar(); 9.12 } while (reader.ch != CR && reader.ch != LF && reader.bp < reader.buflen); 9.13 if (reader.bp < reader.buflen) { 9.14 - comments = addDocReader(comments, processComment(pos, reader.bp, CommentStyle.LINE)); 9.15 + comments = addComment(comments, processComment(pos, reader.bp, CommentStyle.LINE)); 9.16 } 9.17 break; 9.18 } else if (reader.ch == '*') { 9.19 @@ -597,7 +597,7 @@ 9.20 } 9.21 if (reader.ch == '/') { 9.22 reader.scanChar(); 9.23 - comments = addDocReader(comments, processComment(pos, reader.bp, style)); 9.24 + comments = addComment(comments, processComment(pos, reader.bp, style)); 9.25 break; 9.26 } else { 9.27 lexError(pos, "unclosed.comment"); 9.28 @@ -693,10 +693,10 @@ 9.29 } 9.30 } 9.31 //where 9.32 - List<Comment> addDocReader(List<Comment> docReaders, Comment docReader) { 9.33 - return docReaders == null ? 9.34 - List.of(docReader) : 9.35 - docReaders.prepend(docReader); 9.36 + List<Comment> addComment(List<Comment> comments, Comment comment) { 9.37 + return comments == null ? 9.38 + List.of(comment) : 9.39 + comments.prepend(comment); 9.40 } 9.41 9.42 /** Return the position where a lexical error occurred; 9.43 @@ -780,6 +780,10 @@ 9.44 return null; 9.45 } 9.46 9.47 + public int getSourcePos(int pos) { 9.48 + return -1; 9.49 + } 9.50 + 9.51 public CommentStyle getStyle() { 9.52 return cs; 9.53 }
10.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Jun 21 17:08:31 2012 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Jun 25 21:39:16 2012 -0700 10.3 @@ -117,7 +117,7 @@ 10.4 this.allowMethodReferences = source.allowMethodReferences() && 10.5 fac.options.isSet("allowMethodReferences"); 10.6 this.keepDocComments = keepDocComments; 10.7 - docComments = keepDocComments ? new HashMap<JCTree,String>() : null; 10.8 + docComments = newDocCommentTable(keepDocComments); 10.9 this.keepLineMap = keepLineMap; 10.10 this.errorTree = F.Erroneous(); 10.11 endPosTable = newEndPosTable(keepEndPositions); 10.12 @@ -128,6 +128,11 @@ 10.13 ? new SimpleEndPosTable() 10.14 : new EmptyEndPosTable(); 10.15 } 10.16 + 10.17 + protected DocCommentTable newDocCommentTable(boolean keepDocComments) { 10.18 + return keepDocComments ? new SimpleDocCommentTable() : null; 10.19 + } 10.20 + 10.21 /** Switch: Should generics be recognized? 10.22 */ 10.23 boolean allowGenerics; 10.24 @@ -417,21 +422,21 @@ 10.25 10.26 /* ---------- doc comments --------- */ 10.27 10.28 - /** A hashtable to store all documentation comments 10.29 + /** A table to store all documentation comments 10.30 * indexed by the tree nodes they refer to. 10.31 * defined only if option flag keepDocComment is set. 10.32 */ 10.33 - private final Map<JCTree, String> docComments; 10.34 + private final DocCommentTable docComments; 10.35 10.36 /** Make an entry into docComments hashtable, 10.37 * provided flag keepDocComments is set and given doc comment is non-null. 10.38 * @param tree The tree to be used as index in the hashtable 10.39 * @param dc The doc comment to associate with the tree, or null. 10.40 */ 10.41 - void attach(JCTree tree, String dc) { 10.42 + void attach(JCTree tree, Comment dc) { 10.43 if (keepDocComments && dc != null) { 10.44 // System.out.println("doc comment = ");System.out.println(dc);//DEBUG 10.45 - docComments.put(tree, dc); 10.46 + docComments.putComment(tree, dc); 10.47 } 10.48 } 10.49 10.50 @@ -1858,7 +1863,7 @@ 10.51 return List.of(parseStatement()); 10.52 case MONKEYS_AT: 10.53 case FINAL: { 10.54 - String dc = token.comment(CommentStyle.JAVADOC); 10.55 + Comment dc = token.comment(CommentStyle.JAVADOC); 10.56 JCModifiers mods = modifiersOpt(); 10.57 if (token.kind == INTERFACE || 10.58 token.kind == CLASS || 10.59 @@ -1875,13 +1880,13 @@ 10.60 } 10.61 } 10.62 case ABSTRACT: case STRICTFP: { 10.63 - String dc = token.comment(CommentStyle.JAVADOC); 10.64 + Comment dc = token.comment(CommentStyle.JAVADOC); 10.65 JCModifiers mods = modifiersOpt(); 10.66 return List.of(classOrInterfaceOrEnumDeclaration(mods, dc)); 10.67 } 10.68 case INTERFACE: 10.69 case CLASS: 10.70 - String dc = token.comment(CommentStyle.JAVADOC); 10.71 + Comment dc = token.comment(CommentStyle.JAVADOC); 10.72 return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); 10.73 case ENUM: 10.74 case ASSERT: 10.75 @@ -2418,7 +2423,7 @@ 10.76 JCExpression type, 10.77 Name name, 10.78 boolean reqInit, 10.79 - String dc, 10.80 + Comment dc, 10.81 T vdefs) 10.82 { 10.83 vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc)); 10.84 @@ -2434,7 +2439,7 @@ 10.85 /** VariableDeclarator = Ident VariableDeclaratorRest 10.86 * ConstantDeclarator = Ident ConstantDeclaratorRest 10.87 */ 10.88 - JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, String dc) { 10.89 + JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, Comment dc) { 10.90 return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc); 10.91 } 10.92 10.93 @@ -2445,7 +2450,7 @@ 10.94 * @param dc The documentation comment for the variable declarations, or null. 10.95 */ 10.96 JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, 10.97 - boolean reqInit, String dc) { 10.98 + boolean reqInit, Comment dc) { 10.99 type = bracketsOpt(type); 10.100 JCExpression init = null; 10.101 if (token.kind == EQ) { 10.102 @@ -2539,7 +2544,7 @@ 10.103 seenImport = true; 10.104 defs.append(importDeclaration()); 10.105 } else { 10.106 - String docComment = token.comment(CommentStyle.JAVADOC); 10.107 + Comment docComment = token.comment(CommentStyle.JAVADOC); 10.108 if (firstTypeDecl && !seenImport && !seenPackage) { 10.109 docComment = firstToken.comment(CommentStyle.JAVADOC); 10.110 consumedToplevelDoc = true; 10.111 @@ -2597,7 +2602,7 @@ 10.112 /** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration 10.113 * | ";" 10.114 */ 10.115 - JCTree typeDeclaration(JCModifiers mods, String docComment) { 10.116 + JCTree typeDeclaration(JCModifiers mods, Comment docComment) { 10.117 int pos = token.pos; 10.118 if (mods == null && token.kind == SEMI) { 10.119 nextToken(); 10.120 @@ -2612,7 +2617,7 @@ 10.121 * @param mods Any modifiers starting the class or interface declaration 10.122 * @param dc The documentation comment for the class, or null. 10.123 */ 10.124 - JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, String dc) { 10.125 + JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, Comment dc) { 10.126 if (token.kind == CLASS) { 10.127 return classDeclaration(mods, dc); 10.128 } else if (token.kind == INTERFACE) { 10.129 @@ -2656,7 +2661,7 @@ 10.130 * @param mods The modifiers starting the class declaration 10.131 * @param dc The documentation comment for the class, or null. 10.132 */ 10.133 - protected JCClassDecl classDeclaration(JCModifiers mods, String dc) { 10.134 + protected JCClassDecl classDeclaration(JCModifiers mods, Comment dc) { 10.135 int pos = token.pos; 10.136 accept(CLASS); 10.137 Name name = ident(); 10.138 @@ -2685,7 +2690,7 @@ 10.139 * @param mods The modifiers starting the interface declaration 10.140 * @param dc The documentation comment for the interface, or null. 10.141 */ 10.142 - protected JCClassDecl interfaceDeclaration(JCModifiers mods, String dc) { 10.143 + protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) { 10.144 int pos = token.pos; 10.145 accept(INTERFACE); 10.146 Name name = ident(); 10.147 @@ -2708,7 +2713,7 @@ 10.148 * @param mods The modifiers starting the enum declaration 10.149 * @param dc The documentation comment for the enum, or null. 10.150 */ 10.151 - protected JCClassDecl enumDeclaration(JCModifiers mods, String dc) { 10.152 + protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) { 10.153 int pos = token.pos; 10.154 accept(ENUM); 10.155 Name name = ident(); 10.156 @@ -2767,7 +2772,7 @@ 10.157 /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] 10.158 */ 10.159 JCTree enumeratorDeclaration(Name enumName) { 10.160 - String dc = token.comment(CommentStyle.JAVADOC); 10.161 + Comment dc = token.comment(CommentStyle.JAVADOC); 10.162 int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; 10.163 if (token.deprecatedFlag()) { 10.164 flags |= Flags.DEPRECATED; 10.165 @@ -2856,7 +2861,7 @@ 10.166 nextToken(); 10.167 return List.<JCTree>nil(); 10.168 } else { 10.169 - String dc = token.comment(CommentStyle.JAVADOC); 10.170 + Comment dc = token.comment(CommentStyle.JAVADOC); 10.171 int pos = token.pos; 10.172 JCModifiers mods = modifiersOpt(); 10.173 if (token.kind == CLASS || 10.174 @@ -2936,7 +2941,7 @@ 10.175 Name name, 10.176 List<JCTypeParameter> typarams, 10.177 boolean isInterface, boolean isVoid, 10.178 - String dc) { 10.179 + Comment dc) { 10.180 List<JCVariableDecl> params = formalParameters(); 10.181 if (!isVoid) type = bracketsOpt(type); 10.182 List<JCExpression> thrown = List.nil();
11.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Thu Jun 21 17:08:31 2012 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java Mon Jun 25 21:39:16 2012 -0700 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. 11.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.8 * 11.9 * This code is free software; you can redistribute it and/or modify it 11.10 @@ -62,19 +62,54 @@ 11.11 @Override 11.12 protected Comment processComment(int pos, int endPos, CommentStyle style) { 11.13 char[] buf = reader.getRawCharacters(pos, endPos); 11.14 - return new JavadocComment(new ColReader(fac, buf, buf.length), style); 11.15 + return new JavadocComment(new DocReader(fac, buf, buf.length, pos), style); 11.16 } 11.17 11.18 /** 11.19 * This is a specialized version of UnicodeReader that keeps track of the 11.20 - * column position within a given character stream (used for Javadoc processing). 11.21 + * column position within a given character stream (used for Javadoc processing), 11.22 + * and which builds a table for mapping positions in the comment string to 11.23 + * positions in the source file. 11.24 */ 11.25 - static class ColReader extends UnicodeReader { 11.26 + static class DocReader extends UnicodeReader { 11.27 11.28 int col; 11.29 + int startPos; 11.30 11.31 - ColReader(ScannerFactory fac, char[] input, int inputLength) { 11.32 + /** 11.33 + * A buffer for building a table for mapping positions in {@link #sbuf} 11.34 + * to positions in the source buffer. 11.35 + * 11.36 + * The array is organized as a series of pairs of integers: the first 11.37 + * number in each pair specifies a position in the comment text, 11.38 + * the second number in each pair specifies the corresponding position 11.39 + * in the source buffer. The pairs are sorted in ascending order. 11.40 + * 11.41 + * Since the mapping function is generally continuous, with successive 11.42 + * positions in the string corresponding to successive positions in the 11.43 + * source buffer, the table only needs to record discontinuities in 11.44 + * the mapping. The values of intermediate positions can be inferred. 11.45 + * 11.46 + * Discontinuities may occur in a number of places: when a newline 11.47 + * is followed by whitespace and asterisks (which are ignored), 11.48 + * when a tab is expanded into spaces, and when unicode escapes 11.49 + * are used in the source buffer. 11.50 + * 11.51 + * Thus, to find the source position of any position, p, in the comment 11.52 + * string, find the index, i, of the pair whose string offset 11.53 + * ({@code pbuf[i] }) is closest to but not greater than p. Then, 11.54 + * {@code sourcePos(p) = pbuf[i+1] + (p - pbuf[i]) }. 11.55 + */ 11.56 + int[] pbuf = new int[128]; 11.57 + 11.58 + /** 11.59 + * The index of the next empty slot in the pbuf buffer. 11.60 + */ 11.61 + int pp = 0; 11.62 + 11.63 + DocReader(ScannerFactory fac, char[] input, int inputLength, int startPos) { 11.64 super(fac, input, inputLength); 11.65 + this.startPos = startPos; 11.66 } 11.67 11.68 @Override 11.69 @@ -147,19 +182,43 @@ 11.70 break; 11.71 } 11.72 } 11.73 + 11.74 + @Override 11.75 + public void putChar(char ch, boolean scan) { 11.76 + // At this point, bp is the position of the current character in buf, 11.77 + // and sp is the position in sbuf where this character will be put. 11.78 + // Record a new entry in pbuf if pbuf is empty or if sp and its 11.79 + // corresponding source position are not equidistant from the 11.80 + // corresponding values in the latest entry in the pbuf array. 11.81 + // (i.e. there is a discontinuity in the map function.) 11.82 + if ((pp == 0) 11.83 + || (sp - pbuf[pp - 2] != (startPos + bp) - pbuf[pp - 1])) { 11.84 + if (pp + 1 >= pbuf.length) { 11.85 + int[] new_pbuf = new int[pbuf.length * 2]; 11.86 + System.arraycopy(pbuf, 0, new_pbuf, 0, pbuf.length); 11.87 + pbuf = new_pbuf; 11.88 + } 11.89 + pbuf[pp] = sp; 11.90 + pbuf[pp + 1] = startPos + bp; 11.91 + pp += 2; 11.92 + } 11.93 + super.putChar(ch, scan); 11.94 + } 11.95 } 11.96 11.97 - protected class JavadocComment extends JavaTokenizer.BasicComment<ColReader> { 11.98 + protected class JavadocComment extends JavaTokenizer.BasicComment<DocReader> { 11.99 11.100 /** 11.101 * Translated and stripped contents of doc comment 11.102 */ 11.103 private String docComment = null; 11.104 + private int[] docPosns = null; 11.105 11.106 - JavadocComment(ColReader comment_reader, CommentStyle cs) { 11.107 - super(comment_reader, cs); 11.108 + JavadocComment(DocReader reader, CommentStyle cs) { 11.109 + super(reader, cs); 11.110 } 11.111 11.112 + @Override 11.113 public String getText() { 11.114 if (!scanned && cs == CommentStyle.JAVADOC) { 11.115 scanDocComment(); 11.116 @@ -168,6 +227,33 @@ 11.117 } 11.118 11.119 @Override 11.120 + public int getSourcePos(int pos) { 11.121 + // Binary search to find the entry for which the string index is 11.122 + // less than pos. Since docPosns is a list of pairs of integers 11.123 + // we must make sure the index is always even. 11.124 + // If we find an exact match for pos, the other item in the pair 11.125 + // gives the source pos; otherwise, compute the source position 11.126 + // relative to the best match found in the array. 11.127 + if (pos < 0 || pos >= docComment.length()) 11.128 + throw new StringIndexOutOfBoundsException(); 11.129 + if (docPosns == null) 11.130 + return -1; 11.131 + int start = 0; 11.132 + int end = docPosns.length; 11.133 + while (start < end - 2) { 11.134 + // find an even index midway between start and end 11.135 + int index = ((start + end) / 4) * 2; 11.136 + if (docPosns[index] < pos) 11.137 + start = index; 11.138 + else if (docPosns[index] == pos) 11.139 + return docPosns[index + 1]; 11.140 + else 11.141 + end = index; 11.142 + } 11.143 + return docPosns[start + 1] + (pos - docPosns[start]); 11.144 + } 11.145 + 11.146 + @Override 11.147 @SuppressWarnings("fallthrough") 11.148 protected void scanDocComment() { 11.149 try { 11.150 @@ -209,7 +295,8 @@ 11.151 // whitespace, then it consumes any stars, then it 11.152 // puts the rest of the line into our buffer. 11.153 while (comment_reader.bp < comment_reader.buflen) { 11.154 - 11.155 + int begin_bp = comment_reader.bp; 11.156 + char begin_ch = comment_reader.ch; 11.157 // The wsLoop consumes whitespace from the beginning 11.158 // of each line. 11.159 wsLoop: 11.160 @@ -263,10 +350,10 @@ 11.161 break outerLoop; 11.162 } 11.163 } else if (! firstLine) { 11.164 - //The current line does not begin with a '*' so we will indent it. 11.165 - for (int i = 1; i < comment_reader.col; i++) { 11.166 - comment_reader.putChar(' ', false); 11.167 - } 11.168 + // The current line does not begin with a '*' so we will 11.169 + // treat it as comment 11.170 + comment_reader.bp = begin_bp; 11.171 + comment_reader.ch = begin_ch; 11.172 } 11.173 // The textLoop processes the rest of the characters 11.174 // on the line, adding them to our buffer. 11.175 @@ -334,11 +421,14 @@ 11.176 11.177 // Store the text of the doc comment 11.178 docComment = comment_reader.chars(); 11.179 + docPosns = new int[comment_reader.pp]; 11.180 + System.arraycopy(comment_reader.pbuf, 0, docPosns, 0, docPosns.length); 11.181 } else { 11.182 docComment = ""; 11.183 } 11.184 } finally { 11.185 scanned = true; 11.186 + comment_reader = null; 11.187 if (docComment != null && 11.188 docComment.matches("(?sm).*^\\s*@deprecated( |$).*")) { 11.189 deprecatedFlag = true;
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/src/share/classes/com/sun/tools/javac/parser/SimpleDocCommentTable.java Mon Jun 25 21:39:16 2012 -0700 12.3 @@ -0,0 +1,67 @@ 12.4 +/* 12.5 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. Oracle designates this 12.11 + * particular file as subject to the "Classpath" exception as provided 12.12 + * by Oracle in the LICENSE file that accompanied this code. 12.13 + * 12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.17 + * version 2 for more details (a copy is included in the LICENSE file that 12.18 + * accompanied this code). 12.19 + * 12.20 + * You should have received a copy of the GNU General Public License version 12.21 + * 2 along with this work; if not, write to the Free Software Foundation, 12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.23 + * 12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.25 + * or visit www.oracle.com if you need additional information or have any 12.26 + * questions. 12.27 + */ 12.28 + 12.29 +package com.sun.tools.javac.parser; 12.30 + 12.31 +import java.util.HashMap; 12.32 +import java.util.Map; 12.33 + 12.34 +import com.sun.tools.javac.parser.Tokens.Comment; 12.35 +import com.sun.tools.javac.tree.DocCommentTable; 12.36 +import com.sun.tools.javac.tree.JCTree; 12.37 + 12.38 + 12.39 +/** 12.40 + * 12.41 + * <p><b>This is NOT part of any supported API. 12.42 + * If you write code that depends on this, you do so at your own risk. 12.43 + * This code and its internal interfaces are subject to change or 12.44 + * deletion without notice.</b> 12.45 + */ 12.46 +public class SimpleDocCommentTable implements DocCommentTable { 12.47 + Map<JCTree, Comment> table; 12.48 + 12.49 + SimpleDocCommentTable() { 12.50 + table = new HashMap<JCTree, Comment>(); 12.51 + } 12.52 + 12.53 + public boolean hasComment(JCTree tree) { 12.54 + return table.containsKey(tree); 12.55 + } 12.56 + 12.57 + public Comment getComment(JCTree tree) { 12.58 + return table.get(tree); 12.59 + } 12.60 + 12.61 + public String getCommentText(JCTree tree) { 12.62 + Comment c = getComment(tree); 12.63 + return (c == null) ? null : c.getText(); 12.64 + } 12.65 + 12.66 + public void putComment(JCTree tree, Comment c) { 12.67 + table.put(tree, c); 12.68 + } 12.69 + 12.70 +}
13.1 --- a/src/share/classes/com/sun/tools/javac/parser/Tokens.java Thu Jun 21 17:08:31 2012 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Tokens.java Mon Jun 25 21:39:16 2012 -0700 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -294,6 +294,7 @@ 13.11 } 13.12 13.13 String getText(); 13.14 + int getSourcePos(int index); 13.15 CommentStyle getStyle(); 13.16 boolean isDeprecated(); 13.17 } 13.18 @@ -371,11 +372,11 @@ 13.19 * Preserve classic semantics - if multiple javadocs are found on the token 13.20 * the last one is returned 13.21 */ 13.22 - public String comment(Comment.CommentStyle style) { 13.23 - List<Comment> readers = getReaders(Comment.CommentStyle.JAVADOC); 13.24 - return readers.isEmpty() ? 13.25 + public Comment comment(Comment.CommentStyle style) { 13.26 + List<Comment> comments = getComments(Comment.CommentStyle.JAVADOC); 13.27 + return comments.isEmpty() ? 13.28 null : 13.29 - readers.head.getText(); 13.30 + comments.head; 13.31 } 13.32 13.33 /** 13.34 @@ -383,22 +384,22 @@ 13.35 * javadoc comment attached to this token contains the '@deprecated' string 13.36 */ 13.37 public boolean deprecatedFlag() { 13.38 - for (Comment r : getReaders(Comment.CommentStyle.JAVADOC)) { 13.39 - if (r.isDeprecated()) { 13.40 + for (Comment c : getComments(Comment.CommentStyle.JAVADOC)) { 13.41 + if (c.isDeprecated()) { 13.42 return true; 13.43 } 13.44 } 13.45 return false; 13.46 } 13.47 13.48 - private List<Comment> getReaders(Comment.CommentStyle style) { 13.49 + private List<Comment> getComments(Comment.CommentStyle style) { 13.50 if (comments == null) { 13.51 return List.nil(); 13.52 } else { 13.53 ListBuffer<Comment> buf = ListBuffer.lb(); 13.54 - for (Comment r : comments) { 13.55 - if (r.getStyle() == style) { 13.56 - buf.add(r); 13.57 + for (Comment c : comments) { 13.58 + if (c.getStyle() == style) { 13.59 + buf.add(c); 13.60 } 13.61 } 13.62 return buf.toList();
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/src/share/classes/com/sun/tools/javac/tree/DocCommentTable.java Mon Jun 25 21:39:16 2012 -0700 14.3 @@ -0,0 +1,57 @@ 14.4 +/* 14.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. Oracle designates this 14.11 + * particular file as subject to the "Classpath" exception as provided 14.12 + * by Oracle in the LICENSE file that accompanied this code. 14.13 + * 14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.17 + * version 2 for more details (a copy is included in the LICENSE file that 14.18 + * accompanied this code). 14.19 + * 14.20 + * You should have received a copy of the GNU General Public License version 14.21 + * 2 along with this work; if not, write to the Free Software Foundation, 14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.23 + * 14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.25 + * or visit www.oracle.com if you need additional information or have any 14.26 + * questions. 14.27 + */ 14.28 +package com.sun.tools.javac.tree; 14.29 + 14.30 +import com.sun.tools.javac.parser.Tokens.Comment; 14.31 + 14.32 +/** 14.33 + * A table giving the doc comment, if any, for any tree node. 14.34 + * 14.35 + * <p><b>This is NOT part of any supported API. 14.36 + * If you write code that depends on this, you do so at your own 14.37 + * risk. This code and its internal interfaces are subject to change 14.38 + * or deletion without notice.</b> 14.39 + */ 14.40 +public interface DocCommentTable { 14.41 + /** 14.42 + * Check if a tree node has a corresponding doc comment. 14.43 + */ 14.44 + public boolean hasComment(JCTree tree); 14.45 + 14.46 + /** 14.47 + * Get the Comment token containing the doc comment, if any, for a tree node. 14.48 + */ 14.49 + public Comment getComment(JCTree tree); 14.50 + 14.51 + /** 14.52 + * Get the plain text of the doc comment, if any, for a tree node. 14.53 + */ 14.54 + public String getCommentText(JCTree tree); 14.55 + 14.56 + /** 14.57 + * Set the Comment to be associated with a tree node. 14.58 + */ 14.59 + public void putComment(JCTree tree, Comment c); 14.60 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/src/share/classes/com/sun/tools/javac/tree/EndPosTable.java Mon Jun 25 21:39:16 2012 -0700 15.3 @@ -0,0 +1,55 @@ 15.4 +/* 15.5 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. Oracle designates this 15.11 + * particular file as subject to the "Classpath" exception as provided 15.12 + * by Oracle in the LICENSE file that accompanied this code. 15.13 + * 15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.17 + * version 2 for more details (a copy is included in the LICENSE file that 15.18 + * accompanied this code). 15.19 + * 15.20 + * You should have received a copy of the GNU General Public License version 15.21 + * 2 along with this work; if not, write to the Free Software Foundation, 15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.23 + * 15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.25 + * or visit www.oracle.com if you need additional information or have any 15.26 + * questions. 15.27 + */ 15.28 + 15.29 +package com.sun.tools.javac.tree; 15.30 + 15.31 +/** 15.32 + * Specifies the methods to access a mappings of syntax trees to end positions. 15.33 + * <p><b>This is NOT part of any supported API. 15.34 + * If you write code that depends on this, you do so at your own 15.35 + * risk. This code and its internal interfaces are subject to change 15.36 + * or deletion without notice.</b></p> 15.37 + */ 15.38 +public interface EndPosTable { 15.39 + 15.40 + /** 15.41 + * This method will return the end position of a given tree, otherwise a 15.42 + * Positions.NOPOS will be returned. 15.43 + * @param tree JCTree 15.44 + * @return position of the source tree or Positions.NOPOS for non-existent mapping 15.45 + */ 15.46 + public int getEndPos(JCTree tree); 15.47 + 15.48 + /** 15.49 + * Give an old tree and a new tree, the old tree will be replaced with 15.50 + * the new tree, the position of the new tree will be that of the old 15.51 + * tree. 15.52 + * not exist. 15.53 + * @param oldtree a JCTree to be replaced 15.54 + * @param newtree a JCTree to be replaced with 15.55 + * @return position of the old tree or Positions.NOPOS for non-existent mapping 15.56 + */ 15.57 + public int replaceTree(JCTree oldtree, JCTree newtree); 15.58 +}
16.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Jun 21 17:08:31 2012 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Jun 25 21:39:16 2012 -0700 16.3 @@ -1,5 +1,5 @@ 16.4 /* 16.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 16.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 16.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.8 * 16.9 * This code is free software; you can redistribute it and/or modify it 16.10 @@ -25,25 +25,23 @@ 16.11 16.12 package com.sun.tools.javac.tree; 16.13 16.14 +import java.io.IOException; 16.15 +import java.io.StringWriter; 16.16 import java.util.*; 16.17 16.18 -import java.io.IOException; 16.19 -import java.io.StringWriter; 16.20 import javax.lang.model.element.Modifier; 16.21 import javax.lang.model.type.TypeKind; 16.22 import javax.tools.JavaFileObject; 16.23 16.24 +import com.sun.source.tree.*; 16.25 +import com.sun.source.tree.LambdaExpressionTree.BodyKind; 16.26 +import com.sun.source.tree.MemberReferenceTree.ReferenceMode; 16.27 +import com.sun.tools.javac.code.*; 16.28 +import com.sun.tools.javac.code.Scope.*; 16.29 +import com.sun.tools.javac.code.Symbol.*; 16.30 import com.sun.tools.javac.util.*; 16.31 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 16.32 import com.sun.tools.javac.util.List; 16.33 -import com.sun.tools.javac.code.*; 16.34 -import com.sun.tools.javac.code.Scope.*; 16.35 -import com.sun.tools.javac.code.Symbol.*; 16.36 -import com.sun.tools.javac.parser.EndPosTable; 16.37 -import com.sun.source.tree.*; 16.38 -import com.sun.source.tree.LambdaExpressionTree.BodyKind; 16.39 -import com.sun.source.tree.MemberReferenceTree.ReferenceMode; 16.40 - 16.41 import static com.sun.tools.javac.code.BoundKind.*; 16.42 import static com.sun.tools.javac.tree.JCTree.Tag.*; 16.43 16.44 @@ -491,7 +489,7 @@ 16.45 public ImportScope namedImportScope; 16.46 public StarImportScope starImportScope; 16.47 public Position.LineMap lineMap = null; 16.48 - public Map<JCTree, String> docComments = null; 16.49 + public DocCommentTable docComments = null; 16.50 public EndPosTable endPositions = null; 16.51 protected JCCompilationUnit(List<JCAnnotation> packageAnnotations, 16.52 JCExpression pid,
17.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Jun 21 17:08:31 2012 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Mon Jun 25 21:39:16 2012 -0700 17.3 @@ -1,5 +1,5 @@ 17.4 /* 17.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 17.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 17.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.8 * 17.9 * This code is free software; you can redistribute it and/or modify it 17.10 @@ -29,14 +29,12 @@ 17.11 import java.util.*; 17.12 17.13 import com.sun.source.tree.MemberReferenceTree.ReferenceMode; 17.14 - 17.15 +import com.sun.tools.javac.code.*; 17.16 +import com.sun.tools.javac.code.Symbol.*; 17.17 +import com.sun.tools.javac.parser.Tokens.Comment; 17.18 +import com.sun.tools.javac.tree.JCTree.*; 17.19 import com.sun.tools.javac.util.*; 17.20 import com.sun.tools.javac.util.List; 17.21 -import com.sun.tools.javac.code.*; 17.22 - 17.23 -import com.sun.tools.javac.code.Symbol.*; 17.24 -import com.sun.tools.javac.tree.JCTree.*; 17.25 - 17.26 import static com.sun.tools.javac.code.Flags.*; 17.27 import static com.sun.tools.javac.code.Flags.ANNOTATION; 17.28 import static com.sun.tools.javac.tree.JCTree.Tag.*; 17.29 @@ -78,10 +76,10 @@ 17.30 */ 17.31 Name enclClassName; 17.32 17.33 - /** A hashtable mapping trees to their documentation comments 17.34 + /** A table mapping trees to their documentation comments 17.35 * (can be null) 17.36 */ 17.37 - Map<JCTree, String> docComments = null; 17.38 + DocCommentTable docComments = null; 17.39 17.40 /** Align code to be indented to left margin. 17.41 */ 17.42 @@ -233,7 +231,7 @@ 17.43 */ 17.44 public void printDocComment(JCTree tree) throws IOException { 17.45 if (docComments != null) { 17.46 - String dc = docComments.get(tree); 17.47 + String dc = docComments.getCommentText(tree); 17.48 if (dc != null) { 17.49 print("/**"); println(); 17.50 int pos = 0; 17.51 @@ -480,7 +478,7 @@ 17.52 17.53 public void visitVarDef(JCVariableDecl tree) { 17.54 try { 17.55 - if (docComments != null && docComments.get(tree) != null) { 17.56 + if (docComments != null && docComments.hasComment(tree)) { 17.57 println(); align(); 17.58 } 17.59 printDocComment(tree);
18.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jun 21 17:08:31 2012 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon Jun 25 21:39:16 2012 -0700 18.3 @@ -25,15 +25,14 @@ 18.4 18.5 package com.sun.tools.javac.tree; 18.6 18.7 + 18.8 import com.sun.source.tree.Tree; 18.9 +import com.sun.tools.javac.code.*; 18.10 import com.sun.tools.javac.comp.AttrContext; 18.11 import com.sun.tools.javac.comp.Env; 18.12 +import com.sun.tools.javac.tree.JCTree.*; 18.13 import com.sun.tools.javac.util.*; 18.14 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 18.15 -import com.sun.tools.javac.code.*; 18.16 -import com.sun.tools.javac.parser.EndPosTable; 18.17 -import com.sun.tools.javac.tree.JCTree.*; 18.18 - 18.19 import static com.sun.tools.javac.code.Flags.*; 18.20 import static com.sun.tools.javac.tree.JCTree.Tag.*; 18.21 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK; 18.22 @@ -282,6 +281,13 @@ 18.23 return (lit.typetag == TypeTags.BOT); 18.24 } 18.25 18.26 + public static String getCommentText(Env<?> env, JCTree tree) { 18.27 + DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) 18.28 + ? ((JCCompilationUnit) tree).docComments 18.29 + : env.toplevel.docComments; 18.30 + return (docComments == null) ? null : docComments.getCommentText(tree); 18.31 + } 18.32 + 18.33 /** The position of the first statement in a block, or the position of 18.34 * the block itself if it is empty. 18.35 */
19.1 --- a/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Thu Jun 21 17:08:31 2012 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/util/DiagnosticSource.java Mon Jun 25 21:39:16 2012 -0700 19.3 @@ -1,5 +1,5 @@ 19.4 /* 19.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 19.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 19.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.8 * 19.9 * This code is free software; you can redistribute it and/or modify it 19.10 @@ -32,7 +32,7 @@ 19.11 import javax.tools.JavaFileObject; 19.12 19.13 import com.sun.tools.javac.file.JavacFileManager; 19.14 -import com.sun.tools.javac.parser.EndPosTable; 19.15 +import com.sun.tools.javac.tree.EndPosTable; 19.16 import com.sun.tools.javac.tree.JCTree; 19.17 19.18 import static com.sun.tools.javac.util.LayoutCharacters.*;
20.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Jun 21 17:08:31 2012 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Mon Jun 25 21:39:16 2012 -0700 20.3 @@ -1,5 +1,5 @@ 20.4 /* 20.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 20.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 20.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.8 * 20.9 * This code is free software; you can redistribute it and/or modify it 20.10 @@ -35,7 +35,7 @@ 20.11 20.12 import com.sun.tools.javac.api.DiagnosticFormatter; 20.13 import com.sun.tools.javac.code.Lint.LintCategory; 20.14 -import com.sun.tools.javac.parser.EndPosTable; 20.15 +import com.sun.tools.javac.tree.EndPosTable; 20.16 import com.sun.tools.javac.tree.JCTree; 20.17 20.18 import static com.sun.tools.javac.util.JCDiagnostic.DiagnosticType.*;
21.1 --- a/src/share/classes/com/sun/tools/javac/util/Log.java Thu Jun 21 17:08:31 2012 -0700 21.2 +++ b/src/share/classes/com/sun/tools/javac/util/Log.java Mon Jun 25 21:39:16 2012 -0700 21.3 @@ -1,5 +1,5 @@ 21.4 /* 21.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 21.6 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 21.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.8 * 21.9 * This code is free software; you can redistribute it and/or modify it 21.10 @@ -37,7 +37,7 @@ 21.11 import com.sun.tools.javac.api.DiagnosticFormatter; 21.12 import com.sun.tools.javac.main.Main; 21.13 import com.sun.tools.javac.main.Option; 21.14 -import com.sun.tools.javac.parser.EndPosTable; 21.15 +import com.sun.tools.javac.tree.EndPosTable; 21.16 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 21.17 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; 21.18
22.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Thu Jun 21 17:08:31 2012 -0700 22.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocEnter.java Mon Jun 25 21:39:16 2012 -0700 22.3 @@ -1,5 +1,5 @@ 22.4 /* 22.5 - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 22.6 + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 22.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.8 * 22.9 * This code is free software; you can redistribute it and/or modify it 22.10 @@ -25,14 +25,17 @@ 22.11 22.12 package com.sun.tools.javadoc; 22.13 22.14 -import com.sun.tools.javac.util.Context; 22.15 -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 22.16 -import com.sun.tools.javac.util.List; 22.17 + 22.18 +import javax.tools.JavaFileObject; 22.19 + 22.20 import com.sun.tools.javac.code.Kinds; 22.21 import com.sun.tools.javac.code.Symbol.*; 22.22 import com.sun.tools.javac.comp.Enter; 22.23 import com.sun.tools.javac.tree.JCTree.*; 22.24 -import javax.tools.JavaFileObject; 22.25 +import com.sun.tools.javac.tree.TreeInfo; 22.26 +import com.sun.tools.javac.util.Context; 22.27 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 22.28 +import com.sun.tools.javac.util.List; 22.29 22.30 /** 22.31 * Javadoc's own enter phase does a few things above and beyond that 22.32 @@ -77,7 +80,7 @@ 22.33 public void visitTopLevel(JCCompilationUnit tree) { 22.34 super.visitTopLevel(tree); 22.35 if (tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE)) { 22.36 - String comment = tree.docComments.get(tree); 22.37 + String comment = TreeInfo.getCommentText(env, tree); 22.38 docenv.makePackageDoc(tree.packge, comment, tree); 22.39 } 22.40 } 22.41 @@ -87,7 +90,7 @@ 22.42 super.visitClassDef(tree); 22.43 if (tree.sym == null) return; 22.44 if (tree.sym.kind == Kinds.TYP || tree.sym.kind == Kinds.ERR) { 22.45 - String comment = env.toplevel.docComments.get(tree); 22.46 + String comment = TreeInfo.getCommentText(env, tree); 22.47 ClassSymbol c = tree.sym; 22.48 docenv.makeClassDoc(c, comment, tree, env.toplevel.lineMap); 22.49 }
23.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Thu Jun 21 17:08:31 2012 -0700 23.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocMemberEnter.java Mon Jun 25 21:39:16 2012 -0700 23.3 @@ -1,5 +1,5 @@ 23.4 /* 23.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 23.6 + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 23.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.8 * 23.9 * This code is free software; you can redistribute it and/or modify it 23.10 @@ -25,13 +25,14 @@ 23.11 23.12 package com.sun.tools.javadoc; 23.13 23.14 -import com.sun.tools.javac.util.Context; 23.15 -import com.sun.tools.javac.util.Position; 23.16 import com.sun.tools.javac.code.Flags; 23.17 import com.sun.tools.javac.code.Kinds; 23.18 import com.sun.tools.javac.code.Symbol.*; 23.19 import com.sun.tools.javac.comp.MemberEnter; 23.20 import com.sun.tools.javac.tree.JCTree.*; 23.21 +import com.sun.tools.javac.tree.TreeInfo; 23.22 +import com.sun.tools.javac.util.Context; 23.23 +import com.sun.tools.javac.util.Position; 23.24 23.25 /** 23.26 * Javadoc's own memberEnter phase does a few things above and beyond that 23.27 @@ -61,11 +62,12 @@ 23.28 docenv = DocEnv.instance(context); 23.29 } 23.30 23.31 + @Override 23.32 public void visitMethodDef(JCMethodDecl tree) { 23.33 super.visitMethodDef(tree); 23.34 MethodSymbol meth = tree.sym; 23.35 if (meth == null || meth.kind != Kinds.MTH) return; 23.36 - String docComment = env.toplevel.docComments.get(tree); 23.37 + String docComment = TreeInfo.getCommentText(env, tree); 23.38 Position.LineMap lineMap = env.toplevel.lineMap; 23.39 if (meth.isConstructor()) 23.40 docenv.makeConstructorDoc(meth, docComment, tree, lineMap); 23.41 @@ -75,12 +77,13 @@ 23.42 docenv.makeMethodDoc(meth, docComment, tree, lineMap); 23.43 } 23.44 23.45 + @Override 23.46 public void visitVarDef(JCVariableDecl tree) { 23.47 super.visitVarDef(tree); 23.48 if (tree.sym != null && 23.49 tree.sym.kind == Kinds.VAR && 23.50 !isParameter(tree.sym)) { 23.51 - String docComment = env.toplevel.docComments.get(tree); 23.52 + String docComment = TreeInfo.getCommentText(env, tree); 23.53 Position.LineMap lineMap = env.toplevel.lineMap; 23.54 docenv.makeFieldDoc(tree.sym, docComment, tree, lineMap); 23.55 }
24.1 --- a/test/tools/javac/6304921/TestLog.java Thu Jun 21 17:08:31 2012 -0700 24.2 +++ b/test/tools/javac/6304921/TestLog.java Mon Jun 25 21:39:16 2012 -0700 24.3 @@ -1,5 +1,5 @@ 24.4 /* 24.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 24.6 + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. 24.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.8 * 24.9 * This code is free software; you can redistribute it and/or modify it 24.10 @@ -33,9 +33,9 @@ 24.11 import javax.tools.JavaFileObject; 24.12 import javax.tools.SimpleJavaFileObject; 24.13 import com.sun.tools.javac.file.JavacFileManager; 24.14 -import com.sun.tools.javac.parser.EndPosTable; 24.15 import com.sun.tools.javac.parser.Parser; 24.16 import com.sun.tools.javac.parser.ParserFactory; 24.17 +import com.sun.tools.javac.tree.EndPosTable; 24.18 import com.sun.tools.javac.tree.JCTree; 24.19 import com.sun.tools.javac.tree.TreeScanner; 24.20 import com.sun.tools.javac.util.Context;
25.1 --- a/test/tools/javac/failover/CheckAttributedTree.java Thu Jun 21 17:08:31 2012 -0700 25.2 +++ b/test/tools/javac/failover/CheckAttributedTree.java Mon Jun 25 21:39:16 2012 -0700 25.3 @@ -1,5 +1,5 @@ 25.4 /* 25.5 - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 25.6 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 25.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.8 * 25.9 * This code is free software; you can redistribute it and/or modify it 25.10 @@ -68,7 +68,7 @@ 25.11 import com.sun.tools.javac.api.JavacTool; 25.12 import com.sun.tools.javac.code.Symbol; 25.13 import com.sun.tools.javac.code.Type; 25.14 -import com.sun.tools.javac.parser.EndPosTable; 25.15 +import com.sun.tools.javac.tree.EndPosTable; 25.16 import com.sun.tools.javac.tree.JCTree; 25.17 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 25.18 import com.sun.tools.javac.tree.JCTree.JCImport;
26.1 --- a/test/tools/javac/parser/JavacParserTest.java Thu Jun 21 17:08:31 2012 -0700 26.2 +++ b/test/tools/javac/parser/JavacParserTest.java Mon Jun 25 21:39:16 2012 -0700 26.3 @@ -23,7 +23,7 @@ 26.4 26.5 /* 26.6 * @test 26.7 - * @bug 7073631 7159445 26.8 + * @bug 7073631 7159445 7156633 26.9 * @summary tests error and diagnostics positions 26.10 * @author Jan Lahoda 26.11 */ 26.12 @@ -49,11 +49,17 @@ 26.13 import com.sun.tools.javac.api.JavacTaskImpl; 26.14 import com.sun.tools.javac.tree.JCTree; 26.15 import java.io.IOException; 26.16 +import java.lang.annotation.ElementType; 26.17 +import java.lang.annotation.Retention; 26.18 +import java.lang.annotation.RetentionPolicy; 26.19 +import java.lang.annotation.Target; 26.20 +import java.lang.reflect.Method; 26.21 import java.net.URI; 26.22 import java.util.ArrayList; 26.23 import java.util.Arrays; 26.24 import java.util.LinkedList; 26.25 import java.util.List; 26.26 +import java.util.regex.Pattern; 26.27 import javax.tools.Diagnostic; 26.28 import javax.tools.DiagnosticCollector; 26.29 import javax.tools.DiagnosticListener; 26.30 @@ -63,13 +69,15 @@ 26.31 import javax.tools.ToolProvider; 26.32 26.33 public class JavacParserTest extends TestCase { 26.34 - final JavaCompiler tool; 26.35 - public JavacParserTest(String testName) { 26.36 - tool = ToolProvider.getSystemJavaCompiler(); 26.37 - System.out.println("java.home=" + System.getProperty("java.home")); 26.38 + static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 26.39 + 26.40 + private JavacParserTest(){} 26.41 + 26.42 + public static void main(String... args) throws Exception { 26.43 + new JavacParserTest().run(args); 26.44 } 26.45 26.46 - static class MyFileObject extends SimpleJavaFileObject { 26.47 + class MyFileObject extends SimpleJavaFileObject { 26.48 26.49 private String text; 26.50 26.51 @@ -86,11 +94,11 @@ 26.52 /* 26.53 * converts Windows to Unix style LFs for comparing strings 26.54 */ 26.55 - private String normalize(String in) { 26.56 + String normalize(String in) { 26.57 return in.replace(System.getProperty("line.separator"), "\n"); 26.58 } 26.59 26.60 - public CompilationUnitTree getCompilationUnitTree(String code) throws IOException { 26.61 + CompilationUnitTree getCompilationUnitTree(String code) throws IOException { 26.62 26.63 JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.64 null, Arrays.asList(new MyFileObject(code))); 26.65 @@ -98,7 +106,7 @@ 26.66 return cut; 26.67 } 26.68 26.69 - public List<String> getErroneousTreeValues(ErroneousTree node) { 26.70 + List<String> getErroneousTreeValues(ErroneousTree node) { 26.71 26.72 List<String> values = new ArrayList<>(); 26.73 if (node.getErrorTrees() != null) { 26.74 @@ -112,7 +120,8 @@ 26.75 return values; 26.76 } 26.77 26.78 - public void testPositionForSuperConstructorCalls() throws IOException { 26.79 + @Test 26.80 + void testPositionForSuperConstructorCalls() throws IOException { 26.81 assert tool != null; 26.82 26.83 String code = "package test; public class Test {public Test() {super();}}"; 26.84 @@ -149,12 +158,12 @@ 26.85 methodStartPos, pos.getStartPosition(cut, mit.getMethodSelect())); 26.86 assertEquals("testPositionForSuperConstructorCalls", 26.87 methodEndPos, pos.getEndPosition(cut, mit.getMethodSelect())); 26.88 - 26.89 } 26.90 26.91 - public void testPositionForEnumModifiers() throws IOException { 26.92 - 26.93 - String code = "package test; public enum Test {A;}"; 26.94 + @Test 26.95 + void testPositionForEnumModifiers() throws IOException { 26.96 + final String theString = "public"; 26.97 + String code = "package test; " + theString + " enum Test {A;}"; 26.98 26.99 JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.100 null, Arrays.asList(new MyFileObject(code))); 26.101 @@ -163,19 +172,21 @@ 26.102 26.103 ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.104 ModifiersTree mt = clazz.getModifiers(); 26.105 - 26.106 + int spos = code.indexOf(theString); 26.107 + int epos = spos + theString.length(); 26.108 assertEquals("testPositionForEnumModifiers", 26.109 - 38 - 24, pos.getStartPosition(cut, mt)); 26.110 + spos, pos.getStartPosition(cut, mt)); 26.111 assertEquals("testPositionForEnumModifiers", 26.112 - 44 - 24, pos.getEndPosition(cut, mt)); 26.113 + epos, pos.getEndPosition(cut, mt)); 26.114 } 26.115 26.116 - public void testNewClassWithEnclosing() throws IOException { 26.117 + @Test 26.118 + void testNewClassWithEnclosing() throws IOException { 26.119 26.120 - 26.121 + final String theString = "Test.this.new d()"; 26.122 String code = "package test; class Test { " + 26.123 "class d {} private void method() { " + 26.124 - "Object o = Test.this.new d(); } }"; 26.125 + "Object o = " + theString + "; } }"; 26.126 26.127 JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.128 null, Arrays.asList(new MyFileObject(code))); 26.129 @@ -186,13 +197,16 @@ 26.130 ExpressionTree est = 26.131 ((VariableTree) ((MethodTree) clazz.getMembers().get(1)).getBody().getStatements().get(0)).getInitializer(); 26.132 26.133 + final int spos = code.indexOf(theString); 26.134 + final int epos = spos + theString.length(); 26.135 assertEquals("testNewClassWithEnclosing", 26.136 - 97 - 24, pos.getStartPosition(cut, est)); 26.137 + spos, pos.getStartPosition(cut, est)); 26.138 assertEquals("testNewClassWithEnclosing", 26.139 - 114 - 24, pos.getEndPosition(cut, est)); 26.140 + epos, pos.getEndPosition(cut, est)); 26.141 } 26.142 26.143 - public void testPreferredPositionForBinaryOp() throws IOException { 26.144 + @Test 26.145 + void testPreferredPositionForBinaryOp() throws IOException { 26.146 26.147 String code = "package test; public class Test {" 26.148 + "private void test() {" 26.149 @@ -211,7 +225,581 @@ 26.150 condStartPos, condJC.pos); 26.151 } 26.152 26.153 - public void testPositionBrokenSource126732a() throws IOException { 26.154 + @Test 26.155 + void testErrorRecoveryForEnhancedForLoop142381() throws IOException { 26.156 + 26.157 + String code = "package test; class Test { " + 26.158 + "private void method() { " + 26.159 + "java.util.Set<String> s = null; for (a : s) {} } }"; 26.160 + 26.161 + final List<Diagnostic<? extends JavaFileObject>> errors = 26.162 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.163 + 26.164 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.165 + new DiagnosticListener<JavaFileObject>() { 26.166 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.167 + errors.add(diagnostic); 26.168 + } 26.169 + }, null, null, Arrays.asList(new MyFileObject(code))); 26.170 + 26.171 + CompilationUnitTree cut = ct.parse().iterator().next(); 26.172 + 26.173 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.174 + StatementTree forStatement = 26.175 + ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); 26.176 + 26.177 + assertEquals("testErrorRecoveryForEnhancedForLoop142381", 26.178 + Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); 26.179 + assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); 26.180 + } 26.181 + 26.182 + @Test 26.183 + void testPositionAnnotationNoPackage187551() throws IOException { 26.184 + 26.185 + String code = "\n@interface Test {}"; 26.186 + 26.187 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.188 + null, Arrays.asList(new MyFileObject(code))); 26.189 + 26.190 + CompilationUnitTree cut = ct.parse().iterator().next(); 26.191 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.192 + Trees t = Trees.instance(ct); 26.193 + 26.194 + assertEquals("testPositionAnnotationNoPackage187551", 26.195 + 1, t.getSourcePositions().getStartPosition(cut, clazz)); 26.196 + } 26.197 + 26.198 + @Test 26.199 + void testPositionsSane1() throws IOException { 26.200 + performPositionsSanityTest("package test; class Test { " + 26.201 + "private void method() { " + 26.202 + "java.util.List<? extends java.util.List<? extends String>> l; " + 26.203 + "} }"); 26.204 + } 26.205 + 26.206 + @Test 26.207 + void testPositionsSane2() throws IOException { 26.208 + performPositionsSanityTest("package test; class Test { " + 26.209 + "private void method() { " + 26.210 + "java.util.List<? super java.util.List<? super String>> l; " + 26.211 + "} }"); 26.212 + } 26.213 + 26.214 + @Test 26.215 + void testPositionsSane3() throws IOException { 26.216 + performPositionsSanityTest("package test; class Test { " + 26.217 + "private void method() { " + 26.218 + "java.util.List<? super java.util.List<?>> l; } }"); 26.219 + } 26.220 + 26.221 + private void performPositionsSanityTest(String code) throws IOException { 26.222 + 26.223 + final List<Diagnostic<? extends JavaFileObject>> errors = 26.224 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.225 + 26.226 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.227 + new DiagnosticListener<JavaFileObject>() { 26.228 + 26.229 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.230 + errors.add(diagnostic); 26.231 + } 26.232 + }, null, null, Arrays.asList(new MyFileObject(code))); 26.233 + 26.234 + final CompilationUnitTree cut = ct.parse().iterator().next(); 26.235 + final Trees trees = Trees.instance(ct); 26.236 + 26.237 + new TreeScanner<Void, Void>() { 26.238 + 26.239 + private long parentStart = 0; 26.240 + private long parentEnd = Integer.MAX_VALUE; 26.241 + 26.242 + @Override 26.243 + public Void scan(Tree node, Void p) { 26.244 + if (node == null) { 26.245 + return null; 26.246 + } 26.247 + 26.248 + long start = trees.getSourcePositions().getStartPosition(cut, node); 26.249 + 26.250 + if (start == (-1)) { 26.251 + return null; // synthetic tree 26.252 + } 26.253 + assertTrue(node.toString() + ":" + start + "/" + parentStart, 26.254 + parentStart <= start); 26.255 + 26.256 + long prevParentStart = parentStart; 26.257 + 26.258 + parentStart = start; 26.259 + 26.260 + long end = trees.getSourcePositions().getEndPosition(cut, node); 26.261 + 26.262 + assertTrue(node.toString() + ":" + end + "/" + parentEnd, 26.263 + end <= parentEnd); 26.264 + 26.265 + long prevParentEnd = parentEnd; 26.266 + 26.267 + parentEnd = end; 26.268 + 26.269 + super.scan(node, p); 26.270 + 26.271 + parentStart = prevParentStart; 26.272 + parentEnd = prevParentEnd; 26.273 + 26.274 + return null; 26.275 + } 26.276 + 26.277 + private void assertTrue(String message, boolean b) { 26.278 + if (!b) fail(message); 26.279 + } 26.280 + }.scan(cut, null); 26.281 + } 26.282 + 26.283 + @Test 26.284 + void testCorrectWilcardPositions1() throws IOException { 26.285 + performWildcardPositionsTest("package test; import java.util.List; " + 26.286 + "class Test { private void method() { List<? extends List<? extends String>> l; } }", 26.287 + 26.288 + Arrays.asList("List<? extends List<? extends String>> l;", 26.289 + "List<? extends List<? extends String>>", 26.290 + "List", 26.291 + "? extends List<? extends String>", 26.292 + "List<? extends String>", 26.293 + "List", 26.294 + "? extends String", 26.295 + "String")); 26.296 + } 26.297 + 26.298 + @Test 26.299 + void testCorrectWilcardPositions2() throws IOException { 26.300 + performWildcardPositionsTest("package test; import java.util.List; " 26.301 + + "class Test { private void method() { List<? super List<? super String>> l; } }", 26.302 + Arrays.asList("List<? super List<? super String>> l;", 26.303 + "List<? super List<? super String>>", 26.304 + "List", 26.305 + "? super List<? super String>", 26.306 + "List<? super String>", 26.307 + "List", 26.308 + "? super String", 26.309 + "String")); 26.310 + } 26.311 + 26.312 + @Test 26.313 + void testCorrectWilcardPositions3() throws IOException { 26.314 + performWildcardPositionsTest("package test; import java.util.List; " + 26.315 + "class Test { private void method() { List<? super List<?>> l; } }", 26.316 + 26.317 + Arrays.asList("List<? super List<?>> l;", 26.318 + "List<? super List<?>>", 26.319 + "List", 26.320 + "? super List<?>", 26.321 + "List<?>", 26.322 + "List", 26.323 + "?")); 26.324 + } 26.325 + 26.326 + @Test 26.327 + void testCorrectWilcardPositions4() throws IOException { 26.328 + performWildcardPositionsTest("package test; import java.util.List; " + 26.329 + "class Test { private void method() { " + 26.330 + "List<? extends List<? extends List<? extends String>>> l; } }", 26.331 + 26.332 + Arrays.asList("List<? extends List<? extends List<? extends String>>> l;", 26.333 + "List<? extends List<? extends List<? extends String>>>", 26.334 + "List", 26.335 + "? extends List<? extends List<? extends String>>", 26.336 + "List<? extends List<? extends String>>", 26.337 + "List", 26.338 + "? extends List<? extends String>", 26.339 + "List<? extends String>", 26.340 + "List", 26.341 + "? extends String", 26.342 + "String")); 26.343 + } 26.344 + 26.345 + @Test 26.346 + void testCorrectWilcardPositions5() throws IOException { 26.347 + performWildcardPositionsTest("package test; import java.util.List; " + 26.348 + "class Test { private void method() { " + 26.349 + "List<? extends List<? extends List<? extends String >>> l; } }", 26.350 + Arrays.asList("List<? extends List<? extends List<? extends String >>> l;", 26.351 + "List<? extends List<? extends List<? extends String >>>", 26.352 + "List", 26.353 + "? extends List<? extends List<? extends String >>", 26.354 + "List<? extends List<? extends String >>", 26.355 + "List", 26.356 + "? extends List<? extends String >", 26.357 + "List<? extends String >", 26.358 + "List", 26.359 + "? extends String", 26.360 + "String")); 26.361 + } 26.362 + 26.363 + void performWildcardPositionsTest(final String code, 26.364 + List<String> golden) throws IOException { 26.365 + 26.366 + final List<Diagnostic<? extends JavaFileObject>> errors = 26.367 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.368 + 26.369 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.370 + new DiagnosticListener<JavaFileObject>() { 26.371 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.372 + errors.add(diagnostic); 26.373 + } 26.374 + }, null, null, Arrays.asList(new MyFileObject(code))); 26.375 + 26.376 + final CompilationUnitTree cut = ct.parse().iterator().next(); 26.377 + final List<String> content = new LinkedList<String>(); 26.378 + final Trees trees = Trees.instance(ct); 26.379 + 26.380 + new TreeScanner<Void, Void>() { 26.381 + @Override 26.382 + public Void scan(Tree node, Void p) { 26.383 + if (node == null) { 26.384 + return null; 26.385 + } 26.386 + long start = trees.getSourcePositions().getStartPosition(cut, node); 26.387 + 26.388 + if (start == (-1)) { 26.389 + return null; // synthetic tree 26.390 + } 26.391 + long end = trees.getSourcePositions().getEndPosition(cut, node); 26.392 + String s = code.substring((int) start, (int) end); 26.393 + content.add(s); 26.394 + 26.395 + return super.scan(node, p); 26.396 + } 26.397 + }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); 26.398 + 26.399 + assertEquals("performWildcardPositionsTest",golden.toString(), 26.400 + content.toString()); 26.401 + } 26.402 + 26.403 + @Test 26.404 + void testStartPositionForMethodWithoutModifiers() throws IOException { 26.405 + 26.406 + String code = "package t; class Test { <T> void t() {} }"; 26.407 + 26.408 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.409 + null, Arrays.asList(new MyFileObject(code))); 26.410 + CompilationUnitTree cut = ct.parse().iterator().next(); 26.411 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.412 + MethodTree mt = (MethodTree) clazz.getMembers().get(0); 26.413 + Trees t = Trees.instance(ct); 26.414 + int start = (int) t.getSourcePositions().getStartPosition(cut, mt); 26.415 + int end = (int) t.getSourcePositions().getEndPosition(cut, mt); 26.416 + 26.417 + assertEquals("testStartPositionForMethodWithoutModifiers", 26.418 + "<T> void t() {}", code.substring(start, end)); 26.419 + } 26.420 + 26.421 + @Test 26.422 + void testVariableInIfThen1() throws IOException { 26.423 + 26.424 + String code = "package t; class Test { " + 26.425 + "private static void t(String name) { " + 26.426 + "if (name != null) String nn = name.trim(); } }"; 26.427 + 26.428 + DiagnosticCollector<JavaFileObject> coll = 26.429 + new DiagnosticCollector<JavaFileObject>(); 26.430 + 26.431 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.432 + null, Arrays.asList(new MyFileObject(code))); 26.433 + 26.434 + ct.parse(); 26.435 + 26.436 + List<String> codes = new LinkedList<String>(); 26.437 + 26.438 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.439 + codes.add(d.getCode()); 26.440 + } 26.441 + 26.442 + assertEquals("testVariableInIfThen1", 26.443 + Arrays.<String>asList("compiler.err.variable.not.allowed"), 26.444 + codes); 26.445 + } 26.446 + 26.447 + @Test 26.448 + void testVariableInIfThen2() throws IOException { 26.449 + 26.450 + String code = "package t; class Test { " + 26.451 + "private static void t(String name) { " + 26.452 + "if (name != null) class X {} } }"; 26.453 + DiagnosticCollector<JavaFileObject> coll = 26.454 + new DiagnosticCollector<JavaFileObject>(); 26.455 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.456 + null, Arrays.asList(new MyFileObject(code))); 26.457 + 26.458 + ct.parse(); 26.459 + 26.460 + List<String> codes = new LinkedList<String>(); 26.461 + 26.462 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.463 + codes.add(d.getCode()); 26.464 + } 26.465 + 26.466 + assertEquals("testVariableInIfThen2", 26.467 + Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.468 + } 26.469 + 26.470 + @Test 26.471 + void testVariableInIfThen3() throws IOException { 26.472 + 26.473 + String code = "package t; class Test { "+ 26.474 + "private static void t() { " + 26.475 + "if (true) abstract class F {} }}"; 26.476 + DiagnosticCollector<JavaFileObject> coll = 26.477 + new DiagnosticCollector<JavaFileObject>(); 26.478 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.479 + null, Arrays.asList(new MyFileObject(code))); 26.480 + 26.481 + ct.parse(); 26.482 + 26.483 + List<String> codes = new LinkedList<String>(); 26.484 + 26.485 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.486 + codes.add(d.getCode()); 26.487 + } 26.488 + 26.489 + assertEquals("testVariableInIfThen3", 26.490 + Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.491 + } 26.492 + 26.493 + @Test 26.494 + void testVariableInIfThen4() throws IOException { 26.495 + 26.496 + String code = "package t; class Test { "+ 26.497 + "private static void t(String name) { " + 26.498 + "if (name != null) interface X {} } }"; 26.499 + DiagnosticCollector<JavaFileObject> coll = 26.500 + new DiagnosticCollector<JavaFileObject>(); 26.501 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.502 + null, Arrays.asList(new MyFileObject(code))); 26.503 + 26.504 + ct.parse(); 26.505 + 26.506 + List<String> codes = new LinkedList<String>(); 26.507 + 26.508 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.509 + codes.add(d.getCode()); 26.510 + } 26.511 + 26.512 + assertEquals("testVariableInIfThen4", 26.513 + Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.514 + } 26.515 + 26.516 + @Test 26.517 + void testVariableInIfThen5() throws IOException { 26.518 + 26.519 + String code = "package t; class Test { "+ 26.520 + "private static void t() { " + 26.521 + "if (true) } }"; 26.522 + DiagnosticCollector<JavaFileObject> coll = 26.523 + new DiagnosticCollector<JavaFileObject>(); 26.524 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.525 + null, Arrays.asList(new MyFileObject(code))); 26.526 + 26.527 + ct.parse(); 26.528 + 26.529 + List<String> codes = new LinkedList<String>(); 26.530 + 26.531 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.532 + codes.add(d.getCode()); 26.533 + } 26.534 + 26.535 + assertEquals("testVariableInIfThen5", 26.536 + Arrays.<String>asList("compiler.err.illegal.start.of.stmt"), 26.537 + codes); 26.538 + } 26.539 + 26.540 + // see javac bug #6882235, NB bug #98234: 26.541 + @Test 26.542 + void testMissingExponent() throws IOException { 26.543 + 26.544 + String code = "\nclass Test { { System.err.println(0e); } }"; 26.545 + 26.546 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.547 + null, Arrays.asList(new MyFileObject(code))); 26.548 + 26.549 + assertNotNull(ct.parse().iterator().next()); 26.550 + } 26.551 + 26.552 + @Test 26.553 + void testTryResourcePos() throws IOException { 26.554 + 26.555 + final String code = "package t; class Test { " + 26.556 + "{ try (java.io.InputStream in = null) { } } }"; 26.557 + 26.558 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.559 + 26.560 + new TreeScanner<Void, Void>() { 26.561 + @Override 26.562 + public Void visitVariable(VariableTree node, Void p) { 26.563 + if ("in".contentEquals(node.getName())) { 26.564 + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 26.565 + assertEquals("testTryResourcePos", "in = null) { } } }", 26.566 + code.substring(var.pos)); 26.567 + } 26.568 + return super.visitVariable(node, p); 26.569 + } 26.570 + }.scan(cut, null); 26.571 + } 26.572 + 26.573 + @Test 26.574 + void testVarPos() throws IOException { 26.575 + 26.576 + final String code = "package t; class Test { " + 26.577 + "{ java.io.InputStream in = null; } }"; 26.578 + 26.579 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.580 + 26.581 + new TreeScanner<Void, Void>() { 26.582 + 26.583 + @Override 26.584 + public Void visitVariable(VariableTree node, Void p) { 26.585 + if ("in".contentEquals(node.getName())) { 26.586 + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 26.587 + assertEquals("testVarPos","in = null; } }", 26.588 + code.substring(var.pos)); 26.589 + } 26.590 + return super.visitVariable(node, p); 26.591 + } 26.592 + }.scan(cut, null); 26.593 + } 26.594 + 26.595 + // expected erroneous tree: int x = y;(ERROR); 26.596 + @Test 26.597 + void testOperatorMissingError() throws IOException { 26.598 + 26.599 + String code = "package test; public class ErrorTest { " 26.600 + + "void method() { int x = y z } }"; 26.601 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.602 + final List<String> values = new ArrayList<>(); 26.603 + final List<String> expectedValues = 26.604 + new ArrayList<>(Arrays.asList("[z]")); 26.605 + 26.606 + new TreeScanner<Void, Void>() { 26.607 + @Override 26.608 + public Void visitErroneous(ErroneousTree node, Void p) { 26.609 + values.add(getErroneousTreeValues(node).toString()); 26.610 + return null; 26.611 + 26.612 + } 26.613 + }.scan(cut, null); 26.614 + 26.615 + assertEquals("testSwitchError: The Erroneous tree " 26.616 + + "error values: " + values 26.617 + + " do not match expected error values: " 26.618 + + expectedValues, values, expectedValues); 26.619 + } 26.620 + 26.621 + // expected erroneous tree: String s = (ERROR); 26.622 + @Test 26.623 + void testMissingParenthesisError() throws IOException { 26.624 + 26.625 + String code = "package test; public class ErrorTest { " 26.626 + + "void f() {String s = new String; } }"; 26.627 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.628 + final List<String> values = new ArrayList<>(); 26.629 + final List<String> expectedValues = 26.630 + new ArrayList<>(Arrays.asList("[new String()]")); 26.631 + 26.632 + new TreeScanner<Void, Void>() { 26.633 + @Override 26.634 + public Void visitErroneous(ErroneousTree node, Void p) { 26.635 + values.add(getErroneousTreeValues(node).toString()); 26.636 + return null; 26.637 + } 26.638 + }.scan(cut, null); 26.639 + 26.640 + assertEquals("testSwitchError: The Erroneous tree " 26.641 + + "error values: " + values 26.642 + + " do not match expected error values: " 26.643 + + expectedValues, values, expectedValues); 26.644 + } 26.645 + 26.646 + // expected erroneous tree: package test; (ERROR)(ERROR) 26.647 + @Test 26.648 + void testMissingClassError() throws IOException { 26.649 + 26.650 + String code = "package Test; clas ErrorTest { " 26.651 + + "void f() {String s = new String(); } }"; 26.652 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.653 + final List<String> values = new ArrayList<>(); 26.654 + final List<String> expectedValues = 26.655 + new ArrayList<>(Arrays.asList("[, clas]", "[]")); 26.656 + 26.657 + new TreeScanner<Void, Void>() { 26.658 + @Override 26.659 + public Void visitErroneous(ErroneousTree node, Void p) { 26.660 + values.add(getErroneousTreeValues(node).toString()); 26.661 + return null; 26.662 + } 26.663 + }.scan(cut, null); 26.664 + 26.665 + assertEquals("testSwitchError: The Erroneous tree " 26.666 + + "error values: " + values 26.667 + + " do not match expected error values: " 26.668 + + expectedValues, values, expectedValues); 26.669 + } 26.670 + 26.671 + // expected erroneous tree: void m1(int i) {(ERROR);{(ERROR);} 26.672 + @Test 26.673 + void testSwitchError() throws IOException { 26.674 + 26.675 + String code = "package test; public class ErrorTest { " 26.676 + + "int numDays; void m1(int i) { switchh {i} { case 1: " 26.677 + + "numDays = 31; break; } } }"; 26.678 + CompilationUnitTree cut = getCompilationUnitTree(code); 26.679 + final List<String> values = new ArrayList<>(); 26.680 + final List<String> expectedValues = 26.681 + new ArrayList<>(Arrays.asList("[switchh]", "[i]")); 26.682 + 26.683 + new TreeScanner<Void, Void>() { 26.684 + @Override 26.685 + public Void visitErroneous(ErroneousTree node, Void p) { 26.686 + values.add(getErroneousTreeValues(node).toString()); 26.687 + return null; 26.688 + } 26.689 + }.scan(cut, null); 26.690 + 26.691 + assertEquals("testSwitchError: The Erroneous tree " 26.692 + + "error values: " + values 26.693 + + " do not match expected error values: " 26.694 + + expectedValues, values, expectedValues); 26.695 + } 26.696 + 26.697 + // expected erroneous tree: class ErrorTest {(ERROR) 26.698 + @Test 26.699 + void testMethodError() throws IOException { 26.700 + 26.701 + String code = "package Test; class ErrorTest { " 26.702 + + "static final void f) {String s = new String(); } }"; 26.703 + CompilationUnitTree cut = cut = getCompilationUnitTree(code); 26.704 + 26.705 + final List<String> values = new ArrayList<>(); 26.706 + final List<String> expectedValues = 26.707 + new ArrayList<>(Arrays.asList("[\nstatic final void f();]")); 26.708 + 26.709 + new TreeScanner<Void, Void>() { 26.710 + @Override 26.711 + public Void visitErroneous(ErroneousTree node, Void p) { 26.712 + values.add(normalize(getErroneousTreeValues(node).toString())); 26.713 + return null; 26.714 + } 26.715 + }.scan(cut, null); 26.716 + 26.717 + assertEquals("testMethodError: The Erroneous tree " 26.718 + + "error value: " + values 26.719 + + " does not match expected error values: " 26.720 + + expectedValues, values, expectedValues); 26.721 + } 26.722 + 26.723 + /* 26.724 + * The following tests do not work just yet with nb-javac nor javac, 26.725 + * they need further investigation, see CR: 7167356 26.726 + */ 26.727 + 26.728 + void testPositionBrokenSource126732a() throws IOException { 26.729 String[] commands = new String[]{ 26.730 "return Runnable()", 26.731 "do { } while (true)", 26.732 @@ -250,7 +838,7 @@ 26.733 } 26.734 } 26.735 26.736 - public void testPositionBrokenSource126732b() throws IOException { 26.737 + void testPositionBrokenSource126732b() throws IOException { 26.738 String[] commands = new String[]{ 26.739 "break", 26.740 "break A", 26.741 @@ -291,246 +879,7 @@ 26.742 } 26.743 } 26.744 26.745 - public void testErrorRecoveryForEnhancedForLoop142381() throws IOException { 26.746 - 26.747 - String code = "package test; class Test { " + 26.748 - "private void method() { " + 26.749 - "java.util.Set<String> s = null; for (a : s) {} } }"; 26.750 - 26.751 - final List<Diagnostic<? extends JavaFileObject>> errors = 26.752 - new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.753 - 26.754 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.755 - new DiagnosticListener<JavaFileObject>() { 26.756 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.757 - errors.add(diagnostic); 26.758 - } 26.759 - }, null, null, Arrays.asList(new MyFileObject(code))); 26.760 - 26.761 - CompilationUnitTree cut = ct.parse().iterator().next(); 26.762 - 26.763 - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.764 - StatementTree forStatement = 26.765 - ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); 26.766 - 26.767 - assertEquals("testErrorRecoveryForEnhancedForLoop142381", 26.768 - Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); 26.769 - assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); 26.770 - } 26.771 - 26.772 - public void testPositionAnnotationNoPackage187551() throws IOException { 26.773 - 26.774 - String code = "\n@interface Test {}"; 26.775 - 26.776 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.777 - null, Arrays.asList(new MyFileObject(code))); 26.778 - 26.779 - CompilationUnitTree cut = ct.parse().iterator().next(); 26.780 - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.781 - Trees t = Trees.instance(ct); 26.782 - 26.783 - assertEquals("testPositionAnnotationNoPackage187551", 26.784 - 1, t.getSourcePositions().getStartPosition(cut, clazz)); 26.785 - } 26.786 - 26.787 - public void testPositionsSane() throws IOException { 26.788 - performPositionsSanityTest("package test; class Test { " + 26.789 - "private void method() { " + 26.790 - "java.util.List<? extends java.util.List<? extends String>> l; " + 26.791 - "} }"); 26.792 - performPositionsSanityTest("package test; class Test { " + 26.793 - "private void method() { " + 26.794 - "java.util.List<? super java.util.List<? super String>> l; " + 26.795 - "} }"); 26.796 - performPositionsSanityTest("package test; class Test { " + 26.797 - "private void method() { " + 26.798 - "java.util.List<? super java.util.List<?>> l; } }"); 26.799 - } 26.800 - 26.801 - private void performPositionsSanityTest(String code) throws IOException { 26.802 - 26.803 - final List<Diagnostic<? extends JavaFileObject>> errors = 26.804 - new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.805 - 26.806 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.807 - new DiagnosticListener<JavaFileObject>() { 26.808 - 26.809 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.810 - errors.add(diagnostic); 26.811 - } 26.812 - }, null, null, Arrays.asList(new MyFileObject(code))); 26.813 - 26.814 - final CompilationUnitTree cut = ct.parse().iterator().next(); 26.815 - final Trees trees = Trees.instance(ct); 26.816 - 26.817 - new TreeScanner<Void, Void>() { 26.818 - 26.819 - private long parentStart = 0; 26.820 - private long parentEnd = Integer.MAX_VALUE; 26.821 - 26.822 - @Override 26.823 - public Void scan(Tree node, Void p) { 26.824 - if (node == null) { 26.825 - return null; 26.826 - } 26.827 - 26.828 - long start = trees.getSourcePositions().getStartPosition(cut, node); 26.829 - 26.830 - if (start == (-1)) { 26.831 - return null; //synthetic tree 26.832 - } 26.833 - assertTrue(node.toString() + ":" + start + "/" + parentStart, 26.834 - parentStart <= start); 26.835 - 26.836 - long prevParentStart = parentStart; 26.837 - 26.838 - parentStart = start; 26.839 - 26.840 - long end = trees.getSourcePositions().getEndPosition(cut, node); 26.841 - 26.842 - assertTrue(node.toString() + ":" + end + "/" + parentEnd, 26.843 - end <= parentEnd); 26.844 - 26.845 - long prevParentEnd = parentEnd; 26.846 - 26.847 - parentEnd = end; 26.848 - 26.849 - super.scan(node, p); 26.850 - 26.851 - parentStart = prevParentStart; 26.852 - parentEnd = prevParentEnd; 26.853 - 26.854 - return null; 26.855 - } 26.856 - 26.857 - private void assertTrue(String message, boolean b) { 26.858 - if (!b) fail(message); 26.859 - } 26.860 - }.scan(cut, null); 26.861 - } 26.862 - 26.863 - public void testCorrectWilcardPositions() throws IOException { 26.864 - performWildcardPositionsTest("package test; import java.util.List; " + 26.865 - "class Test { private void method() { List<? extends List<? extends String>> l; } }", 26.866 - 26.867 - Arrays.asList("List<? extends List<? extends String>> l;", 26.868 - "List<? extends List<? extends String>>", 26.869 - "List", 26.870 - "? extends List<? extends String>", 26.871 - "List<? extends String>", 26.872 - "List", 26.873 - "? extends String", 26.874 - "String")); 26.875 - performWildcardPositionsTest("package test; import java.util.List; " + 26.876 - "class Test { private void method() { List<? super List<? super String>> l; } }", 26.877 - 26.878 - Arrays.asList("List<? super List<? super String>> l;", 26.879 - "List<? super List<? super String>>", 26.880 - "List", 26.881 - "? super List<? super String>", 26.882 - "List<? super String>", 26.883 - "List", 26.884 - "? super String", 26.885 - "String")); 26.886 - performWildcardPositionsTest("package test; import java.util.List; " + 26.887 - "class Test { private void method() { List<? super List<?>> l; } }", 26.888 - 26.889 - Arrays.asList("List<? super List<?>> l;", 26.890 - "List<? super List<?>>", 26.891 - "List", 26.892 - "? super List<?>", 26.893 - "List<?>", 26.894 - "List", 26.895 - "?")); 26.896 - performWildcardPositionsTest("package test; import java.util.List; " + 26.897 - "class Test { private void method() { " + 26.898 - "List<? extends List<? extends List<? extends String>>> l; } }", 26.899 - 26.900 - Arrays.asList("List<? extends List<? extends List<? extends String>>> l;", 26.901 - "List<? extends List<? extends List<? extends String>>>", 26.902 - "List", 26.903 - "? extends List<? extends List<? extends String>>", 26.904 - "List<? extends List<? extends String>>", 26.905 - "List", 26.906 - "? extends List<? extends String>", 26.907 - "List<? extends String>", 26.908 - "List", 26.909 - "? extends String", 26.910 - "String")); 26.911 - performWildcardPositionsTest("package test; import java.util.List; " + 26.912 - "class Test { private void method() { " + 26.913 - "List<? extends List<? extends List<? extends String >>> l; } }", 26.914 - Arrays.asList("List<? extends List<? extends List<? extends String >>> l;", 26.915 - "List<? extends List<? extends List<? extends String >>>", 26.916 - "List", 26.917 - "? extends List<? extends List<? extends String >>", 26.918 - "List<? extends List<? extends String >>", 26.919 - "List", 26.920 - "? extends List<? extends String >", 26.921 - "List<? extends String >", 26.922 - "List", 26.923 - "? extends String", 26.924 - "String")); 26.925 - } 26.926 - 26.927 - public void performWildcardPositionsTest(final String code, 26.928 - List<String> golden) throws IOException { 26.929 - 26.930 - final List<Diagnostic<? extends JavaFileObject>> errors = 26.931 - new LinkedList<Diagnostic<? extends JavaFileObject>>(); 26.932 - 26.933 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 26.934 - new DiagnosticListener<JavaFileObject>() { 26.935 - public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 26.936 - errors.add(diagnostic); 26.937 - } 26.938 - }, null, null, Arrays.asList(new MyFileObject(code))); 26.939 - 26.940 - final CompilationUnitTree cut = ct.parse().iterator().next(); 26.941 - final List<String> content = new LinkedList<String>(); 26.942 - final Trees trees = Trees.instance(ct); 26.943 - 26.944 - new TreeScanner<Void, Void>() { 26.945 - @Override 26.946 - public Void scan(Tree node, Void p) { 26.947 - if (node == null) { 26.948 - return null; 26.949 - } 26.950 - long start = trees.getSourcePositions().getStartPosition(cut, node); 26.951 - 26.952 - if (start == (-1)) { 26.953 - return null; //synthetic tree 26.954 - } 26.955 - long end = trees.getSourcePositions().getEndPosition(cut, node); 26.956 - String s = code.substring((int) start, (int) end); 26.957 - content.add(s); 26.958 - 26.959 - return super.scan(node, p); 26.960 - } 26.961 - }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); 26.962 - 26.963 - assertEquals("performWildcardPositionsTest",golden.toString(), 26.964 - content.toString()); 26.965 - } 26.966 - 26.967 - public void testStartPositionForMethodWithoutModifiers() throws IOException { 26.968 - 26.969 - String code = "package t; class Test { <T> void t() {} }"; 26.970 - 26.971 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.972 - null, Arrays.asList(new MyFileObject(code))); 26.973 - CompilationUnitTree cut = ct.parse().iterator().next(); 26.974 - ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 26.975 - MethodTree mt = (MethodTree) clazz.getMembers().get(0); 26.976 - Trees t = Trees.instance(ct); 26.977 - int start = (int) t.getSourcePositions().getStartPosition(cut, mt); 26.978 - int end = (int) t.getSourcePositions().getEndPosition(cut, mt); 26.979 - 26.980 - assertEquals("testStartPositionForMethodWithoutModifiers", 26.981 - "<T> void t() {}", code.substring(start, end)); 26.982 - } 26.983 - 26.984 - public void testStartPositionEnumConstantInit() throws IOException { 26.985 + void testStartPositionEnumConstantInit() throws IOException { 26.986 26.987 String code = "package t; enum Test { AAA; }"; 26.988 26.989 @@ -546,342 +895,34 @@ 26.990 assertEquals("testStartPositionEnumConstantInit", -1, start); 26.991 } 26.992 26.993 - public void testVariableInIfThen1() throws IOException { 26.994 - 26.995 - String code = "package t; class Test { " + 26.996 - "private static void t(String name) { " + 26.997 - "if (name != null) String nn = name.trim(); } }"; 26.998 - 26.999 - DiagnosticCollector<JavaFileObject> coll = 26.1000 - new DiagnosticCollector<JavaFileObject>(); 26.1001 - 26.1002 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.1003 - null, Arrays.asList(new MyFileObject(code))); 26.1004 - 26.1005 - ct.parse(); 26.1006 - 26.1007 - List<String> codes = new LinkedList<String>(); 26.1008 - 26.1009 - for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.1010 - codes.add(d.getCode()); 26.1011 + void run(String[] args) throws Exception { 26.1012 + int passed = 0, failed = 0; 26.1013 + final Pattern p = (args != null && args.length > 0) 26.1014 + ? Pattern.compile(args[0]) 26.1015 + : null; 26.1016 + for (Method m : this.getClass().getDeclaredMethods()) { 26.1017 + boolean selected = (p == null) 26.1018 + ? m.isAnnotationPresent(Test.class) 26.1019 + : p.matcher(m.getName()).matches(); 26.1020 + if (selected) { 26.1021 + try { 26.1022 + m.invoke(this, (Object[]) null); 26.1023 + System.out.println(m.getName() + ": OK"); 26.1024 + passed++; 26.1025 + } catch (Throwable ex) { 26.1026 + System.out.printf("Test %s failed: %s %n", m, ex.getCause()); 26.1027 + failed++; 26.1028 + } 26.1029 + } 26.1030 } 26.1031 - 26.1032 - assertEquals("testVariableInIfThen1", 26.1033 - Arrays.<String>asList("compiler.err.variable.not.allowed"), 26.1034 - codes); 26.1035 - } 26.1036 - 26.1037 - public void testVariableInIfThen2() throws IOException { 26.1038 - 26.1039 - String code = "package t; class Test { " + 26.1040 - "private static void t(String name) { " + 26.1041 - "if (name != null) class X {} } }"; 26.1042 - DiagnosticCollector<JavaFileObject> coll = 26.1043 - new DiagnosticCollector<JavaFileObject>(); 26.1044 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.1045 - null, Arrays.asList(new MyFileObject(code))); 26.1046 - 26.1047 - ct.parse(); 26.1048 - 26.1049 - List<String> codes = new LinkedList<String>(); 26.1050 - 26.1051 - for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.1052 - codes.add(d.getCode()); 26.1053 + System.out.printf("Passed: %d, Failed %d%n", passed, failed); 26.1054 + if (failed > 0) { 26.1055 + throw new RuntimeException("Tests failed: " + failed); 26.1056 } 26.1057 - 26.1058 - assertEquals("testVariableInIfThen2", 26.1059 - Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.1060 - } 26.1061 - 26.1062 - public void testVariableInIfThen3() throws IOException { 26.1063 - 26.1064 - String code = "package t; class Test { "+ 26.1065 - "private static void t() { " + 26.1066 - "if (true) abstract class F {} }}"; 26.1067 - DiagnosticCollector<JavaFileObject> coll = 26.1068 - new DiagnosticCollector<JavaFileObject>(); 26.1069 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.1070 - null, Arrays.asList(new MyFileObject(code))); 26.1071 - 26.1072 - ct.parse(); 26.1073 - 26.1074 - List<String> codes = new LinkedList<String>(); 26.1075 - 26.1076 - for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.1077 - codes.add(d.getCode()); 26.1078 + if (passed == 0 && failed == 0) { 26.1079 + throw new AssertionError("No test(s) selected: passed = " + 26.1080 + passed + ", failed = " + failed + " ??????????"); 26.1081 } 26.1082 - 26.1083 - assertEquals("testVariableInIfThen3", 26.1084 - Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.1085 - } 26.1086 - 26.1087 - public void testVariableInIfThen4() throws IOException { 26.1088 - 26.1089 - String code = "package t; class Test { "+ 26.1090 - "private static void t(String name) { " + 26.1091 - "if (name != null) interface X {} } }"; 26.1092 - DiagnosticCollector<JavaFileObject> coll = 26.1093 - new DiagnosticCollector<JavaFileObject>(); 26.1094 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.1095 - null, Arrays.asList(new MyFileObject(code))); 26.1096 - 26.1097 - ct.parse(); 26.1098 - 26.1099 - List<String> codes = new LinkedList<String>(); 26.1100 - 26.1101 - for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.1102 - codes.add(d.getCode()); 26.1103 - } 26.1104 - 26.1105 - assertEquals("testVariableInIfThen4", 26.1106 - Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 26.1107 - } 26.1108 - 26.1109 - public void testVariableInIfThen5() throws IOException { 26.1110 - 26.1111 - String code = "package t; class Test { "+ 26.1112 - "private static void t() { " + 26.1113 - "if (true) } }"; 26.1114 - DiagnosticCollector<JavaFileObject> coll = 26.1115 - new DiagnosticCollector<JavaFileObject>(); 26.1116 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 26.1117 - null, Arrays.asList(new MyFileObject(code))); 26.1118 - 26.1119 - ct.parse(); 26.1120 - 26.1121 - List<String> codes = new LinkedList<String>(); 26.1122 - 26.1123 - for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 26.1124 - codes.add(d.getCode()); 26.1125 - } 26.1126 - 26.1127 - assertEquals("testVariableInIfThen5", 26.1128 - Arrays.<String>asList("compiler.err.illegal.start.of.stmt"), 26.1129 - codes); 26.1130 - } 26.1131 - 26.1132 - //see javac bug #6882235, NB bug #98234: 26.1133 - public void testMissingExponent() throws IOException { 26.1134 - 26.1135 - String code = "\nclass Test { { System.err.println(0e); } }"; 26.1136 - 26.1137 - JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 26.1138 - null, Arrays.asList(new MyFileObject(code))); 26.1139 - 26.1140 - assertNotNull(ct.parse().iterator().next()); 26.1141 - } 26.1142 - 26.1143 - public void testTryResourcePos() throws IOException { 26.1144 - 26.1145 - final String code = "package t; class Test { " + 26.1146 - "{ try (java.io.InputStream in = null) { } } }"; 26.1147 - 26.1148 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1149 - 26.1150 - new TreeScanner<Void, Void>() { 26.1151 - @Override 26.1152 - public Void visitVariable(VariableTree node, Void p) { 26.1153 - if ("in".contentEquals(node.getName())) { 26.1154 - JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 26.1155 - System.out.println(node.getName() + "," + var.pos); 26.1156 - assertEquals("testTryResourcePos", "in = null) { } } }", 26.1157 - code.substring(var.pos)); 26.1158 - } 26.1159 - return super.visitVariable(node, p); 26.1160 - } 26.1161 - }.scan(cut, null); 26.1162 - } 26.1163 - 26.1164 - public void testVarPos() throws IOException { 26.1165 - 26.1166 - final String code = "package t; class Test { " + 26.1167 - "{ java.io.InputStream in = null; } }"; 26.1168 - 26.1169 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1170 - 26.1171 - new TreeScanner<Void, Void>() { 26.1172 - 26.1173 - @Override 26.1174 - public Void visitVariable(VariableTree node, Void p) { 26.1175 - if ("in".contentEquals(node.getName())) { 26.1176 - JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 26.1177 - assertEquals("testVarPos","in = null; } }", 26.1178 - code.substring(var.pos)); 26.1179 - } 26.1180 - return super.visitVariable(node, p); 26.1181 - } 26.1182 - }.scan(cut, null); 26.1183 - } 26.1184 - 26.1185 - // expected erroneous tree: int x = y;(ERROR); 26.1186 - public void testOperatorMissingError() throws IOException { 26.1187 - 26.1188 - String code = "package test; public class ErrorTest { " 26.1189 - + "void method() { int x = y z } }"; 26.1190 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1191 - final List<String> values = new ArrayList<>(); 26.1192 - final List<String> expectedValues = 26.1193 - new ArrayList<>(Arrays.asList("[z]")); 26.1194 - 26.1195 - new TreeScanner<Void, Void>() { 26.1196 - 26.1197 - @Override 26.1198 - public Void visitErroneous(ErroneousTree node, Void p) { 26.1199 - 26.1200 - values.add(getErroneousTreeValues(node).toString()); 26.1201 - return null; 26.1202 - 26.1203 - } 26.1204 - }.scan(cut, null); 26.1205 - 26.1206 - assertEquals("testSwitchError: The Erroneous tree " 26.1207 - + "error values: " + values 26.1208 - + " do not match expected error values: " 26.1209 - + expectedValues, values, expectedValues); 26.1210 - } 26.1211 - 26.1212 - //expected erroneous tree: String s = (ERROR); 26.1213 - public void testMissingParenthesisError() throws IOException { 26.1214 - 26.1215 - String code = "package test; public class ErrorTest { " 26.1216 - + "void f() {String s = new String; } }"; 26.1217 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1218 - final List<String> values = new ArrayList<>(); 26.1219 - final List<String> expectedValues = 26.1220 - new ArrayList<>(Arrays.asList("[new String()]")); 26.1221 - 26.1222 - new TreeScanner<Void, Void>() { 26.1223 - 26.1224 - @Override 26.1225 - public Void visitErroneous(ErroneousTree node, Void p) { 26.1226 - 26.1227 - values.add(getErroneousTreeValues(node).toString()); 26.1228 - return null; 26.1229 - } 26.1230 - }.scan(cut, null); 26.1231 - 26.1232 - assertEquals("testSwitchError: The Erroneous tree " 26.1233 - + "error values: " + values 26.1234 - + " do not match expected error values: " 26.1235 - + expectedValues, values, expectedValues); 26.1236 - } 26.1237 - 26.1238 - //expected erroneous tree: package test; (ERROR)(ERROR) 26.1239 - public void testMissingClassError() throws IOException { 26.1240 - 26.1241 - String code = "package Test; clas ErrorTest { " 26.1242 - + "void f() {String s = new String(); } }"; 26.1243 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1244 - final List<String> values = new ArrayList<>(); 26.1245 - final List<String> expectedValues = 26.1246 - new ArrayList<>(Arrays.asList("[, clas]", "[]")); 26.1247 - 26.1248 - new TreeScanner<Void, Void>() { 26.1249 - 26.1250 - @Override 26.1251 - public Void visitErroneous(ErroneousTree node, Void p) { 26.1252 - 26.1253 - values.add(getErroneousTreeValues(node).toString()); 26.1254 - return null; 26.1255 - } 26.1256 - }.scan(cut, null); 26.1257 - 26.1258 - assertEquals("testSwitchError: The Erroneous tree " 26.1259 - + "error values: " + values 26.1260 - + " do not match expected error values: " 26.1261 - + expectedValues, values, expectedValues); 26.1262 - } 26.1263 - 26.1264 - //expected erroneous tree: void m1(int i) {(ERROR);{(ERROR);} 26.1265 - public void testSwitchError() throws IOException { 26.1266 - 26.1267 - String code = "package test; public class ErrorTest { " 26.1268 - + "int numDays; void m1(int i) { switchh {i} { case 1: " 26.1269 - + "numDays = 31; break; } } }"; 26.1270 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1271 - final List<String> values = new ArrayList<>(); 26.1272 - final List<String> expectedValues = 26.1273 - new ArrayList<>(Arrays.asList("[switchh]", "[i]")); 26.1274 - 26.1275 - new TreeScanner<Void, Void>() { 26.1276 - 26.1277 - @Override 26.1278 - public Void visitErroneous(ErroneousTree node, Void p) { 26.1279 - 26.1280 - values.add(getErroneousTreeValues(node).toString()); 26.1281 - return null; 26.1282 - } 26.1283 - }.scan(cut, null); 26.1284 - 26.1285 - assertEquals("testSwitchError: The Erroneous tree " 26.1286 - + "error values: " + values 26.1287 - + " do not match expected error values: " 26.1288 - + expectedValues, values, expectedValues); 26.1289 - } 26.1290 - 26.1291 - //expected erroneous tree: class ErrorTest {(ERROR) 26.1292 - public void testMethodError() throws IOException { 26.1293 - 26.1294 - String code = "package Test; class ErrorTest { " 26.1295 - + "static final void f) {String s = new String(); } }"; 26.1296 - CompilationUnitTree cut = getCompilationUnitTree(code); 26.1297 - final List<String> values = new ArrayList<>(); 26.1298 - final List<String> expectedValues = 26.1299 - new ArrayList<>(Arrays.asList("[\nstatic final void f();]")); 26.1300 - 26.1301 - new TreeScanner<Void, Void>() { 26.1302 - 26.1303 - @Override 26.1304 - public Void visitErroneous(ErroneousTree node, Void p) { 26.1305 - 26.1306 - values.add(normalize(getErroneousTreeValues(node).toString())); 26.1307 - return null; 26.1308 - } 26.1309 - }.scan(cut, null); 26.1310 - 26.1311 - assertEquals("testMethodError: The Erroneous tree " 26.1312 - + "error value: " + values 26.1313 - + " does not match expected error values: " 26.1314 - + expectedValues, values, expectedValues); 26.1315 - } 26.1316 - 26.1317 - void testsNotWorking() throws IOException { 26.1318 - 26.1319 - // Fails with nb-javac, needs further investigation 26.1320 - testPositionBrokenSource126732a(); 26.1321 - testPositionBrokenSource126732b(); 26.1322 - 26.1323 - // Fails, these tests yet to be addressed 26.1324 - testPositionForEnumModifiers(); 26.1325 - testStartPositionEnumConstantInit(); 26.1326 - } 26.1327 - void testPositions() throws IOException { 26.1328 - testPositionsSane(); 26.1329 - testCorrectWilcardPositions(); 26.1330 - testPositionAnnotationNoPackage187551(); 26.1331 - testPositionForSuperConstructorCalls(); 26.1332 - testPreferredPositionForBinaryOp(); 26.1333 - testStartPositionForMethodWithoutModifiers(); 26.1334 - testVarPos(); 26.1335 - testVariableInIfThen1(); 26.1336 - testVariableInIfThen2(); 26.1337 - testVariableInIfThen3(); 26.1338 - testVariableInIfThen4(); 26.1339 - testVariableInIfThen5(); 26.1340 - testMissingExponent(); 26.1341 - testTryResourcePos(); 26.1342 - testOperatorMissingError(); 26.1343 - testMissingParenthesisError(); 26.1344 - testMissingClassError(); 26.1345 - testSwitchError(); 26.1346 - testMethodError(); 26.1347 - testErrorRecoveryForEnhancedForLoop142381(); 26.1348 - } 26.1349 - 26.1350 - public static void main(String... args) throws IOException { 26.1351 - JavacParserTest jpt = new JavacParserTest("JavacParserTest"); 26.1352 - jpt.testPositions(); 26.1353 - System.out.println("PASS"); 26.1354 } 26.1355 } 26.1356 26.1357 @@ -906,8 +947,6 @@ 26.1358 } 26.1359 26.1360 void assertEquals(String message, Object o1, Object o2) { 26.1361 - System.out.println(o1); 26.1362 - System.out.println(o2); 26.1363 if (o1 != null && o2 != null && !o1.equals(o2)) { 26.1364 fail(message); 26.1365 } 26.1366 @@ -929,4 +968,11 @@ 26.1367 void fail(String message) { 26.1368 throw new RuntimeException(message); 26.1369 } 26.1370 + 26.1371 + /** 26.1372 + * Indicates that the annotated method is a test method. 26.1373 + */ 26.1374 + @Retention(RetentionPolicy.RUNTIME) 26.1375 + @Target(ElementType.METHOD) 26.1376 + public @interface Test {} 26.1377 }
27.1 --- a/test/tools/javac/tree/DocCommentToplevelTest.java Thu Jun 21 17:08:31 2012 -0700 27.2 +++ b/test/tools/javac/tree/DocCommentToplevelTest.java Mon Jun 25 21:39:16 2012 -0700 27.3 @@ -1,5 +1,5 @@ 27.4 /* 27.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 27.6 + * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 27.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.8 * 27.9 * This code is free software; you can redistribute it and/or modify it 27.10 @@ -29,6 +29,7 @@ 27.11 27.12 import com.sun.source.tree.*; 27.13 import com.sun.source.util.*; 27.14 +import com.sun.tools.javac.tree.DocCommentTable; 27.15 import com.sun.tools.javac.tree.JCTree; 27.16 27.17 import java.net.URI; 27.18 @@ -137,16 +138,16 @@ 27.19 27.20 new TreeScanner<ClassTree,Void>() { 27.21 27.22 - Map<JCTree, String> docComments; 27.23 + DocCommentTable docComments; 27.24 27.25 @Override 27.26 public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) { 27.27 docComments = ((JCTree.JCCompilationUnit)node).docComments; 27.28 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && 27.29 (pk != PackageKind.NO_PKG || ik != ImportKind.ZERO); 27.30 - boolean foundComment = docComments.get(node) != null; 27.31 + boolean foundComment = docComments.hasComment((JCTree) node); 27.32 if (expectedComment != foundComment) { 27.33 - error("Unexpected comment " + docComments.get(node) + " on toplevel"); 27.34 + error("Unexpected comment " + docComments.getComment((JCTree) node) + " on toplevel"); 27.35 } 27.36 return super.visitCompilationUnit(node, null); 27.37 } 27.38 @@ -156,9 +157,9 @@ 27.39 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && 27.40 pk == PackageKind.NO_PKG && ik == ImportKind.ZERO && 27.41 node.getSimpleName().toString().equals("First"); 27.42 - boolean foundComment = docComments.get(node) != null; 27.43 + boolean foundComment = docComments.hasComment((JCTree) node); 27.44 if (expectedComment != foundComment) { 27.45 - error("Unexpected comment " + docComments.get(node) + " on class " + node.getSimpleName()); 27.46 + error("Unexpected comment " + docComments.getComment((JCTree) node) + " on class " + node.getSimpleName()); 27.47 } 27.48 return super.visitClass(node, unused); 27.49 }
28.1 --- a/test/tools/javac/tree/TreePosTest.java Thu Jun 21 17:08:31 2012 -0700 28.2 +++ b/test/tools/javac/tree/TreePosTest.java Mon Jun 25 21:39:16 2012 -0700 28.3 @@ -1,5 +1,5 @@ 28.4 /* 28.5 - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 28.6 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.8 * 28.9 * This code is free software; you can redistribute it and/or modify it 28.10 @@ -73,7 +73,7 @@ 28.11 import com.sun.source.util.JavacTask; 28.12 import com.sun.tools.javac.api.JavacTool; 28.13 import com.sun.tools.javac.code.Flags; 28.14 -import com.sun.tools.javac.parser.EndPosTable; 28.15 +import com.sun.tools.javac.tree.EndPosTable; 28.16 import com.sun.tools.javac.tree.JCTree; 28.17 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 28.18 import com.sun.tools.javac.tree.JCTree.JCNewClass;