< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/DocCommentParser.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 171         loop:
 172         while (bp < buflen) {
 173             switch (ch) {
 174                 case '\n': case '\r': case '\f':
 175                     newline = true;
 176                     // fallthrough
 177 
 178                 case ' ': case '\t':
 179                     nextChar();
 180                     break;
 181 
 182                 case '&':
 183                     entity(trees);
 184                     break;
 185 
 186                 case '<':
 187                     newline = false;
 188                     if (isFileContent) {
 189                         switch (phase) {
 190                             case PREAMBLE:
 191                                 if (isEndPreamble()) {
 192                                     trees.add(html());
 193                                     if (textStart == -1) {
 194                                         textStart = bp;
 195                                         lastNonWhite = -1;
 196                                     }
 197                                     // mark this as the start, for processing purposes
 198                                     newline = true;
 199                                     break loop;
 200                                 }
 201                                 break;
 202                             case BODY:
 203                                 if (isEndBody()) {
 204                                     addPendingText(trees, lastNonWhite);
 205                                     break loop;
 206                                 }
 207                                 break;
 208                             default:
 209                                 // fallthrough
 210                         }
 211                     }
 212                     addPendingText(trees, bp - 1);
 213                     trees.add(html());
 214 
 215                     if (phase == Phase.PREAMBLE || phase == Phase.POSTAMBLE) {
 216                         break; // Ignore newlines after html tags, in the meta content
 217                     }
 218                     if (textStart == -1) {
 219                         textStart = bp;
 220                         lastNonWhite = -1;
 221                     }
 222                     break;
 223 


 768                 nextChar();
 769                 if (isHexDigit(ch)) {
 770                     nextChar();
 771                     while (isHexDigit(ch))
 772                         nextChar();
 773                     name = names.fromChars(buf, namep, bp - namep);
 774                 }
 775             }
 776         } else if (isIdentifierStart(ch)) {
 777             name = readIdentifier();
 778         }
 779 
 780         if (name == null)
 781             return erroneous("dc.bad.entity", p);
 782         else {
 783             if (ch != ';')
 784                 return erroneous("dc.missing.semicolon", p);
 785             nextChar();
 786             return m.at(p).newEntityTree(name);
 787         }
 788     }
 789 
 790     /**
 791      * Returns whether this is the end of the preamble of an HTML file.
 792      * The preamble ends with start of {@code body} element followed by
 793      * possible whitespace and the start of a {@code main} element.
 794      *
 795      * @return whether this is the end of the preamble
 796      */
 797     boolean isEndPreamble() {
 798         final int savedpos = bp;
 799         try {
 800             if (ch == '<')
 801                 nextChar();
 802 
 803             if (isIdentifierStart(ch)) {
 804                 String name = StringUtils.toLowerCase(readIdentifier().toString());
 805                 switch (name) {
 806                     case "body":
 807                         // Check if also followed by <main>
 808                         // 1. skip rest of <body>
 809                         while (ch != -1 && ch != '>') {
 810                             nextChar();
 811                         }
 812                         if (ch == '>') {
 813                             nextChar();
 814                         }
 815                         // 2. skip any whitespce
 816                         while (ch != -1 && Character.isWhitespace(ch)) {
 817                             nextChar();
 818                         }
 819                         // 3. check if looking at "<main..."
 820                         if (ch == '<') {
 821                             nextChar();
 822                             if (isIdentifierStart(ch)) {
 823                                 name = StringUtils.toLowerCase(readIdentifier().toString());
 824                                 if (name.equals("main")) {
 825                                     return false;
 826                                 }
 827                             }
 828                         }
 829                         // if <body> is _not_ followed by <main> then this is the
 830                         // end of the preamble
 831                         return true;
 832 
 833                     case "main":
 834                         // <main> is unconditionally the end of the preamble
 835                         return true;
 836                 }
 837             }
 838             return false;
 839         } finally {
 840             bp = savedpos;
 841             ch = buf[bp];
 842         }
 843     }
 844 
 845     /**
 846      * Returns whether this is the end of the main body of the content in a standalone
 847      * HTML file.
 848      * The content ends with the closing tag for a {@code main} or {@code body} element.
 849      *
 850      * @return whether this is the end of the main body of the content
 851      */
 852     boolean isEndBody() {
 853         final int savedpos = bp;
 854         try {
 855             if (ch == '<')
 856                 nextChar();
 857 
 858             if (ch == '/') {
 859                 nextChar();
 860                 if (isIdentifierStart(ch)) {
 861                     String name = StringUtils.toLowerCase(readIdentifier().toString());
 862                     switch (name) {
 863                         case "body":
 864                         case "main":
 865                             return true;
 866                     }
 867                 }
 868             }
 869 
 870             return false;
 871         } finally {
 872             bp = savedpos;
 873             ch = buf[bp];
 874         }
 875 
 876     }
 877 
 878     boolean peek(String s) {
 879         final int savedpos = bp;
 880         try {
 881             if (ch == '<')
 882                 nextChar();
 883 
 884             if (ch == '/') {
 885                 if (s.charAt(0) != ch) {
 886                     return false;
 887                 } else {
 888                     s = s.substring(1, s.length());
 889                     nextChar();
 890                 }
 891             }
 892 
 893             if (isIdentifierStart(ch)) {
 894                 Name name = readIdentifier();
 895                 return StringUtils.toLowerCase(name.toString()).equals(s);


   1 /*
   2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 171         loop:
 172         while (bp < buflen) {
 173             switch (ch) {
 174                 case '\n': case '\r': case '\f':
 175                     newline = true;
 176                     // fallthrough
 177 
 178                 case ' ': case '\t':
 179                     nextChar();
 180                     break;
 181 
 182                 case '&':
 183                     entity(trees);
 184                     break;
 185 
 186                 case '<':
 187                     newline = false;
 188                     if (isFileContent) {
 189                         switch (phase) {
 190                             case PREAMBLE:
 191                                 if (peek("body")) {
 192                                     trees.add(html());
 193                                     if (textStart == -1) {
 194                                         textStart = bp;
 195                                         lastNonWhite = -1;
 196                                     }
 197                                     // mark this as the start, for processing purposes
 198                                     newline = true;
 199                                     break loop;
 200                                 }
 201                                 break;
 202                             case BODY:
 203                                 if (peek("/body")) {
 204                                     addPendingText(trees, lastNonWhite);
 205                                     break loop;
 206                                 }
 207                                 break;
 208                             default:
 209                                 // fallthrough
 210                         }
 211                     }
 212                     addPendingText(trees, bp - 1);
 213                     trees.add(html());
 214 
 215                     if (phase == Phase.PREAMBLE || phase == Phase.POSTAMBLE) {
 216                         break; // Ignore newlines after html tags, in the meta content
 217                     }
 218                     if (textStart == -1) {
 219                         textStart = bp;
 220                         lastNonWhite = -1;
 221                     }
 222                     break;
 223 


 768                 nextChar();
 769                 if (isHexDigit(ch)) {
 770                     nextChar();
 771                     while (isHexDigit(ch))
 772                         nextChar();
 773                     name = names.fromChars(buf, namep, bp - namep);
 774                 }
 775             }
 776         } else if (isIdentifierStart(ch)) {
 777             name = readIdentifier();
 778         }
 779 
 780         if (name == null)
 781             return erroneous("dc.bad.entity", p);
 782         else {
 783             if (ch != ';')
 784                 return erroneous("dc.missing.semicolon", p);
 785             nextChar();
 786             return m.at(p).newEntityTree(name);
 787         }
























































































 788     }
 789 
 790     boolean peek(String s) {
 791         final int savedpos = bp;
 792         try {
 793             if (ch == '<')
 794                 nextChar();
 795 
 796             if (ch == '/') {
 797                 if (s.charAt(0) != ch) {
 798                     return false;
 799                 } else {
 800                     s = s.substring(1, s.length());
 801                     nextChar();
 802                 }
 803             }
 804 
 805             if (isIdentifierStart(ch)) {
 806                 Name name = readIdentifier();
 807                 return StringUtils.toLowerCase(name.toString()).equals(s);


< prev index next >