Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-08-02 15:20:28 -0400
committerkmoore2010-08-02 15:20:28 -0400
commit7dd96143f6d8538781643f88dcba92a76771efe2 (patch)
treea8f5cac341d82019bbef8fe2f47d981a11af440c
parentd25ee292f06b27e8397a5b9c7ea28f96a9f5f7c5 (diff)
downloadwebtools.dali-7dd96143f6d8538781643f88dcba92a76771efe2.tar.gz
webtools.dali-7dd96143f6d8538781643f88dcba92a76771efe2.tar.xz
webtools.dali-7dd96143f6d8538781643f88dcba92a76771efe2.zip
209489 - rename package and folder refactoring participants
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/plugin.properties2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/plugin.xml20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core_refactoring.properties12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JarFile.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmAttributeMapping.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/JarFileRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java22
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java53
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java254
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java191
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java75
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java278
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlEntityMappings.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlMappingFileRef.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEmbeddableImpl.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/logging/EclipseLinkLogging.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/options/EclipseLinkOptions.java14
68 files changed, 1492 insertions, 251 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.properties b/jpa/plugins/org.eclipse.jpt.core/plugin.properties
index 976f2baaf7..3bbaef82fd 100644
--- a/jpa/plugins/org.eclipse.jpt.core/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/plugin.properties
@@ -52,5 +52,7 @@ JPA_DELETE_TYPE_PARTICIPANT_NAME=JPA Delete Type Participant
JPA_DELETE_PACKAGE_OR_FOLDER_PARTICIPANT_NAME=JPA Delete Package or Folder Participant
JPA_DELETE_MAPPING_FILE_PARTICIPANT_NAME=JPA Delete Mapping File Participant
JPA_RENAME_TYPE_PARTICIPANT_NAME=JPA Rename Type Participant
+JPA_RENAME_PACKAGE_PARTICIPANT_NAME=JPA Rename Package Participant
+JPA_RENAME_FOLDER_PARTICIPANT_NAME=JPA Rename Folder Participant
JPA_RENAME_MAPPING_FILE_PARTICIPANT_NAME=JPA Rename Mapping File Participant
\ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
index e577ba54b0..b66f3ef980 100644
--- a/jpa/plugins/org.eclipse.jpt.core/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
@@ -651,6 +651,26 @@
</enablement>
</renameParticipant>
<renameParticipant
+ class="org.eclipse.jpt.core.internal.refactoring.JpaRenamePackageParticipant"
+ id="org.eclipse.jpt.core.ltk.jpaRenamePackageParticipant"
+ name="%JPA_RENAME_PACKAGE_PARTICIPANT_NAME">
+ <enablement>
+ <with variable="element">
+ <instanceof value="org.eclipse.jdt.core.IPackageFragment"/>
+ </with>
+ </enablement>
+ </renameParticipant>
+ <renameParticipant
+ class="org.eclipse.jpt.core.internal.refactoring.JpaRenameFolderParticipant"
+ id="org.eclipse.jpt.core.ltk.jpaRenameFolderParticipant"
+ name="%JPA_RENAME_FOLDER_PARTICIPANT_NAME">
+ <enablement>
+ <with variable="element">
+ <instanceof value="org.eclipse.core.resources.IFolder"/>
+ </with>
+ </enablement>
+ </renameParticipant>
+ <renameParticipant
class="org.eclipse.jpt.core.internal.refactoring.JpaRenameMappingFileParticipant"
id="org.eclipse.jpt.core.ltk.jpaRenameMappingParticipant"
name="%JPA_RENAME_MAPPING_FILE_PARTICIPANT_NAME">
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core_refactoring.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core_refactoring.properties
index dc3879158b..d6d7b8c05d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core_refactoring.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core_refactoring.properties
@@ -23,12 +23,22 @@ JPA_DELETE_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME=Delete mapping f
JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME=loading JPA projects
JPA_RENAME_TYPE_REFACTORING_PARTICIPANT_NAME=JPA rename IType refactoring participant
-JPA_RENAME_PACKAGE_REFACTORING_PARTICIPANT_NAME=JPA rename IPackageFragment refactoring participant
JPA_RENAME_TYPE_REFACTORING_CHANGE_NAME=Rename classes referenced in JPA metadata files
JPA_RENAME_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME=Rename type references in the persistence.xml
JPA_RENAME_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME=Rename type references in the mapping file
JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME=JPA rename type references
+JPA_RENAME_PACKAGE_REFACTORING_PARTICIPANT_NAME=JPA rename IPackageFragment refactoring participant
+JPA_RENAME_PACKAGE_REFACTORING_CHANGE_NAME=Rename packages referenced in JPA metadata files
+JPA_RENAME_PACKAGE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME=Rename package references in the persistence.xml
+JPA_RENAME_PACKAGE_REFACTORING_CHANGE_MAPPING_FILE_NAME=Rename package references in the mapping file
+JPA_RENAME_PACKAGE_REFACTORING_SUB_TASK_NAME=JPA rename package references
+
+JPA_RENAME_FOLDER_REFACTORING_PARTICIPANT_NAME=JPA rename IFolder refactoring participant
+JPA_RENAME_FOLDER_REFACTORING_CHANGE_NAME=Rename folders referenced in JPA metadata files
+JPA_RENAME_FOLDER_REFACTORING_CHANGE_PERSISTENCE_XML_NAME=Rename folder references in the persistence.xml
+JPA_RENAME_FOLDER_REFACTORING_SUB_TASK_NAME=JPA rename folder references
+
JPA_RENAME_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME=JPA rename mapping file refactoring participant
JPA_RENAME_MAPPING_FILE_REFACTORING_SUB_TASK_NAME=JPA rename mapping file references
JPA_RENAME_MAPPING_FILE_REFACTORING_CHANGE_NAME=Rename mapping file references in JPA metadata files
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java
index b8c31e786d..323b381ebb 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java
@@ -9,6 +9,8 @@
******************************************************************************/
package org.eclipse.jpt.core.context;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.core.context.persistence.PersistentTypeContainer;
@@ -52,6 +54,11 @@ public interface MappingFile
*/
void update();
+ /**
+ * Return true if this mapping file exists in the given folder
+ */
+ boolean isIn(IFolder folder);
+
// **************** refactoring *********************************************
@@ -67,4 +74,10 @@ public interface MappingFile
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java
index ff159afff7..756d05b4af 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.core.context;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -168,6 +169,11 @@ public interface PersistentType
*/
boolean isFor(String typeName);
+ /**
+ * Return true if persistent type resolves to a java class in the given package fragment
+ */
+ boolean isIn(IPackageFragment packageFragment);
+
// ********** owner **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JarFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JarFile.java
index 7d6391fe6c..b917cd3dc8 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JarFile.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JarFile.java
@@ -12,6 +12,7 @@ package org.eclipse.jpt.core.context.java;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.JpaContextNode;
import org.eclipse.jpt.core.context.PersistentType;
@@ -67,4 +68,9 @@ public interface JarFile
*/
void validate(List<IMessage> messages, IReporter reporter);
+ /**
+ * Return true if this jar file exists in the given folder
+ */
+ boolean isIn(IFolder folder);
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java
index e1f17c864d..64816715e5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.AccessType;
@@ -185,4 +186,10 @@ public interface EntityMappings
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmAttributeMapping.java
index 550ee7604a..73c5bed05b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmAttributeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmAttributeMapping.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.XmlContextNode;
@@ -103,4 +104,10 @@ public interface OrmAttributeMapping
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java
index cee22a365d..bc8f6ee614 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.IdClassReference;
import org.eclipse.jpt.core.context.XmlContextNode;
@@ -39,4 +40,10 @@ public interface OrmIdClassReference
* The originalType has not yet been renamed, the newName is the new short name.
*/
Iterable<ReplaceEdit> createReplaceEdits(IType originalType, String newName);
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java
index 256a022df1..ee3d5d27dc 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.XmlContextNode;
@@ -99,6 +100,12 @@ public interface OrmPersistentAttribute
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
// ********** miscellaneous **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java
index b0a25e8c91..37a05ab102 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.context.orm;
import java.util.ListIterator;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.PersistentType;
import org.eclipse.jpt.core.context.XmlContextNode;
@@ -137,6 +138,12 @@ public interface OrmPersistentType
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
//******************* misc *******************
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java
index 882062f0aa..4aa8b1c06b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.context.orm;
import java.util.Iterator;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.TypeMapping;
import org.eclipse.jpt.core.context.XmlContextNode;
@@ -98,6 +99,12 @@ public interface OrmTypeMapping
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
// ********** covariant overrides **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java
index 31a0e0fb48..f87cf90b6c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.core.context.persistence;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.PersistentType;
@@ -118,6 +119,13 @@ public interface ClassRef
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming the class's package to the newName.
+ * The originalPackage has not yet been renamed.
+ * If this class is not a part of the original package, then return an empty Iterable.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
// *************************************************************************
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/JarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/JarFileRef.java
index 4bb8fce0b5..93648d5dd2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/JarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/JarFileRef.java
@@ -9,11 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.core.context.persistence;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.PersistentType;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JarFile;
import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Context model corresponding to the
@@ -71,8 +73,17 @@ public interface JarFileRef
* @see org.eclipse.jpt.core.JpaProject#update()
*/
void update(XmlJarFileRef xmlJarFileRef);
-
-
+
+
+ // **************** refactoring *********************************************
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalFolder to the newName.
+ * The originalFolder has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName);
+
+
// **************** queries ************************************************
/**
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java
index 8be104fb3e..465c5861e3 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java
@@ -10,6 +10,8 @@
package org.eclipse.jpt.core.context.persistence;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.MappingFile;
@@ -142,6 +144,18 @@ public interface MappingFileRef
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
/**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalFolder to the newName.
+ * The originalFolder has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName);
+
+ /**
* If this {@link MappingFileRef#isFor(IFile)} the given IFile, create a text
* ReplaceEdit for renaming the mapping file element to the new name.
* Otherwise return an EmptyIterable.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java
index 3f17be91ce..b36d0cf04e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java
@@ -12,6 +12,8 @@ package org.eclipse.jpt.core.context.persistence;
import java.util.Iterator;
import java.util.ListIterator;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.AccessType;
@@ -524,6 +526,13 @@ public interface PersistenceUnit
* If this value does not match the original type, then return an empty Iterable.
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+
+ /**
+ * Create ReplaceEdits for renaming the property value package to the newName.
+ * The originalPackage has not yet been renamed.
+ * If this value is not in the originalPackage, then return an empty Iterable.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
}
// ********** ORM persistence unit defaults **********
@@ -747,6 +756,18 @@ public interface PersistenceUnit
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
/**
+ * Create ReplaceEdits for renaming any references to the originalPackage to the newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalFolder to the newName.
+ * The originalFolder has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName);
+
+ /**
* Create ReplaceEdits for renaming any references to the originalFile to the newName.
* Return an EmptyIterable if there are not any references.
* The originalFile has not yet been renamed, the newName is the new short name.
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java
index c53c1918af..4461791cc4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.core.context.persistence;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.utility.model.Model;
@@ -65,4 +66,10 @@ public interface PersistenceUnitProperties extends Model
*/
Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+ /**
+ * Create ReplaceEdits for renaming any reference to the originalPackage newName.
+ * The originalPackage has not yet been renamed.
+ */
+ Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName);
+
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
index bc32d52603..2bc6232ad5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java
@@ -19,6 +19,7 @@ import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.JpaFile;
import org.eclipse.jpt.core.JpaStructureNode;
@@ -637,6 +638,26 @@ public abstract class AbstractJavaPersistentType
return className != null && className.equals(typeName);
}
+ public boolean isIn(IPackageFragment packageFragment) {
+ String packageName = this.getPackageName();
+ if (packageName != null && packageName.equals(packageFragment.getElementName())) {
+ return true;
+ }
+ return false;
+ }
+
+ protected String getPackageName() {
+ String className = this.getName();
+ if (className == null) {
+ return null;
+ }
+ int packageEnd = className.lastIndexOf('.');
+ if (packageEnd == -1 ) {
+ return null;
+ }
+ return className.substring(0, packageEnd);
+ }
+
public boolean isMapped() {
return this.mapping.isMapped();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java
index 95dc7f6498..8e3205fbba 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java
@@ -16,6 +16,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.JptCorePlugin;
@@ -49,8 +50,10 @@ import org.eclipse.jpt.db.Schema;
import org.eclipse.jpt.db.SchemaContainer;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
@@ -840,6 +843,32 @@ public abstract class AbstractEntityMappings
);
}
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplacePackageEdits(final IPackageFragment originalPackage, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.createPersistentTypeReplacePackageEdits(originalPackage, newName),
+ this.createReplacePackageEdit(originalPackage, newName));
+ }
+
+ public Iterable<ReplaceEdit> createPersistentTypeReplacePackageEdits(final IPackageFragment originalPackage, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<OrmPersistentType, Iterable<ReplaceEdit>>(getPersistentTypes()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(OrmPersistentType persistentType) {
+ return persistentType.createReplacePackageEdits(originalPackage, newName);
+ }
+ }
+ );
+ }
+
+ public Iterable<ReplaceEdit> createReplacePackageEdit(final IPackageFragment originalPackage, final String newName) {
+ if (this.package_ != null && originalPackage.getElementName().equals(this.package_)) {
+ return new SingleElementIterable<ReplaceEdit>(this.xmlEntityMappings.createReplacePackageEdit(newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+
// ********** dispose **********
public void dispose() {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java
index ad10143e0b..56e9aca90f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
@@ -354,6 +355,10 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping>
return EmptyIterable.instance();
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return EmptyIterable.instance();
+ }
+
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
index 725946ccda..a37c280887 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java
@@ -15,6 +15,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.JpaPlatformVariation.Supported;
@@ -1578,6 +1579,18 @@ public abstract class AbstractOrmEntity
return this.idClassReference.createReplaceEdits(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createIdClassReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createIdClassReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.idClassReference.createReplacePackageEdits(originalPackage, newName);
+ }
+
// **************** validation *********************************************
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java
index cee2d7d566..3ba219433a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.orm;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.Table;
@@ -145,6 +146,18 @@ public abstract class AbstractOrmMappedSuperclass extends AbstractOrmTypeMapping
return this.idClassReference.createReplaceEdits(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createIdClassReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createIdClassReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.idClassReference.createReplacePackageEdits(originalPackage, newName);
+ }
+
// **************** validation *********************************************
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java
index 0bcd8e0a63..30f4d59c06 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.BaseColumn;
@@ -606,6 +607,27 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends AbstractXmlM
return this.resourceAttributeMapping.createReplaceMapKeyClassEdit(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createMapKeyClassReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createMapKeyClassReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.specifiedMapKeyClass != null) {
+ if (this.resolvedMapKeyType != null && this.resolvedMapKeyType.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceMapKeyPackageEdit(newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceMapKeyPackageEdit(String newName) {
+ return this.resourceAttributeMapping.createReplaceMapKeyClassPackageEdit(newName);
+ }
+
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java
index 5a5e0a982b..dc3bc64878 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.internal.context.orm;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.MappingKeys;
@@ -238,6 +239,10 @@ public abstract class AbstractOrmPersistentAttribute
return this.attributeMapping.createReplaceTypeEdits(originalType, newName);
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.attributeMapping.createReplacePackageEdits(originalPackage, newName);
+ }
+
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java
index 7405344df8..8cccc841ae 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.orm;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Entity;
@@ -305,6 +306,27 @@ public abstract class AbstractOrmRelationshipMapping<T extends AbstractXmlRelati
return this.resourceAttributeMapping.createReplaceTargetEntityEdit(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createTargetEntityReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createTargetEntityReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.specifiedTargetEntity != null) {
+ if (this.resolvedTargetType != null && this.resolvedTargetType.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceTargetEntityPackageEdit(newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceTargetEntityPackageEdit(String newName) {
+ return this.resourceAttributeMapping.createReplaceTargetEntityPackageEdit(newName);
+ }
+
//*********** validation ***********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java
index 9583beda58..2cb971259b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.orm;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.AttributeMapping;
@@ -379,6 +380,17 @@ public abstract class AbstractOrmTypeMapping<T extends XmlTypeMapping>
return this.resourceTypeMapping.createReplaceTypeEdit(originalType, newName);
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (getPersistentType().isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplacePackageEdit(newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplacePackageEdit(String newName) {
+ return this.resourceTypeMapping.createReplacePackageEdit(newName);
+ }
+
// ********** misc **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java
index a963f4c851..eeb788518e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java
@@ -11,6 +11,7 @@
package org.eclipse.jpt.core.internal.context.orm;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AccessType;
import org.eclipse.jpt.core.context.java.JavaIdClassReference;
@@ -233,6 +234,24 @@ public class GenericOrmIdClassReference
return false;
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplacePackageEdit(newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplacePackageEdit(String newName) {
+ return getIdXmlClassRef().createReplacePackageEdit(newName);
+ }
+
+ protected boolean isIn(IPackageFragment originalPackage) {
+ if (this.idClass != null && this.idClass.isIn(originalPackage)) {
+ return true;
+ }
+ return false;
+ }
+
// **************** validation ********************************************
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java
index cb74ccdf4b..c490df634b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.persistence;
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
@@ -31,6 +32,8 @@ import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -253,8 +256,29 @@ public abstract class AbstractJarFileRef
protected IProject getProject() {
return this.getJpaProject().getProject();
}
-
-
+
+
+ // ********** refactoring **********
+
+ public Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName) {
+ if (this.isIn(originalFolder)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceFolderEdit(originalFolder, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceFolderEdit(IFolder originalFolder, String newName) {
+ return this.xmlJarFileRef.createReplaceFolderEdit(originalFolder, newName);
+ }
+
+ protected boolean isIn(IFolder folder) {
+ if (this.jarFile == null) {
+ return false;
+ }
+ return this.jarFile.isIn(folder);
+ }
+
+
// **************** validation *********************************************
@Override
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
index 220d06c401..7f5d1a16d2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -11,7 +11,9 @@ package org.eclipse.jpt.core.internal.context.persistence;
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaResourceType;
import org.eclipse.jpt.core.JpaStructureNode;
@@ -131,6 +133,13 @@ public abstract class AbstractMappingFileRef
return this.mappingFile != null && file.equals(this.mappingFile.getXmlResource().getFile());
}
+ protected boolean isIn(IFolder folder) {
+ if (this.mappingFile == null) {
+ return false;
+ }
+ return this.mappingFile.isIn(folder);
+ }
+
// ********** mapping file **********
@@ -301,6 +310,13 @@ public abstract class AbstractMappingFileRef
return EmptyIterable.instance();
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.mappingFile != null) {
+ return this.mappingFile.createReplacePackageEdits(originalPackage, newName);
+ }
+ return EmptyIterable.instance();
+ }
+
public Iterable<ReplaceEdit> createReplaceMappingFileEdits(IFile originalFile, String newName) {
if (this.isFor(originalFile)) {
return new SingleElementIterable<ReplaceEdit>(this.createReplaceEdit(originalFile, newName));
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
index 60549c85ce..4cbe0829e4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java
@@ -21,7 +21,9 @@ import java.util.Map;
import java.util.Set;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.core.JpaProject;
@@ -1664,6 +1666,57 @@ public abstract class AbstractPersistenceUnit
return this.options.createReplaceTypeEdits(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ createSpecifiedClassRefReplacePackageEdits(originalPackage, newName),
+ createPersistenceUnitPropertiesReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createSpecifiedClassRefReplacePackageEdits(final IPackageFragment originalPackage, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<ClassRef, Iterable<ReplaceEdit>>(getSpecifiedClassRefs()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(ClassRef classRef) {
+ return classRef.createReplacePackageEdits(originalPackage, newName);
+ }
+ }
+ );
+ }
+
+ protected Iterable<ReplaceEdit> createPersistenceUnitPropertiesReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.options.createReplacePackageEdits(originalPackage, newName);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplaceFolderEdits(final IFolder originalFolder, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.createMappingFileRefReplaceFolderEdits(originalFolder, newName),
+ this.createJarFileRefReplaceFolderEdits(originalFolder, newName));
+ }
+
+ public Iterable<ReplaceEdit> createMappingFileRefReplaceFolderEdits(final IFolder originalFolder, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<MappingFileRef, Iterable<ReplaceEdit>>(getSpecifiedMappingFileRefs()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(MappingFileRef mappingFileRef) {
+ return mappingFileRef.createReplaceFolderEdits(originalFolder, newName);
+ }
+ }
+ );
+ }
+
+ public Iterable<ReplaceEdit> createJarFileRefReplaceFolderEdits(final IFolder originalFolder, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<JarFileRef, Iterable<ReplaceEdit>>(getJarFileRefs()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(JarFileRef jarFileRef) {
+ return jarFileRef.createReplaceFolderEdits(originalFolder, newName);
+ }
+ }
+ );
+ }
+
public Iterable<ReplaceEdit> createReplaceMappingFileEdits(final IFile originalFile, final String newName) {
return new CompositeIterable<ReplaceEdit>(
new TransformationIterable<MappingFileRef, Iterable<ReplaceEdit>>(getMappingFileRefs()) {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
index 55b72fc134..52b608e26d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java
@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
@@ -517,4 +518,8 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel
public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
return EmptyIterable.instance();
}
+
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return EmptyIterable.instance();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java
index f25606219d..1ed06bfd99 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJarFile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Vector;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jpt.core.JpaResourceType;
import org.eclipse.jpt.core.JpaStructureNode;
@@ -207,5 +208,11 @@ public class GenericJarFile
}
// TODO validate 'javaPersistentTypes'
}
+
+ public boolean isIn(org.eclipse.core.resources.IFolder folder) {
+ IResource member = folder.findMember(this.jarResourcePackageFragmentRoot.getFile().getName());
+ IFile file = this.jarResourcePackageFragmentRoot.getFile();
+ return member != null && file != null && member.equals(file);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
index 3b031288b6..0c2d0dd807 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java
@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.JptCorePlugin;
@@ -966,6 +967,24 @@ public class GenericOrmPersistentType
);
}
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.mapping.createReplacePackageEdits(originalPackage, newName),
+ this.createSpecifiedAttributesReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createSpecifiedAttributesReplacePackageEdits(final IPackageFragment originalPackage, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<OrmPersistentAttribute, Iterable<ReplaceEdit>>(getSpecifiedAttributes()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(OrmPersistentAttribute persistentAttribute) {
+ return persistentAttribute.createReplacePackageEdits(originalPackage, newName);
+ }
+ }
+ );
+ }
+
// ********** misc **********
@@ -997,6 +1016,36 @@ public class GenericOrmPersistentType
return (defaultPackage + '.' + className).equals(typeName);
}
+ public boolean isIn(IPackageFragment packageFragment) {
+ String packageName = this.getPackageName();
+ if (packageName != null && packageName.equals(packageFragment.getElementName())) {
+ return true;
+ }
+ String defaultPackage = this.getDefaultPackage();
+ if (defaultPackage == null) {
+ return false;
+ }
+ if (packageName != null) {
+ packageName = defaultPackage + '.' + packageName;
+ }
+ else {
+ packageName = defaultPackage;
+ }
+ return packageName.equals(packageFragment.getElementName());
+ }
+
+ protected String getPackageName() {
+ String className = this.getName();
+ if (className == null) {
+ return null;
+ }
+ int packageEnd = className.lastIndexOf('.');
+ if (packageEnd == -1 ) {
+ return null;
+ }
+ return className.substring(0, packageEnd);
+ }
+
public boolean contains(int textOffset) {
return this.mapping.containsOffset(textOffset);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java
index e498c9a100..e57d75957c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java
@@ -10,7 +10,10 @@
package org.eclipse.jpt.core.internal.jpa1.context.orm;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaFile;
import org.eclipse.jpt.core.JpaResourceType;
@@ -209,6 +212,16 @@ public class GenericOrmXml
}
}
+
+ // ********** misc **********
+
+ public boolean isIn(IFolder folder) {
+ IResource member = folder.findMember(this.getXmlResource().getFile().getName());
+ IFile file = this.getXmlResource().getFile();
+ return member != null && file != null && member.equals(file);
+ }
+
+
// ********** validation **********
public TextRange getValidationTextRange() {
@@ -239,4 +252,11 @@ public class GenericOrmXml
}
return EmptyIterable.instance();
}
+
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.entityMappings != null) {
+ return this.entityMappings.createReplacePackageEdits(originalPackage, newName);
+ }
+ return EmptyIterable.instance();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java
index 320c37be47..d769ea8bd5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.jpa1.context.persistence;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.JptCorePlugin;
@@ -132,6 +133,19 @@ public class GenericClassRef
return this.isFor(type.getFullyQualifiedName('.'));
}
+ protected boolean isInPackage(IPackageFragment packageFragment) {
+ String packageName = this.getPackageName();
+ return packageName == null ? false : packageName.equals(packageFragment.getElementName());
+ }
+
+ protected String getPackageName() {
+ int packageEnd = this.className.lastIndexOf('.');
+ if (packageEnd == -1 ) {
+ return null;
+ }
+ return this.className.substring(0, packageEnd);
+ }
+
public boolean isVirtual() {
return this.xmlJavaClassRef == null;
}
@@ -335,6 +349,20 @@ public class GenericClassRef
return this.xmlJavaClassRef.createReplaceEdit(originalType, newName);
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (isVirtual()) {
+ throw new IllegalStateException();
+ }
+ if (this.isInPackage(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplacePackageEdit(newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplacePackageEdit(String newName) {
+ return this.xmlJavaClassRef.createReplacePackageEdit(newName);
+ }
+
// ********** misc **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
index 0400d8e9af..0550379f9d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericMappingFileRef.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.internal.jpa1.context.persistence;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.persistence.AbstractMappingFileRef;
import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
@@ -103,4 +104,15 @@ public class GenericMappingFileRef
return this.xmlMappingFileRef.createReplaceEdit(originalFile, newName);
}
+ public Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName) {
+ if (this.isIn(originalFolder)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceFolderEdit(originalFolder, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceFolderEdit(IFolder originalFolder, String newName) {
+ return this.xmlMappingFileRef.createReplaceFolderEdit(originalFolder, newName);
+ }
+
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java
index 2c99c33281..2b7ba7c2ab 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.jpt.core.internal.jpa1.context.persistence;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceXmlContextNode;
@@ -80,6 +81,14 @@ public class GenericPersistenceUnitProperty
}
}
+ protected String getValuePackageName() {
+ int packageEnd = this.value == null ? -1 : this.value.lastIndexOf('.');
+ if (packageEnd == -1 ) {
+ return null;
+ }
+ return this.value.substring(0, packageEnd);
+ }
+
// ********** updating **********
@@ -109,6 +118,18 @@ public class GenericPersistenceUnitProperty
return this.xmlProperty.createReplaceTypeEdit(originalType, newName);
}
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ String packageName = getValuePackageName();
+ if (packageName != null && packageName.equals(originalPackage.getElementName())) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplacePackageEdit(newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplacePackageEdit(String newName) {
+ return this.xmlProperty.createReplacePackageEdit(newName);
+ }
+
// ********** misc **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java
index e5790189a8..2ee3097f95 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/ImpliedMappingFileRef.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.internal.jpa1.context.persistence;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.persistence.AbstractMappingFileRef;
import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
@@ -75,6 +76,10 @@ public class ImpliedMappingFileRef
throw new IllegalStateException("Cannot delete this reference since it is implied"); //$NON-NLS-1$
}
+ public Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName) {
+ throw new IllegalStateException("Cannot replace this reference since it is implied"); //$NON-NLS-1$
+ }
+
@Override
protected ReplaceEdit createReplaceEdit(IFile originalFile, String newName) {
StringBuffer buffer = new StringBuffer();
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
index 5de731c1a7..0f97bc33a7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AssociationOverride;
@@ -1069,6 +1070,36 @@ public abstract class AbstractOrmElementCollectionMapping2_0<T extends XmlElemen
return EmptyIterable.instance();
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createMapKeyClassReplacePackageEdits(originalPackage, newName),
+ this.createTargetClassReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createMapKeyClassReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.specifiedMapKeyClass != null) {
+ if (this.resolvedMapKeyType != null && this.resolvedMapKeyType.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceMapKeyPackageEdit(newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceMapKeyPackageEdit(String newName) {
+ return this.resourceAttributeMapping.createReplaceMapKeyClassPackageEdit(newName);
+ }
+
+ protected Iterable<ReplaceEdit> createTargetClassReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.specifiedTargetClass != null) {
+ if (this.resolvedTargetType != null && this.resolvedTargetType.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.resourceAttributeMapping.createReplaceTargetClassPackageEdit(newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java
new file mode 100644
index 0000000000..b21ef88d77
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java
@@ -0,0 +1,254 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.refactoring;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JpaProjectManager;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+
+public abstract class AbstractJpaRenameJavaElementParticipant
+ extends RenameParticipant {
+
+ protected IJavaElement originalJavaElement;
+
+ /**
+ * Store the persistence.xml ReplaceEdits in the checkConditions() call
+ * to avoid duplicated effort in createChange().
+ */
+ protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlReplaceEdits;
+
+ /**
+ * Store the mapping file ReplaceEdits in the checkConditions() call
+ * to avoid duplicated effort in createChange().
+ */
+ protected final Map<IFile, Iterable<ReplaceEdit>> mappingFileReplaceEdits;
+
+ protected AbstractJpaRenameJavaElementParticipant() {
+ super();
+ this.persistenceXmlReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>();
+ this.mappingFileReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>();
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if (!getArguments().getUpdateReferences()) {
+ //we do not want to do any refactoring if the user chooses not to update references
+ return false;
+ }
+ this.originalJavaElement = (IJavaElement) element;
+ return true;
+ }
+
+ protected IJavaElement getOriginalJavaElement() {
+ return this.originalJavaElement;
+ }
+
+
+ //**************** RefactoringParticipant implementation *****************
+
+ /**
+ * Inform the refactoring processor of any files that are going to change. In the process of determining
+ * this go ahead and build up the appropriate ReplaceEdits to be used in the createChange()
+ */
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditionsContext context) throws OperationCanceledException {
+ monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
+ JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager();
+ if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ return null;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 2);
+ sm.subTask(this.getCheckConditionsSubTaskName());
+ ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
+ IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
+
+ for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) {
+ this.createReplaceEdits(sm.newChild(10), jpaProject);
+ }
+ if (sm.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ for (IFile file : this.persistenceXmlReplaceEdits.keySet()) {
+ deltaFactory.change(file);
+ }
+ sm.worked(1);
+ for (IFile file : this.mappingFileReplaceEdits.keySet()) {
+ deltaFactory.change(file);
+ }
+ sm.worked(1);
+
+ return null;
+ }
+
+ protected abstract String getCompositeChangeName();
+
+ /**
+ * This will be appended to the main refactoring task named : 'Checking preconditions...'
+ */
+ protected abstract String getCheckConditionsSubTaskName();
+
+ @Override
+ public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
+ if (this.persistenceXmlReplaceEdits.isEmpty() && this.mappingFileReplaceEdits.isEmpty()) {
+ return null;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlReplaceEdits.size() + this.mappingFileReplaceEdits.size());
+ sm.subTask(this.getCreateChangeSubTaskName());
+ CompositeChange compositeChange = new CompositeChange(this.getCompositeChangeName());
+ for (IFile persistenceXmlFile : this.persistenceXmlReplaceEdits.keySet()) {
+ this.addPersistenceXmlRenameEdits(persistenceXmlFile, compositeChange);
+ sm.worked(1);
+ }
+ for (IFile mappingFile : this.mappingFileReplaceEdits.keySet()) {
+ if (sm.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ this.addMappingFileRenameEdits(mappingFile, compositeChange);
+ sm.worked(1);
+ }
+ //must check for children in case all changes were made in other participant's TextChanges,
+ //want to return null so our node does not appear in the preview tree
+ return compositeChange.getChildren().length == 0 ? null : compositeChange;
+ }
+
+ /**
+ * This will be appended to the main refactoring task named : 'Creating workspace modifications...'
+ */
+ protected abstract String getCreateChangeSubTaskName();
+
+ protected void createReplaceEdits(IProgressMonitor monitor, JpaProject jpaProject) throws OperationCanceledException {
+ PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
+ if (persistenceUnit == null) {
+ return;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, 1 + persistenceUnit.mappingFileRefsSize());
+ Iterable<ReplaceEdit> classRefDeleteEdits = this.createPersistenceXmlReplaceEditsCheckClasspath(persistenceUnit);
+ sm.worked(1);
+ if (!CollectionTools.isEmpty(classRefDeleteEdits)) {
+ this.persistenceXmlReplaceEdits.put(jpaProject.getPersistenceXmlResource().getFile(), classRefDeleteEdits);
+ }
+ for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) {
+ if (sm.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ Iterable<ReplaceEdit> mappingFileReplaceEdits = this.createMappingFileReplaceEditsCheckClasspath(mappingFileRef);
+ if (!CollectionTools.isEmpty(mappingFileReplaceEdits)) {
+ IFile file = (IFile) mappingFileRef.getMappingFile().getResource();
+ this.mappingFileReplaceEdits.put(file, mappingFileReplaceEdits);
+ }
+ sm.worked(1);
+ }
+ }
+
+ protected Iterable<ReplaceEdit> createPersistenceXmlReplaceEditsCheckClasspath(PersistenceUnit persistenceUnit) {
+ //check isOnClassPath since there could be types with the same name in different projects
+ if (persistenceUnit.getJpaProject().getJavaProject().isOnClasspath(this.originalJavaElement)) {
+ return createPersistenceXmlReplaceEdits(persistenceUnit);
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected abstract Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit);
+
+ protected void addPersistenceXmlRenameEdits(IFile persistenceXmlFile, CompositeChange compositeChange) {
+ Iterable<ReplaceEdit> replacePackageEdits = this.persistenceXmlReplaceEdits.get(persistenceXmlFile);
+
+ TextChange textChange = getTextChange(persistenceXmlFile);
+ if (textChange == null) {
+ textChange = new TextFileChange(this.getPersistenceXmlChangeName(), persistenceXmlFile);
+ //TODO probably need to figure out TextEditGroups since these can be used to show check boxes under the file in the preview dialog
+ //also used to add edits to existing changes??
+ MultiTextEdit multiTextEdit = new MultiTextEdit();
+ textChange.setEdit(multiTextEdit);
+// textChange.addTextEditGroup(new TextEditGroup("edit persistence unit", multiTextEdit));???
+ compositeChange.add(textChange);
+ }
+ this.addEdits(textChange, replacePackageEdits);
+ }
+
+ protected abstract String getPersistenceXmlChangeName();
+
+ protected Iterable<ReplaceEdit> createMappingFileReplaceEditsCheckClasspath(MappingFileRef mappingFileRef) {
+ //check isOnClassPath since there could be types with the same name in different projects
+ if (mappingFileRef.getJpaProject().getJavaProject().isOnClasspath(this.originalJavaElement)) {
+ return this.createMappingFileReplaceEdits(mappingFileRef);
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected abstract Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef);
+
+
+ protected void addMappingFileRenameEdits(IFile mappingFile, CompositeChange compositeChange) {
+ Iterable<ReplaceEdit> replacedTypeEdits = this.mappingFileReplaceEdits.get(mappingFile);
+
+ TextChange textChange = getTextChange(mappingFile);
+ if (textChange == null) {
+ textChange = new TextFileChange(this.getMappingFileChangeName(), mappingFile);
+ MultiTextEdit multiTextEdit = new MultiTextEdit();
+ textChange.setEdit(multiTextEdit);
+ compositeChange.add(textChange);
+ }
+ this.addEdits(textChange, replacedTypeEdits);
+ }
+
+ protected abstract String getMappingFileChangeName();
+
+ private PersistenceUnit getPersistenceUnit(JpaProject jpaProject) {
+ PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
+ Persistence persistence = persistenceXml.getPersistence();
+ if (persistence == null) {
+ return null;
+ }
+ if (persistence.persistenceUnitsSize() != 1) {
+ return null; // the context model currently only supports 1 persistence unit
+ }
+ return persistence.persistenceUnits().next();
+ }
+
+ private void addEdits(TextChange textChange, Iterable<? extends TextEdit> textEdits) {
+ for (TextEdit textEdit : textEdits) {
+ try {
+ textChange.addEdit(textEdit);
+ }
+ catch (MalformedTreeException ex) {
+ //log exception and don't add this persistence.xml type deletion to the conflicting change object
+ JptCorePlugin.log(ex);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java
index 409b259542..d975d7a8d6 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java
@@ -31,12 +31,22 @@ public class JpaCoreRefactoringMessages {
public static String JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME;
public static String JPA_RENAME_TYPE_REFACTORING_PARTICIPANT_NAME;
- public static String JPA_RENAME_PACKAGE_REFACTORING_PARTICIPANT_NAME;
public static String JPA_RENAME_TYPE_REFACTORING_CHANGE_NAME;
public static String JPA_RENAME_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME;
public static String JPA_RENAME_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME;
public static String JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME;
+ public static String JPA_RENAME_PACKAGE_REFACTORING_PARTICIPANT_NAME;
+ public static String JPA_RENAME_PACKAGE_REFACTORING_CHANGE_NAME;
+ public static String JPA_RENAME_PACKAGE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME;
+ public static String JPA_RENAME_PACKAGE_REFACTORING_CHANGE_MAPPING_FILE_NAME;
+ public static String JPA_RENAME_PACKAGE_REFACTORING_SUB_TASK_NAME;
+
+ public static String JPA_RENAME_FOLDER_REFACTORING_PARTICIPANT_NAME;
+ public static String JPA_RENAME_FOLDER_REFACTORING_CHANGE_NAME;
+ public static String JPA_RENAME_FOLDER_REFACTORING_CHANGE_PERSISTENCE_XML_NAME;
+ public static String JPA_RENAME_FOLDER_REFACTORING_SUB_TASK_NAME;
+
public static String JPA_RENAME_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME;
public static String JPA_RENAME_MAPPING_FILE_REFACTORING_SUB_TASK_NAME;
public static String JPA_RENAME_MAPPING_FILE_REFACTORING_CHANGE_NAME;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java
index d225fccb6d..b1703b485e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java
@@ -36,6 +36,7 @@ import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant;
import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments;
+import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.text.edits.DeleteEdit;
public class JpaDeletePackageOrFolderParticipant
@@ -69,6 +70,12 @@ public class JpaDeletePackageOrFolderParticipant
@Override
protected boolean initialize(Object element) {
+ if (getProcessor() instanceof RenameProcessor) {
+ //Renaming a package that then ends up with no subpackages or types will call the delete folder participant.
+ //We do not want to delete references in the persistence.xml and mapping files in this case, will be handled
+ //with the rename participant
+ return false;
+ }
this.addElement(element, getArguments());
return true;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java
new file mode 100644
index 0000000000..dfd399dff1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.refactoring;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JpaProjectManager;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * Participant in the rename refactoring of {@link IFolders}s.
+ * If the renamed mapping file is listed in a persistence.xml file of any JpaProject
+ * then a Change object is created that will rename that reference from the file.
+ * If the renamed mapping file is an implied mapping file, then an actual reference to the mapping file will be specified.
+ */
+public class JpaRenameFolderParticipant
+ extends RenameParticipant
+{
+
+ /**
+ * Store the {@link IFolder}s to be renamed
+ */
+
+ protected IFolder originalFolder;
+
+ /**
+ * Store the persistence.xml ReplaceEdit in the checkConditions() call
+ * to avoid duplicated effort in createChange().
+ */
+ protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlReplaceEdits;
+
+ public JpaRenameFolderParticipant() {
+ super();
+ this.persistenceXmlReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>();
+ }
+
+ @Override
+ public String getName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_PARTICIPANT_NAME;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if (!getArguments().getUpdateReferences()) {
+ return false;
+ }
+ this.originalFolder = (IFolder) element;
+ return true;
+ }
+
+
+ //**************** RefactoringParticipant implementation *****************
+
+ /**
+ * Inform the refactoring processor of any files that are going to change. In the process of determining
+ * this go ahead and build up the appropriate ReplaceEdits to be used in the createChange()
+ */
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditionsContext context) throws OperationCanceledException {
+ //since the progress bar will hang if a large JPA project is being loaded,
+ //we can at least set the subtask and report no progress. Only happens first time getJpaProjectManager() is called.
+ monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
+ JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager();
+ if (jpaProjectManager.getJpaProjectsSize() == 0) {
+ return null;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 1);
+ sm.subTask(JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_SUB_TASK_NAME);
+ ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
+ IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
+
+ for (JpaProject jpaProject : JptCorePlugin.getJpaProjectManager().getJpaProjects()) {
+ this.createReplaceEdits(jpaProject);
+ sm.worked(10);
+ }
+ if (sm.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ for (IFile persistenceXmlFile : this.persistenceXmlReplaceEdits.keySet()) {
+ deltaFactory.change(persistenceXmlFile);
+ }
+ sm.worked(1);
+
+ return null;
+ }
+
+ protected void createReplaceEdits(JpaProject jpaProject) throws OperationCanceledException {
+ PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
+ if (persistenceUnit == null) {
+ return;
+ }
+ Iterable<ReplaceEdit> replaceEdits = this.createPersistenceUnitReplaceEdits(persistenceUnit);
+ if (!CollectionTools.isEmpty(replaceEdits)) {
+ this.persistenceXmlReplaceEdits.put(jpaProject.getPersistenceXmlResource().getFile(), replaceEdits);
+ }
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
+ if (this.persistenceXmlReplaceEdits.isEmpty()) {
+ return null;
+ }
+ SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlReplaceEdits.size());
+ sm.subTask(JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_SUB_TASK_NAME);
+ CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_CHANGE_NAME);
+ for (IFile persistenceXmlFile : this.persistenceXmlReplaceEdits.keySet()) {
+ if (sm.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ this.addPersistenceXmlRenameChange(persistenceXmlFile, compositeChange);
+ }
+ //must check for children in case all changes were made in other participants TextChanges,
+ //want to return null so our node does not appear in the preview tree
+ return compositeChange.getChildren().length == 0 ? null : compositeChange;
+ }
+
+ private Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(final PersistenceUnit persistenceUnit) {
+ if (persistenceUnit.getJpaProject().getJavaProject().isOnClasspath(this.originalFolder) || persistenceUnit.getJpaProject().getProject() == this.originalFolder.getProject()) {
+ return persistenceUnit.createReplaceFolderEdits(this.originalFolder, getArguments().getNewName());
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected void addPersistenceXmlRenameChange(IFile persistenceXmlFile, CompositeChange compositeChange) {
+ TextChange textChange = getTextChange(persistenceXmlFile);
+ if (textChange == null) {
+ textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_RENAME_FOLDER_REFACTORING_CHANGE_PERSISTENCE_XML_NAME, persistenceXmlFile);
+ MultiTextEdit multiTextEdit = new MultiTextEdit();
+ textChange.setEdit(multiTextEdit);
+ compositeChange.add(textChange);
+ }
+ Iterable<ReplaceEdit> mappingFileReplaceEdits = this.persistenceXmlReplaceEdits.get(persistenceXmlFile);
+ this.addEdits(textChange, mappingFileReplaceEdits);
+ }
+
+ private PersistenceUnit getPersistenceUnit(JpaProject jpaProject) {
+ PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
+ Persistence persistence = persistenceXml.getPersistence();
+ if (persistence == null) {
+ return null;
+ }
+ if (persistence.persistenceUnitsSize() != 1) {
+ return null; // the context model currently only supports 1 persistence unit
+ }
+ return persistence.persistenceUnits().next();
+ }
+
+ private void addEdits(TextChange textChange, Iterable<? extends TextEdit> textEdits) {
+ for (TextEdit textEdit : textEdits) {
+ try {
+ textChange.addEdit(textEdit);
+ }
+ catch (MalformedTreeException e) {
+ //log exception and don't add this persistence.xml type deletion to the conflicting change object
+ JptCorePlugin.log(e);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java
index 49e760bbfe..f7ad77594a 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java
@@ -54,7 +54,7 @@ public class JpaRenameMappingFileParticipant
protected IFile originalMappingFile;
/**
- * Store the persistence.xml DeleteEdits in the checkConditions() call
+ * Store the persistence.xml ReplaceEdit in the checkConditions() call
* to avoid duplicated effort in createChange().
*/
protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlMappingFileReplaceEdits;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java
new file mode 100644
index 0000000000..941fa4e478
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.refactoring;
+
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jpt.core.context.persistence.MappingFileRef;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.text.edits.ReplaceEdit;
+
+public class JpaRenamePackageParticipant
+ extends AbstractJpaRenameJavaElementParticipant {
+
+
+ public JpaRenamePackageParticipant() {
+ super();
+ }
+
+ @Override
+ public String getName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_PARTICIPANT_NAME;
+ }
+
+ protected IPackageFragment getOriginalPackage() {
+ return (IPackageFragment) super.getOriginalJavaElement();
+ }
+
+
+ //**************** AbstractJpaRenameJavaElementParticipant implementation *****************
+
+ @Override
+ protected Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit) {
+ return persistenceUnit.createReplacePackageEdits(this.getOriginalPackage(), this.getNewName());
+ }
+
+ @Override
+ protected Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef) {
+ return mappingFileRef.createReplacePackageEdits(this.getOriginalPackage(), this.getNewName());
+ }
+
+ protected String getNewName() {
+ return getArguments().getNewName();
+ }
+
+ @Override
+ protected String getCheckConditionsSubTaskName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_SUB_TASK_NAME;
+ }
+
+ @Override
+ protected String getCreateChangeSubTaskName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_SUB_TASK_NAME;
+ }
+
+ @Override
+ protected String getCompositeChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_CHANGE_NAME;
+ }
+
+ @Override
+ protected String getPersistenceXmlChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME;
+ }
+
+ @Override
+ protected String getMappingFileChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_PACKAGE_REFACTORING_CHANGE_MAPPING_FILE_NAME;
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java
index fd70cc5ee6..6333401fca 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java
@@ -11,65 +11,24 @@ package org.eclipse.jpt.core.internal.refactoring;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.core.JpaProject;
-import org.eclipse.jpt.core.JpaProjectManager;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.context.persistence.MappingFileRef;
-import org.eclipse.jpt.core.context.persistence.Persistence;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
-import org.eclipse.jpt.core.context.persistence.PersistenceXml;
-import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
-import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.CompositeChange;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.TextChange;
-import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
-import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
-import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.text.edits.TextEdit;
//TODO RenameTypeArguments.updateSimilarDeclarations() - http://www.eclipse.org/jdt/ui/r3_2/RenameType.html
public class JpaRenameTypeParticipant
- extends RenameParticipant {
+ extends AbstractJpaRenameJavaElementParticipant {
- protected IType originalType;
-
protected final Collection<IType> nestedTypes;
- /**
- * Store the persistence.xml ReplaceEdits in the checkConditions() call
- * to avoid duplicated effort in createChange().
- */
- protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlClassRefReplaceEdits;
-
- /**
- * Store the mapping file ReplaceEdits in the checkConditions() call
- * to avoid duplicated effort in createChange().
- */
- protected final Map<IFile, Iterable<ReplaceEdit>> mappingFilePersistentTypeReplaceEdits;
-
public JpaRenameTypeParticipant() {
super();
this.nestedTypes = new ArrayList<IType>();
- this.persistenceXmlClassRefReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>();
- this.mappingFilePersistentTypeReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>();
}
@Override
@@ -77,15 +36,18 @@ public class JpaRenameTypeParticipant
return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_PARTICIPANT_NAME;
}
+ protected IType getOriginalType() {
+ return (IType) super.getOriginalJavaElement();
+ }
+
@Override
protected boolean initialize(Object element) {
- if (!getArguments().getUpdateReferences()) {
- //we do not want to do any refactoring if the user chooses not to update references
- return false;
+ boolean initialize = super.initialize(element);
+ if (initialize) {
+ this.addNestedTypes(this.getOriginalType());
+ return true;
}
- this.originalType = (IType) element;
- this.addNestedTypes(this.originalType);
- return true;
+ return false;
}
protected void addNestedType(IType renamedType) {
@@ -109,126 +71,51 @@ public class JpaRenameTypeParticipant
}
- //**************** RefactoringParticipant implementation *****************
-
- /**
- * Inform the refactoring processor of any files that are going to change. In the process of determining
- * this go ahead and build up the appropriate ReplaceEdits to be used in the createChange()
- */
- @Override
- public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditionsContext context) throws OperationCanceledException {
- monitor.subTask(JpaCoreRefactoringMessages.JPA_REFACORING_PARTICIPANT_LOADING_JPA_PROJECTS_SUB_TASK_NAME);
- JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager();
- if (jpaProjectManager.getJpaProjectsSize() == 0) {
- return null;
- }
- SubMonitor sm = SubMonitor.convert(monitor, jpaProjectManager.getJpaProjectsSize()*10 + 2);
- sm.subTask(this.getCheckConditionsSubTaskName());
- ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
- IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
-
- for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) {
- this.createReplaceEdits(sm.newChild(10), jpaProject);
- }
- if (sm.isCanceled()) {
- throw new OperationCanceledException();
- }
- for (IFile file : this.persistenceXmlClassRefReplaceEdits.keySet()) {
- deltaFactory.change(file);
- }
- sm.worked(1);
- for (IFile file : this.mappingFilePersistentTypeReplaceEdits.keySet()) {
- deltaFactory.change(file);
- }
- sm.worked(1);
-
- return null;
- }
-
- /**
- * This will be appended to the main refactoring task named : 'Checking preconditions...'
- */
- protected String getCheckConditionsSubTaskName() {
- return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME;
- }
-
+ //**************** AbstractJpaRenameJavaElementParticipant implementation *****************
+
+ @SuppressWarnings("unchecked")
@Override
- public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
- if (this.persistenceXmlClassRefReplaceEdits.isEmpty() && this.mappingFilePersistentTypeReplaceEdits.isEmpty()) {
- return null;
- }
- SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlClassRefReplaceEdits.size() + this.mappingFilePersistentTypeReplaceEdits.size());
- sm.subTask(this.getCreateChangeSubTaskName());
- CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_NAME);
- for (IFile persistenceXmlFile : this.persistenceXmlClassRefReplaceEdits.keySet()) {
- this.addPersistenceXmlRenameTypeChange(persistenceXmlFile, compositeChange);
- sm.worked(1);
- }
- for (IFile mappingFile : this.mappingFilePersistentTypeReplaceEdits.keySet()) {
- if (sm.isCanceled()) {
- throw new OperationCanceledException();
- }
- this.addMappingFileRenameTypeChange(mappingFile, compositeChange);
- sm.worked(1);
- }
- //must check for children in case all changes were made in other participant's TextChanges,
- //want to return null so our node does not appear in the preview tree
- return compositeChange.getChildren().length == 0 ? null : compositeChange;
+ protected Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.createPersistenceXmlReplaceOriginalTypeEdits(persistenceUnit),
+ this.createPersistenceXmlReplaceNestedTypeEdits(persistenceUnit));
}
- /**
- * This will be appended to the main refactoring task named : 'Creating workspace modifications...'
- */
- protected String getCreateChangeSubTaskName() {
- return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME;
+ private Iterable<ReplaceEdit> createPersistenceXmlReplaceOriginalTypeEdits(PersistenceUnit persistenceUnit) {
+ return persistenceUnit.createReplaceTypeEdits(this.getOriginalType(), this.getNewName());
}
- protected void createReplaceEdits(IProgressMonitor monitor, JpaProject jpaProject) throws OperationCanceledException {
- PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject);
- if (persistenceUnit == null) {
- return;
- }
- SubMonitor sm = SubMonitor.convert(monitor, 1 + persistenceUnit.mappingFileRefsSize());
- Iterable<ReplaceEdit> classRefDeleteEdits = this.createPersistenceXmlReplaceTypeEdits(persistenceUnit);
- sm.worked(1);
- if (!CollectionTools.isEmpty(classRefDeleteEdits)) {
- this.persistenceXmlClassRefReplaceEdits.put(jpaProject.getPersistenceXmlResource().getFile(), classRefDeleteEdits);
- }
- for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) {
- if (sm.isCanceled()) {
- throw new OperationCanceledException();
- }
- Iterable<ReplaceEdit> mappingFileReplaceEdits = this.createMappingFileReplaceTypeEdits(mappingFileRef);
- if (!CollectionTools.isEmpty(mappingFileReplaceEdits)) {
- IFile file = (IFile) mappingFileRef.getMappingFile().getResource();
- this.mappingFilePersistentTypeReplaceEdits.put(file, mappingFileReplaceEdits);
+ private Iterable<ReplaceEdit> createPersistenceXmlReplaceNestedTypeEdits(final PersistenceUnit persistenceUnit) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<IType, Iterable<ReplaceEdit>>(this.nestedTypes) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(IType nestedType) {
+ String newName = getNewNameForNestedType(nestedType);
+ return persistenceUnit.createReplaceTypeEdits(nestedType, newName);
+ }
}
- sm.worked(1);
- }
+ );
}
@SuppressWarnings("unchecked")
- private Iterable<ReplaceEdit> createPersistenceXmlReplaceTypeEdits(PersistenceUnit persistenceUnit) {
- //check isOnClassPath since there could be types with the same name in different projects
- if (persistenceUnit.getJpaProject().getJavaProject().isOnClasspath(this.originalType)) {
- return new CompositeIterable<ReplaceEdit>(
- this.createPersistenceXmlReplaceOriginalTypeEdits(persistenceUnit),
- this.createPersistenceXmlReplaceNestedTypeEdits(persistenceUnit));
- }
- return EmptyIterable.instance();
+ @Override
+ protected Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.createMappingFileReplaceOriginalTypeEdits(mappingFileRef),
+ this.createMappingFileReplaceNestedTypeEdits(mappingFileRef));
}
- private Iterable<ReplaceEdit> createPersistenceXmlReplaceOriginalTypeEdits(PersistenceUnit persistenceUnit) {
- return persistenceUnit.createReplaceTypeEdits(this.originalType, this.getNewName());
+ private Iterable<ReplaceEdit> createMappingFileReplaceOriginalTypeEdits(MappingFileRef mappingFileRef) {
+ return mappingFileRef.createReplaceTypeEdits(this.getOriginalType(), this.getNewName());
}
- private Iterable<ReplaceEdit> createPersistenceXmlReplaceNestedTypeEdits(final PersistenceUnit persistenceUnit) {
+ private Iterable<ReplaceEdit> createMappingFileReplaceNestedTypeEdits(final MappingFileRef mappingFileRef) {
return new CompositeIterable<ReplaceEdit>(
new TransformationIterable<IType, Iterable<ReplaceEdit>>(this.nestedTypes) {
@Override
protected Iterable<ReplaceEdit> transform(IType nestedType) {
String newName = getNewNameForNestedType(nestedType);
- return persistenceUnit.createReplaceTypeEdits(nestedType, newName);
+ return mappingFileRef.createReplaceTypeEdits(nestedType, newName);
}
}
);
@@ -237,8 +124,8 @@ public class JpaRenameTypeParticipant
protected String getNewName() {
String newName = getArguments().getNewName();
try {
- if (this.originalType.isMember()) {
- newName = this.originalType.getTypeQualifiedName().substring(0, this.originalType.getTypeQualifiedName().lastIndexOf('$')) + '$' + newName;
+ if (this.getOriginalType().isMember()) {
+ newName = this.getOriginalType().getTypeQualifiedName().substring(0, this.getOriginalType().getTypeQualifiedName().lastIndexOf('$')) + '$' + newName;
}
}
catch (JavaModelException e) {
@@ -248,86 +135,31 @@ public class JpaRenameTypeParticipant
}
protected String getNewNameForNestedType(IType nestedType) {
- return nestedType.getTypeQualifiedName('$').replaceFirst(this.originalType.getElementName(), getArguments().getNewName());
- }
-
- protected void addPersistenceXmlRenameTypeChange(IFile persistenceXmlFile, CompositeChange compositeChange) {
- Iterable<ReplaceEdit> replaceTypeEdits = this.persistenceXmlClassRefReplaceEdits.get(persistenceXmlFile);
-
- TextChange textChange = getTextChange(persistenceXmlFile);
- if (textChange == null) {
- textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME, persistenceXmlFile);
- //TODO probably need to figure out TextEditGroups since these can be used to show check boxes under the file in the preview dialog
- //also used to add edits to existing changes??
- MultiTextEdit multiTextEdit = new MultiTextEdit();
- textChange.setEdit(multiTextEdit);
-// textChange.addTextEditGroup(new TextEditGroup("edit persistence unit", multiTextEdit));???
- compositeChange.add(textChange);
- }
- this.addEdits(textChange, replaceTypeEdits);
- }
-
- @SuppressWarnings("unchecked")
- private Iterable<ReplaceEdit> createMappingFileReplaceTypeEdits(MappingFileRef mappingFileRef) {
- //check isOnClassPath since there could be types with the same name in different projects
- if (mappingFileRef.getJpaProject().getJavaProject().isOnClasspath(this.originalType)) {
- return new CompositeIterable<ReplaceEdit>(
- this.createMappingFileReplaceOriginalTypeEdits(mappingFileRef),
- this.createMappingFileReplaceNestedTypeEdits(mappingFileRef));
- }
- return EmptyIterable.instance();
+ return nestedType.getTypeQualifiedName('$').replaceFirst(this.getOriginalType().getElementName(), getArguments().getNewName());
}
- private Iterable<ReplaceEdit> createMappingFileReplaceOriginalTypeEdits(MappingFileRef mappingFileRef) {
- return mappingFileRef.createReplaceTypeEdits(this.originalType, this.getNewName());
+ @Override
+ protected String getCheckConditionsSubTaskName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME;
}
- private Iterable<ReplaceEdit> createMappingFileReplaceNestedTypeEdits(final MappingFileRef mappingFileRef) {
- return new CompositeIterable<ReplaceEdit>(
- new TransformationIterable<IType, Iterable<ReplaceEdit>>(this.nestedTypes) {
- @Override
- protected Iterable<ReplaceEdit> transform(IType nestedType) {
- String newName = getNewNameForNestedType(nestedType);
- return mappingFileRef.createReplaceTypeEdits(nestedType, newName);
- }
- }
- );
+ @Override
+ protected String getCreateChangeSubTaskName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME;
}
- protected void addMappingFileRenameTypeChange(IFile mappingFile, CompositeChange compositeChange) {
- Iterable<ReplaceEdit> replacedTypeEdits = this.mappingFilePersistentTypeReplaceEdits.get(mappingFile);
-
- TextChange textChange = getTextChange(mappingFile);
- if (textChange == null) {
- textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME, mappingFile);
- MultiTextEdit multiTextEdit = new MultiTextEdit();
- textChange.setEdit(multiTextEdit);
- compositeChange.add(textChange);
- }
- this.addEdits(textChange, replacedTypeEdits);
+ @Override
+ protected String getCompositeChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_NAME;
}
- private PersistenceUnit getPersistenceUnit(JpaProject jpaProject) {
- PersistenceXml persistenceXml = jpaProject.getRootContextNode().getPersistenceXml();
- Persistence persistence = persistenceXml.getPersistence();
- if (persistence == null) {
- return null;
- }
- if (persistence.persistenceUnitsSize() != 1) {
- return null; // the context model currently only supports 1 persistence unit
- }
- return persistence.persistenceUnits().next();
+ @Override
+ protected String getPersistenceXmlChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME;
}
- private void addEdits(TextChange textChange, Iterable<? extends TextEdit> textEdits) {
- for (TextEdit textEdit : textEdits) {
- try {
- textChange.addEdit(textEdit);
- }
- catch (MalformedTreeException ex) {
- //log exception and don't add this persistence.xml type deletion to the conflicting change object
- JptCorePlugin.log(ex);
- }
- }
+ @Override
+ protected String getMappingFileChangeName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME;
}
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
index 887d519751..2100f5364c 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java
@@ -12,11 +12,11 @@ package org.eclipse.jpt.core.internal.resource.java.binary;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
-
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -31,6 +31,7 @@ import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.utility.MethodSignature;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
@@ -46,6 +47,8 @@ final class BinaryPersistentType
private String qualifiedName;
+ private String packageName;
+
private String superclassQualifiedName;
private String declaringTypeName;
@@ -65,6 +68,7 @@ final class BinaryPersistentType
super(parent, new TypeAdapter(type));
this.name = this.buildName();
this.qualifiedName = this.buildQualifiedName();
+ this.packageName = this.buildPackageName();
this.superclassQualifiedName = this.buildSuperclassQualifiedName();
this.declaringTypeName = this.buildDeclaringTypeName();
this.abstract_ = this.buildAbstract();
@@ -82,6 +86,7 @@ final class BinaryPersistentType
super.update();
this.setName(this.buildName());
this.setQualifiedName(this.buildQualifiedName());
+ this.setPackageName(this.buildPackageName());
this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName());
this.setDeclaringTypeName(this.buildDeclaringTypeName());
this.setAbstract(this.buildAbstract());
@@ -157,6 +162,25 @@ final class BinaryPersistentType
return this.getMember().getFullyQualifiedName('.'); // no parameters are included here
}
+ // ***** package
+ public String getPackageName() {
+ return this.packageName;
+ }
+
+ private void setPackageName(String packageName) {
+ String old = this.packageName;
+ this.packageName = packageName;
+ this.firePropertyChanged(PACKAGE_NAME_PROPERTY, old, packageName);
+ }
+
+ private String buildPackageName() {
+ return this.getMember().getPackageFragment().getElementName();
+ }
+
+ public boolean isIn(IPackageFragment packageFragment) {
+ return StringTools.stringsAreEqual(packageFragment.getElementName(), this.packageName);
+ }
+
// ***** superclass qualified name
public String getSuperclassQualifiedName() {
return this.superclassQualifiedName;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
index 058550bb3d..4020394f05 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java
@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Vector;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
@@ -60,6 +61,8 @@ final class SourcePersistentType
private String qualifiedName;
+ private String packageName;
+
private String superclassQualifiedName;
private String declaringTypeName;
@@ -139,6 +142,7 @@ final class SourcePersistentType
super.initialize(astRoot);
this.name = this.buildName(astRoot);
this.qualifiedName = this.buildQualifiedName(astRoot);
+ this.packageName = this.buildPackageName(astRoot);
this.superclassQualifiedName = this.buildSuperclassQualifiedName(astRoot);
this.declaringTypeName = this.buildDeclaringTypeName(astRoot);
this.abstract_ = this.buildAbstract(astRoot);
@@ -179,6 +183,7 @@ final class SourcePersistentType
super.synchronizeWith(astRoot);
this.syncName(this.buildName(astRoot));
this.syncQualifiedName(this.buildQualifiedName(astRoot));
+ this.syncPackageName(this.buildPackageName(astRoot));
this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot));
this.syncDeclaringTypeName(this.buildDeclaringTypeName(astRoot));
this.syncAbstract(this.buildAbstract(astRoot));
@@ -333,6 +338,22 @@ final class SourcePersistentType
return (binding == null) ? null : binding.getQualifiedName();
}
+ // ***** package name
+ public String getPackageName() {
+ return this.packageName;
+ }
+
+ private void syncPackageName(String astPackageName) {
+ String old = this.packageName;
+ this.packageName = astPackageName;
+ this.firePropertyChanged(PACKAGE_NAME_PROPERTY, old, astPackageName);
+ }
+
+ private String buildPackageName(CompilationUnit astRoot) {
+ ITypeBinding binding = this.member.getBinding(astRoot);
+ return (binding == null) ? null : binding.getPackage().getName();
+ }
+
// ***** superclass qualified name
public String getSuperclassQualifiedName() {
return this.superclassQualifiedName;
@@ -353,6 +374,11 @@ final class SourcePersistentType
return (superclass == null) ? null : superclass.getTypeDeclaration().getQualifiedName();
}
+ // ***** package
+ public boolean isIn(IPackageFragment packageFragment) {
+ return StringTools.stringsAreEqual(packageFragment.getElementName(), this.packageName);
+ }
+
// ***** declaring type name
public String getDeclaringTypeName() {
return this.declaringTypeName;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java
index 14db8475e3..fe0ed3fe7f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.resource.java;
import java.util.Iterator;
+import org.eclipse.jdt.core.IPackageFragment;
/**
* Java source code or binary persistent type.
@@ -20,7 +21,7 @@ import java.util.Iterator;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @version 2.3
+ * @version 3.0
* @since 2.0
*/
public interface JavaResourcePersistentType
@@ -39,6 +40,12 @@ public interface JavaResourcePersistentType
String QUALIFIED_NAME_PROPERTY = "qualifiedName"; //$NON-NLS-1$
/**
+ * Return the package name.
+ */
+ String getPackageName();
+ String PACKAGE_NAME_PROPERTY = "packageName"; //$NON-NLS-1$
+
+ /**
* Return the fully qualified name of the type's superclass.
*/
String getSuperclassQualifiedName();
@@ -75,6 +82,8 @@ public interface JavaResourcePersistentType
*/
boolean hasAnyAnnotatedAttributes();
+ boolean isIn(IPackageFragment packageFragment);
+
// ********** types **********
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java
index 2ab9a3427e..3f4bba0d42 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java
@@ -1093,4 +1093,8 @@ public abstract class AbstractXmlMultiRelationshipMapping extends AbstractXmlRel
return getMapKeyClass().createReplaceEdit(originalType, newName);
}
+ public ReplaceEdit createReplaceMapKeyClassPackageEdit(String newName) {
+ return getMapKeyClass().createReplacePackageEdit(newName);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java
index f23098cd78..acc4799417 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java
@@ -391,4 +391,10 @@ public abstract class AbstractXmlRelationshipMapping extends AbstractXmlAttribut
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+ public ReplaceEdit createReplaceTargetEntityPackageEdit(String newName) {
+ int packageLength = this.targetEntity.lastIndexOf('.');
+ int offset = getAttributeNode(JPA.TARGET_ENTITY).getValueRegionStartOffset() + 1; // +1 = opening double quote
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
+
} // RelationshipMapping
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java
index 66e8fe17c5..ba02cf2e2b 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java
@@ -530,4 +530,10 @@ public abstract class AbstractXmlTypeMapping extends AbstractJpaEObject implemen
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+ public ReplaceEdit createReplacePackageEdit(String newName) {
+ int packageLength = this.className.lastIndexOf('.');
+ int offset = getAttributeNode(JPA.CLASS).getValueRegionStartOffset() + 1; // +1 = opening double quote
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
+
} // TypeMapping
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java
index edde3bc7e0..d13fd97c12 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java
@@ -236,4 +236,11 @@ public class XmlClassReference extends AbstractJpaEObject implements JpaEObject
int offset = getAttributeNode(JPA.CLASS).getValueRegionStartOffset() + 1;
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+
+ public ReplaceEdit createReplacePackageEdit(String newName) {
+ int packageLength = this.className.lastIndexOf('.');
+ int offset = getAttributeNode(JPA.CLASS).getValueRegionStartOffset() + 1; // +1 = opening double quote
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java
index 9b4ef50ba3..9880a83e05 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java
@@ -1647,4 +1647,14 @@ public class XmlElementCollection extends AbstractXmlAttributeMapping implements
return getMapKeyClass().createReplaceEdit(originalType, newName);
}
+ public ReplaceEdit createReplaceTargetClassPackageEdit(String newName) {
+ int packageLength = this.targetClass.lastIndexOf('.');
+ int offset = getAttributeNode(JPA2_0.TARGET_CLASS).getValueRegionStartOffset() + 1; // +1 = opening double quote
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
+
+ public ReplaceEdit createReplaceMapKeyClassPackageEdit(String newName) {
+ return getMapKeyClass().createReplacePackageEdit(newName);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlEntityMappings.java
index 7affacee90..2edbf2912e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlEntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlEntityMappings.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2010 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.
@@ -26,6 +26,7 @@ import org.eclipse.jpt.core.internal.utility.translators.SimpleRootTranslator;
import org.eclipse.jpt.core.resource.orm.v2_0.JPA2_0;
import org.eclipse.jpt.core.resource.xml.AbstractJpaRootEObject;
import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
/**
@@ -1105,4 +1106,13 @@ public class XmlEntityMappings extends AbstractJpaRootEObject implements XmlQuer
protected static Translator buildAccessTranslator() {
return new Translator(JPA.ACCESS, OrmPackage.eINSTANCE.getXmlAccessHolder_Access());
}
+
+
+ // ********** refactorings **********
+
+ public ReplaceEdit createReplacePackageEdit(String newName) {
+ int offset = getElementNode(JPA.PACKAGE).getStartStructuredDocumentRegion().getEndOffset();
+ return new ReplaceEdit(offset, this.package_.length(), newName);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java
index 18a6dc13a1..f1d05e6eae 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java
@@ -156,4 +156,7 @@ public interface XmlTypeMapping extends XmlAccessHolder
// ********** refactoring **********
ReplaceEdit createReplaceTypeEdit(IType originalType, String newName);
+
+ ReplaceEdit createReplacePackageEdit(String newName);
+
} // XmlTypeMapping
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java
index fe584e6571..6ea92a1629 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2010 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.
@@ -10,6 +10,7 @@
package org.eclipse.jpt.core.resource.persistence;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -19,7 +20,9 @@ import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject;
import org.eclipse.jpt.core.resource.xml.JpaEObject;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
/**
* <!-- begin-user-doc -->
@@ -232,4 +235,15 @@ public class XmlJarFileRef extends AbstractJpaEObject implements JpaEObject
);
}
+
+ // *********** refactoring ***********
+
+ public ReplaceEdit createReplaceFolderEdit(IFolder originalFolder, String newName) {
+ IDOMNode domNode = getTextNode();
+ String originalName = originalFolder.getName();
+ int nameIndex = this.fileName.indexOf(originalName);
+
+ int offset = domNode.getStartOffset();
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java
index c9e02be73b..3734d8398f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java
@@ -239,4 +239,10 @@ public class XmlJavaClassRef extends AbstractJpaEObject
int offset = getTextNode().getStartOffset();
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+
+ public ReplaceEdit createReplacePackageEdit(String newName) {
+ int packageLength = this.javaClass.lastIndexOf('.');
+ int offset = getTextNode().getStartOffset();
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlMappingFileRef.java
index 960c996d37..9861bbddb5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlMappingFileRef.java
@@ -11,6 +11,7 @@
package org.eclipse.jpt.core.resource.persistence;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
@@ -240,6 +241,8 @@ public class XmlMappingFileRef extends AbstractJpaEObject implements JpaEObject
}
+ // *********** refactoring ***********
+
public ReplaceEdit createReplaceEdit(IFile originalFile, String newName) {
IDOMNode domNode = getTextNode();
String originalName = originalFile.getName();
@@ -248,4 +251,13 @@ public class XmlMappingFileRef extends AbstractJpaEObject implements JpaEObject
int offset = domNode.getStartOffset();
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+
+ public ReplaceEdit createReplaceFolderEdit(IFolder originalFolder, String newName) {
+ IDOMNode domNode = getTextNode();
+ String originalName = originalFolder.getName();
+ int nameIndex = this.fileName.indexOf(originalName);
+
+ int offset = domNode.getStartOffset();
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java
index 30d38b310b..e7b4e1a649 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java
@@ -20,7 +20,6 @@ import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject;
import org.eclipse.jpt.core.resource.xml.JpaEObject;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
/**
* <!-- begin-user-doc -->
@@ -306,15 +305,18 @@ public class XmlProperty extends AbstractJpaEObject implements JpaEObject
}
public ReplaceEdit createReplaceTypeEdit(IType originalType, String newName) {
- IDOMAttr domAttr = getAttributeNode(JPA.PROPERTY__VALUE);
- if (domAttr == null) {
- return null;
- }
String originalName = originalType.getElementName();
int nameIndex = originalType.getFullyQualifiedName('.').lastIndexOf(originalName);
- int offset = domAttr.getValueRegionStartOffset() + 1;
+ int offset = getAttributeNode(JPA.PROPERTY__VALUE).getValueRegionStartOffset() + 1;
return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
}
+ public ReplaceEdit createReplacePackageEdit(String newName) {
+ int packageLength = this.value.lastIndexOf('.');
+
+ int offset = getAttributeNode(JPA.PROPERTY__VALUE).getValueRegionStartOffset() + 1;
+ return new ReplaceEdit(offset, packageLength, newName);
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java
index d36642f217..fa7ff7f5e4 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.eclipselink.core.internal.context.orm;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.orm.EntityMappings;
import org.eclipse.jpt.core.context.orm.OrmTypeMapping;
@@ -121,8 +122,22 @@ public class OrmEclipseLinkCustomizer extends AbstractOrmXmlContextNode
protected void removeResourceCustomizer() {
this.resource.setCustomizer(null);
}
+
+ protected boolean isFor(String typeName) {
+ if (this.customizerPersistentType != null && this.customizerPersistentType.getQualifiedName().equals(typeName)) {
+ return true;
+ }
+ return false;
+ }
-
+ protected boolean isIn(IPackageFragment packageFragment) {
+ if (this.customizerPersistentType != null) {
+ return this.customizerPersistentType.isIn(packageFragment);
+ }
+ return false;
+ }
+
+
// **************** updating **************************************
protected void update(JavaEclipseLinkCustomizer javaCustomizer) {
@@ -158,11 +173,15 @@ public class OrmEclipseLinkCustomizer extends AbstractOrmXmlContextNode
return getResourceCustomizer().createReplaceEdit(originalType, newName);
}
- protected boolean isFor(String typeName) {
- if (this.customizerPersistentType != null && this.customizerPersistentType.getQualifiedName().equals(typeName)) {
- return true;
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.isIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplacePackageEdit(newName));
}
- return false;
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplacePackageEdit(String newName) {
+ return getResourceCustomizer().createReplacePackageEdit(newName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEmbeddableImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEmbeddableImpl.java
index 2c35e4d7a1..546a5b3916 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEmbeddableImpl.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEmbeddableImpl.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.eclipselink.core.internal.context.orm;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEmbeddable;
@@ -111,6 +112,18 @@ public class OrmEclipseLinkEmbeddableImpl
return this.customizer.createReplaceEdits(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createCustomizerReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createCustomizerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.customizer.createReplacePackageEdits(originalPackage, newName);
+ }
+
// **************** validation **************************************
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java
index cbd35cc5e3..7e42ef15cd 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.eclipselink.core.internal.context.orm;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.orm.EntityMappings;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
@@ -146,6 +147,20 @@ public class OrmEclipseLinkEntityImpl
return this.getEntityMappings().resolveJavaResourcePersistentType(className);
}
+ protected boolean classExtractorIsFor(String typeName) {
+ if (this.classExtractorPersistentType != null && this.classExtractorPersistentType.getQualifiedName().equals(typeName)) {
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean classExtractorIsIn(IPackageFragment packageFragment) {
+ if (this.classExtractorPersistentType != null) {
+ return this.classExtractorPersistentType.isIn(packageFragment);
+ }
+ return false;
+ }
+
protected EntityMappings getEntityMappings() {
return (EntityMappings) getMappingFileRoot();
}
@@ -221,11 +236,24 @@ public class OrmEclipseLinkEntityImpl
return EmptyIterable.instance();
}
- protected boolean classExtractorIsFor(String typeName) {
- if (this.classExtractorPersistentType != null && this.classExtractorPersistentType.getQualifiedName().equals(typeName)) {
- return true;
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createCustomizerReplacePackageEdits(originalPackage, newName),
+ this.createClassExtractorReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createCustomizerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.customizer.createReplacePackageEdits(originalPackage, newName);
+ }
+
+ protected Iterable<ReplaceEdit> createClassExtractorReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ if (this.classExtractorIsIn(originalPackage)) {
+ return new SingleElementIterable<ReplaceEdit>(this.getResourceClassExtractor().createReplacePackageEdit(newName));
}
- return false;
+ return EmptyIterable.instance();
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java
index 6422c3b67a..13d9cfd3a3 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.eclipselink.core.internal.context.orm;
import java.util.List;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator;
@@ -158,6 +159,18 @@ public class OrmEclipseLinkMappedSuperclassImpl
return this.customizer.createReplaceEdits(originalType, newName);
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplacePackageEdits(originalPackage, newName),
+ this.createCustomizerReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createCustomizerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.customizer.createReplacePackageEdits(originalPackage, newName);
+ }
+
// *********** validation ************
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
index 217110119d..f723df932a 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnit.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.core.context.persistence.Persistence;
@@ -519,4 +520,13 @@ public class EclipseLinkPersistenceUnit
this.customization.createReplaceTypeEdits(originalType, newName),
this.logging.createReplaceTypeEdits(originalType, newName));
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Iterable<ReplaceEdit> createPersistenceUnitPropertiesReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createPersistenceUnitPropertiesReplacePackageEdits(originalPackage, newName),
+ this.customization.createReplacePackageEdits(originalPackage, newName),
+ this.logging.createReplacePackageEdits(originalPackage, newName));
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java
index 1cafe1ce7b..6ee4fc79df 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java
@@ -16,6 +16,7 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.eclipselink.core.context.persistence.customization.Customization;
@@ -830,4 +831,32 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti
}
return EmptyIterable.instance();
}
+
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.createSessionCustomizerReplacePackageEdits(originalPackage, newName),
+ this.createExceptionHandlerReplacePackageEdits(originalPackage, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createSessionCustomizerReplacePackageEdits(final IPackageFragment originalPackage, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<PersistenceUnit.Property, Iterable<ReplaceEdit>>(getPersistenceUnit().getPropertiesNamed(ECLIPSELINK_SESSION_CUSTOMIZER)) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(PersistenceUnit.Property property) {
+ return property.createReplacePackageEdits(originalPackage, newName);
+ }
+ }
+ );
+ }
+
+ protected Iterable<ReplaceEdit> createExceptionHandlerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ PersistenceUnit.Property property = getPersistenceUnit().getProperty(ECLIPSELINK_EXCEPTION_HANDLER);
+ if (property != null) {
+ return property.createReplacePackageEdits(originalPackage, newName);
+ }
+ return EmptyIterable.instance();
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/logging/EclipseLinkLogging.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/logging/EclipseLinkLogging.java
index f8b24d1d02..ca55006a2c 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/logging/EclipseLinkLogging.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/logging/EclipseLinkLogging.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.eclipselink.core.internal.context.persistence.logging;
import java.util.Map;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.eclipselink.core.context.persistence.logging.Logger;
@@ -378,4 +379,18 @@ public class EclipseLinkLogging extends EclipseLinkPersistenceUnitProperties
}
return EmptyIterable.instance();
}
+
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.createLoggerReplacePackageEdits(originalPackage, newName);
+ }
+
+ protected Iterable<ReplaceEdit> createLoggerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ //find all of the Properties from the persistence unit.
+ PersistenceUnit.Property property = getPersistenceUnit().getProperty(ECLIPSELINK_LOGGER);
+ if (property != null) {
+ return property.createReplacePackageEdits(originalPackage, newName);
+ }
+ return EmptyIterable.instance();
+ }
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/options/EclipseLinkOptions.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/options/EclipseLinkOptions.java
index e91beab105..c7bd4ee69f 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/options/EclipseLinkOptions.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/options/EclipseLinkOptions.java
@@ -10,6 +10,7 @@
package org.eclipse.jpt.eclipselink.core.internal.context.persistence.options;
import java.util.Map;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.eclipselink.core.context.persistence.options.Options;
@@ -414,4 +415,17 @@ public class EclipseLinkOptions extends EclipseLinkPersistenceUnitProperties
}
return EmptyIterable.instance();
}
+
+ @Override
+ public Iterable<ReplaceEdit> createReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ return this.createEventListenerReplacePackageEdits(originalPackage, newName);
+ }
+
+ protected Iterable<ReplaceEdit> createEventListenerReplacePackageEdits(IPackageFragment originalPackage, String newName) {
+ PersistenceUnit.Property property = getPersistenceUnit().getProperty(ECLIPSELINK_SESSION_EVENT_LISTENER);
+ if (property != null) {
+ return property.createReplacePackageEdits(originalPackage, newName);
+ }
+ return EmptyIterable.instance();
+ }
} \ No newline at end of file

Back to the top