KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > definitions > DefinitionsDocumentTest


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-2005 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;
35
36 import edu.rice.cs.drjava.DrJava;
37 import edu.rice.cs.drjava.DrJavaTestCase;
38 import edu.rice.cs.drjava.config.OptionConstants;
39 import edu.rice.cs.drjava.model.GlobalEventNotifier;
40 import edu.rice.cs.drjava.model.definitions.reducedmodel.BraceReduction;
41 import edu.rice.cs.drjava.model.definitions.reducedmodel.HighlightStatus;
42 import edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedModelStates;
43 import edu.rice.cs.drjava.model.definitions.reducedmodel.ReducedToken;
44 import junit.framework.Test;
45 import junit.framework.TestSuite;
46
47 import javax.swing.text.BadLocationException JavaDoc;
48 import java.util.Vector JavaDoc;
49
50 /** Tests the functionality of the definitions document.
51  * @version $Id: DefinitionsDocumentTest.java 4011 2006-09-22 15:31:42Z rcartwright $
52  */

53 public final class DefinitionsDocumentTest extends DrJavaTestCase implements ReducedModelStates {
54   private DefinitionsDocument _defModel;
55   private GlobalEventNotifier _notifier;
56
57   /** Standard constructor.
58     * @param name of the test
59     */

60   public DefinitionsDocumentTest(String JavaDoc name) {
61     super(name);
62   }
63
64   /**
65    * Create a definitions document to work with.
66    */

67   protected void setUp() throws Exception JavaDoc {
68     super.setUp();
69     _notifier = new GlobalEventNotifier();
70     _defModel = new DefinitionsDocument(_notifier);
71     DrJava.getConfig().resetToDefaults();
72   }
73
74   /**
75    * Create a test suite for JUnit to run.
76    * @return a test suite based on this class
77    */

78   public static Test suite() {
79     return new TestSuite(DefinitionsDocumentTest.class);
80   }
81
82   /**
83    * Test insertion.
84    */

85   public void testInsertToDoc() throws BadLocationException JavaDoc {
86     _defModel.insertString(0, "a/*bc */\"\\{}()", null);
87     assertEquals("#0.0", _defModel.getText(0, 8), "a/*bc */");
88     assertEquals("#0.1", 14, _defModel.getCurrentLocation());
89     _defModel.insertString(0, "Start:", null);
90     assertEquals("#1.0", _defModel.getText(0, 14), "Start:a/*bc */");
91     assertEquals("#1.1", 6, _defModel.getCurrentLocation());
92     // document is:
93
// Start:=>a/*bc */"\\{}()
94
BraceReduction _reduced = _defModel.getReduced();
95     assertEquals("2.1", FREE, _reduced.getStateAtCurrent());
96     _reduced.move(2);
97     // document is:
98
// Start:a/=>*bc */"\\{}()
99
assertEquals("2.3", "/*", _reduced.currentToken().getType());
100     _reduced.move(2);
101     // document is:
102
// Start:a/*b=>c */"\\{}()
103
assertEquals("2.4", true, _reduced.currentToken().isGap());
104     assertEquals("2.5", ReducedToken.INSIDE_BLOCK_COMMENT, _reduced.currentToken().getState());
105     _reduced.move(2);
106     // document is:
107
// Start:a/*bc =>*/"\{}()
108
assertEquals("2.6", "*/", _reduced.currentToken().getType());
109     _reduced.move(2);
110     // document is:
111
// Start:a/*bc */=>"\{}()
112
assertEquals("2.7", "\"", _reduced.currentToken().getType());
113     _reduced.move(1);
114     // document is:
115
// Start:a/*bc */"=>\{}()
116
assertEquals("2.8", "\\", _reduced.currentToken().getType());
117     _reduced.move(1);
118     // document is:
119
// Start:a/*bc */"\=>{}()
120
assertEquals("2.9", "{", _reduced.currentToken().getType());
121     _reduced.move(1);
122     // document is:
123
// Start:a/*bc */"\{=>}()
124
assertEquals("2.91", "}", _reduced.currentToken().getType());
125     _reduced.move(1);
126     // document is:
127
// Start:a/*bc */"\{}=>()
128
assertEquals("2.92", "(", _reduced.currentToken().getType());
129     _reduced.move(1);
130     // document is:
131
// Start:a/*bc */"\\{}(=>)
132
assertEquals("2.93", ")", _reduced.currentToken().getType());
133   }
134
135   /**
136    * Test inserting a star between a star-slash combo.
137    * @exception BadLocationException
138    */

139   public void testInsertStarIntoStarSlash() throws BadLocationException JavaDoc {
140     BraceReduction _reduced = _defModel.getReduced();
141     _defModel.insertString(0, "/**/", null);
142     // Put new star between second star and second slash
143
_defModel.insertString(3, "*", null);
144     _defModel.move(-4);
145     assertEquals("1", "/*", _reduced.currentToken().getType());
146     assertEquals("2", ReducedToken.FREE, _reduced.currentToken().getState());
147     _reduced.move(2);
148     assertEquals("3", "*", _reduced.currentToken().getType());
149     assertEquals("4", ReducedToken.INSIDE_BLOCK_COMMENT, _reduced.currentToken().getState());
150     _reduced.move(1);
151     assertEquals("5", "*/", _reduced.currentToken().getType());
152     assertEquals("6", ReducedToken.FREE, _reduced.currentToken().getState());
153   }
154
155   /**
156    * Test inserting a slash between a star-slash combo.
157    * @exception BadLocationException
158    */

159   public void testInsertSlashIntoStarSlash() throws BadLocationException JavaDoc {
160     BraceReduction _reduced = _defModel.getReduced();
161     _defModel.insertString(0, "/**/", null);
162     // Put new slash between second star and second slash
163
_defModel.insertString(3, "/", null);
164     _defModel.move(-4);
165     assertEquals("1", "/*", _reduced.currentToken().getType());
166     assertEquals("2", ReducedToken.FREE, _reduced.currentToken().getState());
167     _reduced.move(2);
168     assertEquals("3", "*/", _reduced.currentToken().getType());
169     assertEquals("4", ReducedToken.FREE, _reduced.currentToken().getState());
170     _reduced.move(2);
171     assertEquals("5", "/", _reduced.currentToken().getType());
172     assertEquals("6", ReducedToken.FREE, _reduced.currentToken().getState());
173   }
174
175   /** Test inserting a star between a slash-star combo.
176    * @exception BadLocationException
177    */

178   public void testInsertStarIntoSlashStar() throws BadLocationException JavaDoc {
179     BraceReduction _reduced = _defModel.getReduced();
180     _defModel.insertString(0, "/**/", null);
181     // Put new star between second star and second slash
182
_defModel.insertString(1, "*", null);
183     _defModel.move(-2);
184     assertEquals("1", "/*", _reduced.currentToken().getType());
185     assertEquals("2", ReducedToken.FREE, _reduced.currentToken().getState());
186     _reduced.move(2);
187     assertEquals("3", "*", _reduced.currentToken().getType());
188     assertEquals("4", ReducedToken.INSIDE_BLOCK_COMMENT, _reduced.currentToken().getState());
189     _reduced.move(1);
190     assertEquals("5", "*/", _reduced.currentToken().getType());
191     assertEquals("6", ReducedToken.FREE, _reduced.currentToken().getState());
192   }
193
194   /** Test removal of text. */
195   public void testDeleteDoc() throws BadLocationException JavaDoc {
196     _defModel.insertString(0, "a/*bc */", null);
197     _defModel.remove(3, 3);
198     assertEquals("#0.0", "a/**/", _defModel.getText(0, 5));
199     assertEquals("#0.1", 3, _defModel.getCurrentLocation());
200     BraceReduction _reduced = _defModel.getReduced();
201     assertEquals("1.0", "*/", _reduced.currentToken().getType());
202     // no longer support getBlockOffset
203
// assertEquals("1.1",0,rm.getBlockOffset());
204
_reduced.move(-2);
205     assertEquals("1.2", "/*", _reduced.currentToken().getType());
206     _reduced.move(2);
207     assertEquals("1.3", ReducedToken.INSIDE_BLOCK_COMMENT, _reduced.getStateAtCurrent());
208   }
209
210   /** Make sure the vector is consistent: all elements immediately adjoin
211    * one another (no overlap), and make sure all indices between start and end
212    * are in the vector. Vector is guaranteed to not have size zero.
213    */

214   private void _checkHighlightStatusConsistent(Vector JavaDoc<HighlightStatus> v,
215                                                int start,
216                                                int end)
217   {
218     // location we're at so far
219
int walk = start;
220     for (int i = 0; i < v.size(); i++) {
221       assertEquals("Item #" + i + "in highlight vector starts at right place",
222                    walk,
223                    v.get(i).getLocation());
224       // Sanity check: length > 0?
225
assertTrue("Item #" + i + " in highlight vector has positive length",
226                  v.get(i).getLength() > 0);
227
228       walk += v.get(i).getLength();
229     }
230     assertEquals("Location after walking highlight vector",
231                  end,
232                  walk);
233   }
234
235   /** Test that keywords are highlighted properly.
236    * @exception BadLocationException
237    */

238   public void testHighlightKeywords1() throws BadLocationException JavaDoc {
239     Vector JavaDoc<HighlightStatus> v;
240     final String JavaDoc s = "public class Foo {\n" +
241       " private int _x = 0;\n" +
242         "}";
243     _defModel.insertString(_defModel.getLength(), s, null);
244     v = _defModel.getHighlightStatus(0, _defModel.getLength());
245     _checkHighlightStatusConsistent(v, 0, _defModel.getLength());
246     // Make sure the keywords are highlighted
247
assertEquals("vector length", 12, v.size());
248     assertEquals(HighlightStatus.KEYWORD, v.get(0).getState());
249     assertEquals(HighlightStatus.NORMAL, v.get(1).getState());
250     assertEquals(HighlightStatus.KEYWORD, v.get(2).getState());
251     assertEquals(HighlightStatus.NORMAL, v.get(3).getState());
252     assertEquals(HighlightStatus.TYPE, v.get(4).getState());
253     assertEquals(HighlightStatus.NORMAL, v.get(5).getState());
254
255     assertEquals(HighlightStatus.KEYWORD, v.get(6).getState());
256     assertEquals(HighlightStatus.NORMAL, v.get(7).getState());
257     assertEquals(HighlightStatus.TYPE, v.get(8).getState());
258     assertEquals(HighlightStatus.NORMAL, v.get(9).getState());
259     assertEquals(HighlightStatus.NUMBER, v.get(10).getState());
260     assertEquals(HighlightStatus.NORMAL, v.get(11).getState());
261   }
262
263   /** This test case simulates what happens when some text is selected
264    * and there is a keyword around too.
265    * In drjava-20010720-1712 there is a bug that if you enter "int Y" and
266    * then try to select "t Y", it exceptions. This is a test for that case.
267    * The important thing about the selecting thing is that because it wants
268    * to render the last three chars selected, it asks for the first two only
269    * in the call to getHighlightStatus.
270    * @exception BadLocationException
271    */

272   public void testHighlightKeywords2() throws BadLocationException JavaDoc {
273     Vector JavaDoc<HighlightStatus> v;
274     final String JavaDoc s = "int y";
275     _defModel.insertString(_defModel.getLength(), s, null);
276     // First sanity check the whole string's status
277
v = _defModel.getHighlightStatus(0, _defModel.getLength());
278     _checkHighlightStatusConsistent(v, 0, _defModel.getLength());
279     // Make sure the keyword is highlighted
280

281     assertEquals("vector length", 2, v.size());
282     assertEquals(HighlightStatus.TYPE, v.get(0).getState());
283     assertEquals(HighlightStatus.NORMAL, v.get(1).getState());
284     // Now only ask for highlights for "in"
285
v = _defModel.getHighlightStatus(0, 2);
286     _checkHighlightStatusConsistent(v, 0, 2);
287     assertEquals("vector length", 1, v.size());
288     assertEquals(0, v.get(0).getLocation());
289     assertEquals(2, v.get(0).getLength());
290   }
291
292   /** Test going to the second line in a two-line document.
293    * @exception BadLocationException
294    */

295   public void testGotoLine1() throws BadLocationException JavaDoc {
296     final String JavaDoc s = "a\n";
297     _defModel.insertString(0, s, null);
298     _defModel.gotoLine(2);
299     assertEquals("#0.0", 2, _defModel.getCurrentLocation());
300   }
301
302   /**
303    * Test going to a specific line.
304    * @exception BadLocationException
305    */

306   public void testGotoLine2() throws BadLocationException JavaDoc {
307     final String JavaDoc s = "abcd\n";
308     _defModel.insertString(0, s, null);
309     _defModel.gotoLine(2);
310     assertEquals("#0.0", 5, _defModel.getCurrentLocation());
311   }
312
313   /**
314    * Test going to the fourth line in a four line document.
315    * @exception BadLocationException
316    */

317   public void testGotoLine3() throws BadLocationException JavaDoc {
318     final String JavaDoc s = "a\nb\nc\n";
319     _defModel.insertString(0, s, null);
320     _defModel.gotoLine(4);
321     assertEquals("#0.0", 6, _defModel.getCurrentLocation());
322   }
323
324   /**
325    * Test going to a line beyond the number of lines in a document
326    * just goes to the end of the file.
327    * @exception BadLocationException
328    */

329   public void testGotoLine4() throws BadLocationException JavaDoc {
330     final String JavaDoc s = "a\nb\nc\n";
331     _defModel.insertString(0, s, null);
332     _defModel.gotoLine(8);
333     assertEquals("#0.0", 6, _defModel.getCurrentLocation());
334   }
335
336   /**
337    * Test going to the first line of an empty document
338    * doesn't do anything funny. It should stay in the same
339    * location.
340    */

341   public void testGotoLine5() {
342     _defModel.gotoLine(1);
343     assertEquals("#0.0", 0, _defModel.getCurrentLocation());
344   }
345
346   /**
347    * Test going to a line that is greater than the line count
348    * of an empty document just keeps you in your current location.
349    */

350   public void testGotoLine6() {
351     _defModel.gotoLine(4);
352     assertEquals("#0.0", 0, _defModel.getCurrentLocation());
353   }
354
355   /**
356    * Test that going to a line within the document's line count
357    * sets the current position to the first character of the line.
358    * @exception BadLocationException
359    */

360   public void testGotoLine7() throws BadLocationException JavaDoc {
361     final String JavaDoc s = "11111\n2222\n33333\n44444";
362     _defModel.insertString(0, s, null);
363     _defModel.gotoLine(3);
364     assertEquals("#0.0", 11, _defModel.getCurrentLocation());
365   }
366
367   /**
368    * Tests returning the current column in the document.
369    */

370   public void testGetColumn1() throws BadLocationException JavaDoc {
371     final String JavaDoc s = "1234567890";
372     assertEquals("#0.0", 0, _defModel.getCurrentCol());
373     _defModel.insertString(0, s, null);
374     assertEquals("#0.1", 10, _defModel.getCurrentCol());
375     _defModel.gotoLine(0);
376     assertEquals("#0.2", 0, _defModel.getCurrentCol());
377   }
378
379
380   /**
381    * Tests returning the current column in the document.
382    */

383   public void testGetColumn2() throws BadLocationException JavaDoc {
384     final String JavaDoc s = "1234567890\n1234\n12345";
385     _defModel.insertString(0, s, null);
386     assertEquals("#0.0", 5, _defModel.getCurrentCol() );
387   }
388
389   /**
390    * Test returning second line in a two-line document.
391    * @exception BadLocationException
392    */

393   public void testGetLine1() throws BadLocationException JavaDoc {
394     final String JavaDoc s = "a\n";
395     _defModel.insertString(0, s, null);
396     _defModel.setCurrentLocation(2);
397     assertEquals("#0.0", 2, _defModel.getCurrentLine());
398   }
399
400   /**
401    * Test going to a specific line.
402    * @exception BadLocationException
403    */

404   public void testGetLine2() throws BadLocationException JavaDoc {
405     final String JavaDoc s = "abcd\n";
406     _defModel.insertString(0, s, null);
407     _defModel.setCurrentLocation(2);
408     assertEquals("#0.0", 1, _defModel.getCurrentLine());
409     _defModel.gotoLine(2);
410     assertEquals("#0.1", 2, _defModel.getCurrentLine());
411   }
412
413   /**
414    * Test going to the fourth line in a four line document.
415    * @exception BadLocationException
416    */

417   public void testGetLine3() throws BadLocationException JavaDoc {
418     final String JavaDoc s = "a\nb\nc\n";
419     _defModel.insertString(0, s, null);
420     _defModel.setCurrentLocation(6);
421     assertEquals("#0.0", 4, _defModel.getCurrentLine());
422   }
423
424   /**
425    * Test going to a line beyond the number of lines in a document
426    * just goes to the end of the file.
427    * @exception BadLocationException
428    */

429   public void testGetLine4() throws BadLocationException JavaDoc {
430     final String JavaDoc s = "a\nb\nc\n";
431     _defModel.insertString(0, s, null);
432     _defModel.gotoLine(8);
433     assertEquals("#0.0", 4, _defModel.getCurrentLine());
434   }
435
436   /**
437    * Test going to the first line of an empty document
438    * doesn't do anything funny. It should stay in the same
439    * location.
440    */

441   public void testGetLine5() {
442     _defModel.setCurrentLocation(0);
443     assertEquals("#0.0", 1, _defModel.getCurrentLine());
444   }
445
446   /**
447    * Test going to a line that is greater than the line count
448    * of an empty document just keeps you in your current location.
449    */

450   public void testGetLine6() {
451     _defModel.gotoLine(4);
452     assertEquals("#0.0", 1, _defModel.getCurrentLine());
453   }
454
455   /**
456    * Test that going to a line within the document's line count
457    * sets the current position to the first character of the line.
458    * @exception BadLocationException
459    */

460   public void testGetLine7() throws BadLocationException JavaDoc {
461     final String JavaDoc s = "12345\n7890\n2345\n789";
462     _defModel.insertString(0, s, null);
463     _defModel.setCurrentLocation(12);
464     assertEquals("#0.0", 3, _defModel.getCurrentLine());
465     _defModel.move(-5);
466     assertEquals("#0.1", 2, _defModel.getCurrentLine());
467     _defModel.setCurrentLocation(19);
468     assertEquals("#0.2", 4, _defModel.getCurrentLine());
469   }
470
471   /**
472    * Tests line numbering output after deletion of a block
473    */

474   public void testGetLineDeleteText() throws BadLocationException JavaDoc{
475     final String JavaDoc s = "123456789\n123456789\n123456789\n123456789\n";
476     _defModel.insertString(0,s,null);
477     _defModel.setCurrentLocation(35);
478     assertEquals("Before delete", 4, _defModel.getCurrentLine() );
479     _defModel.remove(0,30);
480     _defModel.setCurrentLocation(5);
481     assertEquals("After delete", 1, _defModel.getCurrentLine() );
482   }
483
484   /**
485    * Tests line numbering output after deletion of a block
486    */

487   public void testGetLineDeleteText2() throws BadLocationException JavaDoc {
488     final String JavaDoc s = "123456789\n123456789\n123456789\n123456789\n";
489     _defModel.insertString(0,s,null);
490     _defModel.setCurrentLocation(35);
491     assertEquals("Before delete", 4, _defModel.getCurrentLine());
492     _defModel.remove(18,7);
493     assertEquals("After delete", 2, _defModel.getCurrentLine());
494   }
495
496   /**
497    * Test whether removeTabs actually removes all tabs.
498    */

499   public void testRemoveTabs1() {
500     _defModel.setIndent(1);
501     String JavaDoc test = "\t this \t\tis a \t\t\t\t\ttest\t\t";
502     String JavaDoc result = _defModel._removeTabs(test);
503     assertEquals( " this is a test ", result);
504   }
505
506   /**
507    * As of drjava-20020122-1534, files with tabs ended up garbled, with
508    * some of the text jumbled all around (bug #506630).
509    * This test aims to replicate the problem.
510    */

511   public void testRemoveTabs2() {
512    String JavaDoc input =
513     "\ttoken = nextToken(); // read trailing parenthesis\n" +
514     "\tif (token != ')')\n" +
515     "\t throw new ParseException(\"wrong number of arguments to |\");\n";
516
517    String JavaDoc expected =
518     " token = nextToken(); // read trailing parenthesis\n" +
519     " if (token != ')')\n" +
520     " throw new ParseException(\"wrong number of arguments to |\");\n";
521
522     int count = 5000;
523     final StringBuilder JavaDoc bigIn = new StringBuilder JavaDoc(input.length() * count);
524     final StringBuilder JavaDoc bigExp = new StringBuilder JavaDoc(expected.length() * count);
525     for (int i = 0; i < count; i++) {
526       bigIn.append(input);
527       bigExp.append(expected);
528     }
529
530     String JavaDoc result = _defModel._removeTabs(bigIn.toString());
531     assertEquals(bigExp.toString(), result);
532   }
533
534   /**
535    * Test whether tabs are removed as appropriate on call to insertString.
536    */

537   public void testTabRemovalOnInsertString2() throws BadLocationException JavaDoc {
538    String JavaDoc[] inputs = {
539       "\ttoken = nextToken(); // read trailing parenthesis\n",
540       "\tif (token != ')')\n",
541       "\t throw new ParseException(\"wrong number of arguments to |\");\n",
542     };
543
544    String JavaDoc expected =
545     " token = nextToken(); // read trailing parenthesis\n" +
546     " if (token != ')')\n" +
547     " throw new ParseException(\"wrong number of arguments to |\");\n";
548
549     for (int i = 0; i < inputs.length; i++) {
550       _defModel.insertString(_defModel.getLength(), inputs[i], null);
551     }
552
553     assertEquals(expected, _getAllText());
554   }
555
556   /** Test whether tabs are removed as appropriate on call to insertString. */
557   public void testTabRemovalOnInsertString() throws BadLocationException JavaDoc {
558     _defModel.setIndent(1);
559     _defModel.insertString(0, " \t yet \t\tanother\ttest\t", null);
560     String JavaDoc result = _defModel.getText();
561
562     if (_defModel.tabsRemoved()) {
563       assertEquals(" yet another test ", result);
564     }
565     else { // Tabs should have been inserted.
566
assertEquals(" \t yet \t\tanother\ttest\t", result);
567     }
568   }
569
570   /** Test package-finding on empty document. */
571   public void testPackageNameEmpty() throws InvalidPackageException {
572     assertEquals("Package name for empty document", "", _defModel.getPackageName());
573   }
574
575   /** Test package-finding on simple document, with no funny comments. */
576   public void testPackageNameSimple()
577     throws Exception JavaDoc
578   {
579     final String JavaDoc[] comments = {
580       "/* package very.bad; */",
581       "// package terribly.wrong;"
582     };
583
584     final String JavaDoc[] packages = {"edu", "edu.rice", "edu.rice.cs.drjava" };
585
586     for (int i = 0; i < packages.length; i++) {
587       String JavaDoc curPack = packages[i];
588
589       for (int j = 0; j < comments.length; j++) {
590         String JavaDoc curComment = comments[j];
591         setUp();
592         _defModel.insertString(0, curComment + "\n\n" + "package " + curPack + ";\nclass Foo { int x; }\n", null);
593
594         assertEquals("Package name for document with comment " + curComment, curPack, _defModel.getPackageName());
595       }
596     }
597   }
598
599   /** Test package-finding on document with a block comment between parts of package. */
600   public void testPackageNameWeird1() throws BadLocationException JavaDoc, InvalidPackageException {
601     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava;";
602     String JavaDoc normal = "edu.rice.cs.drjava";
603     _defModel.insertString(0, weird, null);
604
605     assertEquals("Package name for weird: '" + weird + "'", normal, _defModel.getPackageName());
606   }
607
608   /** Test package-finding on document with a line comment between parts of package. */
609   public void testPackageNameWeird2() throws BadLocationException JavaDoc, InvalidPackageException {
610     String JavaDoc weird = "package edu . rice //comment!\n.cs.drjava;";
611     String JavaDoc normal = "edu.rice.cs.drjava";
612     _defModel.insertString(0, weird, null);
613
614     assertEquals("Package name for weird: '" + weird + "'", normal, _defModel.getPackageName());
615   }
616
617   /** Puts an otherwise valid package statement after a valid import declaration. This should result in seeing no
618    * package statement (for the purposes of getSourceRoot), so the resulting package name should be "".
619    */

620   public void testGetPackageNameWithPackageStatementAfterImport() throws BadLocationException JavaDoc, InvalidPackageException {
621     String JavaDoc text = "import java.util.*;\npackage junk;\nclass Foo {}";
622     _defModel.insertString(0, text, null);
623     assertEquals("Package name for text with package statement after import", "", _defModel.getPackageName());
624   }
625
626   private String JavaDoc _getAllText() throws BadLocationException JavaDoc { return _defModel.getText(); }
627   
628   /** Tests class name-finding on document. */
629   public void testTopLevelClassName() throws BadLocationException JavaDoc, ClassNameNotFoundException {
630     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; class MyClass<T> implements O{";
631     String JavaDoc result = "MyClass";
632     _defModel.insertString(0, weird, null);
633
634     assertEquals("class name for weird: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
635   }
636
637  /** Test interface name-finding on document */
638   public void testTopLevelInterfaceName() throws BadLocationException JavaDoc, ClassNameNotFoundException {
639     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; \n" + " interface thisInterface { \n" +
640       " class MyClass {";
641     String JavaDoc result = "thisInterface";
642     _defModel.insertString(0, weird, null);
643
644     assertEquals("class name for interface: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
645   }
646
647  /** Test class name-finding on document */
648   public void testTopLevelClassNameWComments() throws BadLocationException JavaDoc, ClassNameNotFoundException {
649     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; \n" +
650       "/* class Y */ \n" +
651       " /* class Foo \n" +
652       " * class Bar \n" +
653       " interface Baz \n" +
654       " */ \n" +
655       "//class Blah\n" +
656       "class MyClass {";
657
658     String JavaDoc result = "MyClass";
659     _defModel.insertString(0, weird, null);
660
661     assertEquals("class name for class: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
662   }
663
664   /** Tests that a keyword with no space following it does not cause a StringOutOfBoundsException (bug 742226). */
665   public void testTopLevelClassNameNoSpace() throws BadLocationException JavaDoc {
666     String JavaDoc c = "class";
667     _defModel.insertString(0, c, null);
668     try {
669       _defModel.getFirstTopLevelClassName();
670       fail("Should not have found a class name");
671     }
672     catch (ClassNameNotFoundException e) {
673       // Good, we expect this
674
}
675   }
676
677   /**
678    * Tests that the word class is not recognized if it is not followed
679    * by whitespace.
680    */

681   public void testTopLevelClassNameWithClassloaderImport()
682     throws BadLocationException JavaDoc, ClassNameNotFoundException
683   {
684     String JavaDoc weird = "import classloader.class; class MyClass {";
685     String JavaDoc result = "MyClass";
686     _defModel.insertString(0, weird, null);
687
688     assertEquals("class name for weird: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
689   }
690
691   /** Tests class name-finding on document. */
692   public void testTopLevelClassNameMisleading() throws BadLocationException JavaDoc, ClassNameNotFoundException {
693     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; \n" +
694       " {class X} \n" +
695       " interface thisInterface { \n" +
696       " class MyInnerClass {";
697     String JavaDoc result = "thisInterface";
698     _defModel.insertString(0, weird, null);
699
700     assertEquals("class name for interface: '" + weird + "'",
701                  result,
702                  _defModel.getFirstTopLevelClassName());
703   }
704
705   /** Tests class name-finding on document */
706   public void testTopLevelInterfaceNameMisleading() throws BadLocationException JavaDoc, ClassNameNotFoundException {
707     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; \n" + " {interface X} " + " \"class Foo\"" +
708       " class MyClass {";
709     String JavaDoc result = "MyClass";
710     _defModel.insertString(0, weird, null);
711
712     assertEquals("class name for user interface: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
713   }
714
715   /** Tests class name-finding on document */
716   public void testTopLevelInterfaceNameMisleading2() throws BadLocationException JavaDoc, ClassNameNotFoundException {
717     String JavaDoc weird = "package edu . rice\n./*interface comment!*/cs.drjava; \n" + " {interface X<T>} " +
718       " \"class interface Foo\"" + " class MyClass extends Foo<T> {";
719     String JavaDoc result = "MyClass";
720     _defModel.insertString(0, weird, null);
721
722     assertEquals("class name for user interface: '" + weird + "'", result, _defModel.getFirstTopLevelClassName());
723   }
724
725   /** Tests class name-finding on document. */
726   public void testTopLevelInterfaceNameBeforeClassName()
727     throws BadLocationException JavaDoc, ClassNameNotFoundException
728   {
729     String JavaDoc weird = "package edu . rice\n./*comment!*/cs.drjava; \n" +
730       " interface thisInterface { \n" +
731       " } \n" +
732       " class thatClass {\n" +
733       " }";
734     String JavaDoc result = "thisInterface";
735     _defModel.insertString(0, weird, null);
736
737     assertEquals("interface should have been chosen, rather than the class: '" + weird + "'",
738                  result,
739                  _defModel.getFirstTopLevelClassName());
740   }
741
742   /** Tests class name-finding on document. */
743   public void testTopLevelClassNameWithDelimiters() throws BadLocationException JavaDoc, ClassNameNotFoundException {
744     String JavaDoc weird1 = "package edu . rice\n./*comment!*/cs.drjava; \n" + " class MyClass<T> {";
745     String JavaDoc result1 = "MyClass";
746     _defModel.insertString(0, weird1, null);
747
748     assertEquals("generics should be removed: '" + weird1 + "'", result1, _defModel.getFirstTopLevelClassName());
749
750     String JavaDoc weird2 = "package edu . rice\n./*comment!*/cs.drjava; \n" + " class My_Class {";
751     String JavaDoc result2 = "My_Class";
752     _defModel.insertString(0, weird2, null);
753
754     assertEquals("underscores should remain: '" + weird1 + "'", result2, _defModel.getFirstTopLevelClassName());
755   }
756
757   /** Tests that the name of a top level enclosing class can be found. */
758   public void testTopLevelEnclosingClassName() throws BadLocationException JavaDoc, ClassNameNotFoundException {
759     String JavaDoc classes =
760       "import foo;\n" + // 12 (including newline)
761
"class C1 {\n" + // 23
762
" void foo() { int a; }\n" + // 47
763
" class C2 { int x;\n" + // 67
764
" int y;\n" + // 78
765
" class C3 {}\n" + // 94
766
" } int b;\n" + // 105
767
"}\n" + // 107
768
"class C4 {\n" + // 118
769
" class C5 {\n" + // 131
770
" void bar() { int c; } class C6 {}\n" + // 169
771
" }\n" + // 173
772
"} class C7 {}"; // 186
773

774     _defModel.insertString(0, classes, null);
775
776     // No enclosing class at start
777
try {
778       String JavaDoc result = _defModel.getEnclosingTopLevelClassName(3);
779       fail("no enclosing class should be found at start");
780     }
781     catch (ClassNameNotFoundException cnnfe) {
782       // Correct: no class name found
783
}
784
785     // No enclosing class before open brace
786
try {
787       _defModel.getEnclosingTopLevelClassName(15);
788       fail("no enclosing class should be found before open brace");
789     }
790     catch (ClassNameNotFoundException cnnfe) {
791       // Correct: no class name found
792
}
793
794     try {
795       String JavaDoc result = _defModel.getEnclosingTopLevelClassName(186);
796       fail("no enclosing class should be found at end of file");
797     }
798     catch (ClassNameNotFoundException cnnfe) {
799       // Correct: no class name found
800
}
801
802     assertEquals("top level class name after first open brace", "C1", _defModel.getEnclosingTopLevelClassName(22));
803     assertEquals("top level class name inside C1", "C1", _defModel.getEnclosingTopLevelClassName(26));
804     assertEquals("top level class name inside method of C1", "C1", _defModel.getEnclosingTopLevelClassName(42));
805     assertEquals("top level class name on C2's brace", "C1", _defModel.getEnclosingTopLevelClassName(58));
806     assertEquals("top level class name after C2's brace", "C1", _defModel.getEnclosingTopLevelClassName(59));
807     assertEquals("top level class name inside C2", "C1", _defModel.getEnclosingTopLevelClassName(68));
808     assertEquals("top level class name inside C3", "C1", _defModel.getEnclosingTopLevelClassName(92));
809     assertEquals("top level class name after C3's close brace", "C1", _defModel.getEnclosingTopLevelClassName(93));
810     assertEquals("top level class name after C2's close brace", "C1", _defModel.getEnclosingTopLevelClassName(100));
811
812     // No enclosing class between classes
813
try {
814       _defModel.getEnclosingTopLevelClassName(107);
815       fail("no enclosing class should be found between classes");
816     }
817     catch (ClassNameNotFoundException cnnfe) {
818       // Correct: no class name found
819
}
820
821     assertEquals("class name inside C4", "C4", _defModel.getEnclosingTopLevelClassName(122));
822     assertEquals("class name inside C5", "C4", _defModel.getEnclosingTopLevelClassName(135));
823     assertEquals("class name inside C6", "C4", _defModel.getEnclosingTopLevelClassName(167));
824     assertEquals("class name inside C7", "C7", _defModel.getEnclosingTopLevelClassName(185));
825
826     // No enclosing class at end
827
try {
828       String JavaDoc result = _defModel.getEnclosingTopLevelClassName(186);
829       fail("no enclosing class should be found at end");
830     }
831     catch (ClassNameNotFoundException cnnfe) {
832       // Correct: no class name found
833
}
834   }
835
836   /** Tests that the correct qualified class name is returned with a package. */
837   public void testQualifiedClassNameWithPackage() throws BadLocationException JavaDoc, ClassNameNotFoundException {
838     String JavaDoc classes =
839       "package foo;\n" + // 13
840
"class C1 {}\n" + // 25
841
"class C2 {}"; // 36
842
_defModel.insertString(0, classes, null);
843
844     assertEquals("qualified class name without pos", "foo.C1", _defModel.getQualifiedClassName());
845     assertEquals("enclosing class name in C1", "C1", _defModel.getEnclosingTopLevelClassName(23));
846     assertEquals("qualified class name with pos in C1", "foo.C1", _defModel.getQualifiedClassName(23));
847     assertEquals("qualified class name with pos in C2", "foo.C2", _defModel.getQualifiedClassName(35));
848
849     // No class name outside classes
850
try {
851       _defModel.getQualifiedClassName(15);
852       fail("no qualified class name should be found outside classes");
853     }
854     catch (ClassNameNotFoundException cnnfe) {
855       // Correct: no class name found
856
}
857   }
858
859   /** Tests that the correct qualified class name is returned without a package. */
860   public void testQualifiedClassNameWithoutPackage() throws BadLocationException JavaDoc, ClassNameNotFoundException {
861     String JavaDoc classes =
862       "class C1 {}\n" + // 12
863
"class C2 {}"; // 36
864
_defModel.insertString(0, classes, null);
865
866     assertEquals("qualified class name without pos", "C1", _defModel.getQualifiedClassName());
867     assertEquals("qualified class name with pos in C1", "C1", _defModel.getQualifiedClassName(10));
868     assertEquals("qualified class name with pos in C2", "C2", _defModel.getQualifiedClassName(22));
869
870     // No class name outside classes
871
try {
872       _defModel.getQualifiedClassName(15);
873       fail("no qualified class name should be found outside classes");
874     }
875     catch (ClassNameNotFoundException cnnfe) {
876       // Correct: no class name found
877
}
878   }
879
880   /** Tests that the name of an enclosing class can be found.
881     *
882     * Note: I started to write this assuming that we would need to find
883     * inner class names, but I'm not sure that's the case. I'm writing
884     * the method for the debugger, which only needs the *top level*
885     * enclosing class. Rather than delete this test, though, I'll leave
886     * it in case we ever need to write getEnclosingClassName().
887     *
888   public void testEnclosingClassName() throws BadLocationException, ClassNameNotFoundException {
889     String classes =
890       "import foo;\n" + // 12 (including newline)
891       "class C1 {\n" + // 23
892       " void foo() { int a; }\n" + // 47
893       " class C2 { int x;\n" + // 67
894       " int y;\n" + // 78
895       " class C3 {}\n" + // 94
896       " } int b;\n" + // 105
897       "}\n" + // 107
898       "class C4 {\n" + // 118
899       "} class C5 {}"; // 131
900     _defModel.insertString(0, classes, null);
901
902     // No enclosing class at start
903     try {
904       String result = _defModel.getEnclosingClassName(3);
905       fail("no enclosing class should be found at start");
906     }
907     catch (ClassNameNotFoundException cnnfe) {
908       // Correct: no class name found
909     }
910
911     // No enclosing class before open brace
912     try {
913       String result = _defModel.getEnclosingClassName(15);
914       fail("no enclosing class should be found before open brace");
915     }
916     catch (ClassNameNotFoundException cnnfe) {
917       // Correct: no class name found
918     }
919
920     assertEquals("class name after first open brace", "C1",
921                  _defModel.getEnclosingClassName(22));
922     assertEquals("class name inside C1", "C1",
923                  _defModel.getEnclosingClassName(26));
924     assertEquals("class name inside method of C1", "C1",
925                  _defModel.getEnclosingClassName(42));
926     assertEquals("class name on C2's brace", "C1",
927                  _defModel.getEnclosingClassName(58));
928     assertEquals("class name after C2's brace", "C2",
929                  _defModel.getEnclosingClassName(59));
930     assertEquals("class name inside C2", "C2",
931                  _defModel.getEnclosingClassName(68));
932     assertEquals("class name inside C3", "C3",
933                  _defModel.getEnclosingClassName(92));
934     assertEquals("class name after C3's close brace", "C2",
935                  _defModel.getEnclosingClassName(93));
936     assertEquals("class name after C2's close brace", "C1",
937                  _defModel.getEnclosingClassName(100));
938
939     // No enclosing class between classes
940     try {
941       String result = _defModel.getEnclosingClassName(107);
942       fail("no enclosing class should be found between classes");
943     }
944     catch (ClassNameNotFoundException cnnfe) {
945       // Correct: no class name found
946     }
947
948     assertEquals("class name inside C4", "C4",
949                  _defModel.getEnclosingClassName(118));
950     assertEquals("class name inside C5", "C5",
951                  _defModel.getEnclosingClassName(130));
952
953     // No enclosing class at end
954     try {
955       String result = _defModel.getEnclosingClassName(131);
956       fail("no enclosing class should be found at end");
957     }
958     catch (ClassNameNotFoundException cnnfe) {
959       // Correct: no class name found
960     }
961   }*/

962
963   /** Verify that undoing a multiple-line indent will be a single undo action
964    * @throws BadLocationException
965    */

966   public void testUndoAndRedoAfterMultipleLineIndent() throws BadLocationException JavaDoc { //this fails
967
String JavaDoc text =
968       "public class stuff {\n" +
969       "private int _int;\n" +
970       "private Bar _bar;\n" +
971       "public void foo() {\n" +
972       "_bar.baz(_int);\n" +
973       "}\n" +
974       "}\n";
975
976     String JavaDoc indented =
977       "public class stuff {\n" +
978       " private int _int;\n" +
979       " private Bar _bar;\n" +
980       " public void foo() {\n" +
981       " _bar.baz(_int);\n" +
982       " }\n" +
983       "}\n";
984
985     _defModel.addUndoableEditListener(_defModel.getUndoManager());
986     DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL,new Integer JavaDoc(2));
987     _defModel.insertString(0,text,null);
988     assertEquals("insertion",text, _defModel.getText());
989     /* This is necessary here and other places where indenting or commenting takes place because the undoListener in DefinitionsPane
990      * currently starts compound edits, but here, there's no DefinitionsPane.
991      * Perhaps there's some way to factor the undoListener in CompoundUndoManager to be the one that starts compound edits
992      * so that it will work with or without the view.
993      */

994     _defModel.getUndoManager().startCompoundEdit();
995     _defModel.indentLines(0,_defModel.getLength());
996     assertEquals("indenting",indented, _defModel.getText());
997     _defModel.getUndoManager().undo();
998     assertEquals("undo",text, _defModel.getText());
999     _defModel.getUndoManager().redo();
1000    assertEquals("redo",indented, _defModel.getText());
1001  }
1002
1003  /** Verify that undoing a multiple-line indent will be a single undo action
1004   * @throws BadLocationException
1005   */

1006  public void testUndoAndRedoAfterMultipleLineCommentAndUncomment()
1007    throws BadLocationException JavaDoc {
1008    String JavaDoc text =
1009      "public class stuff {\n" +
1010      " private int _int;\n" +
1011      " private Bar _bar;\n" +
1012      " public void foo() {\n" +
1013      " _bar.baz(_int);\n" +
1014      " }\n" +
1015      "}\n";
1016
1017    String JavaDoc commented =
1018      "//public class stuff {\n" +
1019      "// private int _int;\n" +
1020      "// private Bar _bar;\n" +
1021      "// public void foo() {\n" +
1022      "// _bar.baz(_int);\n" +
1023      "// }\n" +
1024      "//}\n";
1025
1026    _defModel.addUndoableEditListener(_defModel.getUndoManager());
1027    DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL,new Integer JavaDoc(2));
1028    _defModel.insertString(0,text,null);
1029    assertEquals("insertion",text, _defModel.getText());
1030
1031    _defModel.getUndoManager().startCompoundEdit();
1032    _defModel.commentLines(0,_defModel.getLength());
1033    assertEquals("commenting",commented, _defModel.getText());
1034    _defModel.getUndoManager().undo();
1035    assertEquals("undo commenting",text, _defModel.getText());
1036    _defModel.getUndoManager().redo();
1037    assertEquals("redo commenting",commented, _defModel.getText());
1038
1039    _defModel.getUndoManager().startCompoundEdit();
1040    _defModel.uncommentLines(0,_defModel.getLength());
1041    assertEquals("uncommenting",text, _defModel.getText());
1042    _defModel.getUndoManager().undo();
1043    assertEquals("undo uncommenting",commented, _defModel.getText());
1044    _defModel.getUndoManager().redo();
1045    assertEquals("redo uncommenting",text, _defModel.getText());
1046  }
1047
1048  /** Test method for CompoundUndoManager. Tests that the nested compound edit functionality works correctly.
1049   * @throws BadLocationException
1050   */

1051  public void testCompoundUndoManager() throws BadLocationException JavaDoc {
1052    String JavaDoc text =
1053      "public class foo {\n" +
1054      "int bar;\n" +
1055      "}";
1056
1057    String JavaDoc indented =
1058      "public class foo {\n" +
1059      " int bar;\n" +
1060      "}";
1061    CompoundUndoManager undoManager = _defModel.getUndoManager();
1062
1063    _defModel.addUndoableEditListener(undoManager);
1064    DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL,new Integer JavaDoc(2));
1065
1066    // 1
1067

1068    // Start a compound edit and verify the returned key
1069
int key = undoManager.startCompoundEdit();
1070    assertEquals("Should have returned the correct key.", 0, key);
1071
1072    // Insert a test string into the document
1073
_defModel.insertString(0, text, null);
1074    assertEquals("Should have inserted the text properly.", text, _defModel.getText());
1075
1076    // Indent the lines, so as to trigger a nested compound edit
1077
undoManager.startCompoundEdit();
1078
1079    _defModel.indentLines(0, _defModel.getLength());
1080    assertEquals("Should have indented correctly.", indented, _defModel.getText());
1081
1082    undoManager.undo();
1083    assertEquals("Should have undone correctly.", "", _defModel.getText());
1084
1085    // 2
1086

1087    String JavaDoc commented =
1088      "//public class foo {\n" +
1089      "// int bar;\n" +
1090      "//}";
1091
1092    // Start a compound edit and verify the returned key
1093
key = _defModel.getUndoManager().startCompoundEdit();
1094    assertEquals("Should have returned the correct key.", 2, key);
1095
1096    // Insert a test string into the document
1097
_defModel.insertString(0, text, null);
1098    assertEquals("Should have inserted the text properly.", text,
1099                 _defModel.getText());
1100
1101    // Indent the lines, so as to trigger a nested compond edit
1102
_defModel.indentLines(0, _defModel.getLength());
1103    assertEquals("Should have indented correctly.", indented,
1104                 _defModel.getText());
1105
1106    undoManager.startCompoundEdit();
1107    _defModel.commentLines(0, _defModel.getLength());
1108    assertEquals("Should have commented correctly.", commented,
1109                 _defModel.getText());
1110
1111    // Undo the second compound edit
1112
_defModel.getUndoManager().undo();
1113    assertEquals("Should have undone the commenting.", indented,
1114                 _defModel.getText());
1115
1116    // Undo the first compound edit
1117
_defModel.getUndoManager().undo();
1118    assertEquals("Should have undone the indenting and inserting.", "",
1119                 _defModel.getText());
1120
1121    // 3
1122

1123    // Start a compound edit and verify the returned key
1124
key = _defModel.getUndoManager().startCompoundEdit();
1125    assertEquals("Should have returned the correct key.", 4, key);
1126
1127    // Insert a test string into the document
1128
_defModel.insertString(0, text, null);
1129    assertEquals("Should have inserted the text properly.", text,
1130                 _defModel.getText());
1131
1132    // Indent the lines, so as to trigger a nested compond edit
1133
_defModel.indentLines(0, _defModel.getLength());
1134    assertEquals("Should have indented correctly.", indented,
1135                 _defModel.getText());
1136
1137// // Try to undo the nested edit
1138
// try {
1139
// _defModel.getUndoManager().undo();
1140
// fail("Should not have allowed undoing a nested edit.");
1141
// }
1142
// catch (CannotUndoException e) {
1143
// // Correct: cannot undo a nested edit
1144
// }
1145
//
1146
// try {
1147
// _defModel.getUndoManager().redo();
1148
// fail("Should not have allowed redoing a nested edit.");
1149
// }
1150
// catch (CannotRedoException cre) {
1151
// // Correct: cannot redo a nested edit
1152
// }
1153
//
1154
// Try end the compound edit with a wrong key
1155
try {
1156      _defModel.getUndoManager().endCompoundEdit(key + 2);
1157// fail("Should not have allowed ending a compound edit with a wrong key.");
1158
}
1159    catch (IllegalStateException JavaDoc e) {
1160      assertEquals("Should have printed the correct error message.",
1161                   "Improperly nested compound edits.", e.getMessage());
1162    }
1163
1164    // Indent the lines, so as to trigger a nested compound edit
1165
undoManager.startCompoundEdit();
1166    _defModel.indentLines(0, _defModel.getLength());
1167    assertEquals("Should have indented correctly.", indented, _defModel.getText());
1168
1169    // We've taken out this part of the test because of our change to
1170
// undo where we close the nearest open compound edit upon undo-ing,
1171
// pasting, commenting, un-commenting, indenting, and backspacing.
1172
// We should never have a nested edit anymore.
1173

1174    // Try to undo the nested edit
1175
// try {
1176
// _defModel.getUndoManager().undo();
1177
// fail("Should not have allowed undoing a nested edit.");
1178
// }
1179
// catch (CannotUndoException e) {
1180
// // Correct: cannot undo a nested edit
1181
// }
1182

1183    // End the compound edit and undo
1184
// _defModel.getUndoManager().endCompoundEdit(key);
1185
_defModel.getUndoManager().undo();
1186    assertEquals("Should have undone the indenting and inserting.", "", _defModel.getText());
1187  }
1188
1189  /**
1190   * Verifies that the undo manager correctly determines if the document has
1191   * been modified since the last save.
1192   */

1193  public void testUndoOrRedoSetsUnmodifiedState() throws BadLocationException JavaDoc {
1194    _defModel.addUndoableEditListener(_defModel.getUndoManager());
1195    _defModel.insertString(0, "This is text", null);
1196    assertTrue("Document should be modified.", _defModel.isModifiedSinceSave());
1197    _defModel.getUndoManager().undo();
1198    _defModel.updateModifiedSinceSave();
1199    assertFalse("Document should no longer be modified after undo.", _defModel.isModifiedSinceSave());
1200    _defModel.insertString(0, "This is text", null);
1201    _defModel.resetModification();
1202    assertFalse("Document should not be modified after \"save\".", _defModel.isModifiedSinceSave());
1203    _defModel.getUndoManager().undo();
1204    _defModel.updateModifiedSinceSave();
1205    assertTrue("Document should be modified after undo.", _defModel.isModifiedSinceSave());
1206    _defModel.getUndoManager().redo();
1207    _defModel.updateModifiedSinceSave();
1208    assertFalse("Document should no longer be modified after redo.", _defModel.isModifiedSinceSave());
1209  }
1210
1211  protected final String JavaDoc NEWLINE = System.getProperty("line.separator");
1212  
1213  protected final String JavaDoc NESTED_CLASSES_TEXT =
1214    "/*bof*/package Temp;" + NEWLINE +
1215    "" + NEWLINE +
1216    "public class Test {" + NEWLINE +
1217    " private int i;" + NEWLINE +
1218    " " + NEWLINE +
1219    " public void foo(Test other) {" + NEWLINE +
1220    " i = other.i;" + NEWLINE +
1221    " " + NEWLINE +
1222    " }" + NEWLINE +
1223    " " + NEWLINE +
1224    " public void bar() {" + NEWLINE +
1225    " System.out.println(i);" + NEWLINE +
1226    " }" + NEWLINE +
1227    " " + NEWLINE +
1228    " public static interface Interf {" + NEWLINE +
1229    " static long C = System.currentTimeMillis();" + NEWLINE +
1230    " public void act();" + NEWLINE +
1231    " }" + NEWLINE +
1232    " " + NEWLINE +
1233    " static class Implementor implements Interf {" + NEWLINE +
1234    " public void act() { /*Implementor.act*/" + NEWLINE +
1235    " System.out.println(C);" + NEWLINE +
1236    " Interf inter = new Interf() { /*Implementor$1*/" + NEWLINE +
1237    " public void act() {" + NEWLINE +
1238    " System.out.println(\"Test$Implementor$1\");" + NEWLINE +
1239    " Interf inter = new Interf() { /*Implementor$1$1*/" + NEWLINE +
1240    " public void act() {" + NEWLINE +
1241    " System.out.println(\"Test$Implementor$1$1\");" + NEWLINE +
1242    " }" + NEWLINE +
1243    " };" + NEWLINE +
1244    " Inner<Integer> inn = new Inner<Integer>() { /*Implementor$1$2*/" + NEWLINE +
1245    " public void set(Integer t) { _t = t; }" + NEWLINE +
1246    " };" + NEWLINE +
1247    " } /*b-Implementor$1*/" + NEWLINE +
1248    " }; /*b-Implementor*/" + NEWLINE +
1249    " } /*c-Implementor*/" + NEWLINE +
1250    " " + NEWLINE +
1251    " public abstract class Inner<T> { /*Implementor$Inner*/" + NEWLINE +
1252    " protected T _t; /*b-Implementor$Inner*/" + NEWLINE +
1253    " public abstract void set(T t);" + NEWLINE +
1254    " }" + NEWLINE +
1255    " }" + NEWLINE +
1256    " " + NEWLINE +
1257    " public void anon() { /*anon()*/" + NEWLINE +
1258    " Interf inter = new Interf() { /*Test$1*/" + NEWLINE +
1259    " class NamedInAnonymous implements Interf { /*Test$1$NamedInAnonymous*/" + NEWLINE +
1260    " public void act() {" + NEWLINE +
1261    " System.out.println(\"Test$1$NamedInAnonymous\");" + NEWLINE +
1262    " }" + NEWLINE +
1263    " }" + NEWLINE +
1264    " public void act() { /*b-Test$1*/" + NEWLINE +
1265    " System.out.println(\"Test$1\");" + NEWLINE +
1266    " NamedInAnonymous nia = new NamedInAnonymous();" + NEWLINE +
1267    " nia.act();" + NEWLINE +
1268    " }" + NEWLINE +
1269    " };" + NEWLINE +
1270    " inter.act(); /*b-anon()*/" + NEWLINE +
1271    " Interf inter2 = new Interf() { /*Test$2*/" + NEWLINE +
1272    " public void act() {" + NEWLINE +
1273    " System.out.println(\"Test$2\");" + NEWLINE +
1274    " Interf inter = new Interf() { /*Test$2$1*/" + NEWLINE +
1275    " public void act() {" + NEWLINE +
1276    " System.out.println(\"Test$2$1\");" + NEWLINE +
1277    " }" + NEWLINE +
1278    " };" + NEWLINE +
1279    " inter.act();" + NEWLINE +
1280    " }" + NEWLINE +
1281    " };" + NEWLINE +
1282    " inter2.act();" + NEWLINE +
1283    " Interf inter3 = new Implementor() { /*Test$3*/" + NEWLINE +
1284    " public void act() {" + NEWLINE +
1285    " System.out.println(\"Test$3\");" + NEWLINE +
1286    " }" + NEWLINE +
1287    " };" + NEWLINE +
1288    " inter3.act();" + NEWLINE +
1289    " }" + NEWLINE +
1290    " " + NEWLINE +
1291    " public Test(int j) { if (true) { i = j; } }" + NEWLINE +
1292    " " + NEWLINE +
1293    " protected abstract class Param<T> {" + NEWLINE +
1294    " T _t;" + NEWLINE +
1295    " public Param(T t, T t2) { _t = t; }" + NEWLINE +
1296    " public abstract void paramDo();" + NEWLINE +
1297    " }" + NEWLINE +
1298    " " + NEWLINE +
1299    " public void anon2() {" + NEWLINE +
1300    " Param<Interf> p = new Param<Interf>(/*anon2()*/new Interf() { /*Test$4*/" + NEWLINE +
1301    " public void act() {" + NEWLINE +
1302    " System.out.println(\"parameter 1 = Test$4\");" + NEWLINE +
1303    " Interf i = new Interf() { /*Test$4$1*/" + NEWLINE +
1304    " public void act() {" + NEWLINE +
1305    " System.out.println(\"Test$4$1\");" + NEWLINE +
1306    " }" + NEWLINE +
1307    " };" + NEWLINE +
1308    " }" + NEWLINE +
1309    " }, /*b-anon2()*/ new Interf() { /*Test$5*/" + NEWLINE +
1310    " public void act() {" + NEWLINE +
1311    " System.out.println(\"parameter 2 = Test$5\");" + NEWLINE +
1312    " }" + NEWLINE +
1313    " }) /*c-anon2()*/ { /*Test$6*/" + NEWLINE +
1314    " public void paramDo() {" + NEWLINE +
1315    " System.out.println(\"Test$6\");" + NEWLINE +
1316    " }" + NEWLINE +
1317    " };" + NEWLINE +
1318    " }" + NEWLINE +
1319    "" + NEWLINE +
1320    " public void anon3() {" + NEWLINE +
1321    " Param<Interf> p = new Param<Interf>(/*anon3()*/new Interf() { /*Test$7*/" + NEWLINE +
1322    " class NamedClassAgain {" + NEWLINE +
1323    " void doSomething() { System.out.println(\"doSomething\"); }" + NEWLINE +
1324    " }" + NEWLINE +
1325    " public void act() {" + NEWLINE +
1326    " System.out.println(\"parameter 3 = Test$7\");" + NEWLINE +
1327    " Interf i = new Interf() { /*Test$7$1*/" + NEWLINE +
1328    " public void act() {" + NEWLINE +
1329    " System.out.println(\"Test$7$1\");" + NEWLINE +
1330    " }" + NEWLINE +
1331    " };" + NEWLINE +
1332    " }" + NEWLINE +
1333    " }) /*c-anon2()*/ { /*Test$8*/" + NEWLINE +
1334    " public void paramDo() {" + NEWLINE +
1335    " System.out.println(\"Test$8\");" + NEWLINE +
1336    " }" + NEWLINE +
1337    " };" + NEWLINE +
1338    " }" + NEWLINE +
1339    " " + NEWLINE +
1340    " public static void main(String[] args) {" + NEWLINE +
1341    " Test t1 = new Test(1);" + NEWLINE +
1342    " t1.bar();" + NEWLINE +
1343    " Test t2 = new Test(123);" + NEWLINE +
1344    " t2.bar();" + NEWLINE +
1345    " t1.foo(t2);" + NEWLINE +
1346    " t1.bar();" + NEWLINE +
1347    " Implementor imp = new Implementor();" + NEWLINE +
1348    " imp.act();" + NEWLINE +
1349    " t1.anon();" + NEWLINE +
1350    " }" + NEWLINE +
1351    " public static class Outer {" + NEWLINE +
1352    " public static interface Inner {" + NEWLINE +
1353    " public void innerDo();" + NEWLINE +
1354    " }" + NEWLINE +
1355    " public static interface InnerParam<T> {" + NEWLINE +
1356    " public void innerParam(T t);" + NEWLINE +
1357    " }" + NEWLINE +
1358    " public class Middle<T> {" + NEWLINE +
1359    " T t;" + NEWLINE +
1360    " public abstract class Innerst {" + NEWLINE +
1361    " public abstract void innerstDo();" + NEWLINE +
1362    " }" + NEWLINE +
1363    " " + NEWLINE +
1364    " Innerst i = new Outer.Middle.Innerst() { /*Test$Outer$Middle$1*/" + NEWLINE +
1365    " public void innerstDo() {" + NEWLINE +
1366    " System.out.println(\"Test$Outer$Middle$1\");" + NEWLINE +
1367    " }" + NEWLINE +
1368    " };" + NEWLINE +
1369    " }" + NEWLINE +
1370    " }" + NEWLINE +
1371    " " + NEWLINE +
1372    " public void anonDotTest() {" + NEWLINE +
1373    " Outer.Inner test = new Outer.Inner() { /*Test$9*/" + NEWLINE +
1374    " public void innerDo() {" + NEWLINE +
1375    " System.out.println(\"Test$9\");" + NEWLINE +
1376    " }" + NEWLINE +
1377    " };" + NEWLINE +
1378    " Outer.InnerParam<String> test2 = new Outer.InnerParam<String>() { /*Test$10*/" + NEWLINE +
1379    " public void innerParam(String t) {" + NEWLINE +
1380    " System.out.println(\"Test$10\");" + NEWLINE +
1381    " }" + NEWLINE +
1382    " };" + NEWLINE +
1383    " }" + NEWLINE +
1384    "}" + NEWLINE +
1385    "" + NEWLINE +
1386    "class Foo {" + NEWLINE +
1387    " public void foo() {" + NEWLINE +
1388    " System.out.println(\"foo\");" + NEWLINE +
1389    " FooImplementor fimp = new FooImplementor();" + NEWLINE +
1390    " fimp.act();" + NEWLINE +
1391    " }" + NEWLINE +
1392    " " + NEWLINE +
1393    " static interface FooInterf {" + NEWLINE +
1394    " static long C = System.currentTimeMillis(); /*Foo$FooInterf*/" + NEWLINE +
1395    " public void act();" + NEWLINE +
1396    " }" + NEWLINE +
1397    " " + NEWLINE +
1398    " public static class FooImplementor implements FooInterf { /*Foo$FooImplementor*/" + NEWLINE +
1399    " public void act() {" + NEWLINE +
1400    " System.out.println(C); /*b-Foo$FooImplementor*/" + NEWLINE +
1401    " FooInterf inter = new FooInterf() { /*Foo$FooImplementor$1*/" + NEWLINE +
1402    " public void act() {" + NEWLINE +
1403    " System.out.println(\"Foo$FooImplementor$1\");" + NEWLINE +
1404    " FooInterf inter = new FooInterf() { /*Foo$FooImplementor$1$1*/" + NEWLINE +
1405    " public void act() {" + NEWLINE +
1406    " System.out.println(\"Foo$FooImplementor$1$1\");" + NEWLINE +
1407    " }" + NEWLINE +
1408    " };" + NEWLINE +
1409    " }" + NEWLINE +
1410    " };" + NEWLINE +
1411    " }" + NEWLINE +
1412    " public class Inner<T> { /*Foo$FooImplementor$Inner*/" + NEWLINE +
1413    " T t;" + NEWLINE +
1414    " }" + NEWLINE +
1415    " }" + NEWLINE +
1416    "}" + NEWLINE +
1417    "abstract class Fee {" + NEWLINE +
1418    " public abstract void feeDo();" + NEWLINE +
1419    " public abstract void feeAct();" + NEWLINE +
1420    " protected String s, t, u;" + NEWLINE +
1421    " " + NEWLINE +
1422    " public static class FeeConc extends Fee {/*Fee$FeeConc*/" + NEWLINE +
1423    " {" + NEWLINE +
1424    " s = \"FeeConc/s\";" + NEWLINE +
1425    " }" + NEWLINE +
1426    " public void feeDo() { System.out.println(\"FeeConc/feeDo\"); }" + NEWLINE +
1427    " {" + NEWLINE +
1428    " t = \"FeeConc/t\";" + NEWLINE +
1429    " }" + NEWLINE +
1430    " public abstract void feeAct() { System.out.println(\"FeeConc/feeAct\"); }" + NEWLINE +
1431    " {" + NEWLINE +
1432    " u = \"FeeConc/u\";" + NEWLINE +
1433    " }" + NEWLINE +
1434    " }" + NEWLINE +
1435    " " + NEWLINE +
1436    " public static void main(String[] args) {" + NEWLINE +
1437    " Fee f = new Fee() {/*Fee$1*/" + NEWLINE +
1438    " {" + NEWLINE +
1439    " s = \"Fee$1/s\";" + NEWLINE +
1440    " }" + NEWLINE +
1441    " public void feeDo() { System.out.println(\"Fee$1/feeDo\"); }" + NEWLINE +
1442    " {" + NEWLINE +
1443    " t = \"Fee$1/t\";" + NEWLINE +
1444    " }" + NEWLINE +
1445    " public abstract void feeAct() { System.out.println(\"Fee$1/feeAct\"); }" + NEWLINE +
1446    " {" + NEWLINE +
1447    " u = \"Fee$1/u\";" + NEWLINE +
1448    " }" + NEWLINE +
1449    " };" + NEWLINE +
1450    " }" + NEWLINE +
1451    "}/*eof*/" + NEWLINE;
1452  
1453  /**
1454   * Test finding anonymous class index on document.
1455   */

1456  public void testAnonymousClassIndex() throws BadLocationException JavaDoc, ClassNameNotFoundException {
1457    _defModel.insertString(0, NESTED_CLASSES_TEXT, null);
1458
1459    String JavaDoc substr;
1460    int exp, act;
1461    substr = "{ /*Test$4*/";
1462    exp = 4;
1463    act = _defModel._getAnonymousInnerClassIndex(NESTED_CLASSES_TEXT.indexOf(substr));
1464    assertEquals("index at "+substr+" exp=`"+exp+"`, act=`"+act+"`", exp, act);
1465
1466    substr = "{ /*Test$5*/";
1467    exp = 5;
1468    act = _defModel._getAnonymousInnerClassIndex(NESTED_CLASSES_TEXT.indexOf(substr));
1469    assertEquals("index at "+substr+" exp=`"+exp+"`, act=`"+act+"`", exp, act);
1470
1471    substr = "{ /*Test$6*/";
1472    exp = 6;
1473    act = _defModel._getAnonymousInnerClassIndex(NESTED_CLASSES_TEXT.indexOf(substr));
1474    assertEquals("index at "+substr+" exp=`"+exp+"`, act=`"+act+"`", exp, act);
1475
1476    substr = "{ /*Test$7*/";
1477    exp = 7;
1478    act = _defModel._getAnonymousInnerClassIndex(NESTED_CLASSES_TEXT.indexOf(substr));
1479    assertEquals("index at "+substr+" exp=`"+exp+"`, act=`"+act+"`", exp, act);
1480
1481    substr = "{ /*Test$8*/";
1482    exp = 8;
1483    act = _defModel._getAnonymousInnerClassIndex(NESTED_CLASSES_TEXT.indexOf(substr));
1484    assertEquals("index at "+substr+" exp=`"+exp+"`, act=`"+act+"`", exp, act);
1485  }
1486  
1487  /**
1488   * Test exact class name-finding on document.
1489   */

1490  public void testExactClassName() throws BadLocationException JavaDoc, ClassNameNotFoundException {
1491    _defModel.insertString(0, NESTED_CLASSES_TEXT, null);
1492
1493    String JavaDoc substr, exp1, exp2, act1, act2;
1494    substr = "private int i";
1495    exp1 = "Temp.Test";
1496    exp2 = "Test";
1497    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1498    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1499    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1500    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1501
1502    substr = "= other.i";
1503    exp1 = "Temp.Test";
1504    exp2 = "Test";
1505    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1506    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1507    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1508    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1509
1510    substr = "System.out.println(i)";
1511    exp1 = "Temp.Test";
1512    exp2 = "Test";
1513    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1514    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1515    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1516    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1517
1518    substr = "System.currentTimeMillis";
1519    exp1 = "Temp.Test$Interf";
1520    exp2 = "Interf";
1521    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1522    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1523    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1524    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1525
1526    substr = "Implementor implements Interf";
1527    exp1 = "Temp.Test";
1528    exp2 = "Test";
1529    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1530    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1531    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1532    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1533
1534    substr = "/*Implementor.act*/";
1535    exp1 = "Temp.Test$Implementor";
1536    exp2 = "Implementor";
1537    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1538    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1539    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1540    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1541
1542    substr = "/*Implementor$1*/";
1543    exp1 = "Temp.Test$Implementor$1";
1544    exp2 = "1";
1545    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1546    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1547    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1548    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1549
1550    substr = "\"Test$Implementor$1\"";
1551    exp1 = "Temp.Test$Implementor$1";
1552    exp2 = "1";
1553    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1554    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1555    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1556    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1557
1558    substr = "/*Implementor$1$1*/";
1559    exp1 = "Temp.Test$Implementor$1$1";
1560    exp2 = "1";
1561    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1562    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1563    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1564    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1565
1566    substr = "\"Test$Implementor$1$1\"";
1567    exp1 = "Temp.Test$Implementor$1$1";
1568    exp2 = "1";
1569    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1570    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1571    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1572    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1573
1574    substr = "/*Implementor$1$2*/";
1575    exp1 = "Temp.Test$Implementor$1$2";
1576    exp2 = "2";
1577    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1578    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1579    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1580    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1581
1582    substr = "/*b-Implementor$1*/";
1583    exp1 = "Temp.Test$Implementor$1";
1584    exp2 = "1";
1585    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1586    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1587    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1588    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1589
1590    substr = "/*b-Implementor*/";
1591    exp1 = "Temp.Test$Implementor";
1592    exp2 = "Implementor";
1593    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1594    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1595    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1596    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1597
1598    substr = "/*c-Implementor*/";
1599    exp1 = "Temp.Test$Implementor";
1600    exp2 = "Implementor";
1601    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1602    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1603    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1604    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1605
1606    substr = "/*Implementor$Inner*/";
1607    exp1 = "Temp.Test$Implementor$Inner";
1608    exp2 = "Inner";
1609    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1610    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1611    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1612    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1613
1614    substr = "/*b-Implementor$Inner*/";
1615    exp1 = "Temp.Test$Implementor$Inner";
1616    exp2 = "Inner";
1617    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1618    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1619    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1620    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1621
1622    substr = "/*anon()*/";
1623    exp1 = "Temp.Test";
1624    exp2 = "Test";
1625    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1626    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1627    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1628    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1629
1630    substr = "/*Test$1*/";
1631    exp1 = "Temp.Test$1";
1632    exp2 = "1";
1633    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1634    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1635    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1636    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1637
1638    substr = "/*Test$1$NamedInAnonymous*/";
1639    exp1 = "Temp.Test$1$NamedInAnonymous";
1640    exp2 = "NamedInAnonymous";
1641    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1642    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1643    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1644    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1645
1646    substr = "\"Test$1$NamedInAnonymous\"";
1647    exp1 = "Temp.Test$1$NamedInAnonymous";
1648    exp2 = "NamedInAnonymous";
1649    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1650    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1651    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1652    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1653
1654    substr = "/*b-Test$1*/";
1655    exp1 = "Temp.Test$1";
1656    exp2 = "1";
1657    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1658    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1659    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1660    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1661
1662    substr = "\"Test$1\"";
1663    exp1 = "Temp.Test$1";
1664    exp2 = "1";
1665    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1666    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1667    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1668    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1669
1670    substr = "/*b-anon()*/";
1671    exp1 = "Temp.Test";
1672    exp2 = "Test";
1673    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1674    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1675    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1676    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1677
1678    substr = "/*Test$2*/";
1679    exp1 = "Temp.Test$2";
1680    exp2 = "2";
1681    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1682    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1683    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1684    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1685
1686    substr = "\"Test$2\"";
1687    exp1 = "Temp.Test$2";
1688    exp2 = "2";
1689    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1690    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1691    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1692    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1693
1694    substr = "/*Test$2$1*/";
1695    exp1 = "Temp.Test$2$1";
1696    exp2 = "1";
1697    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1698    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1699    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1700    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1701
1702    substr = "\"Test$2$1\"";
1703    exp1 = "Temp.Test$2$1";
1704    exp2 = "1";
1705    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1706    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1707    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1708    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1709
1710    substr = "/*Test$3*/";
1711    exp1 = "Temp.Test$3";
1712    exp2 = "3";
1713    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1714    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1715    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1716    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1717
1718    substr = "\"Test$3\"";
1719    exp1 = "Temp.Test$3";
1720    exp2 = "3";
1721    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1722    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1723    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1724    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1725
1726    substr = "(true) { i = j; }";
1727    exp1 = "Temp.Test";
1728    exp2 = "Test";
1729    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1730    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1731    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1732    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1733
1734    substr = "new Test(1)";
1735    exp1 = "Temp.Test";
1736    exp2 = "Test";
1737    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1738    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1739    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1740    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1741
1742    substr = "class Foo";
1743    exp1 = "";
1744    exp2 = "";
1745    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1746    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1747    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1748    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1749
1750    substr = "FooImplementor fimp";
1751    exp1 = "Temp.Foo";
1752    exp2 = "Foo";
1753    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1754    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1755    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1756    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1757
1758    substr = "/*Foo$FooInterf*/";
1759    exp1 = "Temp.Foo$FooInterf";
1760    exp2 = "FooInterf";
1761    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1762    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1763    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1764    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1765
1766    substr = "/*Foo$FooImplementor*/";
1767    exp1 = "Temp.Foo$FooImplementor";
1768    exp2 = "FooImplementor";
1769    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1770    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1771    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1772    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1773
1774    substr = "/*b-Foo$FooImplementor*/";
1775    exp1 = "Temp.Foo$FooImplementor";
1776    exp2 = "FooImplementor";
1777    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1778    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1779    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1780    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1781
1782    substr = "/*Foo$FooImplementor$1*/";
1783    exp1 = "Temp.Foo$FooImplementor$1";
1784    exp2 = "1";
1785    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1786    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1787    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1788    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1789
1790    substr = "\"Foo$FooImplementor$1\"";
1791    exp1 = "Temp.Foo$FooImplementor$1";
1792    exp2 = "1";
1793    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1794    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1795    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1796    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1797
1798    substr = "/*Foo$FooImplementor$1$1*/";
1799    exp1 = "Temp.Foo$FooImplementor$1$1";
1800    exp2 = "1";
1801    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1802    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1803    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1804    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1805
1806    substr = "\"Foo$FooImplementor$1$1\"";
1807    exp1 = "Temp.Foo$FooImplementor$1$1";
1808    exp2 = "1";
1809    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1810    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1811    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1812    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1813
1814    substr = "/*Foo$FooImplementor$Inner*/";
1815    exp1 = "Temp.Foo$FooImplementor$Inner";
1816    exp2 = "Inner";
1817    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1818    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1819    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1820    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1821
1822    substr = "/*eof*/";
1823    exp1 = "";
1824    exp2 = "";
1825    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1826    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1827    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1828    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1829
1830    substr = "/*bof*/";
1831    exp1 = "";
1832    exp2 = "";
1833    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1834    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1835    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1836    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1837
1838    substr = "public class Test";
1839    exp1 = "";
1840    exp2 = "";
1841    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1842    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1843    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1844    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1845
1846    substr = "/*anon2()*/";
1847    exp1 = "Temp.Test";
1848    exp2 = "Test";
1849    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1850    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1851    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1852    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1853
1854    substr = "/*Test$4*/";
1855    exp1 = "Temp.Test$4";
1856    exp2 = "4";
1857    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1858    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1859    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1860    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1861
1862    substr = "\"parameter 1 = Test$4\"";
1863    exp1 = "Temp.Test$4";
1864    exp2 = "4";
1865    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1866    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1867    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1868    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1869
1870    substr = "/*Test$4$1*/";
1871    exp1 = "Temp.Test$4$1";
1872    exp2 = "1";
1873    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1874    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1875    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1876    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1877
1878    substr = "\"Test$4$1\"";
1879    exp1 = "Temp.Test$4$1";
1880    exp2 = "1";
1881    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1882    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1883    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1884    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1885
1886    substr = "/*b-anon2()*/";
1887    exp1 = "Temp.Test";
1888    exp2 = "Test";
1889    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1890    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1891    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1892    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1893
1894    substr = "/*Test$5*/";
1895    exp1 = "Temp.Test$5";
1896    exp2 = "5";
1897    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1898    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1899    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1900    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1901
1902    substr = "\"parameter 2 = Test$5\"";
1903    exp1 = "Temp.Test$5";
1904    exp2 = "5";
1905    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1906    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1907    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1908    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1909
1910    substr = "/*c-anon2()*/";
1911    exp1 = "Temp.Test";
1912    exp2 = "Test";
1913    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1914    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1915    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1916    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1917
1918    substr = "/*Test$6*/";
1919    exp1 = "Temp.Test$6";
1920    exp2 = "6";
1921    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1922    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1923    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1924    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1925
1926    substr = "\"Test$6\"";
1927    exp1 = "Temp.Test$6";
1928    exp2 = "6";
1929    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1930    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1931    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1932    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1933
1934    substr = "/*anon3()*/";
1935    exp1 = "Temp.Test";
1936    exp2 = "Test";
1937    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1938    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1939    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1940    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1941
1942    substr = "/*Test$7*/";
1943    exp1 = "Temp.Test$7";
1944    exp2 = "7";
1945    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1946    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1947    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1948    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1949
1950    substr = "\"doSomething\"";
1951    exp1 = "Temp.Test$7$NamedClassAgain";
1952    exp2 = "NamedClassAgain";
1953    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1954    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1955    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1956    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1957
1958    substr = "\"parameter 3 = Test$7\"";
1959    exp1 = "Temp.Test$7";
1960    exp2 = "7";
1961    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1962    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1963    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1964    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1965
1966    substr = "/*Test$7$1*/";
1967    exp1 = "Temp.Test$7$1";
1968    exp2 = "1";
1969    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1970    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1971    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1972    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1973
1974    substr = "\"Test$7$1\"";
1975    exp1 = "Temp.Test$7$1";
1976    exp2 = "1";
1977    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1978    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1979    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1980    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1981
1982    substr = "/*c-anon2()*/";
1983    exp1 = "Temp.Test";
1984    exp2 = "Test";
1985    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1986    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1987    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1988    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1989
1990    substr = "/*Test$8*/";
1991    exp1 = "Temp.Test$8";
1992    exp2 = "8";
1993    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
1994    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
1995    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
1996    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
1997
1998    substr = "\"Test$8\"";
1999    exp1 = "Temp.Test$8";
2000    exp2 = "8";
2001    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2002    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2003    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2004    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2005
2006    substr = "abstract void feeDo()";
2007    exp1 = "Temp.Fee";
2008    exp2 = "Fee";
2009    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2010    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2011    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2012    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2013
2014    substr = "class FeeConc extends Fee";
2015    exp1 = "Temp.Fee";
2016    exp2 = "Fee";
2017    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2018    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2019    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2020    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2021
2022    substr = "/*Fee$FeeConc*/";
2023    exp1 = "Temp.Fee$FeeConc";
2024    exp2 = "FeeConc";
2025    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2026    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2027    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2028    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2029
2030    substr = "\"FeeConc/feeDo\"";
2031    exp1 = "Temp.Fee$FeeConc";
2032    exp2 = "FeeConc";
2033    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2034    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2035    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2036    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2037
2038    substr = "\"FeeConc/feeAct\"";
2039    exp1 = "Temp.Fee$FeeConc";
2040    exp2 = "FeeConc";
2041    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2042    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2043    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2044    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2045
2046    substr = "\"FeeConc/s\"";
2047    exp1 = "Temp.Fee$FeeConc";
2048    exp2 = "FeeConc";
2049    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2050    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2051    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2052    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2053
2054    substr = "\"FeeConc/t\"";
2055    exp1 = "Temp.Fee$FeeConc";
2056    exp2 = "FeeConc";
2057    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2058    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2059    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2060    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2061
2062    substr = "\"FeeConc/u\"";
2063    exp1 = "Temp.Fee$FeeConc";
2064    exp2 = "FeeConc";
2065    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2066    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2067    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2068    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2069
2070    substr = "/*Fee$1*/";
2071    exp1 = "Temp.Fee$1";
2072    exp2 = "1";
2073    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2074    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2075    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2076    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2077
2078    substr = "\"Fee$1/feeDo\"";
2079    exp1 = "Temp.Fee$1";
2080    exp2 = "1";
2081    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2082    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2083    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2084    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2085
2086    substr = "\"Fee$1/feeAct\"";
2087    exp1 = "Temp.Fee$1";
2088    exp2 = "1";
2089    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2090    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2091    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2092    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2093
2094    substr = "\"Fee$1/s\"";
2095    exp1 = "Temp.Fee$1";
2096    exp2 = "1";
2097    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2098    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2099    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2100    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2101
2102    substr = "\"Fee$1/t\"";
2103    exp1 = "Temp.Fee$1";
2104    exp2 = "1";
2105    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2106    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2107    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2108    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2109
2110    substr = "\"Fee$1/u\"";
2111    exp1 = "Temp.Fee$1";
2112    exp2 = "1";
2113    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2114    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2115    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2116    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2117
2118    substr = "/*Test$Outer$Middle$1*/";
2119    exp1 = "Temp.Test$Outer$Middle$1";
2120    exp2 = "1";
2121    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2122    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2123    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2124    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2125
2126    substr = "\"Test$Outer$Middle$1\"";
2127    exp1 = "Temp.Test$Outer$Middle$1";
2128    exp2 = "1";
2129    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2130    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2131    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2132    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2133
2134    substr = "/*Test$9*/";
2135    exp1 = "Temp.Test$9";
2136    exp2 = "9";
2137    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2138    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2139    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2140    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2141
2142    substr = "\"Test$9\"";
2143    exp1 = "Temp.Test$9";
2144    exp2 = "9";
2145    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2146    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2147    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2148    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2149
2150    substr = "/*Test$10*/";
2151    exp1 = "Temp.Test$10";
2152    exp2 = "10";
2153    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2154    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2155    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2156    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2157
2158    substr = "\"Test$10\"";
2159    exp1 = "Temp.Test$10";
2160    exp2 = "10";
2161    act1 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), true);
2162    act2 = _defModel.getEnclosingClassName(NESTED_CLASSES_TEXT.indexOf(substr), false);
2163    assertEquals("class name at "+substr+" exp=`"+exp1+"`, act=`"+act1+"`", exp1, act1);
2164    assertEquals("class name at "+substr+" exp=`"+exp2+"`, act=`"+act2+"`", exp2, act2);
2165  }
2166}
2167
Popular Tags