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.hints.errors;
042:
043: import java.util.Arrays;
044: import java.util.Collections;
045: import java.util.HashSet;
046: import java.util.List;
047: import java.util.Set;
048: import javax.swing.text.Document;
049: import org.netbeans.spi.editor.hints.Fix;
050: import org.openide.cookies.EditorCookie;
051: import org.openide.loaders.DataObject;
052: import org.netbeans.modules.java.hints.infrastructure.HintsTestBase;
053:
054: /**
055: *
056: * @author Jan Lahoda
057: */
058: public class CreateElementTest extends HintsTestBase {
059:
060: /** Creates a new instance of CreateElementTest */
061: public CreateElementTest(String name) {
062: super (name);
063: }
064:
065: public void testBinaryOperator() throws Exception {
066: Set<String> golden = new HashSet<String>(
067: Arrays
068: .asList(
069: "CreateFieldFix:p:org.netbeans.test.java.hints.BinaryOperator:int:[private, static]",
070: "AddParameterOrLocalFix:p:int:true",
071: "AddParameterOrLocalFix:p:int:false"));
072:
073: performTestAnalysisTest(
074: "org.netbeans.test.java.hints.BinaryOperator", 218,
075: golden);
076: performTestAnalysisTest(
077: "org.netbeans.test.java.hints.BinaryOperator", 255,
078: golden);
079: performTestAnalysisTest(
080: "org.netbeans.test.java.hints.BinaryOperator", 294,
081: golden);
082: performTestAnalysisTest(
083: "org.netbeans.test.java.hints.BinaryOperator", 333,
084: golden);
085: }
086:
087: public void testEnhancedForLoop() throws Exception {
088: performTestAnalysisTest(
089: "org.netbeans.test.java.hints.EnhancedForLoop",
090: 186,
091: new HashSet<String>(
092: Arrays
093: .asList(
094: "CreateFieldFix:u:org.netbeans.test.java.hints.EnhancedForLoop:java.lang.Iterable<java.lang.String>:[private, static]",
095: "AddParameterOrLocalFix:u:java.lang.Iterable<java.lang.String>:true",
096: "AddParameterOrLocalFix:u:java.lang.Iterable<java.lang.String>:false")));
097:
098: // performTestAnalysisTest("org.netbeans.test.java.hints.EnhancedForLoop", 244, new HashSet<String>(Arrays.asList(
099: // "CreateFieldFix:u:org.netbeans.test.java.hints.EnhancedForLoop:java.lang.Iterable<java.util.List<? extends java.lang.String>>:[private, static]",
100: // "AddParameterOrLocalFix:u:java.lang.Iterable<java.util.List<? extends java.lang.String>>:true",
101: // "AddParameterOrLocalFix:u:java.lang.Iterable<java.util.List<? extends java.lang.String>>:false"
102: // )));
103: }
104:
105: public void testArrayAccess() throws Exception {
106: Set<String> simpleGoldenWithLocal = new HashSet<String>(
107: Arrays
108: .asList(
109: "CreateFieldFix:x:org.netbeans.test.java.hints.ArrayAccess:int[]:[private, static]",
110: "AddParameterOrLocalFix:x:int[]:true",
111: "AddParameterOrLocalFix:x:int[]:false"));
112:
113: performTestAnalysisTest(
114: "org.netbeans.test.java.hints.ArrayAccess", 170,
115: simpleGoldenWithLocal);
116: performTestAnalysisTest(
117: "org.netbeans.test.java.hints.ArrayAccess", 188,
118: simpleGoldenWithLocal);
119:
120: Set<String> simpleGoldenWithoutLocal = new HashSet<String>(
121: Arrays
122: .asList("CreateFieldFix:x:org.netbeans.test.java.hints.ArrayAccess:int[]:[private]"));
123:
124: performTestAnalysisTest(
125: "org.netbeans.test.java.hints.ArrayAccess", 262,
126: simpleGoldenWithoutLocal);
127: performTestAnalysisTest(
128: "org.netbeans.test.java.hints.ArrayAccess", 283,
129: simpleGoldenWithoutLocal);
130:
131: Set<String> indexGoldenWithLocal = new HashSet<String>(
132: Arrays
133: .asList(
134: "CreateFieldFix:u:org.netbeans.test.java.hints.ArrayAccess:int:[private, static]",
135: "AddParameterOrLocalFix:u:int:true",
136: "AddParameterOrLocalFix:u:int:false"));
137:
138: performTestAnalysisTest(
139: "org.netbeans.test.java.hints.ArrayAccess", 335,
140: indexGoldenWithLocal);
141: performTestAnalysisTest(
142: "org.netbeans.test.java.hints.ArrayAccess", 377,
143: indexGoldenWithLocal);
144:
145: Set<String> indexGoldenWithoutLocal = new HashSet<String>(
146: Arrays
147: .asList("CreateFieldFix:u:org.netbeans.test.java.hints.ArrayAccess:int:[private]"));
148:
149: performTestAnalysisTest(
150: "org.netbeans.test.java.hints.ArrayAccess", 359,
151: indexGoldenWithoutLocal);
152: performTestAnalysisTest(
153: "org.netbeans.test.java.hints.ArrayAccess", 401,
154: indexGoldenWithoutLocal);
155:
156: performTestAnalysisTest(
157: "org.netbeans.test.java.hints.ArrayAccess",
158: 442,
159: new HashSet<String>(
160: Arrays
161: .asList("CreateFieldFix:s:org.netbeans.test.java.hints.ArrayAccess:java.lang.Object[][]:[private]")));
162: }
163:
164: public void testAssignment() throws Exception {
165: Set<String> golden = new HashSet<String>(
166: Arrays
167: .asList(
168: "CreateFieldFix:x:org.netbeans.test.java.hints.Assignment:int:[private, static]",
169: "AddParameterOrLocalFix:x:int:true",
170: "AddParameterOrLocalFix:x:int:false"));
171: performTestAnalysisTest(
172: "org.netbeans.test.java.hints.Assignment", 174, golden);
173: performTestAnalysisTest(
174: "org.netbeans.test.java.hints.Assignment", 186, golden);
175: }
176:
177: public void testVariableDeclaration() throws Exception {
178: Set<String> golden = new HashSet<String>(
179: Arrays
180: .asList(
181: "CreateFieldFix:x:org.netbeans.test.java.hints.VariableDeclaration:int:[private, static]",
182: "AddParameterOrLocalFix:x:int:true",
183: "AddParameterOrLocalFix:x:int:false"));
184:
185: performTestAnalysisTest(
186: "org.netbeans.test.java.hints.VariableDeclaration",
187: 186, golden);
188: }
189:
190: public void testAssert() throws Exception {
191: Set<String> goldenC = new HashSet<String>(
192: Arrays
193: .asList(
194: "CreateFieldFix:c:org.netbeans.test.java.hints.Assert:boolean:[private, static]",
195: "AddParameterOrLocalFix:c:boolean:true",
196: "AddParameterOrLocalFix:c:boolean:false"));
197:
198: performTestAnalysisTest("org.netbeans.test.java.hints.Assert",
199: 159, goldenC);
200:
201: Set<String> goldenS = new HashSet<String>(
202: Arrays
203: .asList(
204: "CreateFieldFix:s:org.netbeans.test.java.hints.Assert:java.lang.Object:[private, static]",
205: "AddParameterOrLocalFix:s:java.lang.Object:true",
206: "AddParameterOrLocalFix:s:java.lang.Object:false"));
207:
208: performTestAnalysisTest("org.netbeans.test.java.hints.Assert",
209: 163, goldenS);
210: }
211:
212: public void testParenthesis() throws Exception {
213: Set<String> goldenC = new HashSet<String>(
214: Arrays
215: .asList("CreateFieldFix:x:org.netbeans.test.java.hints.Parenthesis:int[][]:[private]"));
216:
217: performTestAnalysisTest(
218: "org.netbeans.test.java.hints.Parenthesis", 203,
219: goldenC);
220: }
221:
222: public void testIfAndLoops() throws Exception {
223: Set<String> simple = new HashSet<String>(
224: Arrays
225: .asList(
226: "CreateFieldFix:a:org.netbeans.test.java.hints.IfAndLoops:boolean:[private, static]",
227: "AddParameterOrLocalFix:a:boolean:true",
228: "AddParameterOrLocalFix:a:boolean:false"));
229:
230: performTestAnalysisTest(
231: "org.netbeans.test.java.hints.IfAndLoops", 194, simple);
232: performTestAnalysisTest(
233: "org.netbeans.test.java.hints.IfAndLoops", 247, simple);
234: performTestAnalysisTest(
235: "org.netbeans.test.java.hints.IfAndLoops", 309, simple);
236: performTestAnalysisTest(
237: "org.netbeans.test.java.hints.IfAndLoops", 368, simple);
238:
239: Set<String> complex = new HashSet<String>(
240: Arrays
241: .asList("CreateFieldFix:a:org.netbeans.test.java.hints.IfAndLoops:boolean[]:[private]"));
242:
243: performTestAnalysisTest(
244: "org.netbeans.test.java.hints.IfAndLoops", 214, complex);
245: performTestAnalysisTest(
246: "org.netbeans.test.java.hints.IfAndLoops", 270, complex);
247: performTestAnalysisTest(
248: "org.netbeans.test.java.hints.IfAndLoops", 336, complex);
249: performTestAnalysisTest(
250: "org.netbeans.test.java.hints.IfAndLoops", 395, complex);
251: }
252:
253: public void testTarget() throws Exception {
254: Set<String> simple = new HashSet<String>(
255: Arrays
256: .asList(
257: "CreateFieldFix:a:org.netbeans.test.java.hints.Target:int:[private, static]",
258: "AddParameterOrLocalFix:a:int:true",
259: "AddParameterOrLocalFix:a:int:false"));
260:
261: performTestAnalysisTest("org.netbeans.test.java.hints.Target",
262: 186, simple);
263:
264: Set<String> complex = new HashSet<String>(
265: Arrays
266: .asList("CreateFieldFix:a:org.netbeans.test.java.hints.Target:int:[private]"));
267:
268: performTestAnalysisTest("org.netbeans.test.java.hints.Target",
269: 203, complex);
270: performTestAnalysisTest("org.netbeans.test.java.hints.Target",
271: 224, complex);
272: performTestAnalysisTest("org.netbeans.test.java.hints.Target",
273: 252, complex);
274: }
275:
276: public void testMemberSelect() throws Exception {
277: Set<String> simpleWithStatic = new HashSet<String>(
278: Arrays
279: .asList("CreateFieldFix:a:org.netbeans.test.java.hints.MemberSelect:int:[private, static]"));
280: Set<String> simple = new HashSet<String>(
281: Arrays
282: .asList("CreateFieldFix:a:org.netbeans.test.java.hints.MemberSelect:int:[private]"));
283:
284: performTestAnalysisTest(
285: "org.netbeans.test.java.hints.MemberSelect", 236,
286: simpleWithStatic);
287: performTestAnalysisTest(
288: "org.netbeans.test.java.hints.MemberSelect", 268,
289: simpleWithStatic);
290:
291: performTestAnalysisTest(
292: "org.netbeans.test.java.hints.MemberSelect", 290,
293: simple);
294: performTestAnalysisTest(
295: "org.netbeans.test.java.hints.MemberSelect", 311,
296: simple);
297: }
298:
299: public void testSimple() throws Exception {
300: Set<String> simpleJLOWithLocal = new HashSet<String>(
301: Arrays
302: .asList(
303: "CreateFieldFix:e:org.netbeans.test.java.hints.Simple:java.lang.Object:[private, static]",
304: "AddParameterOrLocalFix:e:java.lang.Object:true",
305: "AddParameterOrLocalFix:e:java.lang.Object:false"));
306: Set<String> simpleJLO = new HashSet<String>(
307: Arrays
308: .asList("CreateFieldFix:e:org.netbeans.test.java.hints.Simple:java.lang.Object:[private]"));
309: Set<String> simpleJLEWithLocal = new HashSet<String>(
310: Arrays
311: .asList(
312: "CreateFieldFix:e:org.netbeans.test.java.hints.Simple:java.lang.Exception:[private, static]",
313: "AddParameterOrLocalFix:e:java.lang.Exception:true",
314: "AddParameterOrLocalFix:e:java.lang.Exception:false"));
315: Set<String> simpleJLE = new HashSet<String>(
316: Arrays
317: .asList("CreateFieldFix:e:org.netbeans.test.java.hints.Simple:java.lang.Exception:[private]"));
318:
319: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
320: 192, simpleJLEWithLocal);
321: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
322: 211, simpleJLE);
323:
324: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
325: 245, simpleJLOWithLocal);
326: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
327: 275, simpleJLO);
328:
329: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
330: 302, simpleJLOWithLocal);
331: performTestAnalysisTest("org.netbeans.test.java.hints.Simple",
332: 342, simpleJLO);
333: }
334:
335: public void testUnary() throws Exception {
336: performTestAnalysisTest(
337: "org.netbeans.test.java.hints.Simple",
338: 382,
339: Collections
340: .singleton("CreateFieldFix:i:org.netbeans.test.java.hints.Simple:int:[private]"));
341:
342: performTestAnalysisTest(
343: "org.netbeans.test.java.hints.Simple",
344: 398,
345: Collections
346: .singleton("CreateFieldFix:b:org.netbeans.test.java.hints.Simple:byte:[private]"));
347: performTestAnalysisTest(
348: "org.netbeans.test.java.hints.Simple",
349: 409,
350: Collections
351: .singleton("CreateFieldFix:b:org.netbeans.test.java.hints.Simple:byte:[private]"));
352:
353: performTestAnalysisTest(
354: "org.netbeans.test.java.hints.Simple",
355: 415,
356: Collections
357: .singleton("CreateFieldFix:l:org.netbeans.test.java.hints.Simple:int:[private]"));
358: }
359:
360: public void testTypevarsAndEnums() throws Exception {
361: performTestAnalysisTest(
362: "org.netbeans.test.java.hints.TypevarsAndErrors", 221,
363: Collections.<String> emptySet());
364: performTestAnalysisTest(
365: "org.netbeans.test.java.hints.TypevarsAndErrors", 243,
366: Collections.<String> emptySet());
367: performTestAnalysisTest(
368: "org.netbeans.test.java.hints.TypevarsAndErrors", 265,
369: Collections.<String> emptySet());
370: performTestAnalysisTest(
371: "org.netbeans.test.java.hints.TypevarsAndErrors", 287,
372: Collections.<String> emptySet());
373: }
374:
375: public void testReturn() throws Exception {
376: performTestAnalysisTest(
377: "org.netbeans.test.java.hints.Return",
378: 164,
379: new HashSet<String>(
380: Arrays
381: .asList(
382: "AddParameterOrLocalFix:l:int:false",
383: "AddParameterOrLocalFix:l:int:true",
384: "CreateFieldFix:l:org.netbeans.test.java.hints.Return:int:[private]")));
385: performTestAnalysisTest(
386: "org.netbeans.test.java.hints.Return",
387: 220,
388: new HashSet<String>(
389: Arrays
390: .asList(
391: "AddParameterOrLocalFix:l:java.util.List:false",
392: "AddParameterOrLocalFix:l:java.util.List:true",
393: "CreateFieldFix:l:org.netbeans.test.java.hints.Return:java.util.List:[private]")));
394: performTestAnalysisTest(
395: "org.netbeans.test.java.hints.Return",
396: 284,
397: new HashSet<String>(
398: Arrays
399: .asList(
400: "AddParameterOrLocalFix:l:java.util.List<java.lang.String>:false",
401: "AddParameterOrLocalFix:l:java.util.List<java.lang.String>:true",
402: "CreateFieldFix:l:org.netbeans.test.java.hints.Return:java.util.List<java.lang.String>:[private]")));
403: performTestAnalysisTest("org.netbeans.test.java.hints.Return",
404: 340, Collections.<String> emptySet());
405: }
406:
407: public void test92419() throws Exception {
408: performTestAnalysisTest(
409: "org.netbeans.test.java.hints.Bug92419",
410: 123,
411: new HashSet<String>(
412: Arrays
413: .asList("CreateClass:org.netbeans.test.java.hints.XXXX:[]:CLASS")));
414: }
415:
416: public void testConditionalExpression() throws Exception {
417: performTestAnalysisTest(
418: "org.netbeans.test.java.hints.CondExpression",
419: 203,
420: new HashSet<String>(
421: Arrays
422: .asList(
423: "AddParameterOrLocalFix:b:boolean:false",
424: "AddParameterOrLocalFix:b:boolean:true",
425: "CreateFieldFix:b:org.netbeans.test.java.hints.CondExpression:boolean:[private]")));
426: performTestAnalysisTest(
427: "org.netbeans.test.java.hints.CondExpression",
428: 235,
429: new HashSet<String>(
430: Arrays
431: .asList(
432: "AddParameterOrLocalFix:b:boolean:false",
433: "AddParameterOrLocalFix:b:boolean:true",
434: "CreateFieldFix:b:org.netbeans.test.java.hints.CondExpression:boolean:[private]")));
435: performTestAnalysisTest(
436: "org.netbeans.test.java.hints.CondExpression",
437: 207,
438: new HashSet<String>(
439: Arrays
440: .asList(
441: "AddParameterOrLocalFix:d:java.lang.CharSequence:false",
442: "AddParameterOrLocalFix:d:java.lang.CharSequence:true",
443: "CreateFieldFix:d:org.netbeans.test.java.hints.CondExpression:java.lang.CharSequence:[private]")));
444: performTestAnalysisTest(
445: "org.netbeans.test.java.hints.CondExpression",
446: 243,
447: new HashSet<String>(
448: Arrays
449: .asList(
450: "AddParameterOrLocalFix:d:java.lang.CharSequence:false",
451: "AddParameterOrLocalFix:d:java.lang.CharSequence:true",
452: "CreateFieldFix:d:org.netbeans.test.java.hints.CondExpression:java.lang.CharSequence:[private]")));
453: }
454:
455: public void testArrayInitializer() throws Exception {
456: performTestAnalysisTest(
457: "org.netbeans.test.java.hints.ArrayInitializer",
458: 210,
459: new HashSet<String>(
460: Arrays
461: .asList(
462: "AddParameterOrLocalFix:f:java.io.File:false",
463: "AddParameterOrLocalFix:f:java.io.File:true",
464: "CreateFieldFix:f:org.netbeans.test.java.hints.ArrayInitializer:java.io.File:[private]")));
465: performTestAnalysisTest(
466: "org.netbeans.test.java.hints.ArrayInitializer",
467: 248,
468: new HashSet<String>(
469: Arrays
470: .asList(
471: "AddParameterOrLocalFix:f:java.io.File:false",
472: "AddParameterOrLocalFix:f:java.io.File:true",
473: "CreateFieldFix:f:org.netbeans.test.java.hints.ArrayInitializer:java.io.File:[private]")));
474: performTestAnalysisTest(
475: "org.netbeans.test.java.hints.ArrayInitializer",
476: 281,
477: new HashSet<String>(
478: Arrays
479: .asList(
480: "AddParameterOrLocalFix:i:int:false",
481: "AddParameterOrLocalFix:i:int:true",
482: "CreateFieldFix:i:org.netbeans.test.java.hints.ArrayInitializer:int:[private]")));
483: }
484:
485: public void test105415() throws Exception {
486: performTestAnalysisTest(
487: "org.netbeans.test.java.hints.Bug105415", 138,
488: Collections.<String> emptySet());
489: }
490:
491: public void test112846() throws Exception {
492: performTestAnalysisTest(
493: "org.netbeans.test.java.hints.Bug112846",
494: 152,
495: new HashSet<String>(
496: Arrays
497: .asList(
498: "AddParameterOrLocalFix:xxx:double[]:false",
499: "AddParameterOrLocalFix:xxx:double[]:true",
500: "CreateFieldFix:xxx:org.netbeans.test.java.hints.Bug112846:double[]:[private]")));
501: }
502:
503: public void test111048() throws Exception {
504: // do not offer to create method in non-writable file/class
505: performTestAnalysisTest(
506: "org.netbeans.test.java.hints.Bug111048", 202,
507: Collections.<String> emptySet());
508: // but do it in writable
509: performTestAnalysisTest(
510: "org.netbeans.test.java.hints.Bug111048",
511: 231,
512: new HashSet<String>(
513: Arrays
514: .asList("CreateMethodFix:contains(java.lang.String string)boolean:org.netbeans.test.java.hints.bb")));
515: // do not offer to create field/inner class in non-writable file/class
516: performTestAnalysisTest(
517: "org.netbeans.test.java.hints.Bug111048", 261,
518: Collections.<String> emptySet());
519: performTestAnalysisTest(
520: "org.netbeans.test.java.hints.Bug111048",
521: 301,
522: new HashSet<String>(
523: Arrays
524: .asList(
525: "CreateInnerClass:org.netbeans.test.java.hints.bb.fieldOrClass:[static]:CLASS",
526: "CreateFieldFix:fieldOrClass:org.netbeans.test.java.hints.bb:java.lang.Object:[static]")));
527: }
528:
529: public void test117431() throws Exception {
530: //do not offer same hint more times for a same unknown variable
531: performTestAnalysisTest(
532: "org.netbeans.test.java.hints.Bug117431",
533: 155,
534: new HashSet<String>(
535: Arrays
536: .asList(
537: "AddParameterOrLocalFix:ii:int:true",
538: "CreateFieldFix:ii:org.netbeans.test.java.hints.Bug117431:int:[private, static]",
539: "AddParameterOrLocalFix:ii:int:false")));
540: //but do offer for a different one
541: performTestAnalysisTest(
542: "org.netbeans.test.java.hints.Bug117431",
543: 219,
544: new HashSet<String>(
545: Arrays
546: .asList(
547: "AddParameterOrLocalFix:kk:int:true",
548: "CreateFieldFix:kk:org.netbeans.test.java.hints.Bug117431:int:[private, static]",
549: "AddParameterOrLocalFix:kk:int:false")));
550: }
551:
552: public void testMethodArgument() throws Exception {
553: //do not offer same hint more times for a same unknown variable
554: performTestAnalysisTest(
555: "org.netbeans.test.java.hints.MethodArgument",
556: 217,
557: new HashSet<String>(
558: Arrays
559: .asList(
560: "AddParameterOrLocalFix:xx:int:true",
561: "CreateFieldFix:xx:org.netbeans.test.java.hints.MethodArgument:int:[private, static]",
562: "AddParameterOrLocalFix:xx:int:false")));
563: }
564:
565: public void testConstructorArgument() throws Exception {
566: //do not offer same hint more times for a same unknown variable
567: performTestAnalysisTest(
568: "org.netbeans.test.java.hints.ConstructorArgument",
569: 181,
570: new HashSet<String>(
571: Arrays
572: .asList(
573: "AddParameterOrLocalFix:xx:int:true",
574: "CreateFieldFix:xx:org.netbeans.test.java.hints.ConstructorArgument:int:[private, static]",
575: "AddParameterOrLocalFix:xx:int:false")));
576: }
577:
578: protected void performTestAnalysisTest(String className,
579: int offset, Set<String> golden) throws Exception {
580: prepareTest(className);
581:
582: DataObject od = DataObject.find(info.getFileObject());
583: EditorCookie ec = (EditorCookie) od.getLookup().lookup(
584: EditorCookie.class);
585:
586: Document doc = ec.openDocument();
587:
588: CreateElement ce = new CreateElement();
589: List<Fix> fixes = ce.analyze(info, offset);
590: Set<String> real = new HashSet<String>();
591:
592: for (Fix f : fixes) {
593: if (f instanceof CreateFieldFix) {
594: real.add(((CreateFieldFix) f).toDebugString(info));
595: continue;
596: }
597: if (f instanceof AddParameterOrLocalFix) {
598: real.add(((AddParameterOrLocalFix) f)
599: .toDebugString(info));
600: continue;
601: }
602: if (f instanceof CreateMethodFix) {
603: real.add(((CreateMethodFix) f).toDebugString(info));
604: continue;
605: }
606: if (f instanceof CreateClassFix) {
607: real.add(((CreateClassFix) f).toDebugString(info));
608: continue;
609: }
610:
611: fail("Fix of incorrect type: " + f.getClass());
612: }
613:
614: assertEquals(golden, real);
615: }
616:
617: @Override
618: protected String testDataExtension() {
619: return "org/netbeans/test/java/hints/CreateElementTest/";
620: }
621:
622: @Override
623: protected boolean createCaches() {
624: return false;
625: }
626:
627: }
|