src/share/jaxws_classes/com/sun/codemodel/internal/JDocComment.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.codemodel.internal;
aoqi@0 27
aoqi@0 28 import java.util.HashMap;
aoqi@0 29 import java.util.Map;
aoqi@0 30
aoqi@0 31 /**
aoqi@0 32 * JavaDoc comment.
aoqi@0 33 *
aoqi@0 34 * <p>
aoqi@0 35 * A javadoc comment consists of multiple parts. There's the main part (that comes the first in
aoqi@0 36 * in the comment section), then the parameter parts (@param), the return part (@return),
aoqi@0 37 * and the throws parts (@throws).
aoqi@0 38 *
aoqi@0 39 * TODO: it would be nice if we have JComment class and we can derive this class from there.
aoqi@0 40 */
aoqi@0 41 public class JDocComment extends JCommentPart implements JGenerable {
aoqi@0 42
aoqi@0 43 private static final long serialVersionUID = 1L;
aoqi@0 44
aoqi@0 45 /** list of @param tags */
aoqi@0 46 private final Map<String,JCommentPart> atParams = new HashMap<String,JCommentPart>();
aoqi@0 47
aoqi@0 48 /** list of xdoclets */
aoqi@0 49 private final Map<String,Map<String,String>> atXdoclets = new HashMap<String,Map<String,String>>();
aoqi@0 50
aoqi@0 51 /** list of @throws tags */
aoqi@0 52 private final Map<JClass,JCommentPart> atThrows = new HashMap<JClass,JCommentPart>();
aoqi@0 53
aoqi@0 54 /**
aoqi@0 55 * The @return tag part.
aoqi@0 56 */
aoqi@0 57 private JCommentPart atReturn = null;
aoqi@0 58
aoqi@0 59 /** The @deprecated tag */
aoqi@0 60 private JCommentPart atDeprecated = null;
aoqi@0 61
aoqi@0 62 private final JCodeModel owner;
aoqi@0 63
aoqi@0 64
aoqi@0 65 public JDocComment(JCodeModel owner) {
aoqi@0 66 this.owner = owner;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 public JDocComment append(Object o) {
aoqi@0 70 add(o);
aoqi@0 71 return this;
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 /**
aoqi@0 75 * Append a text to a @param tag to the javadoc
aoqi@0 76 */
aoqi@0 77 public JCommentPart addParam( String param ) {
aoqi@0 78 JCommentPart p = atParams.get(param);
aoqi@0 79 if(p==null)
aoqi@0 80 atParams.put(param,p=new JCommentPart());
aoqi@0 81 return p;
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 /**
aoqi@0 85 * Append a text to an @param tag.
aoqi@0 86 */
aoqi@0 87 public JCommentPart addParam( JVar param ) {
aoqi@0 88 return addParam( param.name() );
aoqi@0 89 }
aoqi@0 90
aoqi@0 91
aoqi@0 92 /**
aoqi@0 93 * add an @throws tag to the javadoc
aoqi@0 94 */
aoqi@0 95 public JCommentPart addThrows( Class<? extends Throwable> exception ) {
aoqi@0 96 return addThrows( owner.ref(exception) );
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 /**
aoqi@0 100 * add an @throws tag to the javadoc
aoqi@0 101 */
aoqi@0 102 public JCommentPart addThrows( JClass exception ) {
aoqi@0 103 JCommentPart p = atThrows.get(exception);
aoqi@0 104 if(p==null)
aoqi@0 105 atThrows.put(exception,p=new JCommentPart());
aoqi@0 106 return p;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 /**
aoqi@0 110 * Appends a text to @return tag.
aoqi@0 111 */
aoqi@0 112 public JCommentPart addReturn() {
aoqi@0 113 if(atReturn==null)
aoqi@0 114 atReturn = new JCommentPart();
aoqi@0 115 return atReturn;
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 /**
aoqi@0 119 * add an @deprecated tag to the javadoc, with the associated message.
aoqi@0 120 */
aoqi@0 121 public JCommentPart addDeprecated() {
aoqi@0 122 if(atDeprecated==null)
aoqi@0 123 atDeprecated = new JCommentPart();
aoqi@0 124 return atDeprecated;
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 /**
aoqi@0 128 * add an xdoclet.
aoqi@0 129 */
aoqi@0 130 public Map<String,String> addXdoclet(String name) {
aoqi@0 131 Map<String,String> p = atXdoclets.get(name);
aoqi@0 132 if(p==null)
aoqi@0 133 atXdoclets.put(name,p=new HashMap<String,String>());
aoqi@0 134 return p;
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 /**
aoqi@0 138 * add an xdoclet.
aoqi@0 139 */
aoqi@0 140 public Map<String,String> addXdoclet(String name, Map<String,String> attributes) {
aoqi@0 141 Map<String,String> p = atXdoclets.get(name);
aoqi@0 142 if(p==null)
aoqi@0 143 atXdoclets.put(name,p=new HashMap<String,String>());
aoqi@0 144 p.putAll(attributes);
aoqi@0 145 return p;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 /**
aoqi@0 149 * add an xdoclet.
aoqi@0 150 */
aoqi@0 151 public Map<String,String> addXdoclet(String name, String attribute, String value) {
aoqi@0 152 Map<String,String> p = atXdoclets.get(name);
aoqi@0 153 if(p==null)
aoqi@0 154 atXdoclets.put(name,p=new HashMap<String,String>());
aoqi@0 155 p.put(attribute, value);
aoqi@0 156 return p;
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 public void generate(JFormatter f) {
aoqi@0 160 // I realized that we can't use StringTokenizer because
aoqi@0 161 // this will recognize multiple \n as one token.
aoqi@0 162
aoqi@0 163 f.p("/**").nl();
aoqi@0 164
aoqi@0 165 format(f," * ");
aoqi@0 166
aoqi@0 167 f.p(" * ").nl();
aoqi@0 168 for (Map.Entry<String,JCommentPart> e : atParams.entrySet()) {
aoqi@0 169 f.p(" * @param ").p(e.getKey()).nl();
aoqi@0 170 e.getValue().format(f,INDENT);
aoqi@0 171 }
aoqi@0 172 if( atReturn != null ) {
aoqi@0 173 f.p(" * @return").nl();
aoqi@0 174 atReturn.format(f,INDENT);
aoqi@0 175 }
aoqi@0 176 for (Map.Entry<JClass,JCommentPart> e : atThrows.entrySet()) {
aoqi@0 177 f.p(" * @throws ").t(e.getKey()).nl();
aoqi@0 178 e.getValue().format(f,INDENT);
aoqi@0 179 }
aoqi@0 180 if( atDeprecated != null ) {
aoqi@0 181 f.p(" * @deprecated").nl();
aoqi@0 182 atDeprecated.format(f,INDENT);
aoqi@0 183 }
aoqi@0 184 for (Map.Entry<String,Map<String,String>> e : atXdoclets.entrySet()) {
aoqi@0 185 f.p(" * @").p(e.getKey());
aoqi@0 186 if (e.getValue() != null) {
aoqi@0 187 for (Map.Entry<String,String> a : e.getValue().entrySet()) {
aoqi@0 188 f.p(" ").p(a.getKey()).p("= \"").p(a.getValue()).p("\"");
aoqi@0 189 }
aoqi@0 190 }
aoqi@0 191 f.nl();
aoqi@0 192 }
aoqi@0 193 f.p(" */").nl();
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 private static final String INDENT = " * ";
aoqi@0 197 }

mercurial