src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1364
8db45b13526e
child 1736
74cd21f2c2fe
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

bpatel@766 1 /*
jjg@1359 2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
bpatel@766 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bpatel@766 4 *
bpatel@766 5 * This code is free software; you can redistribute it and/or modify it
bpatel@766 6 * under the terms of the GNU General Public License version 2 only, as
bpatel@766 7 * published by the Free Software Foundation. Oracle designates this
bpatel@766 8 * particular file as subject to the "Classpath" exception as provided
bpatel@766 9 * by Oracle in the LICENSE file that accompanied this code.
bpatel@766 10 *
bpatel@766 11 * This code is distributed in the hope that it will be useful, but WITHOUT
bpatel@766 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bpatel@766 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bpatel@766 14 * version 2 for more details (a copy is included in the LICENSE file that
bpatel@766 15 * accompanied this code).
bpatel@766 16 *
bpatel@766 17 * You should have received a copy of the GNU General Public License version
bpatel@766 18 * 2 along with this work; if not, write to the Free Software Foundation,
bpatel@766 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bpatel@766 20 *
bpatel@766 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bpatel@766 22 * or visit www.oracle.com if you need additional information or have any
bpatel@766 23 * questions.
bpatel@766 24 */
bpatel@766 25
bpatel@766 26 package com.sun.tools.doclets.internal.toolkit;
bpatel@766 27
jjg@1364 28 import java.io.IOException;
jjg@1364 29 import java.io.StringWriter;
jjg@1364 30 import java.io.Writer;
jjg@1364 31
bpatel@766 32 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@766 33
bpatel@766 34 /**
bpatel@766 35 * A class to create content for javadoc output pages.
bpatel@766 36 *
jjg@1359 37 * <p><b>This is NOT part of any supported API.
jjg@1359 38 * If you write code that depends on this, you do so at your own risk.
jjg@1359 39 * This code and its internal interfaces are subject to change or
jjg@1359 40 * deletion without notice.</b>
jjg@1359 41 *
bpatel@766 42 * @author Bhavesh Patel
bpatel@766 43 */
bpatel@766 44 public abstract class Content {
bpatel@766 45
bpatel@766 46 /**
bpatel@766 47 * Returns a string representation of the content.
bpatel@766 48 *
bpatel@766 49 * @return string representation of the content
bpatel@766 50 */
jjg@1364 51 @Override
bpatel@766 52 public String toString() {
jjg@1364 53 StringWriter out = new StringWriter();
jjg@1364 54 try {
jjg@1364 55 write(out, true);
jjg@1364 56 } catch (IOException e) {
jjg@1364 57 // cannot happen from StringWriter
jjg@1364 58 throw new DocletAbortException();
jjg@1364 59 }
jjg@1364 60 return out.toString();
bpatel@766 61 }
bpatel@766 62
bpatel@766 63 /**
bpatel@766 64 * Adds content to the existing content.
bpatel@766 65 *
bpatel@766 66 * @param content content that needs to be added
bpatel@766 67 */
bpatel@766 68 public abstract void addContent(Content content);
bpatel@766 69
bpatel@766 70 /**
bpatel@766 71 * Adds a string content to the existing content.
bpatel@766 72 *
bpatel@766 73 * @param stringContent the string content to be added
bpatel@766 74 */
bpatel@766 75 public abstract void addContent(String stringContent);
bpatel@766 76
bpatel@766 77 /**
jjg@1364 78 * Writes content to a writer.
bpatel@766 79 *
bpatel@766 80 */
jjg@1364 81 public abstract boolean write(Writer writer, boolean atNewline) throws IOException ;
bpatel@766 82
bpatel@766 83 /**
bpatel@766 84 * Returns true if the content is empty.
bpatel@766 85 *
bpatel@766 86 * @return true if no content to be displayed else return false
bpatel@766 87 */
bpatel@766 88 public abstract boolean isEmpty();
bpatel@766 89
bpatel@766 90 /**
bpatel@766 91 * Returns true if the content is valid.
bpatel@766 92 *
bpatel@766 93 * @return true if the content is valid else return false
bpatel@766 94 */
bpatel@766 95 public boolean isValid() {
bpatel@766 96 return !isEmpty();
bpatel@766 97 }
bpatel@766 98
bpatel@766 99 /**
bpatel@766 100 * Checks for null values.
bpatel@766 101 *
bpatel@766 102 * @param t reference type to check for null values
bpatel@766 103 * @return the reference type if not null or else throws a null pointer exception
bpatel@766 104 */
bpatel@766 105 protected static <T> T nullCheck(T t) {
bpatel@766 106 t.getClass();
bpatel@766 107 return t;
bpatel@766 108 }
bpatel@766 109
bpatel@766 110 /**
bpatel@766 111 * Returns true if the content ends with a newline character. Empty content
bpatel@766 112 * is considered as ending with new line.
bpatel@766 113 *
bpatel@766 114 * @param contentBuilder content to test for newline character at the end
bpatel@766 115 * @return true if the content ends with newline.
bpatel@766 116 */
bpatel@819 117 protected boolean endsWithNewLine(StringBuilder contentBuilder) {
bpatel@819 118 int contentLength = contentBuilder.length();
bpatel@819 119 if (contentLength == 0) {
bpatel@819 120 return true;
bpatel@819 121 }
bpatel@819 122 int nlLength = DocletConstants.NL.length();
bpatel@819 123 if (contentLength < nlLength) {
bpatel@819 124 return false;
bpatel@819 125 }
bpatel@819 126 int contentIndex = contentLength - 1;
bpatel@819 127 int nlIndex = nlLength - 1;
bpatel@819 128 while (nlIndex >= 0) {
bpatel@819 129 if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) {
bpatel@819 130 return false;
bpatel@819 131 }
bpatel@819 132 contentIndex--;
bpatel@819 133 nlIndex--;
bpatel@819 134 }
bpatel@819 135 return true;
bpatel@766 136 }
bpatel@766 137 }

mercurial