0001: /*
0002: * ====================================================================
0003: * The JRefactory License, Version 1.0
0004: *
0005: * Copyright (c) 2001 JRefactory. All rights reserved.
0006: *
0007: * Redistribution and use in source and binary forms, with or without
0008: * modification, are permitted provided that the following conditions
0009: * are met:
0010: *
0011: * 1. Redistributions of source code must retain the above copyright
0012: * notice, this list of conditions and the following disclaimer.
0013: *
0014: * 2. Redistributions in binary form must reproduce the above copyright
0015: * notice, this list of conditions and the following disclaimer in
0016: * the documentation and/or other materials provided with the
0017: * distribution.
0018: *
0019: * 3. The end-user documentation included with the redistribution,
0020: * if any, must include the following acknowledgment:
0021: * "This product includes software developed by the
0022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
0023: * Alternately, this acknowledgment may appear in the software itself,
0024: * if and wherever such third-party acknowledgments normally appear.
0025: *
0026: * 4. The names "JRefactory" must not be used to endorse or promote
0027: * products derived from this software without prior written
0028: * permission. For written permission, please contact seguin@acm.org.
0029: *
0030: * 5. Products derived from this software may not be called "JRefactory",
0031: * nor may "JRefactory" appear in their name, without prior written
0032: * permission of Mike Atkinson.
0033: *
0034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
0038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0045: * SUCH DAMAGE.
0046: * ====================================================================
0047: *
0048: * This software consists of voluntary contributions made by many
0049: * individuals on behalf of JRefactory. For more information on
0050: * JRefactory, please see
0051: * <http://www.sourceforge.org/projects/jrefactory>.
0052: */
0053: package org.acm.seguin.pretty;
0054:
0055: import java.io.IOException;
0056: import java.io.OutputStreamWriter;
0057: import java.io.PrintWriter;
0058: import java.io.Writer;
0059: import java.util.StringTokenizer;
0060: import java.util.Vector;
0061: import java.util.Comparator;
0062: import net.sourceforge.jrefactory.io.CharStream;
0063: import net.sourceforge.jrefactory.ast.ASTCompilationUnit;
0064: import net.sourceforge.jrefactory.ast.ASTNameList;
0065: import net.sourceforge.jrefactory.ast.ASTName;
0066: import org.acm.seguin.pretty.sort.MultipleOrdering;
0067: import org.acm.seguin.pretty.sort.SameOrdering;
0068: import org.acm.seguin.pretty.sort.TopLevelOrdering;
0069: import org.acm.seguin.util.FileSettings;
0070: import org.acm.seguin.util.MissingSettingsException;
0071: import org.acm.seguin.util.Settings;
0072:
0073: /**
0074: * This object stores all the data necessary to print the the Java file
0075: *
0076: *@author Mike Atkinson
0077: *@author <a href="JRefactory@ladyshot.demon.co.uk">Mike Atkinson</a>
0078: *@version $Id: PrintData.java,v 1.32 2003/11/12 13:44:37 mikeatkinson Exp $
0079: *@created March 6, 1999
0080: */
0081: public class PrintData {
0082: /**
0083: * Description of the Field
0084: */
0085: public int finalLine = -1;
0086: private int last = EMPTY;
0087:
0088: private int INDENT = 4;
0089: private char indentChar = ' ';
0090:
0091: private int codeBlockStyle = BLOCK_STYLE_C;
0092: private int methodBlockStyle = BLOCK_STYLE_C;
0093: private int classBlockStyle = BLOCK_STYLE_C;
0094:
0095: // Set to true after method parameters are formatted, before the
0096: // opening brace
0097: private boolean isMethodBrace = false;
0098:
0099: // Method parameter indentation
0100: private boolean lineUpParams = false;
0101: private boolean inParams = false;
0102: private int lastParamIndent = 0;
0103:
0104: private boolean exprSpace = false;
0105: private int linesBetween = 2;
0106:
0107: private int javadocMinimum = 40;
0108: private int javadocMaximum = 80;
0109:
0110: private boolean spaceAfterCast = true;
0111: private boolean spaceAfterKeyword = true;
0112: private boolean spaceAfterMethod = false;
0113: private boolean spaceInsideCast = false;
0114:
0115: private int javadocStars = 2;
0116: private int originalLine = -1;
0117: private boolean storeJavadocPrinted = false;
0118: private boolean skipNameSpacing = false;
0119: private int cStyleFormatCode = CSC_ALIGN_STAR;
0120: private int cStyleIndent = 2;
0121: private boolean isClassBrace = false;
0122: private boolean emptyBlockOnSingleLine = false;
0123: private boolean castSpace = true;
0124: private boolean documentNestedClasses = true;
0125:
0126: private boolean elseOnNewLine = true;
0127:
0128: private boolean allowSingleLineJavadoc = false;
0129: private boolean firstLineOnCommentStart = false;
0130:
0131: private boolean currentIsSingle = false;
0132:
0133: private boolean variablesAlignWithBlock = false;
0134: private boolean localVariableSpaceInsert = false;
0135: private int linesAfterPackage = 1;
0136: private boolean maintainNewlinesAroundImports = true;
0137: private int linesBeforeClass = 0;
0138: private boolean indentInitializer = false;
0139: private boolean bangSpace = false;
0140: private boolean spaceAroundOps = true;
0141:
0142: private FileSettings bundle;
0143:
0144: private int caseIndent;
0145: private Vector classNameStack;
0146: private int dynamicFieldSpace;
0147: private int fieldNameIndent;
0148: private int fieldSpaceCode;
0149: private Vector fieldStack;
0150: private boolean forceBlock;
0151: private String[] importSortImportant;
0152: private int importSortNeighbourhood;
0153: // Instance Variables
0154: private int indent;
0155: private boolean keepAllJavadoc;
0156: private boolean keepErroneousJavadocTags;
0157: private LineQueue lineQueue;
0158:
0159: private MultipleOrdering morder;
0160: private int newlineCount;
0161: private StringBuffer outputBuffer;
0162: private boolean reformatComments;
0163: private boolean removeExcessBlocks;
0164: private boolean sortTop;
0165: private int surpriseType;
0166: private int tempEqualsLength;
0167:
0168: private boolean lineBeforeExtends = false;
0169: private int extendsIndentation = 1;
0170: private boolean lineBeforeImplements = lineBeforeExtends;
0171: private int implements Indentation = extendsIndentation;
0172: private boolean lineBeforeClassBody = false;
0173: private boolean lineBeforeMultistatementMethodBody = false;
0174: private boolean lineupJavadocIDs = true;
0175: private boolean lineupJavadocDescr = false;
0176:
0177: private boolean sortThrowsStatement = true;
0178: private boolean sortExtendsStatement = true;
0179: private boolean sortImplementsStatement = true;
0180:
0181: private int javadocIndent = -1; // Means it should be loaded from "javadoc.indent"
0182: private boolean c_ownline = true; // Means that c style comments at the end of a
0183: // program line should be placed on their own line.
0184:
0185: private int charStreamType = 4; // character output type (same as input).
0186:
0187: /**
0188: * Use the C style blocks
0189: */
0190: public final static int BLOCK_STYLE_C = 0;
0191: /**
0192: * Use the PASCAL style blocks
0193: */
0194: public final static int BLOCK_STYLE_PASCAL = 1;
0195: /**
0196: * Use the EMACS style of blocks (like pascal but 2 spaces)
0197: */
0198: public final static int BLOCK_STYLE_EMACS = 2;
0199:
0200: // Class Variables
0201: /**
0202: * Description of the Field
0203: */
0204: public static int EMPTY = 0;
0205: /**
0206: * Description of the Field
0207: */
0208: public static int METHOD = 1;
0209: /**
0210: * Description of the Field
0211: */
0212: public static int FIELD = 2;
0213: /**
0214: * Description of the Field
0215: */
0216: public static int INTERFACE = 3;
0217: /**
0218: * Description of the Field
0219: */
0220: public static int CLASS = 3;
0221: /**
0222: * This is used to mark enumerations (which are really classes behind the scenes)
0223: *@since JRefactory 2.7.00
0224: */
0225: public static int ENUM = 3;
0226:
0227: /**
0228: * The indent type for an unexpected end of line - single indent
0229: */
0230: public static int SINGLE_INDENT = 1;
0231: /**
0232: * The indent type for an unexpected end of line - double indent
0233: */
0234: public static int DOUBLE_INDENT = 2;
0235: /**
0236: * The indent type for an unexpected end of line - line up parameters
0237: * indent
0238: */
0239: public static int PARAM_INDENT = 3;
0240: /**
0241: * There should be no indent
0242: */
0243: public static int NO_INDENT = 4;
0244: /**
0245: * A comment with javadoc
0246: */
0247: public final static int JAVADOC_COMMENT = 1;
0248: /**
0249: * A c style comment
0250: */
0251: public final static int C_STYLE_COMMENT = 2;
0252: /**
0253: * A category comment
0254: */
0255: public final static int CATEGORY_COMMENT = 3;
0256: /**
0257: * A single line comment
0258: */
0259: public final static int SINGLE_LINE_COMMENT = 4;
0260:
0261: /**
0262: * Never use dynamic field spacing
0263: */
0264: public final static int DFS_NEVER = 0;
0265:
0266: /**
0267: * ALWAYS use dynamic field spacing
0268: */
0269: public final static int DFS_ALWAYS = 1;
0270:
0271: /**
0272: * Use dynamic field spacing except with javadoc
0273: */
0274: public final static int DFS_NOT_WITH_JAVADOC = 2;
0275:
0276: /**
0277: * Only align on the equals
0278: */
0279: public final static int DFS_ALIGN_EQUALS = 3;
0280: /**
0281: * Leaves C Style comments untouched
0282: */
0283: public final static int CSC_LEAVE_UNTOUCHED = 1;
0284: /**
0285: * Aligns the C style comments with a * to the right
0286: */
0287: public final static int CSC_ALIGN_STAR = 0;
0288: /**
0289: * Aligns the C style comments with a * to the right
0290: */
0291: public final static int CSC_ALIGN_BLANK = 2;
0292: /**
0293: * Maintains spacing in the C style comments, but insists upon a star at
0294: * the right
0295: */
0296: public final static int CSC_MAINTAIN_STAR = 3;
0297:
0298: /**
0299: * Create a print data object
0300: */
0301: public PrintData() {
0302: this (new OutputStreamWriter(System.out));
0303: }
0304:
0305: /**
0306: * Create a print data object
0307: *
0308: *@param out the output stream
0309: */
0310: public PrintData(Writer out) {
0311: indent = 0;
0312: outputBuffer = new StringBuffer();
0313: newlineCount = 0;
0314:
0315: charStreamType = CharStream.JAVA_LIKE;
0316:
0317: // Load the properties
0318: bundle = FileSettings.getRefactoryPrettySettings();
0319: try {
0320: INDENT = bundle.getInteger("indent");
0321: String indentCharacter = bundle.getString("indent.char");
0322: if (indentCharacter.equalsIgnoreCase("space")) {
0323: indentChar = ' ';
0324: } else if (indentCharacter.equalsIgnoreCase("tab")) {
0325: indentChar = '\t';
0326: } else {
0327: indentChar = indentCharacter.charAt(0);
0328: }
0329: charStreamType = bundle.getInteger("char.stream.type");
0330: } catch (MissingSettingsException mre) {
0331: // Default is sufficient
0332: }
0333:
0334: //lineQueue = lineQueueFactory(new PrintWriter(new JavaOutputStreamWriter(out)));
0335: lineQueue = lineQueueFactory(new PrintWriter(out));
0336: //java.util.SortedMap cs = java.nio.charset.Charset.availableCharsets();
0337: //System.out.println("character sets ="+cs.keySet());
0338:
0339: codeBlockStyle = translateBlockStyle("block.style");
0340: methodBlockStyle = translateBlockStyle("method.block.style");
0341: classBlockStyle = translateBlockStyle("class.block.style");
0342:
0343: try {
0344: exprSpace = (new Boolean(bundle.getString("expr.space")))
0345: .booleanValue();
0346: } catch (MissingSettingsException mre) {
0347: // Default is sufficient
0348: }
0349:
0350: try {
0351: lineUpParams = (new Boolean(bundle
0352: .getString("params.lineup"))).booleanValue();
0353: } catch (MissingSettingsException mre) {
0354: // Default is sufficient
0355: }
0356:
0357: try {
0358: linesBetween = Integer.parseInt(bundle
0359: .getString("lines.between"));
0360: } catch (MissingSettingsException mre) {
0361: // Default is sufficient
0362: } catch (NumberFormatException nfe) {
0363: // Default is sufficient
0364: }
0365:
0366: try {
0367: javadocMinimum = bundle.getInteger("javadoc.wordwrap.min");
0368: javadocMaximum = bundle.getInteger("javadoc.wordwrap.max");
0369: } catch (MissingSettingsException snfe) {
0370: // Default is sufficient
0371: }
0372:
0373: try {
0374: spaceAfterCast = bundle.getBoolean("cast.space");
0375: } catch (MissingSettingsException snfe) {
0376: // Default is sufficient
0377: }
0378:
0379: try {
0380: javadocStars = bundle.getInteger("javadoc.star");
0381: } catch (MissingSettingsException snfe) {
0382: // Default is sufficient
0383: }
0384:
0385: try {
0386: spaceAfterKeyword = bundle.getBoolean("keyword.space");
0387: } catch (MissingSettingsException snfe) {
0388: // Default is sufficient
0389: }
0390:
0391: try {
0392: String value = bundle.getString("variable.spacing");
0393: if (value.equalsIgnoreCase("dynamic")) {
0394: fieldSpaceCode = DFS_ALWAYS;
0395: } else if (value.equalsIgnoreCase("javadoc.dynamic")) {
0396: fieldSpaceCode = DFS_NOT_WITH_JAVADOC;
0397: } else if (value.equalsIgnoreCase("align.equals")) {
0398: fieldSpaceCode = DFS_ALIGN_EQUALS;
0399: } else {
0400: fieldSpaceCode = DFS_NEVER;
0401: }
0402: } catch (MissingSettingsException snfe) {
0403: fieldSpaceCode = DFS_NEVER;
0404: }
0405:
0406: morder = new MultipleOrdering(bundle);
0407: classNameStack = new Vector();
0408: fieldStack = new Vector();
0409:
0410: String surpriseReturnString;
0411: try {
0412: surpriseReturnString = bundle.getString("surprise.return");
0413: } catch (MissingSettingsException mse) {
0414: System.out.println("Cannot find surprise.return");
0415: surpriseReturnString = "double";
0416: }
0417:
0418: if (surpriseReturnString.equalsIgnoreCase("single")) {
0419: surpriseType = SINGLE_INDENT;
0420: } else if (surpriseReturnString.equalsIgnoreCase("param")) {
0421: surpriseType = PARAM_INDENT;
0422: } else if (surpriseReturnString.equalsIgnoreCase("none")) {
0423: surpriseType = NO_INDENT;
0424: } else {
0425: surpriseType = DOUBLE_INDENT;
0426: }
0427:
0428: try {
0429: reformatComments = bundle.getBoolean("reformat.comments");
0430: } catch (MissingSettingsException mse) {
0431: reformatComments = true;
0432: }
0433:
0434: try {
0435: fieldNameIndent = bundle.getInteger("field.name.indent");
0436: } catch (MissingSettingsException mse) {
0437: fieldNameIndent = -1;
0438: }
0439:
0440: try {
0441: keepAllJavadoc = bundle.getBoolean("keep.all.javadoc");
0442: } catch (MissingSettingsException mse) {
0443: keepAllJavadoc = false;
0444: }
0445:
0446: try {
0447: forceBlock = bundle.getBoolean("force.block");
0448: } catch (MissingSettingsException mse) {
0449: forceBlock = true;
0450: }
0451:
0452: try {
0453: dynamicFieldSpace = bundle
0454: .getInteger("dynamic.variable.spacing");
0455: } catch (MissingSettingsException mse) {
0456: dynamicFieldSpace = 1;
0457: }
0458:
0459: try {
0460: String temp = bundle.getString("c.style.format");
0461: if (temp.equalsIgnoreCase("leave")) {
0462: cStyleFormatCode = CSC_LEAVE_UNTOUCHED;
0463: } else if (temp.equalsIgnoreCase("maintain.space.star")) {
0464: cStyleFormatCode = CSC_MAINTAIN_STAR;
0465: } else if (temp.equalsIgnoreCase("align.blank")) {
0466: cStyleFormatCode = CSC_ALIGN_BLANK;
0467: } else {
0468: cStyleFormatCode = CSC_ALIGN_STAR;
0469: }
0470: } catch (MissingSettingsException mse) {
0471: cStyleFormatCode = CSC_ALIGN_STAR;
0472: }
0473:
0474: try {
0475: cStyleIndent = bundle.getInteger("c.style.indent");
0476: } catch (MissingSettingsException mse) {
0477: cStyleIndent = 2;
0478: }
0479:
0480: try {
0481: emptyBlockOnSingleLine = bundle
0482: .getBoolean("empty.block.single.line");
0483: } catch (MissingSettingsException mse) {
0484: emptyBlockOnSingleLine = false;
0485: }
0486:
0487: try {
0488: castSpace = !bundle.getBoolean("cast.force.nospace");
0489: } catch (MissingSettingsException mse) {
0490: castSpace = true;
0491: }
0492:
0493: try {
0494: documentNestedClasses = bundle
0495: .getBoolean("document.nested.classes");
0496: } catch (MissingSettingsException mse) {
0497: documentNestedClasses = true;
0498: }
0499:
0500: try {
0501: allowSingleLineJavadoc = bundle
0502: .getBoolean("allow.singleline.javadoc");
0503: } catch (MissingSettingsException mse) {
0504: allowSingleLineJavadoc = false;
0505: }
0506:
0507: try {
0508: firstLineOnCommentStart = bundle
0509: .getBoolean("first.singleline.javadoc");
0510: } catch (MissingSettingsException mse) {
0511: firstLineOnCommentStart = false;
0512: }
0513:
0514: try {
0515: variablesAlignWithBlock = bundle
0516: .getBoolean("variable.align.with.block");
0517: } catch (MissingSettingsException mse) {
0518: variablesAlignWithBlock = false;
0519: }
0520:
0521: try {
0522: elseOnNewLine = bundle.getBoolean("else.start.line");
0523: } catch (MissingSettingsException mse) {
0524: elseOnNewLine = true;
0525: }
0526:
0527: try {
0528: caseIndent = bundle.getInteger("case.indent");
0529: } catch (MissingSettingsException mse) {
0530: caseIndent = INDENT;
0531: }
0532:
0533: try {
0534: sortTop = bundle.getBoolean("sort.top");
0535: } catch (MissingSettingsException mse) {
0536: sortTop = false;
0537: }
0538:
0539: try {
0540: String data = bundle.getString("import.sort.important");
0541: StringTokenizer st = new StringTokenizer(data, ",");
0542: Vector list = new Vector();
0543: while (st.hasMoreTokens()) {
0544: String value = st.nextToken();
0545: if (!value.endsWith(".")) {
0546: value += ".";
0547: }
0548: list.add(value);
0549: }
0550: importSortImportant = (String[]) list
0551: .toArray(new String[list.size()]);
0552: } catch (MissingSettingsException mse) {
0553: importSortImportant = new String[] {};
0554: }
0555:
0556: try {
0557: importSortNeighbourhood = bundle
0558: .getInteger("import.sort.neighbourhood");
0559: } catch (MissingSettingsException mse) {
0560: importSortNeighbourhood = 0;
0561: }
0562:
0563: try {
0564: localVariableSpaceInsert = bundle
0565: .getBoolean("insert.space.around.local.variables");
0566: } catch (MissingSettingsException mse) {
0567: localVariableSpaceInsert = false;
0568: }
0569:
0570: try {
0571: removeExcessBlocks = bundle
0572: .getBoolean("remove.excess.blocks");
0573: } catch (MissingSettingsException mse) {
0574: removeExcessBlocks = false;
0575: }
0576:
0577: try {
0578: linesAfterPackage = bundle
0579: .getInteger("lines.after.package");
0580: } catch (MissingSettingsException mse) {
0581: linesAfterPackage = 0;
0582: }
0583:
0584: try {
0585: maintainNewlinesAroundImports = bundle
0586: .getBoolean("maintain.newlines.around.imports");
0587: } catch (MissingSettingsException mse) {
0588: maintainNewlinesAroundImports = true;
0589: }
0590:
0591: try {
0592: linesBeforeClass = bundle.getInteger("lines.before.class");
0593: } catch (MissingSettingsException mse) {
0594: linesBeforeClass = 0;
0595: }
0596:
0597: try {
0598: lineBeforeExtends = bundle
0599: .getBoolean("line.before.extends");
0600: } catch (MissingSettingsException mse) {
0601: lineBeforeExtends = false;
0602: }
0603:
0604: try {
0605: extendsIndentation = bundle.getInteger("extends.indent");
0606: } catch (MissingSettingsException mse) {
0607: extendsIndentation = 1;
0608: }
0609:
0610: try {
0611: lineBeforeImplements = bundle
0612: .getBoolean("line.before.implements");
0613: } catch (MissingSettingsException mse) {
0614: // implements line break defaults to extends line break
0615: lineBeforeImplements = lineBeforeExtends;
0616: }
0617:
0618: try {
0619: lineBeforeMultistatementMethodBody = bundle
0620: .getBoolean("line.before.multistatement.method.body");
0621: } catch (MissingSettingsException mse) {
0622: lineBeforeMultistatementMethodBody = false;
0623: }
0624:
0625: try {
0626: implements Indentation = bundle
0627: .getInteger("implements.indent");
0628: } catch (MissingSettingsException mse) {
0629: // implements indentation defaults to extends indentation
0630: implements Indentation = extendsIndentation;
0631: }
0632:
0633: try {
0634: indentInitializer = bundle
0635: .getBoolean("indent.in.initializer");
0636: } catch (MissingSettingsException mse) {
0637: indentInitializer = false;
0638: }
0639:
0640: try {
0641: arrayInitializerIndented = bundle
0642: .getBoolean("indent.braces.initializer");
0643: } catch (MissingSettingsException mse) {
0644: arrayInitializerIndented = true;
0645: }
0646:
0647: try {
0648: lineBeforeClassBody = bundle
0649: .getBoolean("line.before.class.body");
0650: } catch (MissingSettingsException mse) {
0651: lineBeforeClassBody = false;
0652: }
0653:
0654: try {
0655: bangSpace = bundle.getBoolean("bang.space");
0656: } catch (MissingSettingsException mse) {
0657: bangSpace = false;
0658: }
0659:
0660: try {
0661: keepErroneousJavadocTags = bundle
0662: .getBoolean("keep.erroneous.tags");
0663: } catch (MissingSettingsException mse) {
0664: keepErroneousJavadocTags = false;
0665: }
0666:
0667: try {
0668: spaceAfterMethod = bundle.getBoolean("method.space");
0669: } catch (MissingSettingsException mse) {
0670: // Default is sufficient
0671: }
0672:
0673: try {
0674: spaceInsideCast = bundle.getBoolean("cast.inside.space");
0675: } catch (MissingSettingsException mse) {
0676: // Default is sufficient
0677: }
0678:
0679: try {
0680: spaceAroundOps = bundle.getBoolean("space.around.ops");
0681: } catch (MissingSettingsException mse) {
0682: // Default is sufficient
0683: }
0684:
0685: try {
0686: String temp = bundle.getString("modifier.order");
0687: temp = temp.toLowerCase();
0688: if (temp.startsWith("alpha"))
0689: modifierOrder = ALPHABETICAL_ORDER;
0690: else
0691: modifierOrder = STANDARD_ORDER;
0692: } catch (MissingSettingsException mse) {
0693: // Default is sufficient
0694: }
0695:
0696: try {
0697: alignStarsWithSlash = bundle
0698: .getBoolean("align.stars.with.slash");
0699: } catch (MissingSettingsException mse) {
0700: alignStarsWithSlash = false;
0701: }
0702:
0703: try {
0704: lineupJavadocIDs = bundle.getBoolean("javadoc.id.lineup");
0705: } catch (MissingSettingsException mse) {
0706: lineupJavadocIDs = true;
0707: }
0708:
0709: try {
0710: lineupJavadocDescr = bundle
0711: .getBoolean("javadoc.descr.lineup");
0712: } catch (MissingSettingsException mse) {
0713: lineupJavadocDescr = false;
0714: }
0715:
0716: try {
0717: taggedJavadocDescription = bundle
0718: .getInteger("javadoc.tag.indent");
0719: } catch (MissingSettingsException mse) {
0720: taggedJavadocDescription = 6;
0721: }
0722:
0723: try {
0724: c_ownline = bundle.getBoolean("cstyle.comment.ownline");
0725: //System.out.println("bundle.getBoolean(\"cstyle.comment.ownline\") => c_ownline="+c_ownline);
0726: } catch (MissingSettingsException mse) {
0727: c_ownline = true;
0728: //System.out.println(" exception => c_ownline="+c_ownline);
0729: }
0730:
0731: try {
0732: sortThrowsStatement = bundle.getBoolean("sort.throws");
0733: } catch (MissingSettingsException mse) {
0734: sortThrowsStatement = true;
0735: }
0736:
0737: try {
0738: sortExtendsStatement = bundle.getBoolean("sort.extends");
0739: } catch (MissingSettingsException mse) {
0740: sortExtendsStatement = true;
0741: }
0742:
0743: try {
0744: sortImplementsStatement = bundle
0745: .getBoolean("sort.implements");
0746: } catch (MissingSettingsException mse) {
0747: sortImplementsStatement = true;
0748: }
0749:
0750: fieldStack = new Vector();
0751: }
0752:
0753: public void setSortThrowsStatement(boolean value) {
0754: sortThrowsStatement = value;
0755: }
0756:
0757: public void setSortExtendsStatement(boolean value) {
0758: sortExtendsStatement = value;
0759: }
0760:
0761: public void setSortImplementsStatement(boolean value) {
0762: sortImplementsStatement = value;
0763: }
0764:
0765: /**
0766: * Sets the AbsoluteCommentSpacing attribute of the PrintData object
0767: *
0768: *@param value The new AbsoluteCommentSpacing value
0769: */
0770: public void setAbsoluteCommentSpacing(int value) {
0771: lineQueue.setAbsoluteCommentSpacing(value);
0772: }
0773:
0774: /**
0775: * Sets the bangSpace attribute of the PrintData object
0776: *
0777: *@param value The new bangSpace value
0778: */
0779: public void setBangSpace(boolean value) {
0780: bangSpace = value;
0781: }
0782:
0783: /**
0784: * Sets the CStyleFormatCode attribute of the PrintData object
0785: *
0786: *@param value The new CStyleFormatCode value
0787: */
0788: public void setCStyleFormatCode(int value) {
0789: cStyleFormatCode = value;
0790: }
0791:
0792: /**
0793: * Sets the CStyleIndent attribute of the PrintData object
0794: *
0795: *@param value The new CStyleIndent value
0796: */
0797: public void setCStyleIndent(int value) {
0798: cStyleIndent = value;
0799: }
0800:
0801: /**
0802: * Sets the caseIndent attribute of the PrintData object
0803: *
0804: *@param value The new caseIndent value
0805: */
0806: public void setCaseIndent(int value) {
0807: caseIndent = value;
0808: }
0809:
0810: /**
0811: * Sets the CastSpace attribute of the PrintData object
0812: *
0813: *@param value The new CastSpace value
0814: */
0815: public void setCastSpace(boolean value) {
0816: castSpace = value;
0817: }
0818:
0819: /**
0820: * Sets the ClassCStyleBlock attribute of the PrintData object
0821: *
0822: *@param value The new ClassCStyleBlock value
0823: */
0824: public void setClassBlockStyle(int value) {
0825: classBlockStyle = value;
0826: }
0827:
0828: /**
0829: * Sets the codeBlockStyle attribute of the PrintData object
0830: *
0831: *@param value The new codeBlockStyle value
0832: */
0833: public void setCodeBlockStyle(int value) {
0834: codeBlockStyle = value;
0835: }
0836:
0837: /**
0838: * Sets the currentIsSingle attribute of the PrintData object
0839: *
0840: *@param value The new currentIsSingle value
0841: */
0842: public void setCurrentIsSingle(boolean value) {
0843: currentIsSingle = value;
0844: }
0845:
0846: /**
0847: * Sets the DocumentNestedClasses attribute of the PrintData object
0848: *
0849: *@param value The new DocumentNestedClasses value
0850: */
0851: public void setDocumentNestedClasses(boolean value) {
0852: documentNestedClasses = value;
0853: }
0854:
0855: /**
0856: * Sets the DynamicFieldSpacing attribute of the PrintData object
0857: *
0858: *@param value The new DynamicFieldSpacing value
0859: */
0860: public void setDynamicFieldSpaces(int value) {
0861: dynamicFieldSpace = value;
0862: }
0863:
0864: /**
0865: * Sets the DynamicFieldSpacing attribute of the PrintData object
0866: *
0867: *@param value The new DynamicFieldSpacing value
0868: */
0869: public void setDynamicFieldSpacing(int value) {
0870: fieldSpaceCode = value;
0871: }
0872:
0873: public void setLineUpParams(boolean value) {
0874: lineUpParams = value;
0875: }
0876:
0877: /**
0878: * Sets the elseOnNewLine attribute of the PrintData object
0879: *
0880: *@param value The new elseOnNewLine value
0881: */
0882: public void setElseOnNewLine(boolean value) {
0883: elseOnNewLine = value;
0884: }
0885:
0886: /**
0887: * Sets the EmptyBlockOnSingleLine attribute of the PrintData object
0888: *
0889: *@param value The new EmptyBlockOnSingleLine value
0890: */
0891: public void setEmptyBlockOnSingleLine(boolean value) {
0892: emptyBlockOnSingleLine = value;
0893: }
0894:
0895: /**
0896: * Sets the ExpressionSpace attribute of the PrintData object
0897: *
0898: *@param value The new ExpressionSpace value
0899: */
0900: public void setExpressionSpace(boolean value) {
0901: exprSpace = value;
0902: }
0903:
0904: /**
0905: * Sets the FinalLine attribute of the PrintData object
0906: *
0907: *@param value The new FinalLine value
0908: */
0909: public void setFinalLine(int value) {
0910: finalLine = value;
0911: }
0912:
0913: /**
0914: * Sets the ForceBlock attribute of the PrintData object
0915: *
0916: *@param value The new ForceBlock value
0917: */
0918: public void setForceBlock(boolean value) {
0919: forceBlock = value;
0920: }
0921:
0922: /**
0923: * Sets the importSortImportant attribute of the PrintData object
0924: *
0925: *@param newImportSortImportant The new importSortImportant value
0926: */
0927: public void setImportSortImportant(String[] newImportSortImportant) {
0928: importSortImportant = newImportSortImportant;
0929: }
0930:
0931: /**
0932: * Sets the importSortNeighbourhood attribute of the PrintData object
0933: *
0934: *@param newImportSortNeighbourhood The new importSortNeighbourhood value
0935: */
0936: public void setImportSortNeighbourhood(
0937: int newImportSortNeighbourhood) {
0938: importSortNeighbourhood = newImportSortNeighbourhood;
0939: }
0940:
0941: /**
0942: * Sets the IncrementalCommentSpacing attribute of the PrintData object
0943: *
0944: *@param value The new IncrementalCommentSpacing value
0945: */
0946: public void setIncrementalCommentSpacing(int value) {
0947: lineQueue.setIncrementalCommentSpacing(value);
0948: }
0949:
0950: /**
0951: * Sets the indentInInitializer attribute of the PrintData object
0952: *
0953: *@param value The new indentInInitializer value
0954: */
0955: public void setIndentInInitializer(boolean value) {
0956: indentInitializer = value;
0957: }
0958:
0959: /**
0960: * Sets the insertSpaceLocalVariables attribute of the PrintData object
0961: *
0962: *@param value The new insertSpaceLocalVariables value
0963: */
0964: public void setInsertSpaceLocalVariables(boolean value) {
0965: localVariableSpaceInsert = value;
0966: }
0967:
0968: /**
0969: * Sets the keepErroneousJavadocTags attribute of the PrintData object
0970: *
0971: *@param value The new keepErroneousJavadocTags value
0972: */
0973: public void setKeepErroneousJavadocTags(boolean value) {
0974: keepErroneousJavadocTags = value;
0975: }
0976:
0977: /**
0978: * Sets the linesAfterPackage attribute of the PrintData object
0979: *
0980: *@param value The new linesAfterPackage value
0981: */
0982: public void setLinesAfterPackage(int value) {
0983: linesAfterPackage = value;
0984: }
0985:
0986: /**
0987: * Sets the linesBeforeClass attribute of the PrintData object
0988: *
0989: *@param value The new linesBeforeClass value
0990: */
0991: public void setLinesBeforeClass(int value) {
0992: linesBeforeClass = value;
0993: }
0994:
0995: /**
0996: * Sets the maintainNewlinesAroundImports attribute of the PrintData object
0997: *
0998: *@param value The new maintainNewlinesAroundImports value
0999: */
1000: public void setMaintainNewlinesAroundImports(boolean value) {
1001: maintainNewlinesAroundImports = value;
1002: }
1003:
1004: /**
1005: * Sets the methodBlockStyle attribute of the PrintData object
1006: *
1007: *@param value The new methodBlockStyle value
1008: */
1009: public void setMethodBlockStyle(int value) {
1010: methodBlockStyle = value;
1011: }
1012:
1013: /**
1014: * Sets the MultipleOrdering attribute of the PrintData object
1015: *
1016: *@param value The new MultipleOrdering value
1017: */
1018: public void setMultipleOrdering(MultipleOrdering value) {
1019: if (value != null) {
1020: morder = value;
1021: }
1022: }
1023:
1024: /**
1025: * Sets the OriginalLine attribute of the PrintData object
1026: *
1027: *@param value The new OriginalLine value
1028: */
1029: public void setOriginalLine(int value) {
1030: originalLine = value;
1031: }
1032:
1033: /**
1034: * Set the output writer
1035: *
1036: *@param newOutput the new output writer
1037: */
1038: public void setOutput(PrintWriter newOutput) {
1039: if (newOutput != null) {
1040: lineQueue = lineQueueFactory(newOutput);
1041: }
1042: }
1043:
1044: /**
1045: * Sets the Ownline attribute of the LineQueue object
1046: *
1047: *@param value The new Ownline value
1048: */
1049: public void setOwnline(boolean value) {
1050: lineQueue.setOwnline(value);
1051: }
1052:
1053: /**
1054: * Sets the OwnlineCode attribute of the PrintData object
1055: *
1056: *@param value The new OwnlineCode value
1057: */
1058: public void setOwnlineCode(boolean value) {
1059: lineQueue.setOwnlineCode(value);
1060: }
1061:
1062: /**
1063: * Records the position of the method's opening parenthesis for use in
1064: * indenting parameters on subsequent lines.
1065: */
1066: public void setParamIndent() {
1067: if (inParams && lastParamIndent == 0) {
1068: lastParamIndent = getLineLength();
1069: }
1070: }
1071:
1072: /**
1073: * Sets the ReformatComments attribute of the PrintData object
1074: *
1075: *@param value The new ReformatComments value
1076: */
1077: public void setReformatComments(boolean value) {
1078: reformatComments = value;
1079: }
1080:
1081: /**
1082: * Sets the removeExcessBlocks attribute of the PrintData object
1083: *
1084: *@param value The new removeExcessBlocks value
1085: */
1086: public void setRemoveExcessBlocks(boolean value) {
1087: removeExcessBlocks = value;
1088: }
1089:
1090: /**
1091: * Sets the SharedIncr attribute of the PrintData object
1092: *
1093: *@param value The new SharedIncr value
1094: */
1095: public void setSharedIncr(boolean value) {
1096: lineQueue.setSharedIncremental(value);
1097: }
1098:
1099: /**
1100: * Sets the singleLineJavadoc attribute of the PrintData object
1101: *
1102: *@param value The new singleLineJavadoc value
1103: */
1104: public void setSingleLineJavadoc(boolean value) {
1105: allowSingleLineJavadoc = value;
1106: }
1107:
1108: /**
1109: * Sets the sortTop attribute of the PrintData object
1110: *
1111: *@param value The new sortTop value
1112: */
1113: public void setSortTop(boolean value) {
1114: sortTop = value;
1115: }
1116:
1117: /**
1118: * Sets the spaceAfterMethod attribute of the PrintData object
1119: *
1120: *@param way The new spaceAfterMethod value
1121: */
1122: public void setSpaceAfterMethod(boolean way) {
1123: spaceAfterMethod = way;
1124: }
1125:
1126: /**
1127: * Sets the spaceAfterKeyword attribute of the PrintData object
1128: *
1129: *@param way The new spaceAfterKeyword value
1130: *@since JRefactory 2.7.00
1131: */
1132: public void setSpaceAfterKeyword(boolean way) {
1133: spaceAfterKeyword = way;
1134: }
1135:
1136: /**
1137: * Sets the spaceAroundOperators attribute of the PrintData object
1138: *
1139: *@param way The new spaceAroundOperators value
1140: */
1141: public void setSpaceAroundOperators(boolean way) {
1142: spaceAroundOps = way;
1143: }
1144:
1145: /**
1146: * Sets the spaceInsideCast attribute of the PrintData object
1147: *
1148: *@param way The new spaceInsideCast value
1149: */
1150: public void setSpaceInsideCast(boolean way) {
1151: spaceInsideCast = way;
1152: }
1153:
1154: /**
1155: * Set the state
1156: *
1157: *@param newState Description of Parameter
1158: */
1159: public void setState(int newState) {
1160: last = newState;
1161: }
1162:
1163: /**
1164: * Sets the variablesAlignWithBlock attribute of the PrintData object
1165: *
1166: *@param value The new variablesAlignWithBlock value
1167: */
1168: public void setVariablesAlignWithBlock(boolean value) {
1169: variablesAlignWithBlock = value;
1170: }
1171:
1172: /**
1173: * Gets the CStyleFormatCode attribute of the PrintData object
1174: *
1175: *@return The CStyleFormatCode value
1176: */
1177: public int getCStyleFormatCode() {
1178: return cStyleFormatCode;
1179: }
1180:
1181: /**
1182: * Gets the CStyleIndent attribute of the PrintData object
1183: *
1184: *@return The CStyleIndent value
1185: */
1186: public int getCStyleIndent() {
1187: return cStyleIndent;
1188: }
1189:
1190: /**
1191: * Gets the CStyleOnline attribute of the PrintData object
1192: *
1193: *@return The CStyleOnline value
1194: */
1195: public boolean getCStyleOwnline() {
1196: //System.out.println("getCStyleOwnline() c_ownline="+c_ownline);
1197: return c_ownline;
1198: }
1199:
1200: /**
1201: * Sets the CStyleOnline attribute of the PrintData object
1202: *
1203: *@param ownline The new CStyleOnline value
1204: */
1205: public void setCStyleOwnline(boolean ownline) {
1206: c_ownline = ownline;
1207: //System.out.println("setCStyleOwnline() => c_ownline="+c_ownline);
1208: }
1209:
1210: /**
1211: * Gets the CurrentClassName attribute of the PrintData object
1212: *
1213: *@return The CurrentClassName value
1214: */
1215: public String getCurrentClassName() {
1216: return (String) classNameStack
1217: .elementAt(classNameStack.size() - 1);
1218: }
1219:
1220: /**
1221: * Gets the DynamicFieldSpacing attribute of the PrintData object
1222: *
1223: *@return The DynamicFieldSpacing value
1224: */
1225: public int getDynamicFieldSpaces() {
1226: return dynamicFieldSpace;
1227: }
1228:
1229: /**
1230: * Gets the FieldNameIndent attribute of the PrintData object
1231: *
1232: *@return The FieldNameIndent value
1233: */
1234: public int getFieldNameIndent() {
1235: return fieldNameIndent;
1236: }
1237:
1238: /**
1239: * Return the code for field and local variable spacing
1240: *
1241: *@return the code
1242: */
1243: public int getFieldSpaceCode() {
1244: return fieldSpaceCode;
1245: }
1246:
1247: /**
1248: * Gets the FinalLine attribute of the PrintData object
1249: *
1250: *@return The FinalLine value
1251: */
1252: public int getFinalLine() {
1253: return finalLine;
1254: }
1255:
1256: /**
1257: * Gets the importSortImportant attribute of the PrintData object
1258: *
1259: *@return The importSortImportant value
1260: */
1261: public String[] getImportSortImportant() {
1262: return importSortImportant;
1263: }
1264:
1265: /**
1266: * Gets the importSortNeighbourhood attribute of the PrintData object
1267: *
1268: *@return The importSortNeighbourhood value
1269: */
1270: public int getImportSortNeighbourhood() {
1271: return importSortNeighbourhood;
1272: }
1273:
1274: /**
1275: * Return the indent string
1276: *
1277: *@return an appropriate length string
1278: */
1279: public String getIndentString() {
1280: StringBuffer buffer = new StringBuffer();
1281: for (int ndx = 0; ndx < indent; ndx++) {
1282: buffer.append(indentChar);
1283: }
1284: return buffer.toString();
1285: }
1286:
1287: /**
1288: * Returns the number of spaces between the JavaDoc asterisks and the
1289: * comment text.
1290: *
1291: *@return the number of spaces between the JavaDoc asterisks and the
1292: * comment
1293: */
1294: public int getJavadocIndent() {
1295: if (javadocIndent >= 0) {
1296: return javadocIndent;
1297: }
1298: try {
1299: javadocIndent = bundle.getInteger("javadoc.indent");
1300: return javadocIndent;
1301: } catch (MissingSettingsException mre) {
1302: javadocIndent = 2;
1303: return javadocIndent;
1304: }
1305: }
1306:
1307: /**
1308: * Sets the number of spaces between the JavaDoc asterisks and the
1309: * comment text.
1310: *
1311: *@param indent the number of spaces between the JavaDoc asterisks and the
1312: * comment
1313: *@since JRefactory 2.7.02
1314: */
1315: public void setJavadocIndent(int indent) {
1316: javadocIndent = indent;
1317: }
1318:
1319: /**
1320: * Gets the JavadocStarCount attribute of the PrintData object
1321: *
1322: *@return The JavadocStarCount value
1323: */
1324: public int getJavadocStarCount() {
1325: return javadocStars;
1326: }
1327:
1328: /**
1329: * Gets the JavadocWordWrapMaximum attribute of the PrintData object
1330: *
1331: *@return The JavadocWordWrapMaximum value
1332: */
1333: public int getJavadocWordWrapMaximum() {
1334: return javadocMaximum;
1335: }
1336:
1337: /**
1338: * Sets the JavadocWordWrapMaximum attribute of the PrintData object
1339: *
1340: *@param wrap The JavadocWordWrapMaximum value
1341: *@since JRefactory 2.7.00
1342: */
1343: public void setJavadocWordWrapMaximum(int wrap) {
1344: javadocMaximum = wrap;
1345: }
1346:
1347: /**
1348: * Gets the JavadocWordWrapMinimum attribute of the PrintData object
1349: *
1350: *@return The JavadocWordWrapMinimum value
1351: */
1352: public int getJavadocWordWrapMinimum() {
1353: return javadocMinimum;
1354: }
1355:
1356: /**
1357: * Sets the JavadocWordWrapMinimum attribute of the PrintData object
1358: *
1359: *@param wrap The JavadocWordWrapMinimum value
1360: *@since JRefactory 2.7.00
1361: */
1362: public void setJavadocWordWrapMinimum(int wrap) {
1363: javadocMinimum = wrap;
1364: }
1365:
1366: /**
1367: * Get the length of the line
1368: *
1369: *@return the length of the buffer
1370: */
1371: public int getLineLength() {
1372: return outputBuffer.length();
1373: }
1374:
1375: /**
1376: * Gets the linesAfterPackage attribute of the PrintData object
1377: *
1378: *@return The linesAfterPackage value
1379: */
1380: public int getLinesAfterPackage() {
1381: return linesAfterPackage;
1382: }
1383:
1384: /**
1385: * Gets the linesBeforeClass attribute of the PrintData object
1386: *
1387: *@return The linesBeforeClass value
1388: */
1389: public int getLinesBeforeClass() {
1390: return linesBeforeClass;
1391: }
1392:
1393: /**
1394: * Gets the Order attribute of the PrintData object
1395: *
1396: *@return The Order value
1397: */
1398: public MultipleOrdering getOrder() {
1399: return morder;
1400: }
1401:
1402: /**
1403: * Gets the OriginalLine attribute of the PrintData object
1404: *
1405: *@return The OriginalLine value
1406: */
1407: public int getOriginalLine() {
1408: return originalLine;
1409: }
1410:
1411: /**
1412: * Returns the indentation to use for parameters on new lines. If the
1413: * <code>
1414: * params.lineup</code> property is true, parameters on new lines are lined
1415: * up with the method's open parenthesis.
1416: *
1417: *@return The ParamIndent value
1418: */
1419: // public int getParamIndent()
1420: // {
1421: // System.out.print("getParamIndent() inParams="+inParams+", lineUpParams="+lineUpParams);
1422: // if (inParams && lineUpParams) {
1423: // System.out.println(" ->"+lastParamIndent);
1424: // return lastParamIndent;
1425: // }
1426: // System.out.println(" ->"+0);
1427: // return 0;
1428: // }
1429:
1430: /**
1431: * Gets the Settings attribute of the PrintData object
1432: *
1433: *@return The Settings value
1434: */
1435: public Settings getSettings() {
1436: return bundle;
1437: }
1438:
1439: /**
1440: * Return the state of the pretty printer
1441: *
1442: *@return an integer representing the state
1443: */
1444: public int getState() {
1445: return last;
1446: }
1447:
1448: /**
1449: * Gets the SurpriseReturn attribute of the PrintData object
1450: *
1451: *@return The SurpriseReturn value
1452: */
1453: public int getSurpriseReturn() {
1454: return surpriseType;
1455: }
1456:
1457: public boolean isSortTop() {
1458: return sortTop;
1459: }
1460:
1461: /**
1462: * Gets the TopOrder attribute of the PrintData object
1463: *
1464: *@param node Description of the Parameter
1465: *@return The TopOrder value
1466: */
1467: public Comparator getTopOrder(ASTCompilationUnit node) {
1468: try {
1469: if (sortTop) {
1470: return new TopLevelOrdering(node, this );
1471: }
1472: } catch (MissingSettingsException mre) {
1473: }
1474:
1475: return new SameOrdering();
1476: }
1477:
1478: public void sortThrows(ASTNameList node) {
1479: if (sortThrowsStatement) {
1480: node.sort(new AlphaOrdering());
1481: }
1482: }
1483:
1484: public void sortImplements(ASTNameList node) {
1485: if (sortImplementsStatement) {
1486: node.sort(new AlphaOrdering());
1487: }
1488: }
1489:
1490: public void sortExtends(ASTNameList node) {
1491: if (sortExtendsStatement) {
1492: node.sort(new AlphaOrdering());
1493: }
1494: }
1495:
1496: private final static class AlphaOrdering implements Comparator {
1497: public int compare(Object o1, Object o2) {
1498: String lhs = ((ASTName) o1).getName();
1499: int index = lhs.lastIndexOf(".");
1500: if (index >= 0) {
1501: lhs = lhs.substring(index + 1);
1502: }
1503: String rhs = ((ASTName) o2).getName();
1504: index = rhs.lastIndexOf(".");
1505: if (index >= 0) {
1506: rhs = rhs.substring(index + 1);
1507: }
1508: return lhs.compareTo(rhs);
1509: }
1510: }
1511:
1512: /**
1513: * Gets the AllJavadocKept attribute of the PrintData object
1514: *
1515: *@return The AllJavadocKept value
1516: */
1517: public boolean isAllJavadocKept() {
1518: return keepAllJavadoc;
1519: }
1520:
1521: /**
1522: * Gets the allowSingleLineJavadoc attribute of the PrintData object
1523: *
1524: *@return The allowSingleLineJavadoc value
1525: */
1526: public boolean isAllowSingleLineJavadoc() {
1527: return allowSingleLineJavadoc;
1528: }
1529:
1530: /**
1531: * Gets the firstLineOnCommentStart attribute of the PrintData object
1532: *
1533: *@return The firstLineOnCommentStart value
1534: *@since 2.9.2
1535: */
1536: public boolean isFirstLineOnCommentStart() {
1537: return firstLineOnCommentStart;
1538: }
1539:
1540: /**
1541: * Gets the bangSpace attribute of the PrintData object
1542: *
1543: *@return The bangSpace value
1544: */
1545: public boolean isBangSpace() {
1546: return bangSpace;
1547: }
1548:
1549: /**
1550: * Is the output buffer empty?
1551: *
1552: *@return true if the output buffer is empty
1553: */
1554: public boolean isBufferEmpty() {
1555: return (outputBuffer.toString().trim().length() == 0);
1556: }
1557:
1558: /**
1559: * Gets the CastSpace attribute of the PrintData object
1560: *
1561: *@return The CastSpace value
1562: */
1563: public boolean isCastSpace() {
1564: return castSpace;
1565: }
1566:
1567: /**
1568: * Returns true if the catch statement is on a new line
1569: *
1570: *@return true if catch should start a line
1571: */
1572: public boolean isCatchOnNewLine() {
1573: try {
1574: return bundle.getBoolean("catch.start.line");
1575: } catch (MissingSettingsException mse) {
1576: return true;
1577: }
1578: }
1579:
1580: /**
1581: * Gets the currentSingle attribute of the PrintData object
1582: *
1583: *@return The currentSingle value
1584: */
1585: public boolean isCurrentSingle() {
1586: return currentIsSingle;
1587: }
1588:
1589: /**
1590: * Gets the DynamicFieldSpacing attribute of the PrintData object
1591: *
1592: *@param javadocPrinted Description of Parameter
1593: *@return The DynamicFieldSpacing value
1594: */
1595: public boolean isDynamicFieldSpacing(boolean javadocPrinted) {
1596: if (skipNameSpacing) {
1597: return false;
1598: }
1599: return (!javadocPrinted && (fieldSpaceCode == DFS_NOT_WITH_JAVADOC))
1600: || (fieldSpaceCode == DFS_ALWAYS);
1601: }
1602:
1603: /**
1604: * Returns true if the else statement is on a new line
1605: *
1606: *@return true if else should start a line
1607: */
1608: public boolean isElseOnNewLine() {
1609: return elseOnNewLine;
1610: }
1611:
1612: /**
1613: * Gets the EmptyBlockOnSingleLine attribute of the PrintData object
1614: *
1615: *@return The EmptyBlockOnSingleLine value
1616: */
1617: public boolean isEmptyBlockOnSingleLine() {
1618: return emptyBlockOnSingleLine;
1619: }
1620:
1621: /**
1622: * Gets the FieldNameIndented attribute of the PrintData object
1623: *
1624: *@return The FieldNameIndented value
1625: */
1626: public boolean isFieldNameIndented() {
1627: return (fieldNameIndent > 0);
1628: }
1629:
1630: /**
1631: * Gets the ForcingBlock attribute of the PrintData object
1632: *
1633: *@return The ForcingBlock value
1634: */
1635: public boolean isForcingBlock() {
1636: return forceBlock;
1637: }
1638:
1639: /**
1640: * Gets the indentInInitailzer attribute of the PrintData object
1641: *
1642: *@return The indentInInitailzer value
1643: */
1644: public boolean isIndentInInitailzer() {
1645: return indentInitializer;
1646: }
1647:
1648: /**
1649: * Gets the insertSpaceLocalVariables attribute of the PrintData object
1650: *
1651: *@return The insertSpaceLocalVariables value
1652: */
1653: public boolean isInsertSpaceLocalVariables() {
1654: return localVariableSpaceInsert;
1655: }
1656:
1657: /**
1658: * Returns true if JavaDoc IDs (param, returns, etc.) should be lined up.
1659: *
1660: *@return True if lining up comments, false otherwise
1661: */
1662: public boolean isJavadocLinedUp() {
1663: return lineupJavadocIDs;
1664: }
1665:
1666: /**
1667: * Gets the keepErroneousJavadocTags attribute of the PrintData object
1668: *
1669: *@return The keepErroneousJavadocTags value
1670: */
1671: public boolean isKeepErroneousJavadocTags() {
1672: return keepErroneousJavadocTags;
1673: }
1674:
1675: /**
1676: * Is the output buffer empty?
1677: *
1678: *@return true if the output buffer is empty
1679: */
1680: public boolean isLineIndented() {
1681: return (isBufferEmpty())
1682: && ((outputBuffer.toString().length() > 0) || (indent == 0));
1683: }
1684:
1685: /**
1686: * Gets the maintainNewlinesAroundImports attribute of the PrintData object
1687: *
1688: *@return The maintainNewlinesAroundImports value
1689: */
1690: public boolean isMaintainNewlinesAroundImports() {
1691: return maintainNewlinesAroundImports;
1692: }
1693:
1694: /**
1695: * Gets the NestedClassDocumented attribute of the PrintData object
1696: *
1697: *@return The NestedClassDocumented value
1698: */
1699: public boolean isNestedClassDocumented() {
1700: return documentNestedClasses;
1701: }
1702:
1703: /**
1704: * Gets the ReformatComments attribute of the PrintData object
1705: *
1706: *@return The ReformatComments value
1707: */
1708: public boolean isReformatComments() {
1709: return reformatComments;
1710: }
1711:
1712: /**
1713: * Gets the removeExcessBlocks attribute of the PrintData object
1714: *
1715: *@return The removeExcessBlocks value
1716: */
1717: public boolean isRemoveExcessBlocks() {
1718: return removeExcessBlocks;
1719: }
1720:
1721: /**
1722: * Gets the SpaceAfterCast attribute of the PrintData object
1723: *
1724: *@return The SpaceAfterCast value
1725: */
1726: public boolean isSpaceAfterCast() {
1727: return spaceAfterCast;
1728: }
1729:
1730: /**
1731: * Determines whether there should be a space between a keyword such as
1732: * 'if' or 'while' and the opening brace that follows it.
1733: *
1734: *@return The SpaceAfterKeyword value
1735: */
1736: public boolean isSpaceAfterKeyword() {
1737: return spaceAfterKeyword;
1738: }
1739:
1740: /**
1741: * Determines whether there should be a space between a method call and the
1742: * opening brace that follows it.
1743: *
1744: *@return The SpaceAfterMethod value
1745: */
1746: public boolean isSpaceAfterMethod() {
1747: return spaceAfterMethod;
1748: }
1749:
1750: /**
1751: * Gets the spaceAroundOperators attribute of the PrintData object
1752: *
1753: *@return The spaceAroundOperators value
1754: */
1755: public boolean isSpaceAroundOperators() {
1756: return spaceAroundOps;
1757: }
1758:
1759: /**
1760: * Determines if there should be a space between the '*' and the '@' in a
1761: * javadoc comment.
1762: *
1763: *@return true if there should be a space
1764: */
1765: public boolean isSpaceBeforeAt() {
1766: try {
1767: return bundle.getBoolean("space.before.javadoc");
1768: } catch (MissingSettingsException mre) {
1769: return false;
1770: }
1771: }
1772:
1773: /**
1774: * Determines if there is a space inside the cast parens
1775: *
1776: *@return The SpaceAfterKeyword value
1777: */
1778: public boolean isSpaceInsideCast() {
1779: return spaceInsideCast;
1780: }
1781:
1782: /**
1783: * Gets the ThrowsOnNewline attribute of the PrintData object
1784: *
1785: *@return The ThrowsOnNewline value
1786: */
1787: public boolean isThrowsOnNewline() {
1788: try {
1789: return bundle.getBoolean("throws.newline");
1790: } catch (MissingSettingsException mse) {
1791: return false;
1792: }
1793: }
1794:
1795: /**
1796: * Gets the variablesAlignWithBlock attribute of the PrintData object
1797: *
1798: *@return The variablesAlignWithBlock value
1799: */
1800: public boolean isVariablesAlignWithBlock() {
1801: return variablesAlignWithBlock;
1802: }
1803:
1804: /**
1805: * Append a comment to the output
1806: *
1807: *@param string the input string
1808: *@param type Description of Parameter
1809: */
1810: public void appendComment(String string, int type) {
1811: if (type == CATEGORY_COMMENT) {
1812: lineQueue.appendCategoryComment(string, outputBuffer
1813: .toString());
1814: newlineCount++;
1815: } else if (type == SINGLE_LINE_COMMENT) {
1816: lineQueue.appendSingleLineComment(string, outputBuffer
1817: .toString());
1818: newlineCount--;
1819: } else {
1820: append(string);
1821: }
1822: }
1823:
1824: /**
1825: * Append constant to the output
1826: *
1827: *@param string the input string
1828: */
1829: public void appendConstant(String string) {
1830: outputBuffer.append(string);
1831: }
1832:
1833: /**
1834: * Append a keyword to the output
1835: *
1836: *@param string the input string
1837: */
1838: public void appendKeyword(String string) {
1839: append(string);
1840: }
1841:
1842: /**
1843: * Append text to the output
1844: *
1845: *@param string the input string
1846: */
1847: public void appendText(String string) {
1848: append(string);
1849: }
1850:
1851: /**
1852: * Backspace
1853: */
1854: public void backspace() {
1855: outputBuffer.setLength(outputBuffer.length() - 1);
1856: }
1857:
1858: /**
1859: * Start a block
1860: */
1861: public void beginBlock() {
1862: beginBlock(true, true);
1863: }
1864:
1865: /**
1866: * Start a block
1867: *
1868: *@param space Description of the Parameter
1869: */
1870: public void beginBlock(boolean space) {
1871: beginBlock(space, true);
1872: }
1873:
1874: /**
1875: * Start a block
1876: *
1877: *@param space Description of Parameter
1878: *@param newlineAfter Description of the Parameter
1879: */
1880: public void beginBlock(boolean space, boolean newlineAfter) {
1881: int currentStyle = getCurrentBlockStyle();
1882:
1883: if (currentStyle == BLOCK_STYLE_C) {
1884: if (space) {
1885: space();
1886: }
1887: append("{");
1888: } else {
1889: if (currentStyle == BLOCK_STYLE_EMACS) {
1890: incrIndent();
1891: }
1892: indent();
1893: append("{");
1894: }
1895:
1896: isMethodBrace = false;
1897: isClassBrace = false;
1898: if (newlineAfter) {
1899: newline();
1900: }
1901: incrIndent();
1902: }
1903:
1904: /**
1905: * Start a Class
1906: */
1907: public void beginClass() {
1908: if (last != EMPTY) {
1909: for (int ndx = 0; ndx < linesBetween; ndx++) {
1910: newline();
1911: }
1912: }
1913: last = EMPTY;
1914: }
1915:
1916: /**
1917: * Start an expression
1918: *
1919: *@param notEmpty Description of Parameter
1920: */
1921: public void beginExpression(boolean notEmpty) {
1922: if (notEmpty == false || exprSpace == false) {
1923: append("(");
1924: } else {
1925: append("( ");
1926: }
1927: }
1928:
1929: /**
1930: * Start a Enum
1931: *@since JRefactory 2.7.00
1932: */
1933: public void beginEnum() {
1934: if ((last == EMPTY) || (last == ENUM)) {
1935: } else {
1936: for (int ndx = 0; ndx < linesBetween; ndx++) {
1937: newline();
1938: }
1939: }
1940: }
1941:
1942: /**
1943: * Start a Field
1944: */
1945: public void beginField() {
1946: if ((last == EMPTY) || (last == FIELD)) {
1947: } else {
1948: for (int ndx = 0; ndx < linesBetween; ndx++) {
1949: newline();
1950: }
1951: }
1952: }
1953:
1954: /**
1955: * Start a Interface
1956: */
1957: public void beginInterface() {
1958: if (last != EMPTY) {
1959: for (int ndx = 0; ndx < linesBetween; ndx++) {
1960: newline();
1961: }
1962: }
1963: last = EMPTY;
1964: }
1965:
1966: /**
1967: * Start a Method
1968: */
1969: public void beginMethod() {
1970: if (last != EMPTY) {
1971: for (int ndx = 0; ndx < linesBetween; ndx++) {
1972: newline();
1973: }
1974: }
1975: }
1976:
1977: /**
1978: * Indicates that a class's open brace is about to be formatted.
1979: */
1980: public void classBrace() {
1981: // This is reset to false in beginBlock after formatting
1982: isClassBrace = true;
1983: }
1984:
1985: /**
1986: * Closes the output stream
1987: */
1988: public void close() {
1989: flush();
1990: lineQueue.getOutput().close();
1991: }
1992:
1993: /**
1994: * Consume a newline
1995: *
1996: *@return true when we were expecting this newline
1997: */
1998: public boolean consumeNewline() {
1999: lineQueue.flushFirstLine();
2000:
2001: if (!isBufferEmpty()) {
2002: newlineCount = 0;
2003: }
2004:
2005: if (newlineCount > 0) {
2006: newlineCount--;
2007: return true;
2008: } else {
2009: newline();
2010: lineQueue.flush();
2011: return false;
2012: }
2013: }
2014:
2015: /**
2016: * Description of the Method
2017: */
2018: public void decrCaseIndent() {
2019: incrIndent(-caseIndent);
2020: }
2021:
2022: /**
2023: * Decrement the indent by the default amount
2024: */
2025: public void decrIndent() {
2026: incrIndent(-INDENT);
2027: }
2028:
2029: /**
2030: * End a block
2031: *
2032: *@param newline Description of Parameter
2033: *@param newlineBefore Description of the Parameter
2034: */
2035: public void endBlock(boolean newline, boolean newlineBefore) {
2036: decrIndent();
2037: if (newlineBefore || (outputBuffer.length() == 0)) {
2038: indent();
2039: }
2040: if (getCurrentBlockStyle() == BLOCK_STYLE_EMACS) {
2041: decrIndent();
2042: }
2043: append("}");
2044: if (newline) {
2045: newline();
2046: }
2047:
2048: isMethodBrace = false;
2049: isClassBrace = false;
2050: }
2051:
2052: /**
2053: * End a block
2054: */
2055: public void endBlock() {
2056: endBlock(true, true);
2057: }
2058:
2059: /**
2060: * End a Class
2061: */
2062: public void endClass() {
2063: last = CLASS;
2064: }
2065:
2066: /**
2067: * End an expression
2068: *
2069: *@param notEmpty Description of Parameter
2070: */
2071: public void endExpression(boolean notEmpty) {
2072: if (notEmpty == false || exprSpace == false) {
2073: append(")");
2074: } else {
2075: append(" )");
2076: }
2077: }
2078:
2079: /**
2080: * End a Enum
2081: *@since JRefactory 2.7.00
2082: */
2083: public void endEnum() {
2084: last = ENUM;
2085: }
2086:
2087: /**
2088: * End a Field
2089: */
2090: public void endField() {
2091: last = FIELD;
2092: }
2093:
2094: /**
2095: * End a Interface
2096: */
2097: public void endInterface() {
2098: last = INTERFACE;
2099: }
2100:
2101: /**
2102: * End a Method
2103: */
2104: public void endMethod() {
2105: last = METHOD;
2106: }
2107:
2108: /**
2109: * Sets the state for being inside a method declaration. Used for lining up
2110: * parameters with the method's open parenthesis.
2111: */
2112: public void enterMethodDecl() {
2113: inParams = true;
2114: lastParamIndent = 0;
2115: }
2116:
2117: /**
2118: * Indicates that we've exited a method declaration.
2119: */
2120: public void exitMethodDecl() {
2121: inParams = false;
2122: lastParamIndent = 0;
2123: }
2124:
2125: /**
2126: * Flushes the buffer
2127: */
2128: public void flush() {
2129: lineQueue.flush();
2130: }
2131:
2132: /**
2133: * Description of the Method
2134: */
2135: public void incrCaseIndent() {
2136: incrIndent(caseIndent);
2137: }
2138:
2139: /**
2140: * Increment the indent by the default amount
2141: */
2142: public void incrIndent() {
2143: incrIndent(INDENT);
2144: }
2145:
2146: /**
2147: * Indent the output
2148: */
2149: public void indent() {
2150: if (!isBufferEmpty()) {
2151: newline();
2152: }
2153:
2154: outputBuffer.setLength(0);
2155: append(getIndentString());
2156: }
2157:
2158: /**
2159: * Inserts a surprise indent
2160: *
2161: *@param printData the print data
2162: */
2163: public void surpriseIndent() {
2164: if (lineUpParams && (lastParamIndent > 0)) {
2165: indent();
2166: for (int ndx = 0; ndx < lastParamIndent - indent; ndx++) {
2167: append(" ");
2168: }
2169: } else if (getSurpriseReturn() == SINGLE_INDENT) {
2170: incrIndent();
2171: indent();
2172: decrIndent();
2173: } else if (getSurpriseReturn() == DOUBLE_INDENT) {
2174: incrIndent();
2175: incrIndent();
2176: indent();
2177: decrIndent();
2178: decrIndent();
2179: } else if (getSurpriseReturn() == PARAM_INDENT) {
2180: incrIndent();
2181: incrIndent();
2182: incrIndent();
2183: indent();
2184: decrIndent();
2185: decrIndent();
2186: decrIndent();
2187: } else if (getSurpriseReturn() == NO_INDENT) {
2188: indent();
2189: }
2190: }
2191:
2192: /**
2193: * Indicates that a method's open brace is about to be formatted.
2194: */
2195: public void methodBrace() {
2196: // This is reset to false in beginBlock after formatting
2197: isMethodBrace = true;
2198: }
2199:
2200: /**
2201: * Add a newline
2202: */
2203: public void newline() {
2204: String save = "";
2205:
2206: if (isBufferEmpty()) {
2207: outputBuffer.setLength(0);
2208: lineQueue.println("");
2209: newlineCount++;
2210: } else {
2211: save = outputBuffer.toString();
2212: lineQueue.println(outputBuffer.toString());
2213: outputBuffer.setLength(0);
2214: newlineCount = 1;
2215: }
2216: }
2217:
2218: /**
2219: * Description of the Method
2220: */
2221: public void popCurrentClassName() {
2222: classNameStack.removeElementAt(classNameStack.size() - 1);
2223: }
2224:
2225: /**
2226: * Description of the Method
2227: */
2228: public void popFieldSize() {
2229: fieldStack.removeElementAt(fieldStack.size() - 1);
2230: }
2231:
2232: /**
2233: * Description of the Method
2234: *
2235: *@param name Description of Parameter
2236: */
2237: public void pushCurrentClassName(String name) {
2238: classNameStack.addElement(name);
2239: }
2240:
2241: /**
2242: * Description of the Method
2243: *
2244: *@param size Description of Parameter
2245: */
2246: public void pushFieldSize(FieldSize size) {
2247: fieldStack.addElement(size);
2248: }
2249:
2250: /**
2251: * Description of the Method
2252: */
2253: public void reset() {
2254: outputBuffer.setLength(0);
2255: }
2256:
2257: /**
2258: * Description of the Method
2259: */
2260: public void saveCurrentLine() {
2261: setFinalLine(lineQueue.getCurrentLine());
2262: }
2263:
2264: /**
2265: * Add a space
2266: */
2267: public void space() {
2268: append(" ");
2269: }
2270:
2271: /**
2272: * Description of the Method
2273: *
2274: *@return Description of the Returned Value
2275: */
2276: public FieldSize topFieldSize() {
2277: return (FieldSize) fieldStack.elementAt(fieldStack.size() - 1);
2278: }
2279:
2280: /**
2281: * Increment the indent
2282: *
2283: *@param incr the amount to increment the indent
2284: */
2285: protected void incrIndent(int incr) {
2286: indent += incr;
2287: if (indent < 0) {
2288: indent = 0;
2289: }
2290: }
2291:
2292: /**
2293: * Get the indent
2294: *
2295: *@return the indent
2296: *@since JRefactory 2.7.00
2297: */
2298: public int getIndent() {
2299: return indent;
2300: }
2301:
2302: /**
2303: * Creates a line queue object
2304: *
2305: *@param output the output stream
2306: *@return the queue
2307: */
2308: protected LineQueue lineQueueFactory(PrintWriter output) {
2309: return new LineQueue(output);
2310: }
2311:
2312: /**
2313: * Sets the AllJavadocKept attribute of the PrintData object
2314: *
2315: *@param value The new AllJavadocKept value
2316: */
2317: void setAllJavadocKept(boolean value) {
2318: keepAllJavadoc = value;
2319: }
2320:
2321: /**
2322: * Sets the SkipNameSpacing attribute of the PrintData object
2323: *
2324: *@param value The new SkipNameSpacing value
2325: */
2326: void setSkipNameSpacing(boolean value) {
2327: skipNameSpacing = value;
2328: }
2329:
2330: /**
2331: * Sets the StoreJavadocPrinted attribute of the PrintData object
2332: *
2333: *@param value The new StoreJavadocPrinted value
2334: */
2335: void setStoreJavadocPrinted(boolean value) {
2336: storeJavadocPrinted = value;
2337: }
2338:
2339: /**
2340: * Sets the TempEqualsLength attribute of the PrintData object
2341: *
2342: *@param value The new TempEqualsLength value
2343: */
2344: void setTempEqualsLength(int value) {
2345: tempEqualsLength = value;
2346: }
2347:
2348: /**
2349: * Gets the SkipNameSpacing attribute of the PrintData object
2350: *
2351: *@return The SkipNameSpacing value
2352: */
2353: boolean getSkipNameSpacing() {
2354: return skipNameSpacing;
2355: }
2356:
2357: /**
2358: * Gets the TempEqualsLength attribute of the PrintData object
2359: *
2360: *@return The TempEqualsLength value
2361: */
2362: int getTempEqualsLength() {
2363: return tempEqualsLength;
2364: }
2365:
2366: /**
2367: * Gets the StoreJavadocPrinted attribute of the PrintData object
2368: *
2369: *@return The StoreJavadocPrinted value
2370: */
2371: boolean isStoreJavadocPrinted() {
2372: return storeJavadocPrinted;
2373: }
2374:
2375: /**
2376: * Determine what the current block style is
2377: *
2378: *@return true if we are using the C style now
2379: */
2380: private int getCurrentBlockStyle() {
2381: if (isClassBrace) {
2382: return classBlockStyle;
2383: }
2384:
2385: if (isMethodBrace) {
2386: return methodBlockStyle;
2387: }
2388:
2389: return codeBlockStyle;
2390: }
2391:
2392: /**
2393: * Returns the method block style
2394: */
2395: public int getMethodBlockStyle() {
2396: return methodBlockStyle;
2397: }
2398:
2399: /**
2400: * Append a string to the output
2401: *
2402: *@param string the input string
2403: */
2404: private void append(String string) {
2405: outputBuffer.append(string);
2406: }
2407:
2408: /**
2409: * Translates the key in the Settings into the block style
2410: *
2411: *@param key Description of the Parameter
2412: *@return Description of the Return Value
2413: */
2414: private int translateBlockStyle(String key) {
2415: try {
2416: String code = bundle.getString(key);
2417: if (code.equalsIgnoreCase("PASCAL")) {
2418: return BLOCK_STYLE_PASCAL;
2419: }
2420: if (code.equalsIgnoreCase("EMACS")) {
2421: return BLOCK_STYLE_EMACS;
2422: }
2423: } catch (MissingSettingsException mre) {
2424: // Default is sufficient
2425: }
2426: return BLOCK_STYLE_C;
2427: }
2428:
2429: public void setLineBeforeClassBody(boolean value) {
2430: lineBeforeClassBody = value;
2431: }
2432:
2433: public boolean isLineBeforeClassBody() {
2434: return lineBeforeClassBody;
2435: }
2436:
2437: public void setLineBeforeExtends(boolean value) {
2438: lineBeforeExtends = value;
2439: }
2440:
2441: public boolean isLineBeforeExtends() {
2442: return lineBeforeExtends;
2443: }
2444:
2445: public void setExtendsIndentation(int value) {
2446: extendsIndentation = value;
2447: }
2448:
2449: public int getExtendsIndentation() {
2450: return extendsIndentation;
2451: }
2452:
2453: public void setLineBeforeImplements(boolean value) {
2454: lineBeforeImplements = value;
2455: }
2456:
2457: public boolean isLineBeforeImplements() {
2458: return lineBeforeImplements;
2459: }
2460:
2461: public void setLineBeforeMultistatementMethodBody(boolean value) {
2462: lineBeforeMultistatementMethodBody = value;
2463: }
2464:
2465: public boolean isLineBeforeMultistatementMethodBody() {
2466: return lineBeforeMultistatementMethodBody;
2467: }
2468:
2469: public void setImplementsIndentation(int value) {
2470: implements Indentation = value;
2471: }
2472:
2473: public int getImplementsIndentation() {
2474: return implements Indentation;
2475: }
2476:
2477: private boolean arrayInitializerIndented = true;
2478:
2479: public void setArrayInitializerIndented(boolean way) {
2480: arrayInitializerIndented = way;
2481: }
2482:
2483: public boolean isArrayInitializerIndented() {
2484: return arrayInitializerIndented;
2485: }
2486:
2487: public final static int ALPHABETICAL_ORDER = 1;
2488: public final static int STANDARD_ORDER = 2;
2489: private int modifierOrder = STANDARD_ORDER;
2490:
2491: public void setModifierOrder(int value) {
2492: modifierOrder = value;
2493: }
2494:
2495: public int getModifierOrder() {
2496: return modifierOrder;
2497: }
2498:
2499: private boolean alignStarsWithSlash = false;
2500:
2501: public void setAlignStarsWithSlash(boolean value) {
2502: alignStarsWithSlash = value;
2503: }
2504:
2505: public boolean isStarsAlignedWithSlash() {
2506: return alignStarsWithSlash;
2507: }
2508:
2509: public void setLineupJavadocIDs(boolean way) {
2510: lineupJavadocIDs = way;
2511: }
2512:
2513: public void setLineupJavadocDescr(boolean way) {
2514: lineupJavadocDescr = way;
2515: }
2516:
2517: public boolean isJavadocDescriptionLinedup() {
2518: return lineupJavadocDescr;
2519: }
2520:
2521: private int taggedJavadocDescription = 6;
2522:
2523: public int getTaggedJavadocDescription() {
2524: return taggedJavadocDescription;
2525: }
2526:
2527: public void setTaggedJavadocDescription(int value) {
2528: taggedJavadocDescription = value;
2529: }
2530:
2531: public StringBuffer getBuffer() {
2532: return outputBuffer;
2533: }
2534:
2535: private static class JavaOutputStreamWriter extends Writer {
2536: Writer out = null;
2537:
2538: public JavaOutputStreamWriter(Writer out) {
2539: this .out = out;
2540: }
2541:
2542: /**
2543: * Write a single character.
2544: *
2545: * @exception IOException If an I/O error occurs
2546: */
2547: public void write(int c) throws IOException {
2548: if (c > 127) {
2549: System.out.println("writing character=" + c);
2550: out.write('\\');
2551: out.write('u');
2552: out.write(toHex((c >> 12) & 0x0F));
2553: out.write(toHex((c >> 8) & 0x0F));
2554: out.write(toHex((c >> 4) & 0x0F));
2555: out.write(toHex(c & 0x0F));
2556: } else {
2557: out.write(c);
2558: }
2559: }
2560:
2561: /**
2562: * Write a portion of an array of characters.
2563: *
2564: * @param cbuf Buffer of characters
2565: * @param off Offset from which to start writing characters
2566: * @param len Number of characters to write
2567: *
2568: * @exception IOException If an I/O error occurs
2569: */
2570: public void write(char cbuf[], int off, int len)
2571: throws IOException {
2572: char[] nbuf = null;
2573: int nlen = 0;
2574: for (int i = off; i < off + len; i++) {
2575: char c = cbuf[i];
2576: if (c > 127) {
2577: if (nbuf == null) {
2578: nbuf = new char[len * 4];
2579: for (int j = off; j < i; j++) {
2580: nbuf[j - off] = cbuf[j];
2581: }
2582: nlen = i - off;
2583: }
2584: System.out.println("writing character=" + c);
2585: nbuf[nlen++] = '\\';
2586: nbuf[nlen++] = 'u';
2587: nbuf[nlen++] = toHex((c >> 12) & 0x0F);
2588: nbuf[nlen++] = toHex((c >> 8) & 0x0F);
2589: nbuf[nlen++] = toHex((c >> 4) & 0x0F);
2590: nbuf[nlen++] = toHex(c & 0x0F);
2591: } else if (nbuf != null) {
2592: nbuf[nlen++] = c;
2593: }
2594: }
2595:
2596: if (nbuf == null) {
2597: out.write(cbuf, off, len);
2598: } else {
2599: out.write(nbuf, 0, nlen);
2600: }
2601: }
2602:
2603: private char toHex(int x) {
2604: switch (x) {
2605: case 0:
2606: return '0';
2607: case 1:
2608: return '1';
2609: case 2:
2610: return '2';
2611: case 3:
2612: return '3';
2613: case 4:
2614: return '4';
2615: case 5:
2616: return '5';
2617: case 6:
2618: return '6';
2619: case 7:
2620: return '7';
2621: case 8:
2622: return '8';
2623: case 9:
2624: return '9';
2625: case 10:
2626: return 'A';
2627: case 11:
2628: return 'B';
2629: case 12:
2630: return 'C';
2631: case 13:
2632: return 'D';
2633: case 14:
2634: return 'E';
2635: case 15:
2636: return 'F';
2637: }
2638: return '0';
2639: }
2640:
2641: /**
2642: * Write a portion of a string.
2643: *
2644: * @param str A String
2645: * @param off Offset from which to start writing characters
2646: * @param len Number of characters to write
2647: *
2648: * @exception IOException If an I/O error occurs
2649: */
2650: public void write(String str, int off, int len)
2651: throws IOException {
2652: write(str.toCharArray(), off, len);
2653: }
2654:
2655: /**
2656: * Flush the stream.
2657: *
2658: * @exception IOException If an I/O error occurs
2659: */
2660: public void flush() throws IOException {
2661: out.flush();
2662: }
2663:
2664: /**
2665: * Close the stream.
2666: *
2667: * @exception IOException If an I/O error occurs
2668: */
2669: public void close() throws IOException {
2670: out.close();
2671: }
2672: }
2673: }
|