KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > indent > IndentRulesTestCase


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2006 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.definitions.indent;
35
36 import edu.rice.cs.drjava.DrJavaTestCase;
37 import edu.rice.cs.drjava.model.AbstractDJDocument;
38
39 import javax.swing.text.AbstractDocument JavaDoc;
40 import javax.swing.text.BadLocationException JavaDoc;
41 //import edu.rice.cs.drjava.model.definitions.DefinitionsDocument;
42

43 /**
44  * Superclass for all test classes for the indentation decision tree.
45  * @version $Id: IndentRulesTestCase.java 4026 2006-10-31 15:50:16Z rcartwright $
46  */

47 public abstract class IndentRulesTestCase extends DrJavaTestCase {
48
49   protected volatile AbstractDJDocument _doc;
50 // private String _indent;
51
// private GlobalEventNotifier _notifier;
52

53   /** Sets up the test environment. */
54   public void setUp() throws Exception JavaDoc {
55     super.setUp();
56     //_notifier = new GlobalEventNotifier();
57
//_doc = new DefinitionsDocument(_notifier);
58
_doc = new AbstractDJDocument() {
59       protected int startCompoundEdit() {
60         //Do nothing
61
return 0;
62       }
63       protected void endCompoundEdit(int key) { /* Do nothing. */ }
64       protected void endLastCompoundEdit() { /* Do nothing. */ }
65       protected void addUndoRedo(AbstractDocument.DefaultDocumentEvent JavaDoc chng, Runnable JavaDoc undoCommand, Runnable JavaDoc doCommand) {
66         /* Do nothing. */
67       }
68       protected void _styleChanged() { /* Do nothing. */ }
69       protected Indenter makeNewIndenter(int indentLevel) { return new Indenter(indentLevel); }
70     };
71   }
72   
73   public void tearDown() throws Exception JavaDoc {
74     _doc = null;
75     //_notifier = null;
76
System.gc();
77     super.tearDown();
78   }
79   
80   /** Clears the text of the _doc field and sets it to the given string.
81    */

82   protected final void _setDocText(String JavaDoc text)
83     throws BadLocationException JavaDoc {
84     _doc.clear();
85     _doc.insertString(0, text, null);
86   }
87   
88   /**
89    * Sets the number of spaces to include in the indent string.
90    *
91   protected final void _setIndentSize(int size) {
92     _indent = "";
93     for (int i=0; i < size; i++) {
94       _indent = _indent + " ";
95     }
96   }*/

97   
98   /**
99    * Gets the length of the indent string.
100    * @return Number of spaces in the indent string.
101    *
102   protected final int _getIndentSize() {
103     return _indent.length();
104   }*/

105   
106   /**
107    * Get a string containing the specified number of indents.
108    * @param numLevels Number of indent strings to return
109    *
110   protected String _getIndentString(int numLevels) {
111     String indent = "";
112     for (int i=0; i < numLevels; i++) {
113       indent += _indent;
114     }
115     return indent;
116   }*/

117
118   /**
119    * Inserts an indent of the specificed number of levels at the given
120    * index in the string.
121    * @param text String to insert indent into
122    * @param index Position in string to add indent
123    * @param numLevels Number of indents to insert
124    *
125   protected String _addIndent(String text, int index, int numLevels) {
126     String start = text.substring(0, index);
127     String end = text.substring(index);
128     String indent = _getIndentString(numLevels);
129     return start.concat(indent).concat(end);
130   }*/

131   
132   /**
133    * Asserts that the document contains the expected text.
134    * @param expected what text of document should be
135    */

136   protected void _assertContents(String JavaDoc expected) throws BadLocationException JavaDoc {
137     assertEquals("document contents",
138                  expected,
139                  _doc.getText());
140   }
141
142 }
143
Popular Tags