Author: vyemialyanchyk
Date: 2009-03-31 14:02:40 -0400 (Tue, 31 Mar 2009)
New Revision: 14391
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Document.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Document.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Document.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Document.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapMockTests.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapTest.java
Log:
JBIDE-3842
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -173,7 +173,7 @@
collector.collect(icu);
}
collector.resolveRelations();
- if (collector.getNonAbstractCUNumber() > 0) {
+ if (collector.getNonInterfaceCUNumber() > 0) {
processor.setAnnotationStylePreference(collector.getAnnotationStylePreference());
processor.modify(javaProject, collector.getMapCUs_Info(), true);
}
@@ -219,7 +219,7 @@
collector.initCollector(javaProject);
collector.collect(cu);
collector.resolveRelations();
- if (collector.getNonAbstractCUNumber() > 0) {
+ if (collector.getNonInterfaceCUNumber() > 0) {
processor.modify(javaProject, collector.getMapCUs_Info(), true);
}
else {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -713,6 +713,21 @@
return nonAbstractCUNumber;
}
+ public int getNonInterfaceCUNumber() {
+ Iterator<Map.Entry<String, EntityInfo>> it = null;
+ int nonInterfaceCUNumber = 0;
+ // generate RefFieldInfoMap (for simple process)
+ it = mapCUs_Info.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<String, EntityInfo> entry = it.next();
+ EntityInfo entryInfo = entry.getValue();
+ if (!entryInfo.isInterfaceFlag()) {
+ nonInterfaceCUNumber++;
+ }
+ }
+ return nonInterfaceCUNumber;
+ }
+
public AnnotStyle getAnnotationStylePreference() {
return annotationStylePreference;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -167,6 +167,14 @@
updateAnnotationRelInfo(node, mappedBy, fullyQualifiedName,
RefType.MANY2MANY, JPAConst.ANNOTATION_MANY2MANY, JPAConst.IMPORT_MANY2MANY);
}
+ else if (JPAConst.isAnnotationMappedSuperclass(fullyQualifiedName)) {
+ entityInfo.setAddEntityFlag(false);
+ entityInfo.setAddMappedSuperclassFlag(false);
+ entityInfo.removeRequiredImport(JPAConst.IMPORT_ENTITY);
+ entityInfo.addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ }
+ else if (JPAConst.isAnnotationVersion(fullyQualifiedName)) {
+ }
return true;
}
@@ -239,7 +247,15 @@
}
public boolean visit(TypeDeclaration node) {
- entityInfo.setAbstractFlag(entityInfo.isAbstractFlag() || node.isInterface());
+ boolean isAbstruct = entityInfo.isAbstractFlag() ||
+ Modifier.isAbstract(node.getModifiers()) || node.isInterface();
+ entityInfo.setAbstractFlag(isAbstruct);
+ if (isAbstruct) {
+ entityInfo.setAddEntityFlag(false);
+ entityInfo.setAddMappedSuperclassFlag(true);
+ entityInfo.removeRequiredImport(JPAConst.IMPORT_ENTITY);
+ entityInfo.addRequiredImport(JPAConst.IMPORT_MAPPEDSUPERCLASS);
+ }
entityInfo.setInterfaceFlag(node.isInterface());
Type superType = node.getSuperclassType();
if (superType != null) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -52,6 +52,10 @@
*/
protected boolean addEntityFlag = true;
/*
+ * if true - "@MappedSuperclass" annotation should be added
+ */
+ protected boolean addMappedSuperclassFlag = false;
+ /*
* existing imports set
*/
protected Set<String> setExistingImports = new TreeSet<String>();
@@ -288,6 +292,14 @@
this.addEntityFlag = addEntityFlag;
}
+ public boolean isAddMappedSuperclassFlag() {
+ return addMappedSuperclassFlag;
+ }
+
+ public void setAddMappedSuperclassFlag(boolean addMappedSuperclassFlag) {
+ this.addMappedSuperclassFlag = addMappedSuperclassFlag;
+ }
+
public boolean isAddSerializableInterfaceFlag() {
return addSerializableInterfaceFlag;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -231,7 +231,7 @@
try {
while (it.hasNext()) {
Map.Entry<String, EntityInfo> entry = it.next();
- if (entry.getValue().isAbstractFlag()) {
+ if (entry.getValue().isInterfaceFlag()) {
continue;
}
collectModification(bufferManager, entry.getKey(), entry.getValue(), entities);
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -98,7 +98,7 @@
}
public boolean addImport(CompilationUnit node, String importDeclaration) {
- String[] importDeclarations = importDeclaration.split("\\."); //$NON-NLS-1$
+ String[] importDeclarations = importDeclaration.split("\\."); //$NON-NLS-1$
if (importDeclarations.length <= 1) {
return false;
}
@@ -138,6 +138,12 @@
}
public boolean visit(TypeDeclaration node) {
+ if (entityInfo.isAddMappedSuperclassFlag()) {
+ MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
+ matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_MAPPEDSUPERCLASS));
+ ListRewrite lrw = rewriter.getListRewrite(node, TypeDeclaration.MODIFIERS2_PROPERTY);
+ lrw.insertFirst(matd, null);
+ }
if (entityInfo.isAddEntityFlag()) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_ENTITY));
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Document.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Document.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/Document.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -13,7 +13,7 @@
import java.util.Set;
@javax.persistence.Entity
-public class Document {
+public class Document extends DocumentBase {
@javax.persistence.Id
protected Long documentId;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/fields/DocumentBase.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -10,7 +10,9 @@
******************************************************************************/
package test.annotated.fields;
+import javax.persistence.MappedSuperclass;
+
public abstract class DocumentBase {
- protected Long globalDocumentIdentificator;
+ protected String globalDocumentIdentificator;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Document.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Document.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/Document.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -13,7 +13,7 @@
import java.util.Set;
@javax.persistence.Entity
-public class Document {
+public class Document extends DocumentBase {
private Long documentId;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/project/test/annotated/getters/DocumentBase.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -10,7 +10,8 @@
******************************************************************************/
package test.annotated.getters;
+@MappedSuperclass
public abstract class DocumentBase {
- protected Long globalDocumentIdentificator;
+ protected String globalDocumentIdentificator;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Document.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Document.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/Document.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -16,7 +16,7 @@
import javax.persistence.ManyToOne;
@javax.persistence.Entity
-public class Document {
+public class Document extends DocumentBase {
@GeneratedValue @javax.persistence.Id
protected Long documentId;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/fields/DocumentBase.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -15,5 +15,5 @@
@MappedSuperclass
public abstract class DocumentBase {
- protected Long globalDocumentIdentificator;
+ protected String globalDocumentIdentificator;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Document.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Document.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/Document.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -16,7 +16,7 @@
import javax.persistence.ManyToOne;
@javax.persistence.Entity
-public class Document {
+public class Document extends DocumentBase {
private Long documentId;
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/res/specimen/test/annotated/getters/DocumentBase.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -15,5 +15,5 @@
@MappedSuperclass
public abstract class DocumentBase {
- protected Long globalDocumentIdentificator;
+ protected String globalDocumentIdentificator;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapMockTests.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapMockTests.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapMockTests.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -107,6 +107,10 @@
inSequence(sequence);
will(returnValue(2));
+ allowing(allEntitiesInfoCollector).getNonInterfaceCUNumber();
+ inSequence(sequence);
+ will(returnValue(2));
+
allowing(allEntitiesInfoCollector).getAnnotationStylePreference();
inSequence(sequence);
will(returnValue(AnnotStyle.GETTERS));
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapTest.java 2009-03-31
17:21:28 UTC (rev 14390)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JPAMapTest.java 2009-03-31
18:02:40 UTC (rev 14391)
@@ -139,7 +139,7 @@
collector.resolveRelations();
processor.modify(javaProject, collector.getMapCUs_Info(), false);
//
- //checkItem("DocumentBase"); //$NON-NLS-1$
+ checkItem("DocumentBase"); //$NON-NLS-1$
checkItem("Document"); //$NON-NLS-1$
checkItem("Foto"); //$NON-NLS-1$
checkItem("Passport"); //$NON-NLS-1$