Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
blob: de9bae3ebee7a60f73245dd489a7bc5039e085c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
/*******************************************************************************
 * Copyright (c) 2009, 2010 Mia-Software.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Gregoire DUPE (Mia-Software)
 *    Romain Dervaux (Mia-Software)
 *    Fabien Giquel (Mia-Software) - Bug 339720 : MoDisco Discoverers (infra + techno) API clean
 *******************************************************************************/

package org.eclipse.gmt.modisco.java.discoverer.tests;

import java.util.Iterator;

import org.eclipse.gmt.modisco.java.AbstractMethodDeclaration;
import org.eclipse.gmt.modisco.java.Annotation;
import org.eclipse.gmt.modisco.java.AnnotationMemberValuePair;
import org.eclipse.gmt.modisco.java.BodyDeclaration;
import org.eclipse.gmt.modisco.java.ClassDeclaration;
import org.eclipse.gmt.modisco.java.Comment;
import org.eclipse.gmt.modisco.java.CompilationUnit;
import org.eclipse.gmt.modisco.java.ConstructorDeclaration;
import org.eclipse.gmt.modisco.java.FieldDeclaration;
import org.eclipse.gmt.modisco.java.InheritanceKind;
import org.eclipse.gmt.modisco.java.Initializer;
import org.eclipse.gmt.modisco.java.InterfaceDeclaration;
import org.eclipse.gmt.modisco.java.Javadoc;
import org.eclipse.gmt.modisco.java.MethodDeclaration;
import org.eclipse.gmt.modisco.java.MethodRef;
import org.eclipse.gmt.modisco.java.NamedElement;
import org.eclipse.gmt.modisco.java.Package;
import org.eclipse.gmt.modisco.java.PackageAccess;
import org.eclipse.gmt.modisco.java.SingleVariableDeclaration;
import org.eclipse.gmt.modisco.java.TagElement;
import org.eclipse.gmt.modisco.java.TextElement;
import org.eclipse.gmt.modisco.java.TypeAccess;
import org.eclipse.gmt.modisco.java.TypeDeclaration;
import org.eclipse.gmt.modisco.java.TypeParameter;
import org.eclipse.gmt.modisco.java.VariableDeclarationFragment;
import org.eclipse.gmt.modisco.java.VisibilityKind;
import org.eclipse.gmt.modisco.java.discoverer.tests.utils.AbstractDiscoverTest;
import org.eclipse.gmt.modisco.java.internal.util.JavaUtil;
import org.junit.Assert;
import org.junit.Test;

/**
 * @deprecated use matching org.eclipse.modisco.x.y.z component
 */
@Deprecated
public class JavaJUnitEMF extends AbstractDiscoverTest {

	private static final int MAGIC_NUMBER = 3;

	@Override
	protected String getTargetProjectName() {
		return Activator.PLUGIN_ID + "_test001"; //$NON-NLS-1$
	}

	@Override
	protected String getSourcesReferencePath() {
		return "/workspace/test001/"; //$NON-NLS-1$
	}

	/**
	 * Bug 325108 - Java Discoverer : DanglingHREFException with a block comment
	 * construct
	 */
	@Test
	public void testBug325108() {
		Assert.assertTrue("Resource must not have any errors", getResource() //$NON-NLS-1$
				.getErrors().size() == 0);
	}

	@Test
	public void test001() {
		Package p1 = (Package) JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test001.p1"); //$NON-NLS-1$
		Assert.assertNotNull("test001.p1 should exists", p1); //$NON-NLS-1$
		Assert.assertTrue("test001.p1 should contain only one element.", p1 //$NON-NLS-1$
				.getOwnedElements().size() == 1);
		Package p2 = (Package) JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test001.p2"); //$NON-NLS-1$
		Assert.assertNotNull("test001.p2 should exists", p2); //$NON-NLS-1$
		Assert.assertTrue("test001.p2 should contain only one element.", p2 //$NON-NLS-1$
				.getOwnedElements().size() == 1);
		NamedElement class1 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test001.p1.Class1"); //$NON-NLS-1$
		Assert.assertNotNull("test001.p1.Class1 should exists", class1); //$NON-NLS-1$
		Assert.assertFalse(
				"test001.p1.Class1 not must be a proxy", class1.isProxy()); //$NON-NLS-1$
		NamedElement class2 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test001.p2.Class2"); //$NON-NLS-1$
		Assert.assertNotNull("java.lang.String should exists", class2); //$NON-NLS-1$
		Assert.assertFalse(
				"java.lang.String must not be a proxy", class2.isProxy()); //$NON-NLS-1$
	}

	@Test
	public void test002() {
		NamedElement class1 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test002.Class1"); //$NON-NLS-1$
		Assert.assertNotNull("test002.Class1 should exists", class1); //$NON-NLS-1$
		Assert.assertFalse(
				"test002.Class1 not must be a proxy", class1.isProxy()); //$NON-NLS-1$
		NamedElement class4 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test002.Class1.Class4"); //$NON-NLS-1$
		Assert.assertNotNull("test002.Class1.Class4 should exists", class4); //$NON-NLS-1$
		Assert.assertFalse("test002.Class1.Class4 not must be a proxy", class4 //$NON-NLS-1$
				.isProxy());
		NamedElement class2 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test002.Class2"); //$NON-NLS-1$
		Assert.assertNotNull("test002.Class2 should exists", class2); //$NON-NLS-1$
		Assert.assertFalse(
				"test002.Class2 not must be a proxy", class2.isProxy()); //$NON-NLS-1$
		NamedElement class3 = JavaUtil.getNamedElementByQualifiedName(
				getModel(), "test002.Class2.Class3"); //$NON-NLS-1$
		Assert.assertNotNull("test002.Class2.Class3 should exists", class3); //$NON-NLS-1$
		Assert.assertFalse("test002.Class2.Class3 not must be a proxy", class3 //$NON-NLS-1$
				.isProxy());
	}

	@Test
	public void test003() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"java.lang.String"); //$NON-NLS-1$
		Assert.assertNotNull("java.lang.String should exists", ne); //$NON-NLS-1$
		Assert.assertTrue("java.lang.String must be a proxy", ne.isProxy()); //$NON-NLS-1$
		ConstructorDeclaration stringConstructor = (ConstructorDeclaration) JavaUtil
				.getNamedElementByQualifiedName(getModel(),
						"java.lang.String.String()"); //$NON-NLS-1$
		Assert.assertTrue("java.lang.String.String() should be proxy", //$NON-NLS-1$
				stringConstructor.isProxy());
	}

	@Test
	public void packageaccess() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"packageaccess"); //$NON-NLS-1$
		Assert.assertNotNull("packageaccess should exists", ne); //$NON-NLS-1$

		NamedElement resolvedPckAccess = JavaUtil
				.getNamedElementByQualifiedName(getModel(),
						"packageaccess.PackageAccess"); //$NON-NLS-1$
		Assert.assertNotNull("packageaccess.PackageAccess should exists", //$NON-NLS-1$
				resolvedPckAccess);

		Assert.assertTrue(
				"type PackageAccess should have only one super interface", //$NON-NLS-1$
				((TypeDeclaration) resolvedPckAccess).getSuperInterfaces()
						.size() == 1);

		TypeAccess typAcc = ((TypeDeclaration) resolvedPckAccess)
				.getSuperInterfaces().get(0);

		Assert.assertTrue("super interface should be an interface", //$NON-NLS-1$
				typAcc.getType() instanceof InterfaceDeclaration);
		Assert.assertTrue("qualifier should be a PackageAccess", //$NON-NLS-1$
				typAcc.getQualifier() instanceof PackageAccess);

		PackageAccess qualifier = (PackageAccess) typAcc.getQualifier();

		Assert.assertTrue(
				"wrong qualified package name ", JavaUtil.getQualifiedName(//$NON-NLS-1$
						qualifier.getPackage()).equals(
						"javax.swing.text.html.parser")); //$NON-NLS-1$
	}

	@Test
	public void validation() {
		int nbError = new JavaValidation().validate(getResource(), System.out);
		Assert.assertEquals("Validation", 0, nbError); //$NON-NLS-1$
	}

	@Test
	public void varargs() {
		ClassDeclaration classDecl = (ClassDeclaration) JavaUtil
				.getNamedElementByQualifiedName(getModel(), "varargs.VarArgs2"); //$NON-NLS-1$
		Iterator<BodyDeclaration> bodyDeclarations = classDecl
				.getBodyDeclarations().iterator();
		while (bodyDeclarations.hasNext()) {
			BodyDeclaration bodyDeclaration = bodyDeclarations.next();
			if (bodyDeclaration.getName().equals("m1")) { //$NON-NLS-1$
				MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
				SingleVariableDeclaration singleVariableDeclaration = methodDeclaration
						.getParameters().get(0);
				Assert.assertTrue("The parameter must be a varargs.", //$NON-NLS-1$
						singleVariableDeclaration.isVarargs());
			}
		}

	}

	@Test
	public void annotations() {
		// the annotation on the class
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"annotations.MyAnnotatedClass"); //$NON-NLS-1$
		Assert.assertNotNull("annotations.MyAnnotatedClass should exists", ne); //$NON-NLS-1$
		TypeDeclaration klass = (TypeDeclaration) ne;
		Assert.assertTrue(
				"MyAnnotatedClass should have only one annotation", klass //$NON-NLS-1$
						.getAnnotations().size() == 1);
		Annotation klassAnnotation = klass.getAnnotations().get(0);
		Assert.assertTrue("wrong qualified name of the annotation", JavaUtil //$NON-NLS-1$
						.getQualifiedName(klassAnnotation.getType().getType())
						.equals("java.lang.Deprecated")); //$NON-NLS-1$
		Assert.assertTrue(
				"values of the annotation should be empty", klassAnnotation //$NON-NLS-1$
						.getValues().size() == 0);

		// the annotation on the returnRawList() method
		NamedElement ne2 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"annotations.MyAnnotatedClass.returnRawList()"); //$NON-NLS-1$
		Assert.assertNotNull(
				"annotations.MyAnnotatedClass.returnRawList() should exists", //$NON-NLS-1$
				ne);
		MethodDeclaration method = (MethodDeclaration) ne2;
		Assert.assertTrue(
				"returnRawList() should have only one annotation", method //$NON-NLS-1$
						.getAnnotations().size() == 1);
		Annotation methodAnnotation = method.getAnnotations().get(0);
		Assert.assertTrue(Messages.JavaJUnitEMF_62,
				JavaUtil.getQualifiedName(methodAnnotation.getType().getType())
						.equals("java.lang.SuppressWarnings")); //$NON-NLS-1$
		Assert.assertTrue(
				"annotation should have only one value", methodAnnotation //$NON-NLS-1$
						.getValues().size() == 1);
		AnnotationMemberValuePair ann = methodAnnotation.getValues().get(0);
		Assert.assertNull(
				"member of the annotation should be null", ann.getMember()); //$NON-NLS-1$
		Assert.assertNotNull("value of the annotation should not be null", ann //$NON-NLS-1$
				.getValue());

		// the annotation on the toString() method
		NamedElement ne4 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"annotations.MyAnnotatedClass.toString()"); //$NON-NLS-1$
		Assert.assertNotNull(
				"annotations.MyAnnotatedClass.toString() should exists", //$NON-NLS-1$
				ne);
		MethodDeclaration toString = (MethodDeclaration) ne4;
		Assert.assertTrue(
				"toString() should have only one annotation", toString //$NON-NLS-1$
						.getAnnotations().size() == 1);
		Annotation toStringAnnotation = toString.getAnnotations().get(0);
		Assert.assertTrue("wrong qualified name of the annotation", JavaUtil //$NON-NLS-1$
				.getQualifiedName(toStringAnnotation.getType().getType())
				.equals("java.lang.Override")); //$NON-NLS-1$
		Assert.assertTrue("values of the annotation should be empty", //$NON-NLS-1$
				toStringAnnotation.getValues().size() == 0);

	}

	@Test
	public void duplicateproxy() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"java.util.ArrayList"); //$NON-NLS-1$
		Assert.assertNotNull("java.util.ArrayList should exists", ne); //$NON-NLS-1$

		NamedElement ne2 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"java.util.ArrayList.ArrayList()"); //$NON-NLS-1$
		Assert.assertNotNull(
				"java.util.ArrayList.ArrayList() should exists", ne); //$NON-NLS-1$

		Assert.assertTrue(
				"method should be a constructor", //$NON-NLS-1$
				((AbstractMethodDeclaration) ne2) instanceof ConstructorDeclaration);

		Assert.assertTrue("method should be a proxy", ne2.isProxy()); //$NON-NLS-1$

		Assert.assertTrue(
				"method should have only 3 usages", //$NON-NLS-1$
				((AbstractMethodDeclaration) ne2).getUsages().size() == JavaJUnitEMF.MAGIC_NUMBER);
	}

	@Test
	public void initializer() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"initializer.InitializerTest"); //$NON-NLS-1$
		Assert.assertNotNull("initializer.InitializerTest should exists", ne); //$NON-NLS-1$

		TypeDeclaration test = (TypeDeclaration) ne;
		Assert.assertTrue("class should have only 2 body declarations", test //$NON-NLS-1$
				.getBodyDeclarations().size() == 2);
		Assert.assertTrue("body declaration should be an Initializer", test //$NON-NLS-1$
				.getBodyDeclarations().get(0) instanceof Initializer);
		Assert.assertTrue("body declaration should be an Initializer", test //$NON-NLS-1$
				.getBodyDeclarations().get(1) instanceof Initializer);
	}

	@Test
	public void comments() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"comments.Comments"); //$NON-NLS-1$
		Assert.assertNotNull("comments.Comments should exists", ne); //$NON-NLS-1$

		TypeDeclaration type = (TypeDeclaration) ne;
		CompilationUnit cu = ne.getOriginalCompilationUnit();
		Assert.assertEquals(
				"CompilationUnit should have 1 comments", 1, cu.getComments().size()); //$NON-NLS-1$

		Assert.assertTrue(
				"CompilationUnit comment should be located at the beginning", //$NON-NLS-1$
				cu.getComments().get(0).isPrefixOfParent());
		Assert.assertTrue(
				"CompilationUnit comment should be located at the beginning", //$NON-NLS-1$
				!cu.getComments().get(0).isEnclosedByParent());

		Assert.assertEquals(
				"type should have 2 comments", 2, type.getComments().size()); //$NON-NLS-1$
		Assert.assertTrue(
				"second comment of type should be located at the end", //$NON-NLS-1$
				!type.getComments().get(1).isPrefixOfParent());
		Assert.assertTrue(
				"second comment of type should be located at the end", //$NON-NLS-1$
				!type.getComments().get(1).isEnclosedByParent());

		Comment c = type.getComments().get(0);
		Assert.assertTrue(Messages.JavaJUnitEMF_88, c instanceof Javadoc);
		Javadoc firstDoc = (Javadoc) c;
		Assert.assertTrue("first comment should be 3 tags", firstDoc.getTags() //$NON-NLS-1$
				.size() == JavaJUnitEMF.MAGIC_NUMBER);

		Assert.assertTrue("1st tag should have only 2 fragments", firstDoc //$NON-NLS-1$
				.getTags().get(0).getFragments().size() == 2);

		Assert.assertTrue(
				"1st fragment should be a TextElement", //$NON-NLS-1$
				firstDoc.getTags().get(0).getFragments().get(0) instanceof TextElement);
		Assert.assertTrue("1st fragment should have no tag name", firstDoc //$NON-NLS-1$
				.getTags().get(0).getTagName() == null
				|| firstDoc.getTags().get(0).getTagName().length() == 0);
		Assert.assertTrue(
				"2nd fragment should be a TagElement", //$NON-NLS-1$
				firstDoc.getTags().get(0).getFragments().get(1) instanceof TagElement);
		Assert.assertTrue("2nd fragment should have '@link' as tag name", //$NON-NLS-1$
				((TagElement) firstDoc.getTags().get(0).getFragments().get(1))
						.getTagName().equals("@link")); //$NON-NLS-1$

		Assert.assertTrue("2nd tag should have '@author' as tag name", //$NON-NLS-1$
				firstDoc.getTags().get(1).getTagName().equals("@author")); //$NON-NLS-1$

		Assert.assertTrue("3rd tag should have '@see' as tag name", firstDoc //$NON-NLS-1$
				.getTags().get(2).getTagName().equals("@see")); //$NON-NLS-1$
		Assert.assertTrue("3rd tag should have one fragment", firstDoc //$NON-NLS-1$
				.getTags().get(2).getFragments().size() == 1);
		Assert.assertTrue(
				"1st fragment should be a MethodRef", //$NON-NLS-1$
				firstDoc.getTags().get(2).getFragments().get(0) instanceof MethodRef);
		MethodRef methodref = (MethodRef) firstDoc.getTags().get(2)
				.getFragments().get(0);
		Assert.assertTrue(
				"wrong qualified name for method", JavaUtil //$NON-NLS-1$
						.getQualifiedName(methodref.getMethod()).equals(
								"java.lang.String.toString()")); //$NON-NLS-1$
		Assert.assertNotNull("qualifier should not be null", methodref //$NON-NLS-1$
				.getQualifier());

	}

	@Test
	public void classorifaceproxy() {
		NamedElement ne1 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"classorifaceproxy.p1.Iface1"); //$NON-NLS-1$
		Assert.assertNotNull("classorifaceproxy.p1.Iface1 should exists", ne1); //$NON-NLS-1$

		NamedElement ne2 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"classorifaceproxy.p2.Iface2"); //$NON-NLS-1$
		Assert.assertNotNull("classorifaceproxy.p2.Iface2 should exists", ne2); //$NON-NLS-1$

		Assert.assertTrue("Iface1 should be an interface", //$NON-NLS-1$
				ne1 instanceof InterfaceDeclaration);
		Assert.assertTrue("Iface2 should be an interface", //$NON-NLS-1$
				ne2 instanceof InterfaceDeclaration);
	}

	@Test
	public void parameterizedtypeinmethoddecl() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"parameterizedtypeinmethoddecl.Class1"); //$NON-NLS-1$
		Assert.assertNotNull(
				"parameterizedtypeinmethoddecl.Class1 should exist", ne); //$NON-NLS-1$
		for (Iterator<BodyDeclaration> iterator = ((TypeDeclaration) ne)
				.getBodyDeclarations().iterator(); iterator.hasNext();) {
			BodyDeclaration body = iterator.next();
			if (body.getName().equals(Messages.JavaJUnitEMF_113)) {

				MethodDeclaration method = (MethodDeclaration) body;
				Assert.assertTrue(
						"method accept() should have 2 type parameters", //$NON-NLS-1$
						method.getTypeParameters().size() == 2);
				TypeParameter returnType = method.getTypeParameters().get(0);
				TypeParameter parameter = method.getTypeParameters().get(1);
				Assert.assertSame(
						"types should be equals", returnType, method.getReturnType() //$NON-NLS-1$
								.getType());
				Assert.assertSame(
						"types should be equals", parameter, method.getParameters() //$NON-NLS-1$
								.get(1).getType().getType());
			}
		}
	}

	@Test
	public void modifiers() {
		NamedElement ne = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"modifiers.Modifiers"); //$NON-NLS-1$
		Assert.assertNotNull("modifiers.Modifiers should exist", ne); //$NON-NLS-1$
		TypeDeclaration type = (TypeDeclaration) ne;
		Assert.assertTrue(type.getModifier().getVisibility()
				.equals(VisibilityKind.PUBLIC));
		Assert.assertTrue(type.getModifier().getInheritance()
				.equals(InheritanceKind.ABSTRACT));

		NamedElement ne1 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"modifiers.Modifiers.f"); //$NON-NLS-1$
		Assert.assertNotNull("modifiers.Modifiers.f should exist", ne1); //$NON-NLS-1$

		VariableDeclarationFragment var = (VariableDeclarationFragment) ne1;
		FieldDeclaration field = (FieldDeclaration) var.getVariablesContainer();
		Assert.assertTrue(field.getModifier().getInheritance()
				.equals(InheritanceKind.NONE));
		Assert.assertTrue(field.getModifier().getVisibility()
				.equals(VisibilityKind.PRIVATE));
		Assert.assertTrue(field.getModifier().isStatic());
		Assert.assertTrue(field.getModifier().isTransient());
		Assert.assertTrue(field.getModifier().isVolatile());
		Assert.assertFalse(field.getModifier().isNative());
		Assert.assertFalse(field.getModifier().isStrictfp());
		Assert.assertFalse(field.getModifier().isSynchronized());

		NamedElement ne2 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"modifiers.Modifiers.method()"); //$NON-NLS-1$
		Assert.assertNotNull("modifiers.Modifiers.method() should exist", ne2); //$NON-NLS-1$
		MethodDeclaration method = (MethodDeclaration) ne2;
		Assert.assertTrue(method.getModifier().getInheritance()
				.equals(InheritanceKind.FINAL));
		Assert.assertTrue(method.getModifier().getVisibility()
				.equals(VisibilityKind.PROTECTED));
		Assert.assertTrue(method.getModifier().isSynchronized());
		Assert.assertTrue(method.getModifier().isNative());
		Assert.assertFalse(method.getModifier().isStatic());
		Assert.assertFalse(method.getModifier().isStrictfp());
		Assert.assertFalse(method.getModifier().isTransient());
		Assert.assertFalse(method.getModifier().isVolatile());
	}

	@Test
	public void proxyField() {
		// PFClass1
		NamedElement ne1 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p1.PFClass1.s1"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p1.PFClass1.s1 should exist", ne1); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p1.PFClass1.s1 should not be a proxy", ne1 //$NON-NLS-1$
						.isProxy());

		NamedElement ne2 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p1.PFClass1.s2"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p1.PFClass1.s2 should exist", ne2); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p1.PFClass1.s2 should not be a proxy", ne2 //$NON-NLS-1$
						.isProxy());

		NamedElement ne3 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p1.PFClass1"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p1.PFClass1 should exist", ne3); //$NON-NLS-1$
		TypeDeclaration pfClass1 = (TypeDeclaration) ne3;

		for (Iterator<BodyDeclaration> iterator = pfClass1
				.getBodyDeclarations().iterator(); iterator.hasNext();) {
			BodyDeclaration body = iterator.next();
			if (body instanceof FieldDeclaration) {
				Assert.assertTrue("field should have 2 fragments", //$NON-NLS-1$
						((FieldDeclaration) body).getFragments().size() == 2);
				Assert.assertSame(ne1, ((FieldDeclaration) body).getFragments()
						.get(0));
				Assert.assertSame(ne2, ((FieldDeclaration) body).getFragments()
						.get(1));
			}
		}

		// PFClass2
		NamedElement ne5 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.a1"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.a1 should exist", ne5); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.a1 should not be a proxy", ne5 //$NON-NLS-1$
						.isProxy());

		NamedElement ne6 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.a2"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.a2 should exist", ne6); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.a2 should not be a proxy", ne6 //$NON-NLS-1$
						.isProxy());

		Assert.assertSame(
				"fragments should have the same fieldDeclaration", ne5 //$NON-NLS-1$
						.eContainer(), ne6.eContainer());

		NamedElement ne7 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.b1"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.b1 should exist", ne7); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.b1 should not be a proxy", ne7 //$NON-NLS-1$
						.isProxy());

		NamedElement ne8 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.b2"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.b2 should exist", ne8); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.b2 should not be a proxy", ne8 //$NON-NLS-1$
						.isProxy());

		Assert.assertSame(
				"fragments should have the same fieldDeclaration", ne7 //$NON-NLS-1$
						.eContainer(), ne8.eContainer());

		NamedElement ne9 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.c1"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.c1 should exist", ne9); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.c1 should not be a proxy", ne9 //$NON-NLS-1$
						.isProxy());

		NamedElement ne10 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2.c2"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2.c2 should exist", ne10); //$NON-NLS-1$
		Assert.assertFalse(
				"proxyField.p2.PFClass2.c2 should not be a proxy", ne10 //$NON-NLS-1$
						.isProxy());

		Assert.assertSame(
				"fragments should have the same fieldDeclaration", ne9 //$NON-NLS-1$
						.eContainer(), ne10.eContainer());

		NamedElement ne11 = JavaUtil.getNamedElementByQualifiedName(getModel(),
				"proxyField.p2.PFClass2"); //$NON-NLS-1$
		Assert.assertNotNull("proxyField.p2.PFClass2 should exist", ne11); //$NON-NLS-1$
		TypeDeclaration pfClass2 = (TypeDeclaration) ne11;

		for (Iterator<BodyDeclaration> iterator = pfClass2
				.getBodyDeclarations().iterator(); iterator.hasNext();) {
			BodyDeclaration body = iterator.next();
			if (body instanceof FieldDeclaration) {
				Assert.assertTrue("field should have 2 fragments", //$NON-NLS-1$
						((FieldDeclaration) body).getFragments().size() == 2);
			}
		}
	}

}

Back to the top