001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.definitions.indent;
038:
039: import edu.rice.cs.drjava.DrJavaTestCase;
040: import edu.rice.cs.drjava.model.AbstractDJDocument;
041:
042: import javax.swing.text.AbstractDocument;
043: import javax.swing.text.BadLocationException;
044:
045: //import edu.rice.cs.drjava.model.definitions.DefinitionsDocument;
046:
047: /**
048: * Superclass for all test classes for the indentation decision tree.
049: * @version $Id: IndentRulesTestCase.java 4255 2007-08-28 19:17:37Z mgricken $
050: */
051: public abstract class IndentRulesTestCase extends DrJavaTestCase {
052:
053: protected volatile AbstractDJDocument _doc;
054:
055: // private String _indent;
056: // private GlobalEventNotifier _notifier;
057:
058: /** Sets up the test environment. */
059: public void setUp() throws Exception {
060: super .setUp();
061: //_notifier = new GlobalEventNotifier();
062: //_doc = new DefinitionsDocument(_notifier);
063: _doc = new AbstractDJDocument() {
064: protected int startCompoundEdit() {
065: //Do nothing
066: return 0;
067: }
068:
069: protected void endCompoundEdit(int key) { /* Do nothing. */
070: }
071:
072: protected void endLastCompoundEdit() { /* Do nothing. */
073: }
074:
075: protected void addUndoRedo(
076: AbstractDocument.DefaultDocumentEvent chng,
077: Runnable undoCommand, Runnable doCommand) {
078: /* Do nothing. */
079: }
080:
081: protected void _styleChanged() { /* Do nothing. */
082: }
083:
084: protected Indenter makeNewIndenter(int indentLevel) {
085: return new Indenter(indentLevel);
086: }
087: };
088: }
089:
090: public void tearDown() throws Exception {
091: _doc = null;
092: //_notifier = null;
093: System.gc();
094: super .tearDown();
095: }
096:
097: /** Clears the text of the _doc field and sets it to the given string.
098: */
099: protected final void _setDocText(String text)
100: throws BadLocationException {
101: _doc.clear();
102: _doc.insertString(0, text, null);
103: }
104:
105: /**
106: * Sets the number of spaces to include in the indent string.
107: *
108: protected final void _setIndentSize(int size) {
109: _indent = "";
110: for (int i=0; i < size; i++) {
111: _indent = _indent + " ";
112: }
113: }*/
114:
115: /**
116: * Gets the length of the indent string.
117: * @return Number of spaces in the indent string.
118: *
119: protected final int _getIndentSize() {
120: return _indent.length();
121: }*/
122:
123: /**
124: * Get a string containing the specified number of indents.
125: * @param numLevels Number of indent strings to return
126: *
127: protected String _getIndentString(int numLevels) {
128: String indent = "";
129: for (int i=0; i < numLevels; i++) {
130: indent += _indent;
131: }
132: return indent;
133: }*/
134:
135: /**
136: * Inserts an indent of the specificed number of levels at the given
137: * index in the string.
138: * @param text String to insert indent into
139: * @param index Position in string to add indent
140: * @param numLevels Number of indents to insert
141: *
142: protected String _addIndent(String text, int index, int numLevels) {
143: String start = text.substring(0, index);
144: String end = text.substring(index);
145: String indent = _getIndentString(numLevels);
146: return start.concat(indent).concat(end);
147: }*/
148:
149: /**
150: * Asserts that the document contains the expected text.
151: * @param expected what text of document should be
152: */
153: protected void _assertContents(String expected)
154: throws BadLocationException {
155: assertEquals("document contents", expected, _doc.getText());
156: }
157:
158: }
|