Author: dgeraskov
Date: 2010-03-24 10:02:28 -0400 (Wed, 24 Mar 2010)
New Revision: 21002
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6051
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2010-03-24
09:49:39 UTC (rev 21001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/ConfigurationActor.java 2010-03-24
14:02:28 UTC (rev 21002)
@@ -261,6 +261,8 @@
*/
protected EntityInfo entityInfo;
+ private TypeDeclaration currentType;
+
TypeVisitor typeVisitor;
public void setEntities(Map<String, EntityInfo> entities) {
@@ -297,6 +299,7 @@
@SuppressWarnings("unchecked")
public boolean visit(TypeDeclaration node) {
+ currentType = node;
if ("".equals(entityInfo.getPrimaryIdName())){ //$NON-NLS-1$
//try to guess id
FieldDeclaration[] fields = node.getFields();
@@ -354,7 +357,9 @@
if (prop == null) {
continue;
}
-
+ if (!varHasGetterAndSetter(var)){
+ prop.setPropertyAccessorName("field"); //$NON-NLS-1$
+ }
String name = var.getName().getIdentifier();
if (name.equals(primaryIdName)) {
rootClass.setIdentifierProperty(prop);
@@ -366,6 +371,28 @@
return true;
}
+ private boolean varHasGetterAndSetter(VariableDeclarationFragment var){
+ String name = var.getName().getIdentifier();
+ String setterName = "set" + Character.toUpperCase(name.charAt(0)) +
name.substring(1); //$NON-NLS-1$
+ String getterName = "get" + Character.toUpperCase(name.charAt(0)) +
name.substring(1); //$NON-NLS-1$
+ String getterName2 = null;
+ Type varType = ((FieldDeclaration)var.getParent()).getType();
+ if (varType.isPrimitiveType()
+ && ((PrimitiveType)varType).getPrimitiveTypeCode() ==
PrimitiveType.BOOLEAN){
+ getterName2 = "is" + Character.toUpperCase(name.charAt(0)) +
name.substring(1); //$NON-NLS-1$
+ }
+ boolean setterFound = false, getterFound = false;
+ MethodDeclaration[] mds = currentType.getMethods();
+ for (MethodDeclaration methodDeclaration : mds) {
+ String methodName = methodDeclaration.getName().getIdentifier();
+ if (methodName.equals(setterName)) setterFound = true;
+ if (methodName.equals(getterName)) getterFound = true;
+ if (methodName.equals(getterName2)) getterFound = true;
+ if (setterFound && getterFound) return true;
+ }
+ return false;
+ }
+
@Override
public boolean visit(MethodDeclaration node) {
if (!entityInfo.isInterfaceFlag()) return super.visit(node);
@@ -404,7 +431,7 @@
protected Property createProperty(String varName, Type varType) {
typeVisitor.init(varName, entityInfo);
varType.accept(typeVisitor);
- Property p = typeVisitor.getProperty();
+ Property p = typeVisitor.getProperty();
return p;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-03-24
09:49:39 UTC (rev 21001)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2010-03-24
14:02:28 UTC (rev 21002)
@@ -299,7 +299,6 @@
for (Entry<IJavaProject, Configuration> entry : configs.entrySet()) {
Configuration config = entry.getValue();
HibernateMappingGlobalSettings hmgs = new HibernateMappingGlobalSettings();
- hmgs.setDefaultAccess("field"); //$NON-NLS-1$
//final IPath projPath = entry.getKey().getProject().getLocation();
IPath place2Gen =
previewPage.getRootPlace2Gen().append(entry.getKey().getElementName());