Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 399453
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TypeAnnotationSyntaxTest.java (-1 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2012 IBM Corporation and others.
2
 * Copyright (c) 2009, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 3790-3793 Link Here
3790
			"}\n";
3790
			"}\n";
3791
	checkParse(CHECK_PARSER, source.toCharArray(), null, "test0137", expectedUnitToString);
3791
	checkParse(CHECK_PARSER, source.toCharArray(), null, "test0137", expectedUnitToString);
3792
}
3792
}
3793
public void test0138() throws IOException {
3794
	String source = 
3795
			"import java.lang.annotation.Target;\n" +
3796
			"import static java.lang.annotation.ElementType.*;\n" +
3797
			"public class X {\n" +
3798
			"	public void foo() {\n" +
3799
			"		int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [bar()] @Marker @Marker2 [];\n" +
3800
			"		int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [X.bar2(2)] @Marker @Marker2 [];\n" +
3801
			"	}\n" +
3802
			"	public int bar() {\n" +
3803
			"		return 2;\n" +
3804
			"	}\n" +
3805
			"	public static int bar2(int k) {\n" +
3806
			"		return k;\n" + 
3807
			"	}\n" +
3808
			"}\n" +
3809
			"@Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
3810
			"@interface Marker {}\n" +
3811
			"@Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
3812
			"@interface Marker2 {}\n";
3813
	String expectedUnitToString = 
3814
			"import java.lang.annotation.Target;\n" + 
3815
			"import static java.lang.annotation.ElementType.*;\n" + 
3816
			"public class X {\n" + 
3817
			"  public X() {\n" + 
3818
			"    super();\n" + 
3819
			"  }\n" + 
3820
			"  public void foo() {\n" + 
3821
			"    int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [bar()] @Marker @Marker2 [];\n" + 
3822
			"    int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [X.bar2(2)] @Marker @Marker2 [];\n" + 
3823
			"  }\n" + 
3824
			"  public int bar() {\n" + 
3825
			"    return 2;\n" + 
3826
			"  }\n" + 
3827
			"  public static int bar2(int k) {\n" + 
3828
			"    return k;\n" + 
3829
			"  }\n" + 
3830
			"}\n" + 
3831
			"@Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {\n" + 
3832
			"}\n" + 
3833
			"@Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker2 {\n" + 
3834
			"}\n";
3835
	checkParse(CHECK_PARSER, source.toCharArray(), null, "test0137", expectedUnitToString);
3836
}
3793
}
3837
}
(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java (+36 lines)
Lines 3117-3120 Link Here
3117
			"The annotation @Marker2 is disallowed for this location\n" + 
3117
			"The annotation @Marker2 is disallowed for this location\n" + 
3118
			"----------\n"); 
3118
			"----------\n"); 
3119
	}
3119
	}
3120
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399453
3121
	public void testBug399453() {
3122
		this.runNegativeTest(
3123
				new String[]{
3124
					"X.java",
3125
					"import java.lang.annotation.Target;\n" +
3126
					"import static java.lang.annotation.ElementType.*;\n" +
3127
					"public class X {\n" +
3128
					"	public void foo() {\n" +
3129
					"		int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] @Marker @Marker2 [];\n" +
3130
					"		int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker X.bar2(2)] @Marker @Marker2 [];\n" +
3131
					"	}\n" +
3132
					"	public int bar() {\n" +
3133
					"		return 2;\n" +
3134
					"	}\n" +
3135
					"	public static int bar2(int k) {\n" +
3136
					"		return k;\n" + 
3137
					"	}\n" +
3138
					"}\n" +
3139
					"@Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
3140
					"@interface Marker {}\n" +
3141
					"@Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
3142
					"@interface Marker2 {}\n"
3143
				},
3144
				"----------\n" + 
3145
				"1. ERROR in X.java (at line 5)\n" + 
3146
				"	int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] @Marker @Marker2 [];\n" + 
3147
				"	                                                                               ^^^^^^^\n" + 
3148
				"Syntax error, type annotations are illegal here\n" + 
3149
				"----------\n" + 
3150
				"2. ERROR in X.java (at line 6)\n" + 
3151
				"	int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker X.bar2(2)] @Marker @Marker2 [];\n" + 
3152
				"	                                                                               ^^^^^^^\n" + 
3153
				"Syntax error, type annotations are illegal here\n" + 
3154
				"----------\n"); 
3155
	}
3120
}
3156
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-12 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 5126-5147 Link Here
5126
		this.identifierLengthPtr--;
5126
		this.identifierLengthPtr--;
5127
	} else {
5127
	} else {
5128
		this.identifierLengthStack[this.identifierLengthPtr]--;
5128
		this.identifierLengthStack[this.identifierLengthPtr]--;
5129
		int length = this.typeAnnotationLengthStack[this.typeAnnotationLengthPtr--];
5130
		Annotation [] typeAnnotations;
5131
		if (length != 0) {
5132
			System.arraycopy(
5133
					this.typeAnnotationStack,
5134
					(this.typeAnnotationPtr -= length) + 1,
5135
					typeAnnotations = new Annotation[length],
5136
					0,
5137
					length);
5138
			problemReporter().misplacedTypeAnnotations(typeAnnotations[0], typeAnnotations[typeAnnotations.length - 1]);
5139
		}
5140
		m.receiver = getUnspecifiedReference();
5129
		m.receiver = getUnspecifiedReference();
5141
		m.sourceStart = m.receiver.sourceStart;
5130
		m.sourceStart = m.receiver.sourceStart;
5142
	}
5131
	}
5132
	rejectTypeAnnotationsOnMethodInvocation();
5143
	pushOnExpressionStack(m);
5133
	pushOnExpressionStack(m);
5144
}
5134
}
5135
private void rejectTypeAnnotationsOnMethodInvocation() {
5136
	int length = this.typeAnnotationLengthStack[this.typeAnnotationLengthPtr--];
5137
	Annotation [] typeAnnotations;
5138
	if (length != 0) {
5139
		System.arraycopy(
5140
				this.typeAnnotationStack,
5141
				(this.typeAnnotationPtr -= length) + 1,
5142
				typeAnnotations = new Annotation[length],
5143
				0,
5144
				length);
5145
		problemReporter().misplacedTypeAnnotations(typeAnnotations[0], typeAnnotations[typeAnnotations.length - 1]);
5146
	}
5147
}
5145
protected void consumeMethodInvocationNameWithTypeArguments() {
5148
protected void consumeMethodInvocationNameWithTypeArguments() {
5146
	// MethodInvocation ::= Name '.' TypeArguments 'Identifier' '(' ArgumentListopt ')'
5149
	// MethodInvocation ::= Name '.' TypeArguments 'Identifier' '(' ArgumentListopt ')'
5147
5150

Return to bug 399453