Mon, 19 Nov 2012 16:10:34 -0800
8002304: Group methods by types in methods summary section
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2010, 2012, 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
23 * questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit;
28 import java.io.IOException;
29 import java.io.StringWriter;
30 import java.io.Writer;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
34 /**
35 * A class to create content for javadoc output pages.
36 *
37 * <p><b>This is NOT part of any supported API.
38 * If you write code that depends on this, you do so at your own risk.
39 * This code and its internal interfaces are subject to change or
40 * deletion without notice.</b>
41 *
42 * @author Bhavesh Patel
43 */
44 public abstract class Content {
46 /**
47 * Returns a string representation of the content.
48 *
49 * @return string representation of the content
50 */
51 @Override
52 public String toString() {
53 StringWriter out = new StringWriter();
54 try {
55 write(out, true);
56 } catch (IOException e) {
57 // cannot happen from StringWriter
58 throw new DocletAbortException();
59 }
60 return out.toString();
61 }
63 /**
64 * Adds content to the existing content.
65 *
66 * @param content content that needs to be added
67 */
68 public abstract void addContent(Content content);
70 /**
71 * Adds a string content to the existing content.
72 *
73 * @param stringContent the string content to be added
74 */
75 public abstract void addContent(String stringContent);
77 /**
78 * Writes content to a writer.
79 *
80 */
81 public abstract boolean write(Writer writer, boolean atNewline) throws IOException ;
83 /**
84 * Returns true if the content is empty.
85 *
86 * @return true if no content to be displayed else return false
87 */
88 public abstract boolean isEmpty();
90 /**
91 * Returns true if the content is valid.
92 *
93 * @return true if the content is valid else return false
94 */
95 public boolean isValid() {
96 return !isEmpty();
97 }
99 /**
100 * Checks for null values.
101 *
102 * @param t reference type to check for null values
103 * @return the reference type if not null or else throws a null pointer exception
104 */
105 protected static <T> T nullCheck(T t) {
106 t.getClass();
107 return t;
108 }
110 /**
111 * Returns true if the content ends with a newline character. Empty content
112 * is considered as ending with new line.
113 *
114 * @param contentBuilder content to test for newline character at the end
115 * @return true if the content ends with newline.
116 */
117 protected boolean endsWithNewLine(StringBuilder contentBuilder) {
118 int contentLength = contentBuilder.length();
119 if (contentLength == 0) {
120 return true;
121 }
122 int nlLength = DocletConstants.NL.length();
123 if (contentLength < nlLength) {
124 return false;
125 }
126 int contentIndex = contentLength - 1;
127 int nlIndex = nlLength - 1;
128 while (nlIndex >= 0) {
129 if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) {
130 return false;
131 }
132 contentIndex--;
133 nlIndex--;
134 }
135 return true;
136 }
137 }