Author: vyemialyanchyk
Date: 2009-10-19 11:17:05 -0400 (Mon, 19 Oct 2009)
New Revision: 18163
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfosCollection.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/DebugJavaCompletionProposalComputer.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/SaveQueryEditorListener.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java
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/ChangeStructure.java
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/wizard/HibernateJPARefactoring.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4328 - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/DebugJavaCompletionProposalComputer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/DebugJavaCompletionProposalComputer.java 2009-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/DebugJavaCompletionProposalComputer.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -99,6 +99,7 @@
}
+ @SuppressWarnings("unchecked")
public List computeContextInformation(ContentAssistInvocationContext context,
IProgressMonitor monitor) {
// TODO Auto-generated method stub
return Collections.EMPTY_LIST;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/SaveQueryEditorListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/SaveQueryEditorListener.java 2009-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/SaveQueryEditorListener.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -49,6 +49,7 @@
* @author Dmitry Geraskov
*
*/
+@SuppressWarnings("restriction")
public class SaveQueryEditorListener implements IPropertyListener {
public static final String id =
"AbstractQueryEditor.ReplaceString"; //$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java 2009-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActionDelegate.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -31,6 +31,7 @@
*
* @author Vitali
*/
+@SuppressWarnings("restriction")
public class JPAMapToolActionDelegate extends AbstractHandler implements
IObjectActionDelegate,
IEditorActionDelegate, IViewActionDelegate {
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/actions/JPAMapToolActor.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -64,6 +64,7 @@
*
* @author Vitali Yemialyanchyk
*/
+@SuppressWarnings("restriction")
public class JPAMapToolActor {
/**
@@ -201,7 +202,6 @@
/**
* update compilation unit of currently opened editor
*/
- @SuppressWarnings("restriction")
public void updateOpen() {
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
@@ -265,7 +265,6 @@
/**
* @param sel - current selected workspace element for processing
*/
- @SuppressWarnings("restriction")
synchronized private void updateSelectedItems(ISelection sel) {
//System.out.println("Blah! " + selection); //$NON-NLS-1$
if (sel instanceof TextSelection) {
@@ -343,7 +342,6 @@
* @param obj
* @return exclusion result
*/
- @SuppressWarnings("restriction")
protected boolean excludeElement(Object obj) {
boolean res = false;
if (obj instanceof JarPackageFragmentRoot) {
@@ -372,7 +370,6 @@
* Process object - java element to collect all it's children CompilationUnits
* @param obj
*/
- @SuppressWarnings("restriction")
protected void processJavaElements(Object obj) {
if (obj instanceof ICompilationUnit) {
ICompilationUnit cu = (ICompilationUnit)obj;
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/AllEntitiesInfoCollector.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.eclipse.jdt.ui.internal.jpa.collect;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -689,6 +690,7 @@
* its dependencies
* @param icu - startup point entity compilation unit
*/
+ @SuppressWarnings("unchecked")
public void collect(ICompilationUnit icu) {
if (icu == null) {
@@ -701,33 +703,48 @@
if (cu.types() == null || cu.types().size() == 0 ) {
return;
}
- Object tmp = cu.types().get(0);
- if (!(tmp instanceof TypeDeclaration)) {
+ boolean hasTypeDeclaration = false;
+ Iterator it = cu.types().iterator();
+ while (it.hasNext()) {
+ Object tmp = it.next();
+ if (tmp instanceof TypeDeclaration) {
+ hasTypeDeclaration = true;
+ break;
+ }
+ }
+ if (!hasTypeDeclaration) {
// ignore EnumDeclaration & AnnotationTypeDeclaration
return;
}
- String fullyQualifiedName = null;
+ ArrayList<String> fullyQualifiedNames = new ArrayList<String>();
//TODO: should inspect all types in cu? so next method to get fullyQualifiedName:
- //((TypeDeclaration)tmp).resolveBinding().getBinaryName()
if (cu.getTypeRoot() == null || cu.getTypeRoot().findPrimaryType() == null) {
- //fullyQualifiedName = ((TypeDeclaration)tmp).resolveBinding().getBinaryName();
- return;
+ it = cu.types().iterator();
+ while (it.hasNext()) {
+ Object tmp = it.next();
+ if (tmp instanceof TypeDeclaration) {
+ fullyQualifiedNames.add(((TypeDeclaration)tmp).resolveBinding().getBinaryName());
+ }
+ }
} else {
- fullyQualifiedName = cu.getTypeRoot().findPrimaryType().getFullyQualifiedName();
+ fullyQualifiedNames.add(cu.getTypeRoot().findPrimaryType().getFullyQualifiedName());
}
- if (mapCUs_Info.containsKey(fullyQualifiedName)) {
- return;
- }
- CollectEntityInfo finder = new CollectEntityInfo();
- cu.accept(finder);
- EntityInfo result = finder.getEntityInfo();
- if (result != null) {
- result.adjustParameters();
- mapCUs_Info.put(fullyQualifiedName, result);
- Iterator<String> it = result.getDependences();
- while (it.hasNext()) {
- String fullyQualifiedNameTmp = it.next();
- collect(fullyQualifiedNameTmp);
+ Iterator<String> itFQNames = fullyQualifiedNames.iterator();
+ while (itFQNames.hasNext()) {
+ String fullyQualifiedName = itFQNames.next();
+ if (!mapCUs_Info.containsKey(fullyQualifiedName)) {
+ CollectEntityInfo finder = new CollectEntityInfo(fullyQualifiedName);
+ cu.accept(finder);
+ EntityInfo result = finder.getEntityInfo();
+ if (result != null) {
+ result.adjustParameters();
+ mapCUs_Info.put(fullyQualifiedName, result);
+ Iterator<String> itDep = result.getDependences();
+ while (itDep.hasNext()) {
+ String fullyQualifiedNameTmp = itDep.next();
+ collect(fullyQualifiedNameTmp);
+ }
+ }
}
}
}
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/collect/CollectEntityInfo.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -60,14 +60,19 @@
* storage of collected info
*/
protected EntityInfo entityInfo = new EntityInfo();
+
+ protected String fullyQualifiedName = null;
+ public CollectEntityInfo(String fullyQualifiedName) {
+ this.fullyQualifiedName = fullyQualifiedName;
+ entityInfo.setFullyQualifiedName(fullyQualifiedName);
+ }
+
public EntityInfo getEntityInfo() {
return entityInfo;
}
public boolean visit(CompilationUnit node) {
- entityInfo.setFullyQualifiedName(
- node.getTypeRoot().findPrimaryType().getFullyQualifiedName());
if (node.getProblems().length > 0) {//this includes warnings too
entityInfo.setCompilerProblemsFlag(true);
}
@@ -288,6 +293,11 @@
public boolean visit(TypeDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ String nodeName = typeBinding == null ? null : typeBinding.getBinaryName();
+ if (fullyQualifiedName == null || !fullyQualifiedName.equalsIgnoreCase(nodeName)) {
+ return false;
+ }
boolean isAbstruct = entityInfo.isAbstractFlag() ||
Modifier.isAbstract(node.getModifiers()) || node.isInterface();
entityInfo.setAbstractFlag(isAbstruct);
@@ -595,10 +605,12 @@
}
else if (type.isQualifiedType()) {
QualifiedType qt = (QualifiedType)type;
+ @SuppressWarnings("unused")
ITypeBinding tb = qt.resolveBinding();
}
else if (type.isWildcardType()) {
WildcardType wt = (WildcardType)type;
+ @SuppressWarnings("unused")
ITypeBinding tb = wt.resolveBinding();
}
return true;
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfo.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.jdt.ui.internal.jpa.common;
import java.util.Iterator;
@@ -581,6 +581,10 @@
setExistingImports.remove(existingImport);
}
+ public void collectExistingImport(Set<String> setExistingImports) {
+ setExistingImports.addAll(this.setExistingImports);
+ }
+
public void addRequiredImport(String requiredImport) {
setRequiredImports.add(requiredImport);
}
@@ -589,6 +593,10 @@
setRequiredImports.remove(requiredImport);
}
+ public void collectRequiredImport(Set<String> setRequiredImports) {
+ setRequiredImports.addAll(this.setRequiredImports);
+ }
+
public boolean needImport(String checkImport) {
return (!setExistingImports.contains(checkImport) &&
setRequiredImports.contains(checkImport));
}
@@ -600,4 +608,27 @@
public int getFromMethodCounter() {
return fromMethodCounter;
}
+
+ public String toString() {
+ return getFullyQualifiedName();
+ }
+
+ public int hashCode() {
+ return getFullyQualifiedName().hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof EntityInfo)) {
+ return false;
+ }
+ EntityInfo ei = (EntityInfo)obj;
+ if (getFullyQualifiedName().equals(ei.getFullyQualifiedName()) &&
+ getFullyQualifiedParentName().equals(ei.getFullyQualifiedParentName())) {
+ return true;
+ }
+ return false;
+ }
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfosCollection.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfosCollection.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/common/EntityInfosCollection.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.jdt.ui.internal.jpa.common;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ICompilationUnit;
+
+/**
+ * To handle EntityInfo bundle complex properties:
+ * for example several EntityInfos in one file ->
+ * so here is necessary to handle it's imports
+ *
+ * @author Vitali
+ */
+public class EntityInfosCollection {
+
+ /**
+ * path to the innermost resource enclosing these EntityInfos
+ */
+ protected IPath path;
+ /**
+ *
+ */
+ protected ICompilationUnit iCompilationUnit;
+ /**
+ *
+ */
+ protected org.eclipse.jdt.core.dom.CompilationUnit compilationUnit;
+ /**
+ * collection of EntityInfo's
+ */
+ protected HashMap<String, EntityInfo> entityInfos = new HashMap<String,
EntityInfo>();
+ /**
+ * existing imports set
+ */
+ protected Set<String> setExistingImports = new TreeSet<String>();
+ /**
+ * required imports set
+ */
+ protected Set<String> setRequiredImports = new TreeSet<String>();
+
+ public void addEntityInfo(EntityInfo ei) {
+ entityInfos.put(ei.getFullyQualifiedName(), ei);
+ }
+
+ public EntityInfo getEntityInfo(String fullyQualifiedName) {
+ return entityInfos.get(fullyQualifiedName);
+ }
+
+ public void updateExistingImportSet() {
+ setExistingImports.clear();
+ Iterator<EntityInfo> it = entityInfos.values().iterator();
+ while (it.hasNext()) {
+ it.next().collectExistingImport(setExistingImports);
+ }
+ }
+
+ public void updateRequiredImportSet() {
+ setRequiredImports.clear();
+ Iterator<EntityInfo> it = entityInfos.values().iterator();
+ while (it.hasNext()) {
+ it.next().collectRequiredImport(setRequiredImports);
+ }
+ }
+
+ public boolean needImport(String checkImport) {
+ return (!setExistingImports.contains(checkImport) &&
setRequiredImports.contains(checkImport));
+ }
+
+ public IPath getPath() {
+ return path;
+ }
+
+ public void setPath(IPath path) {
+ this.path = path;
+ }
+
+ public ICompilationUnit getICompilationUnit() {
+ return iCompilationUnit;
+ }
+
+ public void setICompilationUnit(ICompilationUnit iCompilationUnit) {
+ this.iCompilationUnit = iCompilationUnit;
+ }
+
+ public org.eclipse.jdt.core.dom.CompilationUnit getCompilationUnit() {
+ return compilationUnit;
+ }
+
+ public void setCompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit)
{
+ this.compilationUnit = compilationUnit;
+ }
+
+ public String toString() {
+ StringBuffer res = new StringBuffer();
+ Iterator<EntityInfo> it = entityInfos.values().iterator();
+ while (it.hasNext()) {
+ res.append(it.next());
+ res.append(";"); //$NON-NLS-1$
+ }
+ return res.toString();
+ }
+
+ public int hashCode() {
+ return toString().hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof EntityInfosCollection)) {
+ return false;
+ }
+ EntityInfosCollection eic = (EntityInfosCollection)obj;
+ if (toString().equals(eic.toString())) {
+ return true;
+ }
+ return false;
+ }
+}
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/AllEntitiesProcessor.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -1,36 +1,38 @@
/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.eclipse.jdt.ui.internal.jpa.process;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.text.edits.MalformedTreeException;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.jdt.ui.Activator;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfosCollection;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.Utils;
import org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard.HibernateJPAWizard;
import org.hibernate.eclipse.jdt.ui.internal.jpa.process.wizard.IHibernateJPAWizardData;
@@ -216,7 +218,7 @@
}
}
if (performChange) {
- performChange(bufferManager);
+ performCommit(entities, bufferManager);
}
performDisconnect(bufferManager);
}
@@ -233,23 +235,22 @@
changes.clear();
}
- protected void performChange(ITextFileBufferManager bufferManager) {
+ protected void performCommit(final Map<String, EntityInfo> entities,
+ ITextFileBufferManager bufferManager) {
+
+ HashSet<IPath> paths = new HashSet<IPath>();
for (int i = 0; i < changes.size(); i++) {
ChangeStructure cs = changes.get(i);
+ paths.add(cs.path);
+ }
+ Iterator<IPath> it = paths.iterator();
+ while (it.hasNext()) {
+ ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(it.next(),
LocationKind.IFILE);
try {
- if (cs.textFileBuffer != null && cs.textEdit != null &&
- ((cs.change != null && cs.change.isEnabled()) || (cs.change == null))) {
- IDocument document = cs.textFileBuffer.getDocument();
- cs.textEdit.apply(document);
- // commit changes to underlying file
- cs.textFileBuffer.commit(null, true);
- }
+ // commit changes to underlying file
+ textFileBuffer.commit(null, true);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
- } catch (MalformedTreeException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("MalformedTreeException:
", e); //$NON-NLS-1$
- } catch (BadLocationException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("BadLocationException:
", e); //$NON-NLS-1$
}
}
}
@@ -258,58 +259,73 @@
Map<String, EntityInfo> entities) {
changes.clear();
+ HashMap<IPath, EntityInfosCollection> modifications = new HashMap<IPath,
EntityInfosCollection>();
Iterator<Map.Entry<String, EntityInfo>> it =
entities.entrySet().iterator();
- try {
- while (it.hasNext()) {
- Map.Entry<String, EntityInfo> entry = it.next();
- if (entry.getValue().isInterfaceFlag()) {
- continue;
+ while (it.hasNext()) {
+ Map.Entry<String, EntityInfo> entry = it.next();
+ if (entry.getValue().isInterfaceFlag()) {
+ continue;
+ }
+ final String fullyQualifiedName = entry.getKey();
+ ICompilationUnit icu = Utils.findCompilationUnit(javaProject, fullyQualifiedName);
+ org.eclipse.jdt.core.dom.CompilationUnit cu = Utils.getCompilationUnit(icu, true);
+ final IPath path = cu.getJavaElement().getPath();
+ EntityInfosCollection eiCollection = null;
+ if (modifications.containsKey(path)) {
+ eiCollection = modifications.get(path);
+ } else {
+ eiCollection = new EntityInfosCollection();
+ eiCollection.setPath(path);
+ eiCollection.setICompilationUnit(icu);
+ eiCollection.setCompilationUnit(cu);
+ modifications.put(path, eiCollection);
+ try {
+ bufferManager.connect(path, LocationKind.IFILE, null);
+ } catch (CoreException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
}
- collectModification(bufferManager, entry.getKey(), entry.getValue(), entities);
}
- } catch (CoreException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e);
//$NON-NLS-1$
+ final EntityInfo entityInfo = entry.getValue();
+ //
+ entityInfo.updateColumnAnnotationImport(defaultStrLength != columnLength);
+ entityInfo.updateVersionImport(enableOptLock &&
entityInfo.isAddVersionFlag());
+ //
+ eiCollection.addEntityInfo(entityInfo);
}
+ Iterator<EntityInfosCollection> itEIC = modifications.values().iterator();
+ while (itEIC.hasNext()) {
+ EntityInfosCollection eic = itEIC.next();
+ eic.updateExistingImportSet();
+ eic.updateRequiredImportSet();
+ collectModification(bufferManager, eic, entities);
+ }
}
- public void collectModification(ITextFileBufferManager bufferManager, String
fullyQualifiedName,
- EntityInfo entityInfo, Map<String, EntityInfo> entities) throws CoreException {
+ public void collectModification(ITextFileBufferManager bufferManager,
+ EntityInfosCollection entityInfos, Map<String, EntityInfo> entities) {
- //
- entityInfo.updateColumnAnnotationImport(defaultStrLength != columnLength);
- entityInfo.updateVersionImport(enableOptLock &&
entityInfo.isAddVersionFlag());
- //
ChangeStructure cs = new ChangeStructure();
- cs.fullyQualifiedName = fullyQualifiedName;
- ICompilationUnit icu = Utils.findCompilationUnit(javaProject, fullyQualifiedName);
- org.eclipse.jdt.core.dom.CompilationUnit cu = Utils.getCompilationUnit(icu, false);
- cs.path = cu.getJavaElement().getPath();
- try {
- bufferManager.connect(cs.path, LocationKind.IFILE, null);
- cs.textFileBuffer = bufferManager.getTextFileBuffer(cs.path, LocationKind.IFILE);
- // retrieve the buffer
- cs.icu = icu;
- AST ast = cu.getAST();
- ASTRewrite rewriter = ASTRewrite.create(ast);
- // ... rewrite
- ProcessEntityInfo processor = new ProcessEntityInfo();
- processor.setAnnotationStyle(annotationStyle);
- processor.setDefaultStrLength(defaultStrLength);
- processor.setEnableOptLock(enableOptLock);
- processor.setEntityInfo(entityInfo);
- processor.setEntities(entities);
- processor.setASTRewrite(rewriter);
- cu.accept(processor);
- ////
- IDocument documentChange = cs.textFileBuffer.getDocument();
- cs.textEdit = rewriter.rewriteAST(documentChange, JavaCore.getOptions());
- // add change to array of changes
- changes.add(cs);
- } catch (JavaModelException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException: ",
e); //$NON-NLS-1$
- } catch (MalformedTreeException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("MalformedTreeException:
", e); //$NON-NLS-1$
- }
+ cs.icu = entityInfos.getICompilationUnit();
+ cs.path = entityInfos.getPath();
+ ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(cs.path,
LocationKind.IFILE);
+ // retrieve the buffer
+ AST ast = entityInfos.getCompilationUnit().getAST();
+ ASTRewrite rewriter = ASTRewrite.create(ast);
+ // ... rewrite
+ ProcessEntityInfo processor = new ProcessEntityInfo();
+ processor.setAnnotationStyle(annotationStyle);
+ processor.setDefaultStrLength(defaultStrLength);
+ processor.setEnableOptLock(enableOptLock);
+ processor.setEntityInfos(entityInfos);
+ processor.setEntities(entities);
+ processor.setASTRewrite(rewriter);
+ entityInfos.getCompilationUnit().accept(processor);
+ ////
+ IDocument documentChange = textFileBuffer.getDocument();
+ cs.textEdit = rewriter.rewriteAST(documentChange, JavaCore.getOptions());
+ //cs.textEdit = rewriter.rewriteAST();
+ // add change to array of changes
+ changes.add(cs);
}
public boolean showRefactoringDialog(final Map<String, EntityInfo> entities,
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java 2009-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ChangeStructure.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -1,6 +1,5 @@
package org.hibernate.eclipse.jdt.ui.internal.jpa.process;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.ltk.core.refactoring.Change;
@@ -10,10 +9,8 @@
* group all information about changes of document in one structure
*/
public class ChangeStructure {
- public String fullyQualifiedName;
public IPath path;
public ICompilationUnit icu;
public TextEdit textEdit;
- public ITextFileBuffer textFileBuffer;
public Change change;
}
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-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/ProcessEntityInfo.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -25,6 +25,7 @@
import org.eclipse.jdt.core.dom.ExpressionStatement;
import org.eclipse.jdt.core.dom.FieldAccess;
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;
@@ -47,6 +48,7 @@
import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.CollectEntityInfo;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfo;
+import org.hibernate.eclipse.jdt.ui.internal.jpa.common.EntityInfosCollection;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.JPAConst;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.OwnerType;
import org.hibernate.eclipse.jdt.ui.internal.jpa.common.RefColumnInfo;
@@ -64,6 +66,10 @@
public class ProcessEntityInfo extends ASTVisitor {
/**
+ * information about entity's annotations for whole compilation unit
+ */
+ protected EntityInfosCollection entityInfos;
+ /**
* information about entity's annotations
*/
protected EntityInfo entityInfo;
@@ -88,8 +94,8 @@
*/
protected boolean enableOptLock = false;
- public void setEntityInfo(EntityInfo entityInfo) {
- this.entityInfo = entityInfo;
+ public void setEntityInfos(EntityInfosCollection entityInfos) {
+ this.entityInfos = entityInfos;
}
public void setEntities(Map<String, EntityInfo> entities) {
@@ -101,11 +107,12 @@
}
public boolean visit(CompilationUnit node) {
+ entityInfo = null;
// TODO: sort all imports in alphabetic order
//ListRewrite lrw = rewriter.getListRewrite(node, CompilationUnit.IMPORTS_PROPERTY);
for (int i = 0; i < JPAConst.ALL_IMPORTS.size(); i++) {
String tmp = JPAConst.ALL_IMPORTS.get(i);
- if (entityInfo.needImport(tmp)) {
+ if (entityInfos.needImport(tmp)) {
addImport(node, tmp);
}
}
@@ -154,6 +161,15 @@
@SuppressWarnings("unchecked")
public boolean visit(TypeDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ String nodeName = typeBinding == null ? null : typeBinding.getBinaryName();
+ if (nodeName == null) {
+ return false;
+ }
+ entityInfo = entityInfos.getEntityInfo(nodeName);
+ if (entityInfo == null) {
+ return false;
+ }
if (entityInfo.isAddMappedSuperclassFlag()) {
MarkerAnnotation matd = rewriter.getAST().newMarkerAnnotation();
matd.setTypeName(rewriter.getAST().newSimpleName(JPAConst.ANNOTATION_MAPPEDSUPERCLASS));
@@ -299,6 +315,9 @@
@SuppressWarnings("unchecked")
public boolean visit(FieldDeclaration node) {
+ if (entityInfo == null) {
+ return false;
+ }
if (annotationStyle != AnnotStyle.FIELDS) {
return true;
}
@@ -443,6 +462,9 @@
@SuppressWarnings("unchecked")
public boolean visit(MethodDeclaration node) {
+ if (entityInfo == null) {
+ return false;
+ }
if (annotationStyle != AnnotStyle.GETTERS) {
return true;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java 2009-10-19
14:01:47 UTC (rev 18162)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/jpa/process/wizard/HibernateJPARefactoring.java 2009-10-19
15:17:05 UTC (rev 18163)
@@ -34,7 +34,7 @@
* change info storage
*/
protected ArrayList<ChangeStructure> changes;
-
+
public HibernateJPARefactoring(ArrayList<ChangeStructure> changes) {
this.changes = changes;
}
@@ -55,9 +55,9 @@
final CompositeChange cc = new CompositeChange(""); //$NON-NLS-1$
for (int i = 0; i < changes.size(); i++) {
ChangeStructure cs = changes.get(i);
- String change_name = cs.fullyQualifiedName;
+ final String change_name = cs.path.toString();
TextFileChange change = new TextFileChange(change_name, (IFile)cs.icu.getResource());
- change.setSaveMode(TextFileChange.FORCE_SAVE);
+ change.setSaveMode(TextFileChange.LEAVE_DIRTY);
change.setEdit(cs.textEdit);
cs.change = change;
cc.add(change);