langtools/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java
changeset 46184 f1325703ea85
parent 43374 d312a15c5fcf
equal deleted inserted replaced
46183:5091e36e106b 46184:f1325703ea85
    68 import com.sun.source.doctree.ReturnTree;
    68 import com.sun.source.doctree.ReturnTree;
    69 import com.sun.source.doctree.SerialDataTree;
    69 import com.sun.source.doctree.SerialDataTree;
    70 import com.sun.source.doctree.SerialFieldTree;
    70 import com.sun.source.doctree.SerialFieldTree;
    71 import com.sun.source.doctree.SinceTree;
    71 import com.sun.source.doctree.SinceTree;
    72 import com.sun.source.doctree.StartElementTree;
    72 import com.sun.source.doctree.StartElementTree;
       
    73 import com.sun.source.doctree.SummaryTree;
    73 import com.sun.source.doctree.TextTree;
    74 import com.sun.source.doctree.TextTree;
    74 import com.sun.source.doctree.ThrowsTree;
    75 import com.sun.source.doctree.ThrowsTree;
    75 import com.sun.source.doctree.UnknownBlockTagTree;
    76 import com.sun.source.doctree.UnknownBlockTagTree;
    76 import com.sun.source.doctree.UnknownInlineTagTree;
    77 import com.sun.source.doctree.UnknownInlineTagTree;
    77 import com.sun.source.doctree.UsesTree;
    78 import com.sun.source.doctree.UsesTree;
   105     Set<Element> foundParams = new HashSet<>();
   106     Set<Element> foundParams = new HashSet<>();
   106     Set<TypeMirror> foundThrows = new HashSet<>();
   107     Set<TypeMirror> foundThrows = new HashSet<>();
   107     Map<Element, Set<String>> foundAnchors = new HashMap<>();
   108     Map<Element, Set<String>> foundAnchors = new HashMap<>();
   108     boolean foundInheritDoc = false;
   109     boolean foundInheritDoc = false;
   109     boolean foundReturn = false;
   110     boolean foundReturn = false;
       
   111     boolean hasNonWhitespaceText = false;
   110 
   112 
   111     public enum Flag {
   113     public enum Flag {
   112         TABLE_HAS_CAPTION,
   114         TABLE_HAS_CAPTION,
   113         HAS_ELEMENT,
   115         HAS_ELEMENT,
   114         HAS_HEADING,
   116         HAS_HEADING,
   187 
   189 
   188         foundParams.clear();
   190         foundParams.clear();
   189         foundThrows.clear();
   191         foundThrows.clear();
   190         foundInheritDoc = false;
   192         foundInheritDoc = false;
   191         foundReturn = false;
   193         foundReturn = false;
       
   194         hasNonWhitespaceText = false;
   192 
   195 
   193         scan(new DocTreePath(p, tree), null);
   196         scan(new DocTreePath(p, tree), null);
   194 
   197 
   195         if (!isOverridingMethod) {
   198         if (!isOverridingMethod) {
   196             switch (env.currElement.getKind()) {
   199             switch (env.currElement.getKind()) {
   243 
   246 
   244     // <editor-fold defaultstate="collapsed" desc="Text and entities.">
   247     // <editor-fold defaultstate="collapsed" desc="Text and entities.">
   245 
   248 
   246     @Override @DefinedBy(Api.COMPILER_TREE)
   249     @Override @DefinedBy(Api.COMPILER_TREE)
   247     public Void visitText(TextTree tree, Void ignore) {
   250     public Void visitText(TextTree tree, Void ignore) {
   248         if (hasNonWhitespace(tree)) {
   251         hasNonWhitespaceText = hasNonWhitespace(tree);
       
   252         if (hasNonWhitespaceText) {
   249             checkAllowsText(tree);
   253             checkAllowsText(tree);
   250             markEnclosingTag(Flag.HAS_TEXT);
   254             markEnclosingTag(Flag.HAS_TEXT);
   251         }
   255         }
   252         return null;
   256         return null;
   253     }
   257     }
   904         warnIfEmpty(tree, tree.getBody());
   908         warnIfEmpty(tree, tree.getBody());
   905         return super.visitSince(tree, ignore);
   909         return super.visitSince(tree, ignore);
   906     }
   910     }
   907 
   911 
   908     @Override @DefinedBy(Api.COMPILER_TREE)
   912     @Override @DefinedBy(Api.COMPILER_TREE)
       
   913     public Void visitSummary(SummaryTree node, Void aVoid) {
       
   914         int idx = env.currDocComment.getFullBody().indexOf(node);
       
   915         // Warn if the node is preceded by non-whitespace characters,
       
   916         // or other non-text nodes.
       
   917         if ((idx == 1 && hasNonWhitespaceText) || idx > 1) {
       
   918             env.messages.warning(SYNTAX, node, "dc.invalid.summary", node.getTagName());
       
   919         }
       
   920         return super.visitSummary(node, aVoid);
       
   921     }
       
   922 
       
   923     @Override @DefinedBy(Api.COMPILER_TREE)
   909     public Void visitThrows(ThrowsTree tree, Void ignore) {
   924     public Void visitThrows(ThrowsTree tree, Void ignore) {
   910         ReferenceTree exName = tree.getExceptionName();
   925         ReferenceTree exName = tree.getExceptionName();
   911         Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
   926         Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName));
   912         if (ex == null) {
   927         if (ex == null) {
   913             env.messages.error(REFERENCE, tree, "dc.ref.not.found");
   928             env.messages.error(REFERENCE, tree, "dc.ref.not.found");
  1089     }
  1104     }
  1090 
  1105 
  1091     boolean hasNonWhitespace(TextTree tree) {
  1106     boolean hasNonWhitespace(TextTree tree) {
  1092         String s = tree.getBody();
  1107         String s = tree.getBody();
  1093         for (int i = 0; i < s.length(); i++) {
  1108         for (int i = 0; i < s.length(); i++) {
       
  1109             Character c = s.charAt(i);
  1094             if (!Character.isWhitespace(s.charAt(i)))
  1110             if (!Character.isWhitespace(s.charAt(i)))
  1095                 return true;
  1111                 return true;
  1096         }
  1112         }
  1097         return false;
  1113         return false;
  1098     }
  1114     }