bug 368575 - @Property should only be allowed on fields inside external
types
diff --git a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/binding/annotationType/PropertyAnnotationProxy.java b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/binding/annotationType/PropertyAnnotationProxy.java
index e9d670f..c3ebcc9 100644
--- a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/binding/annotationType/PropertyAnnotationProxy.java
+++ b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/binding/annotationType/PropertyAnnotationProxy.java
@@ -15,9 +15,12 @@
 import java.util.List;
 
 import org.eclipse.edt.compiler.binding.AbstractValidationProxy;
+import org.eclipse.edt.compiler.binding.AnnotationValidationRule;
 import org.eclipse.edt.compiler.binding.FieldAccessValidationRule;
+import org.eclipse.edt.compiler.binding.UserDefinedAnnotationValidationRule;
 import org.eclipse.edt.compiler.binding.UserDefinedFieldAccessAnnotationValidationRule;
 import org.eclipse.edt.compiler.internal.core.validation.annotation.PropertyFieldAccessValidator;
+import org.eclipse.edt.compiler.internal.core.validation.annotation.PropertyValidator;
 import org.eclipse.edt.mof.utils.NameUtile;
 
 
@@ -26,6 +29,10 @@
 	
 	private static PropertyAnnotationProxy INSTANCE = new PropertyAnnotationProxy();
 	
+	private static final List<AnnotationValidationRule> myAnnotations = new ArrayList();
+	static {
+		myAnnotations.add(new UserDefinedAnnotationValidationRule(PropertyValidator.class));
+	}
 	
 	private static final List<FieldAccessValidationRule> fieldAccessAnnotations = new ArrayList();
 	static {
@@ -40,6 +47,11 @@
 	}
 	
 	@Override
+	public List<AnnotationValidationRule> getAnnotationValidators() {
+		return myAnnotations;
+	}
+	
+	@Override
 	public List<FieldAccessValidationRule> getFieldAccessValidators() {
 		return fieldAccessAnnotations;
 	}
diff --git a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/EGLValidationResources.properties b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/EGLValidationResources.properties
index 6d13bfe..a80a90a 100644
--- a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/EGLValidationResources.properties
+++ b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/EGLValidationResources.properties
@@ -205,6 +205,7 @@
 3423=Invalid attempt to write to field {0}, which specifies a get method but not a set method.
 #In message 3424, do not translate: set, get
 3424=Invalid attempt to read from field {0}, which specifies a set method but not a get method.
+3425=The annotation {0} can only be specified on fields inside ExternalTypes.
 
 #In message 3427, do not translate: Interface
 3427=The type {0} must be an Interface part.
@@ -225,7 +226,7 @@
 3441=The exception {0} has already been named in another onException clause.
 3444=The type {0} must be an exception record.
 
-3446=The subtype of an external type must match the subtype of any external types it extends.
+3446=The subtype of an ExternalType must match the subtype of any ExternalTypes it extends.
 
 3458=The part, part type, statement, or operator {0} is not supported in this version of the language.
 3461=The value for property {0} must be the name of a function within part {1}. Functions defined in other parts are not allowed.
diff --git a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/IProblemRequestor.java b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/IProblemRequestor.java
index ea0ae5f..e31dd3a 100644
--- a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/IProblemRequestor.java
+++ b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/builder/IProblemRequestor.java
@@ -154,6 +154,7 @@
 	public static final int EXTERNALTYPE_MUST_EXTEND_EXTERNALTYPE = 3421;
 	public static final int CANNOT_WRITE_TO_EXTERNALTYPE_FIELD_WITH_NO_SETTER = 3423;
 	public static final int CANNOT_READ_FROM_EXTERNALTYPE_FIELD_WITH_NO_GETTER = 3424;
+	public static final int PROPERTY_ANNOTATION_MUST_BE_IN_EXTERNALTYPE= 3425;
 	public static final int INTERFACE_MUST_EXTEND_INTERFACE = 3427;
 	public static final int INVOCATION_MUST_BE_IN_TRY = 3428;
 	public static final int TYPE_NOT_INSTANTIABLE = 3433;
diff --git a/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/validation/annotation/PropertyValidator.java b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/validation/annotation/PropertyValidator.java
new file mode 100644
index 0000000..294d845
--- /dev/null
+++ b/core/org.eclipse.edt.compiler/src/org/eclipse/edt/compiler/internal/core/validation/annotation/PropertyValidator.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright © 2013 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.edt.compiler.internal.core.validation.annotation;
+
+import java.util.Map;
+
+import org.eclipse.edt.compiler.core.ast.Node;
+import org.eclipse.edt.compiler.internal.core.builder.IProblemRequestor;
+import org.eclipse.edt.compiler.internal.core.lookup.ICompilerOptions;
+import org.eclipse.edt.compiler.internal.util.BindingUtil;
+import org.eclipse.edt.mof.egl.Element;
+import org.eclipse.edt.mof.egl.ExternalType;
+import org.eclipse.edt.mof.egl.Member;
+import org.eclipse.edt.mof.egl.Part;
+
+public class PropertyValidator implements IAnnotationValidationRule {
+
+	@Override
+	public void validate(Node errorNode, Node target, Element targetElement, Map<String, Object> allAnnotationsAndFields, IProblemRequestor problemRequestor, ICompilerOptions compilerOptions) {
+		// @Property is only allowed on fields of external types.
+		if (targetElement instanceof Member) {
+			Part declarer = BindingUtil.getDeclaringPart((Member)targetElement);
+			if (declarer != null && !(declarer instanceof ExternalType)) {
+				problemRequestor.acceptProblem(errorNode, IProblemRequestor.PROPERTY_ANNOTATION_MUST_BE_IN_EXTERNALTYPE, new String[]{"@Property"}); //$NON-NLS-1$
+			}
+		}
+	}
+}