test/tools/javac/tree/DocCommentToplevelTest.java

changeset 1280
5c0b3faeb0b0
parent 1113
d346ab55031b
child 2525
2eb010b6cb22
equal deleted inserted replaced
1279:34e254ffd0e7 1280:5c0b3faeb0b0
1 /* 1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
27 * @summary Javac tokens should retain state 27 * @summary Javac tokens should retain state
28 */ 28 */
29 29
30 import com.sun.source.tree.*; 30 import com.sun.source.tree.*;
31 import com.sun.source.util.*; 31 import com.sun.source.util.*;
32 import com.sun.tools.javac.tree.DocCommentTable;
32 import com.sun.tools.javac.tree.JCTree; 33 import com.sun.tools.javac.tree.JCTree;
33 34
34 import java.net.URI; 35 import java.net.URI;
35 import java.util.*; 36 import java.util.*;
36 import javax.tools.*; 37 import javax.tools.*;
135 void check(CompilationUnitTree cu) { 136 void check(CompilationUnitTree cu) {
136 checks++; 137 checks++;
137 138
138 new TreeScanner<ClassTree,Void>() { 139 new TreeScanner<ClassTree,Void>() {
139 140
140 Map<JCTree, String> docComments; 141 DocCommentTable docComments;
141 142
142 @Override 143 @Override
143 public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) { 144 public ClassTree visitCompilationUnit(CompilationUnitTree node, Void unused) {
144 docComments = ((JCTree.JCCompilationUnit)node).docComments; 145 docComments = ((JCTree.JCCompilationUnit)node).docComments;
145 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && 146 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
146 (pk != PackageKind.NO_PKG || ik != ImportKind.ZERO); 147 (pk != PackageKind.NO_PKG || ik != ImportKind.ZERO);
147 boolean foundComment = docComments.get(node) != null; 148 boolean foundComment = docComments.hasComment((JCTree) node);
148 if (expectedComment != foundComment) { 149 if (expectedComment != foundComment) {
149 error("Unexpected comment " + docComments.get(node) + " on toplevel"); 150 error("Unexpected comment " + docComments.getComment((JCTree) node) + " on toplevel");
150 } 151 }
151 return super.visitCompilationUnit(node, null); 152 return super.visitCompilationUnit(node, null);
152 } 153 }
153 154
154 @Override 155 @Override
155 public ClassTree visitClass(ClassTree node, Void unused) { 156 public ClassTree visitClass(ClassTree node, Void unused) {
156 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC && 157 boolean expectedComment = tdk == ToplevelDocKind.HAS_DOC &&
157 pk == PackageKind.NO_PKG && ik == ImportKind.ZERO && 158 pk == PackageKind.NO_PKG && ik == ImportKind.ZERO &&
158 node.getSimpleName().toString().equals("First"); 159 node.getSimpleName().toString().equals("First");
159 boolean foundComment = docComments.get(node) != null; 160 boolean foundComment = docComments.hasComment((JCTree) node);
160 if (expectedComment != foundComment) { 161 if (expectedComment != foundComment) {
161 error("Unexpected comment " + docComments.get(node) + " on class " + node.getSimpleName()); 162 error("Unexpected comment " + docComments.getComment((JCTree) node) + " on class " + node.getSimpleName());
162 } 163 }
163 return super.visitClass(node, unused); 164 return super.visitClass(node, unused);
164 } 165 }
165 }.scan(cu, null); 166 }.scan(cu, null);
166 } 167 }

mercurial