001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.java.editor.semantic;
042:
043: import java.util.List;
044: import javax.swing.text.AttributeSet;
045: import javax.swing.text.Document;
046: import javax.swing.text.StyledDocument;
047: import junit.framework.Test;
048: import junit.framework.TestSuite;
049: import org.netbeans.api.editor.settings.AttributesUtilities;
050: import org.netbeans.api.java.source.CompilationController;
051: import org.netbeans.api.java.source.test.support.MemoryValidator;
052: import org.netbeans.modules.java.editor.options.MarkOccurencesSettings;
053: import org.netbeans.modules.java.editor.semantic.TestBase.Performer;
054: import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
055: import org.openide.text.NbDocument;
056:
057: /**XXX: constructors throwing an exception are not marked as exit points
058: *
059: * @author Jan Lahoda
060: */
061: public class MarkOccDetTest extends TestBase {
062:
063: public MarkOccDetTest(String testName) {
064: super (testName);
065: }
066:
067: public static Test suite() {
068: return MemoryValidator
069: .wrap(new TestSuite(MarkOccDetTest.class));
070: }
071:
072: public void testExitPointForReturnTypesVoid() throws Exception {
073: performTest("ExitPoints", 7, 12);
074: }
075:
076: public void testExitPointForReturnTypesInt() throws Exception {
077: performTest("ExitPoints", 17, 12);
078: }
079:
080: public void testExitPointForReturnTypesObject() throws Exception {
081: performTest("ExitPoints", 27, 12);
082: }
083:
084: public void testExitPt4RetTypesVoid4MethThrowExc() throws Exception {
085: performTest("ExitPoints", 37, 12);
086: }
087:
088: public void testExitPointForThrowsNPE() throws Exception {
089: performTest("ExitPoints", 37, 45);
090: }
091:
092: public void testExitPointForThrowsBLE() throws Exception {
093: performTest("ExitPoints", 37, 85);
094: }
095:
096: public void testExitPointForArray() throws Exception {
097: performTest("ExitPoints", 104, 13);
098: }
099:
100: public void testExitPointStartedMethod() throws Exception {
101: performTest("ExitPointsStartedMethod", 5, 13);
102: }
103:
104: public void testExitPointEmptyMethod() throws Exception {
105: performTest("ExitPointsEmptyMethod", 5, 13);
106: }
107:
108: public void testExitPointForParametrizedReturnType()
109: throws Exception {
110: performTest("ExitPoints", 100, 20);
111: performTest("ExitPoints", 100, 25);
112: performTest("ExitPoints", 100, 30);
113: }
114:
115: public void testConstructorThrows() throws Exception {
116: performTest("ExitPoints", 88, 90, true);
117: }
118:
119: public void testUsagesField1() throws Exception {
120: performTest("Usages", 7, 19);
121: performTest("Usages", 14, 10);
122: performTest("Usages", 17, 17);
123: performTest("Usages", 26, 10);
124: }
125:
126: public void testUsagesField2() throws Exception {
127: performTest("Usages", 6, 18);
128: }
129:
130: public void testUsagesField3() throws Exception {
131: performTest("Usages", 10, 14);
132: performTest("Usages", 13, 9);
133: performTest("Usages", 20, 13);
134: performTest("Usages", 25, 9);
135: }
136:
137: public void testUsagesField4() throws Exception {
138: performTest("Usages", 11, 16);
139: performTest("Usages", 15, 10);
140: performTest("Usages", 22, 14);
141: performTest("Usages", 27, 10);
142: }
143:
144: public void testUsagesField5() throws Exception {
145: performTest("Usages", 18, 19);
146: performTest("Usages", 21, 14);
147: }
148:
149: public void testUsagesMethodTrivial() throws Exception {
150: performTest("Usages", 9, 20);
151: performTest("Usages", 29, 11);
152: }
153:
154: public void testUsagesIgnore() throws Exception {
155: performTest("Usages", 9, 24);
156: performTest("Usages", 4, 21);
157: }
158:
159: public void testUsagesClassTrivial() throws Exception {
160: performTest("Usages", 4, 17);
161: performTest("Usages", 31, 12);
162: }
163:
164: public void testMemberSelect1() throws Exception {
165: performTest("MemberSelect", 2, 29);
166: performTest("MemberSelect", 6, 70);
167: performTest("MemberSelect", 7, 30);
168: }
169:
170: public void testMemberSelect2() throws Exception {
171: performTest("MemberSelect", 14, 33);
172: }
173:
174: public void testMemberSelect3() throws Exception {
175: performTest("MemberSelect", 13, 30);
176: }
177:
178: public void testSimpleFallThroughExitPoint() throws Exception {
179: performTest("MethodFallThroughExitPoints", 4, 13);
180: }
181:
182: public void testFallThroughExitPointWithIf() throws Exception {
183: performTest("MethodFallThroughExitPoints", 7, 13);
184: }
185:
186: public void testNotFallThroughIfWithElse() throws Exception {
187: performTest("MethodFallThroughExitPoints", 12, 13);
188: }
189:
190: public void testFallThroughExitPointWithTryCatch() throws Exception {
191: performTest("MethodFallThroughExitPoints", 19, 13);
192: }
193:
194: public void testNotFallThroughTryCatchWithReturns()
195: throws Exception {
196: performTest("MethodFallThroughExitPoints", 28, 13);
197: }
198:
199: public void testNotFallThroughFinallyWithReturn() throws Exception {
200: performTest("MethodFallThroughExitPoints", 38, 13);
201: }
202:
203: public void testNotFallThroughThrow() throws Exception {
204: performTest("MethodFallThroughExitPoints", 46, 13);
205: }
206:
207: public void testMarkCorrespondingMethods1a() throws Exception {
208: performTest("MarkCorrespondingMethods1", 7, 55);
209: performTest("MarkCorrespondingMethods1", 7, 64);
210: }
211:
212: public void testMarkCorrespondingMethods1b() throws Exception {
213: performTest("MarkCorrespondingMethods1", 7, 83);
214: }
215:
216: public void testMarkCorrespondingMethods1c() throws Exception {
217: performTest("MarkCorrespondingMethods1", 74, 44);
218: performTest("MarkCorrespondingMethods1", 74, 49);
219: performTest("MarkCorrespondingMethods1", 74, 53);
220: performTest("MarkCorrespondingMethods1", 74, 56);
221: performTest("MarkCorrespondingMethods1", 74, 32);
222: }
223:
224: public void testMarkCorrespondingMethods1d() throws Exception {
225: performTest("MarkCorrespondingMethods1", 74, 70);
226: }
227:
228: public void testMarkCorrespondingMethods1e() throws Exception {
229: performTest("MarkCorrespondingMethods1", 98, 55);
230: }
231:
232: public void testMarkCorrespondingMethods1f() throws Exception {
233: performTest("MarkCorrespondingMethods1", 108, 40);
234: }
235:
236: public void testBreakContinue1() throws Exception {
237: performTest("BreakOrContinue", 9, 31);
238: performTest("BreakOrContinue", 19, 27);
239: performTest("BreakOrContinue", 29, 29);
240: }
241:
242: public void testBreakContinue2() throws Exception {
243: performTest("BreakOrContinue", 10, 31);
244: performTest("BreakOrContinue", 12, 31);
245: performTest("BreakOrContinue", 22, 31);
246: performTest("BreakOrContinue", 31, 31);
247: performTest("BreakOrContinue", 39, 25);
248: performTest("BreakOrContinue", 44, 20);
249: }
250:
251: public void testBreakContinue3() throws Exception {
252: performTest("BreakOrContinue", 11, 31);
253: performTest("BreakOrContinue", 16, 24);
254: performTest("BreakOrContinue", 26, 24);
255: }
256:
257: public void testBreakContinue4() throws Exception {
258: performTest("BreakOrContinue", 8, 31);
259: }
260:
261: public void testBreakContinue5() throws Exception {
262: performTest("BreakOrContinue", 36, 20);
263: performTest("BreakOrContinue", 42, 20);
264: }
265:
266: public void testBreakContinue6() throws Exception {
267: performTest("BreakOrContinue", 52, 32);
268: performTest("BreakOrContinue", 56, 32);
269: }
270:
271: public void testBreakContinue7() throws Exception {
272: performTest("BreakOrContinue", 53, 32);
273: performTest("BreakOrContinue", 55, 32);
274: }
275:
276: public void testBreakContinue8() throws Exception {
277: performTest("BreakOrContinue", 51, 32);
278: }
279:
280: public void testBreakContinue9() throws Exception {
281: performTest("BreakOrContinue", 54, 32);
282: }
283:
284: public void testBreakContinue10() throws Exception {
285: performTest("BreakOrContinue", 61, 20);
286: performTest("BreakOrContinue", 68, 20);
287: }
288:
289: public void testBreakContinue11() throws Exception {
290: performTest("BreakOrContinue", 64, 23);
291: performTest("BreakOrContinue", 71, 23);
292: }
293:
294: public void testBreakContinue12() throws Exception {
295: performTest("BreakOrContinue", 78, 20);
296: performTest("BreakOrContinue", 81, 25);
297: }
298:
299: private void performTest(String name, final int line,
300: final int column) throws Exception {
301: performTest(name, line, column, false);
302: }
303:
304: private void performTest(String name, final int line,
305: final int column, boolean doCompileRecursively)
306: throws Exception {
307: performTest(name, new Performer() {
308: public void compute(CompilationController info,
309: Document doc,
310: SemanticHighlighter.ErrorDescriptionSetter setter) {
311: int offset = NbDocument.findLineOffset(
312: (StyledDocument) doc, line)
313: + column;
314: List<int[]> spans = new MarkOccurrencesHighlighter(null)
315: .processImpl(info, MarkOccurencesSettings
316: .getCurrentNode(), doc, offset);
317:
318: if (spans != null) {
319: AttributeSet as = AttributesUtilities
320: .createImmutable("", Boolean.TRUE);
321: OffsetsBag bag = new OffsetsBag(doc);
322:
323: for (int[] span : spans) {
324: bag.addHighlight(span[0], span[1], as);
325: }
326:
327: setter.setHighlights(doc, bag);
328: }
329: }
330: }, doCompileRecursively);
331: }
332:
333: protected ColoringAttributes getColoringAttribute() {
334: return ColoringAttributes.MARK_OCCURRENCES;
335: }
336:
337: }
|