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. |
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 } |