summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2012-08-13 10:48:55 (EDT)
committerKaren Butzke2012-08-13 12:20:54 (EDT)
commit9669809779bacac5b79f13099f152dd2322be8a3 (patch)
treeb91e0cf088d26d4ba800875cf42eec88ca752e73
parentd97c0065c41be06d6a3ce7d38f3536ee410d5241 (diff)
downloadwebtools.dali-9669809779bacac5b79f13099f152dd2322be8a3.zip
webtools.dali-9669809779bacac5b79f13099f152dd2322be8a3.tar.gz
webtools.dali-9669809779bacac5b79f13099f152dd2322be8a3.tar.bz2
bug 373430 - element collection with primitive target class and map key
class has incorrect errors
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceElementCollection2_0Annotation.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceMapKeyClass2_0Annotation.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java37
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java42
5 files changed, 89 insertions, 9 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
index 3169d32..36d824f 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java
@@ -1699,6 +1699,11 @@ public abstract class AbstractJavaElementCollectionMapping2_0
return (annotation == null) ? null : annotation.getTargetClassTextRange();
}
+ protected TextRange getMapKeyClassTextRange(CompilationUnit astRoot) {
+ MapKeyClass2_0Annotation annotation = this.getMapKeyClassAnnotation();
+ return annotation == null ? getMappingAnnotationTextRange(astRoot) : annotation.getTextRange(astRoot);
+ }
+
protected void validateMapKeyClass(List<IMessage> messages, CompilationUnit astRoot) {
if (this.getPersistentAttribute().getJpaContainerDefinition().isMap()) {
this.validateMapKeyClass_(messages, astRoot);
@@ -1724,7 +1729,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0
JpaValidationMessages.MAP_KEY_CLASS_NOT_DEFINED,
EMPTY_STRING_ARRAY,
this,
- this.getValidationTextRange(astRoot)
+ this.getMapKeyClassTextRange(astRoot)
)
);
}
@@ -1742,7 +1747,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0
JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_CLASS_MUST_BE_ENTITY_EMBEDDABLE_OR_BASIC_TYPE,
new String[] {this.getName(), this.getFullyQualifiedMapKeyClass()},
this,
- this.getTargetClassTextRange(astRoot)
+ this.getValidationTextRange(astRoot)
)
);
} else {
@@ -1752,7 +1757,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0
JpaValidationMessages.MAP_KEY_CLASS_MUST_BE_ENTITY_EMBEDDABLE_OR_BASIC_TYPE,
new String[] {this.getFullyQualifiedMapKeyClass()},
this,
- this.getTargetClassTextRange(astRoot)
+ this.getMapKeyClassTextRange(astRoot)
)
);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceElementCollection2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceElementCollection2_0Annotation.java
index c4f307f..5ae96c6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceElementCollection2_0Annotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceElementCollection2_0Annotation.java
@@ -16,7 +16,7 @@ import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotati
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.TypeStringExpressionConverter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
@@ -198,7 +198,7 @@ public final class SourceElementCollection2_0Annotation
private static DeclarationAnnotationElementAdapter<String> buildTargetClassAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) {
// TODO what about QualifiedType?
- return buildAnnotationElementAdapter(annotationAdapter, elementName, SimpleTypeStringExpressionConverter.instance());
+ return buildAnnotationElementAdapter(annotationAdapter, elementName, TypeStringExpressionConverter.instance());
}
private static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceMapKeyClass2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceMapKeyClass2_0Annotation.java
index 67103ce..f545e0d 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceMapKeyClass2_0Annotation.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/resource/java/source/SourceMapKeyClass2_0Annotation.java
@@ -15,7 +15,7 @@ import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.common.core.internal.utility.jdt.TypeStringExpressionConverter;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement;
@@ -141,7 +141,7 @@ public final class SourceMapKeyClass2_0Annotation
// ********** static methods **********
protected static DeclarationAnnotationElementAdapter<String> buildValueAdapter() {
- return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, JPA2_0.MAP_KEY_CLASS__VALUE, SimpleTypeStringExpressionConverter.instance());
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, JPA2_0.MAP_KEY_CLASS__VALUE, TypeStringExpressionConverter.instance());
}
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
index 92f9653..1b2160c 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/ElementCollection2_0AnnotationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. 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.
@@ -66,6 +66,19 @@ public class ElementCollection2_0AnnotationTests extends JavaResourceModel2_0Tes
});
}
+ private ICompilationUnit createTestElementCollectionWithPrimitiveTargetClass() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_0.ELEMENT_COLLECTION);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@ElementCollection(targetClass = byte.class)");
+ }
+ });
+ }
+
public void testElementCollection() throws Exception {
ICompilationUnit cu = this.createTestElementCollection();
JavaResourceType resourceType = buildJavaResourceType(cu);
@@ -167,4 +180,26 @@ public class ElementCollection2_0AnnotationTests extends JavaResourceModel2_0Tes
assertEquals("Foo", elementCollection.getFullyQualifiedTargetClassName()); //bug 196200 changed this
}
+
+ public void testGetPrimitiveTargetClass() throws Exception {
+ ICompilationUnit cu = this.createTestElementCollectionWithPrimitiveTargetClass();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(JPA2_0.ELEMENT_COLLECTION);
+ assertEquals("byte", elementCollection.getTargetClass());
+ }
+
+ public void testSetPrimitiveTargetClass() throws Exception {
+ ICompilationUnit cu = this.createTestElementCollection();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ ElementCollection2_0Annotation elementCollection = (ElementCollection2_0Annotation) resourceField.getAnnotation(JPA2_0.ELEMENT_COLLECTION);
+ assertEquals(null, elementCollection.getTargetClass());
+
+ elementCollection.setTargetClass("int");
+
+ assertSourceContains("@ElementCollection(targetClass = int.class)", cu);
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
index 8d64639..54746b5 100644
--- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
+++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/resource/java/MapKeyClass2_0AnnotationTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. 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.
@@ -53,6 +53,19 @@ public class MapKeyClass2_0AnnotationTests extends JavaResourceModel2_0TestCase
});
}
+ private ICompilationUnit createTestMapKeyClassWithPrimitiveValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA2_0.MAP_KEY_CLASS);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@MapKeyClass(value=int.class)");
+ }
+ });
+ }
+
public void testMapKeyClass() throws Exception {
ICompilationUnit cu = this.createTestMapKeyClass();
JavaResourceType resourceType = buildJavaResourceType(cu);
@@ -106,4 +119,31 @@ public class MapKeyClass2_0AnnotationTests extends JavaResourceModel2_0TestCase
assertSourceContains("@MapKeyClass(" + TYPE_NAME + ".class)", cu);
}
+ public void testGetPrimitiveValue() throws Exception {
+ ICompilationUnit cu = this.createTestMapKeyClassWithPrimitiveValue();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(JPA2_0.MAP_KEY_CLASS);
+ assertEquals("int", mapKeyClass.getValue());
+ assertEquals("int", mapKeyClass.getFullyQualifiedClassName());
+ }
+
+ public void testSetPrimitiveValue() throws Exception {
+ ICompilationUnit cu = this.createTestMapKeyClassWithValue();
+ JavaResourceType resourceType = buildJavaResourceType(cu);
+ JavaResourceField resourceField = CollectionTools.get(resourceType.getFields(), 0);
+
+ MapKeyClass2_0Annotation mapKeyClass = (MapKeyClass2_0Annotation) resourceField.getAnnotation(JPA2_0.MAP_KEY_CLASS);
+ assertEquals(MAP_KEY_CLASS_VALUE, mapKeyClass.getValue());
+
+ mapKeyClass.setValue("int");
+ assertEquals("int", mapKeyClass.getValue());
+
+ assertSourceContains("@MapKeyClass(int.class)", cu);
+
+ mapKeyClass.setValue(null);
+
+ assertSourceDoesNotContain("@MapKeyClass(", cu);
+ }
}