PoorDocCommentTable.java revision 3233:b5d08bc0d224
1283625Sdim/*
2283625Sdim * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3283625Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4283625Sdim *
5283625Sdim * This code is free software; you can redistribute it and/or modify it
6283625Sdim * under the terms of the GNU General Public License version 2 only, as
7283625Sdim * published by the Free Software Foundation.
8283625Sdim *
9283625Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10283625Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11283625Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12283625Sdim * version 2 for more details (a copy is included in the LICENSE file that
13283625Sdim * accompanied this code).
14283625Sdim *
15283625Sdim * You should have received a copy of the GNU General Public License version
16283625Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17283625Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18283625Sdim *
19283625Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20283625Sdim * or visit www.oracle.com if you need additional information or have any
21283625Sdim * questions.
22283625Sdim */
23283625Sdim
24283625Sdimpackage sampleapi.util;
25283625Sdim
26283625Sdimimport java.util.HashMap;
27283625Sdim
28283625Sdimimport com.sun.tools.javac.parser.Tokens.Comment;
29283625Sdimimport com.sun.tools.javac.tree.DCTree.DCDocComment;
30283625Sdimimport com.sun.tools.javac.tree.DocCommentTable;
31283625Sdimimport com.sun.tools.javac.tree.JCTree;
32283625Sdim
33283625Sdim/*
34283625Sdim * This class is replica of LazyDocCommentTable from com.sun.tools.javac.parser
35283625Sdim * package. It's created due to restrictions of LazyDocCommentTable (cannot be
36283625Sdim * used outside the package) and implements minimal functionality necessary
37283625Sdim * for doc comment generation purposes.
38283625Sdim */
39283625Sdimpublic class PoorDocCommentTable implements DocCommentTable {
40283625Sdim
41283625Sdim    HashMap<JCTree, Comment> table;
42283625Sdim
43283625Sdim    public PoorDocCommentTable() {
44283625Sdim        table = new HashMap<>();
45283625Sdim    }
46296417Sdim
47296417Sdim    public boolean hasComment(JCTree tree) {
48283625Sdim        return table.containsKey(tree);
49296417Sdim    }
50296417Sdim
51296417Sdim    public Comment getComment(JCTree tree) {
52283625Sdim        return table.get(tree);
53283625Sdim    }
54283625Sdim
55283625Sdim    public String getCommentText(JCTree tree) {
56283625Sdim        Comment c = getComment(tree);
57283625Sdim        return (c == null) ? null : c.getText();
58283625Sdim    }
59283625Sdim
60283625Sdim    public DCDocComment getCommentTree(JCTree tree) {
61283625Sdim        return null; // no need for generator purposes, Pretty does not call it
62283625Sdim    }
63283625Sdim
64283625Sdim    public void putComment(JCTree tree, Comment c) {
65283625Sdim        table.put(tree, c);
66283625Sdim    }
67296417Sdim}
68296417Sdim