Author: vyemialyanchyk
Date: 2009-03-30 13:57:43 -0400 (Mon, 30 Mar 2009)
New Revision: 14380
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/CollectEntityInfo.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java
Log:
JBIDE-4028
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-30
15:34:48 UTC (rev 14379)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-03-30
17:57:43 UTC (rev 14380)
@@ -59,7 +59,7 @@
/**
* pair of 2 particular fields from 2 particular entities
*/
- protected class ProcessItem {
+ static protected class ProcessItem {
// field names
public String fieldId = null;
public String fieldId2 = null;
@@ -503,9 +503,23 @@
pi.refEntityInfo2.mappedBy = pi.fieldId;
updateOwner(pi);
}
+ else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
+ pi.refEntityInfo.refType = RefType.ONE2MANY;
+ pi.refEntityInfo.mappedBy = pi.fieldId2;
+ pi.refEntityInfo2.refType = RefType.MANY2ONE;
+ pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
+ }
}
else if (pi.refEntityInfo.refType == RefType.MANY2ONE) {
- if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
+ if (pi.refEntityInfo2.refType == RefType.ONE2MANY) {
+ pi.refEntityInfo.refType = RefType.MANY2ONE;
+ pi.refEntityInfo.mappedBy = pi.fieldId2;
+ pi.refEntityInfo2.refType = RefType.ONE2MANY;
+ pi.refEntityInfo2.mappedBy = pi.fieldId;
+ updateOwner(pi);
+ }
+ else if (pi.refEntityInfo2.refType == RefType.MANY2ONE) {
pi.refEntityInfo.refType = RefType.ONE2ONE;
pi.refEntityInfo.mappedBy = pi.fieldId2;
pi.refEntityInfo2.refType = RefType.ONE2ONE;
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-30
15:34:48 UTC (rev 14379)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-03-30
17:57:43 UTC (rev 14380)
@@ -14,7 +14,6 @@
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
@@ -251,9 +250,10 @@
SourceType sourceT = (SourceType)tb.getJavaElement();
try {
entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName();
- } catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("error", e);
}
+ catch (JavaModelException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
+ }
}
entityInfo.addDependency(entityFullyQualifiedName);
entityInfo.setFullyQualifiedParentName(entityFullyQualifiedName);
@@ -308,7 +308,7 @@
}
public boolean visit(MethodDeclaration node) {
- if (node.getName().getFullyQualifiedName().compareTo(entityInfo.getName()) == 0) {
+ if (node.getName().getFullyQualifiedName().compareTo(entityInfo.getName()) == 0 ||
node.isConstructor()) {
// this is constructor declaration - process it separately
entityInfo.setImplicitConstructorFlag(false);
if (node.parameters().size() == 0) {
@@ -317,14 +317,14 @@
return true;
}
// -) is it setter?
- if (node.getName().getIdentifier().startsWith("set")//$NON-NLS-1$
+ if (node.getName().getIdentifier().startsWith("set") //$NON-NLS-1$
&& node.parameters().size() == 1) {
// setter - do not process it
return true;
}
// +) is it getter?
- if (!(node.getName().getIdentifier().startsWith("get")//$NON-NLS-1$
- || node.getName().getIdentifier().startsWith("is"))//$NON-NLS-1$
+ if (!(node.getName().getIdentifier().startsWith("get") //$NON-NLS-1$
+ || node.getName().getIdentifier().startsWith("is")) //$NON-NLS-1$
|| node.parameters().size() > 0) {
// not the getter - do not process it
return true;
@@ -337,7 +337,8 @@
List<String> list = new ArrayList<String>();
if (returnIdentifier != null){
list.add(returnIdentifier);
- } else {
+ }
+ else {
//this need to do not lost primiry id
//and add references for interface
if (entityInfo.isInterfaceFlag()){
@@ -377,7 +378,8 @@
entityInfo.addPrimaryIdCandidate(name);
}
}
- } else if (type.isSimpleType()) {
+ }
+ else if (type.isSimpleType()) {
SimpleType st = (SimpleType)type;
ITypeBinding tb = st.resolveBinding();
if (tb != null) {
@@ -386,7 +388,8 @@
SourceType sourceT = (SourceType)tb.getJavaElement();
try {
entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName();
- } catch (JavaModelException e) {
+ }
+ catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
entityInfo.addDependency(entityFullyQualifiedName);
@@ -408,7 +411,8 @@
}
}
}
- } else if (type.isArrayType()) {
+ }
+ else if (type.isArrayType()) {
ArrayType at = (ArrayType)type;
Type componentType = at;
while (componentType.isArrayType()){
@@ -421,7 +425,8 @@
SourceType sourceT = (SourceType)tb.getJavaElement();
try {
entityFullyQualifiedName = sourceT.getFullyQualifiedParameterizedName();
- } catch (JavaModelException e) {
+ }
+ catch (JavaModelException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
entityInfo.addDependency(entityFullyQualifiedName);
@@ -432,7 +437,8 @@
}
}
}
- } else if (type.isParameterizedType()) {
+ }
+ else if (type.isParameterizedType()) {
ParameterizedType pt = (ParameterizedType)type;
Type typeP = (Type)pt.getType();
ITypeBinding tb = typeP.resolveBinding();
@@ -478,10 +484,12 @@
}
}
}
- } else if (type.isQualifiedType()) {
+ }
+ else if (type.isQualifiedType()) {
QualifiedType qt = (QualifiedType)type;
ITypeBinding tb = qt.resolveBinding();
- } else if (type.isWildcardType()) {
+ }
+ else if (type.isWildcardType()) {
WildcardType wt = (WildcardType)type;
ITypeBinding tb = wt.resolveBinding();
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java 2009-03-30
15:34:48 UTC (rev 14379)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/JPAConst.java 2009-03-30
17:57:43 UTC (rev 14380)
@@ -19,6 +19,8 @@
public static final String IMPORT_ONE2MANY = "javax.persistence.OneToMany";
//$NON-NLS-1$
public static final String IMPORT_MANY2ONE = "javax.persistence.ManyToOne";
//$NON-NLS-1$
public static final String IMPORT_MANY2MANY = "javax.persistence.ManyToMany";
//$NON-NLS-1$
+ public static final String IMPORT_MAPPEDSUPERCLASS =
"javax.persistence.MappedSuperclass"; //$NON-NLS-1$
+ public static final String IMPORT_VERSION = "javax.persistence.Version";
//$NON-NLS-1$
public static final String ANNOTATION_SERIALIZABLE = "Serializable";
//$NON-NLS-1$
public static final String ANNOTATION_ENTITY = "Entity"; //$NON-NLS-1$
@@ -29,6 +31,8 @@
public static final String ANNOTATION_ONE2MANY = "OneToMany"; //$NON-NLS-1$
public static final String ANNOTATION_MANY2ONE = "ManyToOne"; //$NON-NLS-1$
public static final String ANNOTATION_MANY2MANY = "ManyToMany"; //$NON-NLS-1$
+ public static final String ANNOTATION_MAPPEDSUPERCLASS = "MappedSuperclass";
//$NON-NLS-1$
+ public static final String ANNOTATION_VERSION = "Version"; //$NON-NLS-1$
public static final Vector<String> ALL_IMPORTS = new Vector<String>();
@@ -42,6 +46,8 @@
ALL_IMPORTS.add(IMPORT_ONE2MANY);
ALL_IMPORTS.add(IMPORT_MANY2ONE);
ALL_IMPORTS.add(IMPORT_MANY2MANY);
+ ALL_IMPORTS.add(IMPORT_MAPPEDSUPERCLASS);
+ ALL_IMPORTS.add(IMPORT_VERSION);
}
static public String getRefType(RefType refType) {
@@ -115,4 +121,20 @@
}
return false;
}
+
+ static public boolean isAnnotationMappedSuperclass(String fullyQualifiedName) {
+ if (ANNOTATION_MAPPEDSUPERCLASS.compareTo(fullyQualifiedName) == 0 ||
+ IMPORT_MAPPEDSUPERCLASS.compareTo(fullyQualifiedName) == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ static public boolean isAnnotationVersion(String fullyQualifiedName) {
+ if (ANNOTATION_VERSION.compareTo(fullyQualifiedName) == 0 ||
+ IMPORT_VERSION.compareTo(fullyQualifiedName) == 0) {
+ return true;
+ }
+ return false;
+ }
}
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-30
15:34:48 UTC (rev 14379)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-03-30
17:57:43 UTC (rev 14380)
@@ -17,19 +17,23 @@
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.ArrayType;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.BodyDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.ParameterizedType;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.ReturnStatement;
import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
@@ -238,7 +242,7 @@
}
}
}
- if (type.isSimpleType() || type.isParameterizedType()) {
+ if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
Iterator itVarNames = node.fragments().iterator();
String fieldId = ""; //$NON-NLS-1$
RefType refType = RefType.UNDEF;
@@ -256,7 +260,7 @@
}
}
Set<RefFieldInfo> setRFI = entityInfo.getRefFieldInfoSet(fullyQualifiedName2);
- if (!annotated && setRFI != null) {
+ if (!annotated && setRFI != null && isSimilarType(type,
fullyQualifiedName2)) {
RefEntityInfo rei = entityInfo.getFieldIdRefEntityInfo(fieldId);
// try to process bidirectional relationships:
// nRefType == JPAConst.ONE2ONE - OneToOne - the owning side corresponds
@@ -290,6 +294,23 @@
if (annotationStyle != AnnotStyle.GETTERS) {
return true;
}
+ if (node.getName().getFullyQualifiedName().compareTo(entityInfo.getName()) == 0 ||
node.isConstructor()) {
+ // this is constructor declaration
+ return true;
+ }
+ // -) is it setter?
+ if (node.getName().getIdentifier().startsWith("set") //$NON-NLS-1$
+ && node.parameters().size() == 1) {
+ // setter - do not process it
+ return true;
+ }
+ // +) is it getter?
+ if (!(node.getName().getIdentifier().startsWith("get") //$NON-NLS-1$
+ || node.getName().getIdentifier().startsWith("is")) //$NON-NLS-1$
+ || node.parameters().size() > 0) {
+ // not the getter - do not process it
+ return true;
+ }
Type type = node.getReturnType2();
if (type == null) {
return true;
@@ -323,7 +344,7 @@
}
}
}
- if (type.isSimpleType() || type.isParameterizedType()) {
+ if (type.isSimpleType() || type.isParameterizedType() || type.isArrayType()) {
String fieldId = ""; //$NON-NLS-1$
RefType refType = RefType.UNDEF;
boolean annotated = false;
@@ -332,10 +353,8 @@
refType = entityInfo.getFieldIdRelValue(fieldId);
annotated = entityInfo.getFieldIdAnnotatedValue(fieldId);
fullyQualifiedName2 = entityInfo.getFieldIdFQNameValue(fieldId);
- if (refType != RefType.UNDEF) {
- }
Set<RefFieldInfo> setRFI = entityInfo.getRefFieldInfoSet(fullyQualifiedName2);
- if (!annotated && setRFI != null) {
+ if (!annotated && setRFI != null && isSimilarType(type,
fullyQualifiedName2)) {
RefEntityInfo rei = entityInfo.getFieldIdRefEntityInfo(fieldId);
// try to process bidirectional relationships:
// nRefType == JPAConst.ONE2ONE - OneToOne - the owning side corresponds
@@ -364,6 +383,30 @@
}
return true;
}
+
+ // simple type name check
+ public boolean isSimilarType(Type type, String fullyQualifiedName) {
+ String typeName = null;
+ if (type.isSimpleType()) {
+ SimpleType st = (SimpleType)type;
+ typeName = st.getName().getFullyQualifiedName();
+ }
+ else if (type.isArrayType()) {
+ ArrayType at = (ArrayType)type;
+ Type componentType = at;
+ while (componentType.isArrayType()){
+ componentType = ((ArrayType)componentType).getComponentType();
+ }
+ if (componentType.isSimpleType()) {
+ SimpleType st = (SimpleType)componentType;
+ typeName = st.getName().getFullyQualifiedName();
+ }
+ }
+ if (typeName != null && fullyQualifiedName.indexOf(typeName) == -1) {
+ return false;
+ }
+ return true;
+ }
public boolean addSimpleMarkerAnnotation(BodyDeclaration node, String name) {
if (name == null || name.length() == 0) {