update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / source / codeStyle / javadoc / JDComment.java
blobcedc9647c49ee443c51754151bc266a9f9375779
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.psi.impl.source.codeStyle.javadoc;
18 import org.jetbrains.annotations.NonNls;
20 import java.util.ArrayList;
22 /**
23 * @author max
26 /**
27 * @author Dmitry Skavish
29 public class JDComment {
30 protected CommentFormatter myFormatter;
32 String description;
33 protected ArrayList unknownList;
34 protected ArrayList seeAlsoList;
35 protected String since;
36 String deprecated;
38 //protected LinkedHashMap xdocTagMap = new LinkedHashMap();
40 public JDComment(CommentFormatter formatter) {
41 myFormatter = formatter;
44 protected static boolean isNull(String s) {
45 return s == null || s.trim().length() == 0;
48 protected static boolean isNull(ArrayList l) {
49 return l == null || l.size() == 0;
52 public String generate(String indent) {
53 final String prefix;
54 if (myFormatter.getSettings().JD_LEADING_ASTERISKS_ARE_ENABLED) {
55 prefix = indent + " * ";
56 } else {
57 prefix = indent;
60 @NonNls StringBuffer sb = new StringBuffer();
61 // sb.append("/**\n");
63 int start = sb.length();
65 if (!isNull(description)) {
66 sb.append(myFormatter.getParser().splitIntoCLines(description, prefix));
68 if (myFormatter.getSettings().JD_ADD_BLANK_AFTER_DESCRIPTION) {
69 sb.append(prefix);
70 sb.append('\n');
74 generateSpecial(prefix, sb);
76 if (!isNull(unknownList) && myFormatter.getSettings().JD_KEEP_INVALID_TAGS) {
77 for (Object aUnknownList : unknownList) {
78 String s = (String)aUnknownList;
79 sb.append(myFormatter.getParser().splitIntoCLines(s, prefix));
84 if( xdocTagMap.size() > 0 ) {
85 Iterator it = xdocTagMap.values().iterator();
86 while( it.hasNext() ) {
87 ArrayList list = (ArrayList) it.next();
88 for( int i = 0; i<list.size(); i++ ) {
89 XDTag tag = (XDTag) list.get(i);
90 tag.append(sb, prefix);
91 if( myFormatter.getSettings().add_blank_after_xdoclet_tag ) {
92 sb.append(prefix);
93 sb.append('\n');
97 }*/
99 if (!isNull(seeAlsoList)) {
100 for (Object aSeeAlsoList : seeAlsoList) {
101 String s = (String)aSeeAlsoList;
102 sb.append(prefix);
103 sb.append("@see ");
104 sb.append(myFormatter.getParser().splitIntoCLines(s, prefix + " ", false));
108 if (!isNull(since)) {
109 sb.append(prefix);
110 sb.append("@since ");
111 sb.append(myFormatter.getParser().splitIntoCLines(since, prefix + " ", false));
114 if (deprecated != null) {
115 sb.append(prefix);
116 sb.append("@deprecated ");
117 sb.append(myFormatter.getParser().splitIntoCLines(deprecated, prefix + " ", false));
120 if (sb.length() == start) return null;
122 // if it ends with a blank line delete that
123 int nlen = sb.length() - prefix.length() - 1;
124 if (sb.substring(nlen, sb.length()).equals(prefix + "\n")) {
125 sb.delete(nlen, sb.length());
128 if( !myFormatter.getSettings().JD_DO_NOT_WRAP_ONE_LINE_COMMENTS ||
129 sb.indexOf("\n") != sb.length()-1 ) {
130 sb.insert(0, "/**\n");
131 sb.append(indent);
133 else {
134 sb.replace(0, prefix.length(), "/** ");
135 sb.deleteCharAt(sb.length()-1);
137 sb.append(" */");
139 return sb.toString();
142 protected void generateSpecial(String prefix, StringBuffer sb) {
145 public void addSeeAlso(String seeAlso) {
146 if (seeAlsoList == null) {
147 seeAlsoList = new ArrayList();
149 seeAlsoList.add(seeAlso);
152 public void addUnknownTag(String unknownTag) {
153 if (unknownList == null) {
154 unknownList = new ArrayList();
156 unknownList.add(unknownTag);
159 public void addXDocTag( XDTag tag ) {
160 getXdocTagList(tag.getNamespaceDesc()).add(tag);
163 public ArrayList getXdocTagList( String nsName ) {
164 ArrayList list = (ArrayList) xdocTagMap.get(nsName);
165 if( list == null ) {
166 list = new ArrayList();
167 xdocTagMap.put(nsName, list);
169 return list;
172 public ArrayList getXdocTagList( XDNamespaceDesc desc ) {
173 return getXdocTagList(desc.getName());
176 public ArrayList getSeeAlsoList() {
177 return seeAlsoList;
180 public void setUnknownList(ArrayList unknownList) {
181 this.unknownList = unknownList;
184 public void setSeeAlsoList(ArrayList seeAlsoList) {
185 this.seeAlsoList = seeAlsoList;
188 public ArrayList getUnknownList() {
189 return unknownList;
192 public String getSince() {
193 return since;
196 public void setSince(String since) {
197 this.since = since;
200 public String getDeprecated() {
201 return deprecated;
204 public void setDeprecated(String deprecated) {
205 this.deprecated = deprecated;
208 public String getDescription() {
209 return description;
212 public void setDescription(String description) {
213 this.description = description;