View | Details | Raw Unified | Return to bug 186342 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NullAnnotationModelTests.java (+66 lines)
Lines 15-20 Link Here
15
import java.io.StringBufferInputStream;
15
import java.io.StringBufferInputStream;
16
import java.net.URL;
16
import java.net.URL;
17
import java.util.Hashtable;
17
import java.util.Hashtable;
18
import java.util.List;
18
19
19
import junit.framework.Test;
20
import junit.framework.Test;
20
21
Lines 33-38 Link Here
33
import org.eclipse.jdt.core.dom.AST;
34
import org.eclipse.jdt.core.dom.AST;
34
import org.eclipse.jdt.core.dom.ASTParser;
35
import org.eclipse.jdt.core.dom.ASTParser;
35
import org.eclipse.jdt.core.dom.CompilationUnit;
36
import org.eclipse.jdt.core.dom.CompilationUnit;
37
import org.eclipse.jdt.core.dom.MarkerAnnotation;
38
import org.eclipse.jdt.core.dom.MethodDeclaration;
39
import org.eclipse.jdt.core.dom.Modifier;
40
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
41
import org.eclipse.jdt.core.dom.TypeDeclaration;
36
42
37
public class NullAnnotationModelTests extends ReconcilerTests {
43
public class NullAnnotationModelTests extends ReconcilerTests {
38
44
Lines 415-418 Link Here
415
    		deleteProject("P");
421
    		deleteProject("P");
416
    	}
422
    	}
417
	}
423
	}
424
425
	// A synthetic annotation from a default should not be converted to DOM AST
426
	public void testAnnotationAST1() throws CoreException, InterruptedException {
427
    	try {
428
			// Resources creation
429
			IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB", this.ANNOTATION_LIB}, "bin", "1.5");
430
			p.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED);
431
432
			this.createFolder("/P/p1");
433
			// bug could only be triggered if ASTConvert actually finds a '@'
434
			// so in addition to the synthetic annotation there must also be a real one:
435
			String annotSourceString =
436
				"package p1;\n" +
437
				"import java.lang.annotation.ElementType;\n" + 
438
				"import java.lang.annotation.Target;\n" + 
439
				"@Target({ElementType.PARAMETER,ElementType.METHOD})\n" +
440
				"public @interface Annot {}\n";
441
			this.createFile(
442
				"/P/p1/Annot.java",
443
	    			annotSourceString);
444
			String c1SourceString =
445
				"package p1;\n" +
446
				"@org.eclipse.jdt.annotation.NonNullByDefault\n" +
447
				"public class C1 {\n" +
448
				"	 public @Annot Object foo(@Annot Object arg) {\n" +
449
				"         return this;\n" +
450
				"	 }\n" +
451
				"}\n";
452
			this.createFile(
453
				"/P/p1/C1.java",
454
	    			c1SourceString);
455
456
			this.problemRequestor.initialize(c1SourceString.toCharArray());
457
458
			final ICompilationUnit unit = getCompilationUnit("/P/p1/C1.java").getWorkingCopy(this.wcOwner, null);
459
			assertNoProblem(c1SourceString.toCharArray(), unit);
460
461
			ASTParser parser = ASTParser.newParser(AST.JLS4);
462
			parser.setProject(p);
463
			parser.setResolveBindings(true);
464
			parser.setSource(unit);
465
			CompilationUnit ast = (CompilationUnit) parser.createAST(null);
466
			assertNotNull("ast should not be null", ast);
467
			TypeDeclaration type = (TypeDeclaration) ast.types().get(0);
468
			assertNotNull("type should not be null", type);
469
			MethodDeclaration method = (MethodDeclaration) type.bodyDeclarations().get(0);
470
			assertNotNull("method should not be null", method);
471
			SingleVariableDeclaration arg = (SingleVariableDeclaration) method.parameters().get(0);
472
			assertNotNull("argument should not be null", arg);
473
			List modifiers = arg.modifiers();
474
			assertEquals("Should have exactly one modifier", 1, modifiers.size());
475
			assertEquals("Unexpected modifier", "@Annot", ((MarkerAnnotation)modifiers.get(0)).toString());
476
			modifiers = method.modifiers();
477
			assertEquals("Method should have exactly two modifiers", 2, modifiers.size());
478
			assertEquals("Unexpected modifier #1 for method", "public", ((Modifier)modifiers.get(0)).toString());
479
			assertEquals("Unexpected modifier #2 for method", "@Annot", ((MarkerAnnotation)modifiers.get(1)).toString());
480
    	} finally {
481
    		deleteProject("P");
482
    	}
483
	}
418
}
484
}
(-)a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java (-2 / +19 lines)
Lines 4361-4366 Link Here
4361
			int indexInAnnotations = 0;
4361
			int indexInAnnotations = 0;
4362
			while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4362
			while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4363
				IExtendedModifier modifier = null;
4363
				IExtendedModifier modifier = null;
4364
				switchToken:
4364
				switch(token) {
4365
				switch(token) {
4365
					case TerminalTokens.TokenNameabstract:
4366
					case TerminalTokens.TokenNameabstract:
4366
						modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
4367
						modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
Lines 4398-4404 Link Here
4398
					case TerminalTokens.TokenNameAT :
4399
					case TerminalTokens.TokenNameAT :
4399
						// we have an annotation
4400
						// we have an annotation
4400
						if (annotations != null && indexInAnnotations < annotations.length) {
4401
						if (annotations != null && indexInAnnotations < annotations.length) {
4401
							org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4402
							// method may have synthetic annotations, skip them:
4403
							org.eclipse.jdt.internal.compiler.ast.Annotation annotation;
4404
							do {
4405
								if (indexInAnnotations == annotations.length)
4406
									break switchToken;
4407
								annotation = annotations[indexInAnnotations++];
4408
							} while ((annotation.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsSynthetic) != 0);
4402
							modifier = convert(annotation);
4409
							modifier = convert(annotation);
4403
							this.scanner.resetTo(annotation.declarationSourceEnd + 1, modifiersEnd);
4410
							this.scanner.resetTo(annotation.declarationSourceEnd + 1, modifiersEnd);
4404
						}
4411
						}
Lines 4512-4517 Link Here
4512
					int token;
4519
					int token;
4513
					while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4520
					while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
4514
						IExtendedModifier modifier = null;
4521
						IExtendedModifier modifier = null;
4522
						switchToken:
4515
						switch(token) {
4523
						switch(token) {
4516
							case TerminalTokens.TokenNameabstract:
4524
							case TerminalTokens.TokenNameabstract:
4517
								modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
4525
								modifier = createModifier(Modifier.ModifierKeyword.ABSTRACT_KEYWORD);
Lines 4549-4555 Link Here
4549
							case TerminalTokens.TokenNameAT :
4557
							case TerminalTokens.TokenNameAT :
4550
								// we have an annotation
4558
								// we have an annotation
4551
								if (annotations != null && indexInAnnotations < annotations.length) {
4559
								if (annotations != null && indexInAnnotations < annotations.length) {
4552
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4560
									// argument may have synthetic annotations, skip them:
4561
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation;
4562
									do {
4563
										if (indexInAnnotations == annotations.length)
4564
											break switchToken;
4565
										annotation = annotations[indexInAnnotations++];
4566
									} while ((annotation.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsSynthetic) != 0);
4553
									modifier = convert(annotation);
4567
									modifier = convert(annotation);
4554
									this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
4568
									this.scanner.resetTo(annotation.declarationSourceEnd + 1, this.compilationUnitSourceLength);
4555
								}
4569
								}
Lines 4623-4628 Link Here
4623
							break;
4637
							break;
4624
						case TerminalTokens.TokenNameAT :
4638
						case TerminalTokens.TokenNameAT :
4625
							// we have an annotation
4639
							// we have an annotation
4640
							// (local variable has no synthetic annotations, no need to skip them)
4626
							if (annotations != null && indexInAnnotations < annotations.length) {
4641
							if (annotations != null && indexInAnnotations < annotations.length) {
4627
								org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4642
								org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4628
								modifier = convert(annotation);
4643
								modifier = convert(annotation);
Lines 4725-4730 Link Here
4725
								break;
4740
								break;
4726
							case TerminalTokens.TokenNameAT :
4741
							case TerminalTokens.TokenNameAT :
4727
								// we have an annotation
4742
								// we have an annotation
4743
								// (local variable has no synthetic annotations, no need to skip them)
4728
								if (annotations != null && indexInAnnotations < annotations.length) {
4744
								if (annotations != null && indexInAnnotations < annotations.length) {
4729
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4745
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4730
									modifier = convert(annotation);
4746
									modifier = convert(annotation);
Lines 4806-4811 Link Here
4806
								break;
4822
								break;
4807
							case TerminalTokens.TokenNameAT :
4823
							case TerminalTokens.TokenNameAT :
4808
								// we have an annotation
4824
								// we have an annotation
4825
								// (local variable has no synthetic annotations, no need to skip them)
4809
								if (annotations != null && indexInAnnotations < annotations.length) {
4826
								if (annotations != null && indexInAnnotations < annotations.length) {
4810
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4827
									org.eclipse.jdt.internal.compiler.ast.Annotation annotation = annotations[indexInAnnotations++];
4811
									modifier = convert(annotation);
4828
									modifier = convert(annotation);

Return to bug 186342