< prev index next >

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

Print this page




  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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.parser;
  27 
  28 import java.text.BreakIterator;
  29 import java.util.HashMap;
  30 import java.util.Map;
  31 
  32 import com.sun.source.doctree.AttributeTree.ValueKind;

  33 import com.sun.tools.javac.parser.DocCommentParser.TagParser.Kind;
  34 import com.sun.tools.javac.parser.Tokens.Comment;
  35 import com.sun.tools.javac.parser.Tokens.TokenKind;
  36 import com.sun.tools.javac.tree.DCTree;
  37 import com.sun.tools.javac.tree.DCTree.DCAttribute;
  38 import com.sun.tools.javac.tree.DCTree.DCDocComment;
  39 import com.sun.tools.javac.tree.DCTree.DCEndElement;
  40 import com.sun.tools.javac.tree.DCTree.DCEndPosTree;
  41 import com.sun.tools.javac.tree.DCTree.DCErroneous;
  42 import com.sun.tools.javac.tree.DCTree.DCIdentifier;
  43 import com.sun.tools.javac.tree.DCTree.DCReference;
  44 import com.sun.tools.javac.tree.DCTree.DCStartElement;
  45 import com.sun.tools.javac.tree.DCTree.DCText;
  46 import com.sun.tools.javac.tree.DocTreeMaker;
  47 import com.sun.tools.javac.tree.JCTree;
  48 import com.sun.tools.javac.util.DiagnosticSource;
  49 import com.sun.tools.javac.util.List;
  50 import com.sun.tools.javac.util.ListBuffer;
  51 import com.sun.tools.javac.util.Log;
  52 import com.sun.tools.javac.util.Name;


1305             },
1306 
1307             // {@linkplain package.class#member label}
1308             new TagParser(Kind.INLINE, DCTree.Kind.LINK_PLAIN) {
1309                 public DCTree parse(int pos) throws ParseException {
1310                     DCReference ref = reference(true);
1311                     List<DCTree> label = inlineContent();
1312                     return m.at(pos).newLinkPlainTree(ref, label);
1313                 }
1314             },
1315 
1316             // {@literal text}
1317             new TagParser(Kind.INLINE, DCTree.Kind.LITERAL, true) {
1318                 public DCTree parse(int pos) throws ParseException {
1319                     DCTree text = inlineText(WhitespaceRetentionPolicy.REMOVE_FIRST_SPACE);
1320                     nextChar();
1321                     return m.at(pos).newLiteralTree((DCText) text);
1322                 }
1323             },
1324 






1325             // @param parameter-name description
1326             new TagParser(Kind.BLOCK, DCTree.Kind.PARAM) {
1327                 public DCTree parse(int pos) throws ParseException {
1328                     skipWhitespace();
1329 
1330                     boolean typaram = false;
1331                     if (ch == '<') {
1332                         typaram = true;
1333                         nextChar();
1334                     }
1335 
1336                     DCIdentifier id = identifier();
1337 
1338                     if (typaram) {
1339                         if (ch != '>')
1340                             throw new ParseException("dc.gt.expected");
1341                         nextChar();
1342                     }
1343 
1344                     skipWhitespace();


1510                     nextChar();
1511                     throw new ParseException("dc.unexpected.content");
1512                 }
1513             },
1514 
1515             // @version version-text
1516             new TagParser(Kind.BLOCK, DCTree.Kind.VERSION) {
1517                 public DCTree parse(int pos) {
1518                     List<DCTree> description = blockContent();
1519                     return m.at(pos).newVersionTree(description);
1520                 }
1521             },
1522         };
1523 
1524         tagParsers = new HashMap<>();
1525         for (TagParser p: parsers)
1526             tagParsers.put(names.fromString(p.getTreeKind().tagName), p);
1527 
1528     }
1529 










1530 }


  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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.parser;
  27 
  28 import java.text.BreakIterator;
  29 import java.util.HashMap;
  30 import java.util.Map;
  31 
  32 import com.sun.source.doctree.AttributeTree.ValueKind;
  33 import com.sun.source.doctree.DocTree;
  34 import com.sun.tools.javac.parser.DocCommentParser.TagParser.Kind;
  35 import com.sun.tools.javac.parser.Tokens.Comment;
  36 import com.sun.tools.javac.parser.Tokens.TokenKind;
  37 import com.sun.tools.javac.tree.DCTree;
  38 import com.sun.tools.javac.tree.DCTree.DCAttribute;
  39 import com.sun.tools.javac.tree.DCTree.DCDocComment;
  40 import com.sun.tools.javac.tree.DCTree.DCEndElement;
  41 import com.sun.tools.javac.tree.DCTree.DCEndPosTree;
  42 import com.sun.tools.javac.tree.DCTree.DCErroneous;
  43 import com.sun.tools.javac.tree.DCTree.DCIdentifier;
  44 import com.sun.tools.javac.tree.DCTree.DCReference;
  45 import com.sun.tools.javac.tree.DCTree.DCStartElement;
  46 import com.sun.tools.javac.tree.DCTree.DCText;
  47 import com.sun.tools.javac.tree.DocTreeMaker;
  48 import com.sun.tools.javac.tree.JCTree;
  49 import com.sun.tools.javac.util.DiagnosticSource;
  50 import com.sun.tools.javac.util.List;
  51 import com.sun.tools.javac.util.ListBuffer;
  52 import com.sun.tools.javac.util.Log;
  53 import com.sun.tools.javac.util.Name;


1306             },
1307 
1308             // {@linkplain package.class#member label}
1309             new TagParser(Kind.INLINE, DCTree.Kind.LINK_PLAIN) {
1310                 public DCTree parse(int pos) throws ParseException {
1311                     DCReference ref = reference(true);
1312                     List<DCTree> label = inlineContent();
1313                     return m.at(pos).newLinkPlainTree(ref, label);
1314                 }
1315             },
1316 
1317             // {@literal text}
1318             new TagParser(Kind.INLINE, DCTree.Kind.LITERAL, true) {
1319                 public DCTree parse(int pos) throws ParseException {
1320                     DCTree text = inlineText(WhitespaceRetentionPolicy.REMOVE_FIRST_SPACE);
1321                     nextChar();
1322                     return m.at(pos).newLiteralTree((DCText) text);
1323                 }
1324             },
1325 
1326             // {@getter text}
1327             new AccessorParser(DCTree.Kind.GETTER),
1328 
1329             // {@getter text}
1330             new AccessorParser(DCTree.Kind.SETTER),
1331 
1332             // @param parameter-name description
1333             new TagParser(Kind.BLOCK, DCTree.Kind.PARAM) {
1334                 public DCTree parse(int pos) throws ParseException {
1335                     skipWhitespace();
1336 
1337                     boolean typaram = false;
1338                     if (ch == '<') {
1339                         typaram = true;
1340                         nextChar();
1341                     }
1342 
1343                     DCIdentifier id = identifier();
1344 
1345                     if (typaram) {
1346                         if (ch != '>')
1347                             throw new ParseException("dc.gt.expected");
1348                         nextChar();
1349                     }
1350 
1351                     skipWhitespace();


1517                     nextChar();
1518                     throw new ParseException("dc.unexpected.content");
1519                 }
1520             },
1521 
1522             // @version version-text
1523             new TagParser(Kind.BLOCK, DCTree.Kind.VERSION) {
1524                 public DCTree parse(int pos) {
1525                     List<DCTree> description = blockContent();
1526                     return m.at(pos).newVersionTree(description);
1527                 }
1528             },
1529         };
1530 
1531         tagParsers = new HashMap<>();
1532         for (TagParser p: parsers)
1533             tagParsers.put(names.fromString(p.getTreeKind().tagName), p);
1534 
1535     }
1536 
1537     class AccessorParser extends TagParser {
1538         AccessorParser(DocTree.Kind kind) {
1539             super(Kind.BLOCK, kind, true);
1540         }
1541 
1542         public DCTree parse(int pos) throws ParseException {
1543             List<DCTree> desc = blockContent();
1544             return m.at(pos).newAccessorTree(treeKind, desc);
1545         }
1546     }
1547 }
< prev index next >