Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFile.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java12
-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.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmIdClassReference.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/MappingFileRef.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnitProperties.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractEntityMappings.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java34
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java33
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdClassReference.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractMappingFileRef.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java39
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnitProperties.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentType.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmXml.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericClassRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/persistence/GenericPersistenceUnitProperty.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java43
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java333
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlRelationshipMapping.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlTypeMapping.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlClassReference.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlElementCollection.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/XmlTypeMapping.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJavaClassRef.java15
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlProperty.java17
40 files changed, 915 insertions, 43 deletions
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 b8c7e4a331..b8c31e786d 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
@@ -13,6 +13,7 @@ import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.MappingFileRef;
import org.eclipse.jpt.core.context.persistence.PersistentTypeContainer;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* JPA mapping file (typically <code>orm.xml</code>).
@@ -60,4 +61,10 @@ public interface MappingFile
*/
Iterable<DeleteEdit> createDeleteTypeEdits(IType type);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 580b01f628..ff159afff7 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,7 +12,6 @@ package org.eclipse.jpt.core.context;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -26,7 +25,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
* 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 PersistentType
@@ -161,6 +160,15 @@ public interface PersistentType
void validate(List<IMessage> messages, IReporter reporter);
+ // ********** misc **********
+
+ /**
+ * Return whether the persistent type applies to the
+ * specified type name qualified with '.'.
+ */
+ boolean isFor(String typeName);
+
+
// ********** owner **********
/**
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 44825e9741..e1f17c864d 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
@@ -22,6 +22,7 @@ import org.eclipse.jpt.db.Schema;
import org.eclipse.jpt.db.SchemaContainer;
import org.eclipse.jpt.utility.internal.iterables.ListIterable;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Context <code>orm.xml</code> entity mappings.
@@ -178,4 +179,10 @@ public interface EntityMappings
*/
Iterable<DeleteEdit> createDeleteTypeEdits(IType type);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 041497ffdc..550ee7604a 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,11 +9,13 @@
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.resource.orm.Attributes;
import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
/**
*
@@ -24,7 +26,7 @@ import org.eclipse.jpt.core.utility.TextRange;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @version 2.2
+ * @version 3.0
* @since 2.3
*/
public interface OrmAttributeMapping
@@ -92,4 +94,13 @@ public interface OrmAttributeMapping
*/
void update();
+
+ //******************* refactoring *******************
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 29130b5174..cee22a365d 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,9 +10,11 @@
*******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.IdClassReference;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JavaIdClassReference;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Provisional API: This interface is part of an interim API that is still
@@ -21,11 +23,20 @@ import org.eclipse.jpt.core.context.java.JavaIdClassReference;
* 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.3
*/
public interface OrmIdClassReference
extends IdClassReference, XmlContextNode
{
void update(JavaIdClassReference javaIdClassReference);
+
+
+ // ********** refactoring **********
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceEdits(IType originalType, 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 6d4a9ee181..256a022df1 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,9 +9,11 @@
******************************************************************************/
package org.eclipse.jpt.core.context.orm;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* ORM persistent attribute
@@ -22,7 +24,7 @@ import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
* 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 OrmPersistentAttribute
@@ -79,12 +81,6 @@ public interface OrmPersistentAttribute
*/
void makeSpecified(String mappingKey);
-
- // ********** miscellaneous **********
-
- boolean contains(int textOffset);
-
- void nameChanged(String oldName, String newName);
// ********** updating **********
@@ -93,8 +89,24 @@ public interface OrmPersistentAttribute
* resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()}
*/
void update();
-
-
+
+
+ // ********** refactoring **********
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+
+
+ // ********** miscellaneous **********
+
+ boolean contains(int textOffset);
+
+ void nameChanged(String oldName, String newName);
+
+
/**
* interface allowing persistent attributes to be used in multiple places
* (e.g. virtual and specified orm persistent attributes)
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 61a2792bc2..b0a25e8c91 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
@@ -15,6 +15,7 @@ import org.eclipse.jpt.core.context.PersistentType;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Context <code>orm.xml</code> persistent type.
@@ -130,16 +131,16 @@ public interface OrmPersistentType
*/
Iterable<DeleteEdit> createDeleteTypeEdits(IType type);
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+
//******************* misc *******************
boolean contains(int textOffset);
-
- /**
- * Return whether the persistent type applies to the
- * specified type.
- */
- boolean isFor(String typeName);
void classChanged(String oldClass, String newClass);
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 b71048f5c8..882062f0aa 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,12 +11,14 @@ package org.eclipse.jpt.core.context.orm;
import java.util.Iterator;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.TypeMapping;
import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.resource.orm.XmlEntityMappings;
import org.eclipse.jpt.core.resource.orm.XmlTypeMapping;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
/**
*
@@ -90,6 +92,13 @@ public interface OrmTypeMapping
*/
DeleteEdit createDeleteEdit();
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+
+
// ********** covariant overrides **********
OrmPersistentType getPersistentType();
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 f4263974ba..31a0e0fb48 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
@@ -16,6 +16,7 @@ import org.eclipse.jpt.core.context.XmlContextNode;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Context model corresponding to the XML resource model
@@ -110,6 +111,13 @@ public interface ClassRef
*/
Iterable<DeleteEdit> createDeleteTypeEdits(IType type);
+ /**
+ * Create ReplaceEdits for renaming the class element to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ * If this ClassRef does not match the original type, then return an empty Iterable.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
+
// *************************************************************************
@@ -118,5 +126,5 @@ public interface ClassRef
* the given text offset
*/
boolean containsOffset(int textOffset);
-
+
}
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 44cf3ac8ce..8be104fb3e 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
@@ -136,6 +136,12 @@ public interface MappingFileRef
Iterable<DeleteEdit> createDeleteMappingFileEdits(IFile file);
/**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 ab06f4d4db..3f17be91ce 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
@@ -429,6 +429,13 @@ public interface PersistenceUnit
Property getProperty(String propertyName);
/**
+ * Return all the properties in the persistence unit with the specified
+ * name. Return an empty Iterable if the persistence unit does not contain
+ * a property with the specified name.
+ */
+ Iterable<Property> getPropertiesNamed(String propertyName);
+
+ /**
* Return the persistence unit's properties with names beginning with the
* specified prefix.
*/
@@ -510,6 +517,13 @@ public interface PersistenceUnit
XmlProperty getXmlProperty();
void update();
+
+ /**
+ * Create ReplaceEdits for renaming the property value to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ * If this value does not match the original type, then return an empty Iterable.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName);
}
// ********** ORM persistence unit defaults **********
@@ -727,6 +741,12 @@ public interface PersistenceUnit
Iterable<DeleteEdit> createDeleteMappingFileEdits(IFile file);
/**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 ec987bc355..c53c1918af 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,8 +9,10 @@
*******************************************************************************/
package org.eclipse.jpt.core.context.persistence;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.utility.model.Model;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Provisional API: This interface is part of an interim API that is still
@@ -19,7 +21,7 @@ import org.eclipse.jpt.utility.model.Model;
* 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.3
*/
public interface PersistenceUnitProperties extends Model
@@ -54,4 +56,13 @@ public interface PersistenceUnitProperties extends Model
*/
void propertyRemoved(String propertyName);
+
+ // ************ refactoring **************
+
+ /**
+ * Create ReplaceEdits for renaming any references to the originalType to the newName.
+ * The originalType has not yet been renamed, the newName is the new short name.
+ */
+ Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, 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 c3be5d891e..bc32d52603 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
@@ -632,6 +632,11 @@ public abstract class AbstractJavaPersistentType
// ********** misc **********
+ public boolean isFor(String typeName) {
+ String className = this.getName();
+ return className != null && className.equals(typeName);
+ }
+
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 efabd0ad54..95dc7f6498 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
@@ -55,6 +55,7 @@ import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -828,6 +829,16 @@ public abstract class AbstractEntityMappings
);
}
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(final IType originalType, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<OrmPersistentType, Iterable<ReplaceEdit>>(getPersistentTypes()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(OrmPersistentType persistentType) {
+ return persistentType.createReplaceTypeEdits(originalType, newName);
+ }
+ }
+ );
+ }
// ********** 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 ed650203bb..ad10143e0b 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.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.ColumnMapping;
@@ -50,8 +51,10 @@ import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -345,6 +348,13 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping>
}
+ // ********** refactoring **********
+
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return EmptyIterable.instance();
+ }
+
+
// ********** validation **********
@Override
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 e25a980363..725946ccda 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.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.JpaPlatformVariation.Supported;
import org.eclipse.jpt.core.context.AssociationOverride;
@@ -94,6 +95,7 @@ import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -1560,8 +1562,23 @@ public abstract class AbstractOrmEntity
public void removeFromResourceModel(XmlEntityMappings entityMappings) {
entityMappings.getEntities().remove(this.resourceTypeMapping);
}
-
-
+
+
+ //************************* refactoring ************************
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplaceTypeEdits(originalType, newName),
+ this.createIdClassReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createIdClassReplaceTypeEdits(IType originalType, String newName) {
+ return this.idClassReference.createReplaceEdits(originalType, newName);
+ }
+
+
// **************** validation *********************************************
@Override
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 bd30ea7c6b..cee2d7d566 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.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.Table;
import org.eclipse.jpt.core.context.java.JavaIdClassReference;
@@ -24,7 +25,9 @@ import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator;
import org.eclipse.jpt.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator;
import org.eclipse.jpt.core.resource.orm.XmlEntityMappings;
import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass;
+import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -126,7 +129,25 @@ public abstract class AbstractOrmMappedSuperclass extends AbstractOrmTypeMapping
super.update();
this.idClassReference.update(getJavaIdClassReferenceForDefaults());
}
-
+
+
+ //************************* refactoring ************************
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplaceTypeEdits(originalType, newName),
+ this.createIdClassReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createIdClassReplaceTypeEdits(IType originalType, String newName) {
+ return this.idClassReference.createReplaceEdits(originalType, newName);
+ }
+
+
+ // **************** validation *********************************************
+
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
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 e460f4a76a..0bcd8e0a63 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.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.BaseColumn;
import org.eclipse.jpt.core.context.BaseOverride;
@@ -51,7 +52,11 @@ import org.eclipse.jpt.core.resource.orm.XmlColumn;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.db.Table;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -575,8 +580,33 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends AbstractXmlM
public String getMetamodelFieldMapKeyTypeName() {
return MappingTools.getMetamodelFieldMapKeyTypeName(this);
}
-
-
+
+
+ //************* refactoring *************
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplaceTypeEdits(originalType, newName),
+ this.createMapKeyClassReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createMapKeyClassReplaceTypeEdits(IType originalType, String newName) {
+ if (this.specifiedMapKeyClass != null) {
+ String originalName = originalType.getFullyQualifiedName('.');
+ if (this.resolvedMapKeyType != null && this.resolvedMapKeyType.isFor(originalName)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceMapKeyClassEdit(originalType, newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceMapKeyClassEdit(IType originalType, String newName) {
+ return this.resourceAttributeMapping.createReplaceMapKeyClassEdit(originalType, newName);
+ }
+
+
// ********** validation **********
@Override
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 fb0eab8ee7..5a5e0a982b 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.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AccessType;
@@ -27,6 +28,7 @@ import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmPersistentAttribute2_0;
import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -230,6 +232,13 @@ public abstract class AbstractOrmPersistentAttribute
}
+ // ********** refactoring **********
+
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return this.attributeMapping.createReplaceTypeEdits(originalType, newName);
+ }
+
+
// ********** validation **********
@Override
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 975ffef534..7405344df8 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.IType;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Entity;
import org.eclipse.jpt.core.context.FetchType;
@@ -29,9 +30,13 @@ import org.eclipse.jpt.core.jpa2.context.orm.OrmCascade2_0;
import org.eclipse.jpt.core.resource.orm.AbstractXmlRelationshipMapping;
import org.eclipse.jpt.core.utility.TextRange;
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.SingleElementIterable;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -275,6 +280,34 @@ public abstract class AbstractOrmRelationshipMapping<T extends AbstractXmlRelati
return (this.resolvedTargetEntity == null) ? null : this.resolvedTargetEntity.getIdAttribute();
}
+
+ //************ refactoring ************
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplaceTypeEdits(originalType, newName),
+ this.createTargetEntityReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createTargetEntityReplaceTypeEdits(IType originalType, String newName) {
+ if (this.specifiedTargetEntity != null) {
+ String originalName = originalType.getFullyQualifiedName('.');
+ if (this.resolvedTargetType != null && this.resolvedTargetType.isFor(originalName)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceTargetEntityEdit(originalType, newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceTargetEntityEdit(IType originalType, String newName) {
+ return this.resourceAttributeMapping.createReplaceTargetEntityEdit(originalType, newName);
+ }
+
+
+ //*********** validation ***********
+
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
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 c90b95eb1b..9583beda58 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.IType;
import org.eclipse.jpt.core.JpaStructureNode;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
@@ -30,10 +31,13 @@ import org.eclipse.jpt.db.Schema;
import org.eclipse.jpt.db.Table;
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.FilteringIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -359,11 +363,22 @@ public abstract class AbstractOrmTypeMapping<T extends XmlTypeMapping>
//************************* refactoring ************************
-
+
public DeleteEdit createDeleteEdit() {
return this.resourceTypeMapping.createDeleteEdit();
}
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ if (getPersistentType().isFor(originalType.getFullyQualifiedName('.'))) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceTypeEdit(originalType, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceTypeEdit(IType originalType, String newName) {
+ return this.resourceTypeMapping.createReplaceTypeEdit(originalType, 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 5b9a999399..a963f4c851 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.IType;
import org.eclipse.jpt.core.context.AccessType;
import org.eclipse.jpt.core.context.java.JavaIdClassReference;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
@@ -25,6 +26,9 @@ import org.eclipse.jpt.core.resource.orm.XmlClassReference;
import org.eclipse.jpt.core.resource.orm.XmlIdClassContainer;
import org.eclipse.jpt.core.resource.orm.XmlTypeMapping;
import org.eclipse.jpt.core.utility.TextRange;
+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.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -207,8 +211,29 @@ public class GenericOrmIdClassReference
}
}
}
-
-
+
+
+ //************************* refactoring ************************
+
+ public Iterable<ReplaceEdit> createReplaceEdits(IType originalType, String newName) {
+ if (this.isFor(originalType.getFullyQualifiedName('.'))) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceEdit(originalType, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceEdit(IType originalType, String newName) {
+ return getIdXmlClassRef().createReplaceEdit(originalType, newName);
+ }
+
+ protected boolean isFor(String typeName) {
+ if (this.idClass != null && this.idClass.isFor(typeName)) {
+ return true;
+ }
+ return false;
+ }
+
+
// **************** validation ********************************************
public TextRange getValidationTextRange() {
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 2d4c57ef2d..f2f7fb1598 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
@@ -293,6 +293,13 @@ public abstract class AbstractMappingFileRef
return EmptyIterable.instance();
}
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ if (this.mappingFile != null) {
+ return this.mappingFile.createReplaceTypeEdits(originalType, 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 06bade806f..701d717c28 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
@@ -137,8 +137,8 @@ public abstract class AbstractPersistenceUnit
protected boolean defaultDelimitedIdentifiers;
//****** PersistenceUnit2_0 features
- private PersistenceUnitProperties connection;
- private PersistenceUnitProperties options;
+ protected PersistenceUnitProperties connection;
+ protected PersistenceUnitProperties options;
protected SharedCacheMode specifiedSharedCacheMode;
protected SharedCacheMode defaultSharedCacheMode;
@@ -967,6 +967,19 @@ public abstract class AbstractPersistenceUnit
return null;
}
+ public Iterable<Property> getPropertiesNamed(final String propertyName) {
+ if (propertyName == null) {
+ throw new NullPointerException();
+ }
+ return new FilteringIterable<Property>(CollectionTools.iterable(this.properties())) {
+ @Override
+ protected boolean accept(Property property) {
+ String pName = property.getName();
+ return (pName != null) && pName.equals(propertyName);
+ }
+ };
+ }
+
public Iterator<Property> propertiesWithNamePrefix(final String propertyNamePrefix) {
if (propertyNamePrefix == null) {
throw new NullPointerException();
@@ -1629,6 +1642,28 @@ public abstract class AbstractPersistenceUnit
);
}
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ createSpecifiedClassRefReplaceTypeEdits(originalType, newName),
+ createPersistenceUnitPropertiesReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createSpecifiedClassRefReplaceTypeEdits(final IType originalType, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<ClassRef, Iterable<ReplaceEdit>>(getSpecifiedClassRefs()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(ClassRef classRef) {
+ return classRef.createReplaceTypeEdits(originalType, newName);
+ }
+ }
+ );
+ }
+
+ protected Iterable<ReplaceEdit> createPersistenceUnitPropertiesReplaceTypeEdits(IType originalType, String newName) {
+ return this.options.createReplaceTypeEdits(originalType, 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 0fe0ea4cd0..55b72fc134 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,13 +14,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.context.persistence.PersistenceUnitProperties;
import org.eclipse.jpt.utility.internal.ReflectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* AbstractPersistenceUnitProperties
@@ -508,5 +510,11 @@ public abstract class AbstractPersistenceUnitProperties extends AbstractModel
sb.deleteCharAt(sb.length() - 1); // remove the last delimiter
return sb.toString();
}
-
+
+
+ // ********** refactoring ************
+
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return EmptyIterable.instance();
+ }
}
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 298a00ef07..3b031288b6 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
@@ -61,6 +61,7 @@ import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.utility.internal.iterators.ChainIterator;
import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
@@ -69,6 +70,7 @@ import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator;
import org.eclipse.jpt.utility.internal.iterators.FilteringIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -946,6 +948,24 @@ public class GenericOrmPersistentType
return EmptyIterable.instance();
}
+ @SuppressWarnings("unchecked")
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ this.mapping.createReplaceTypeEdits(originalType, newName),
+ this.createSpecifiedAttributesReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createSpecifiedAttributesReplaceTypeEdits(final IType originalType, final String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ new TransformationIterable<OrmPersistentAttribute, Iterable<ReplaceEdit>>(getSpecifiedAttributes()) {
+ @Override
+ protected Iterable<ReplaceEdit> transform(OrmPersistentAttribute persistentAttribute) {
+ return persistentAttribute.createReplaceTypeEdits(originalType, newName);
+ }
+ }
+ );
+ }
+
// ********** misc **********
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 44877ab1d6..e498c9a100 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
@@ -27,6 +27,7 @@ import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -231,4 +232,11 @@ public class GenericOrmXml
}
return EmptyIterable.instance();
}
+
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ if (this.entityMappings != null) {
+ return this.entityMappings.createReplaceTypeEdits(originalType, 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 6098fbfe47..320c37be47 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
@@ -31,6 +31,7 @@ import org.eclipse.jpt.utility.internal.Tools;
import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -320,6 +321,20 @@ public class GenericClassRef
return this.xmlJavaClassRef.createDeleteEdit();
}
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ if (isVirtual()) {
+ throw new IllegalStateException();
+ }
+ if (this.isFor(originalType)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceEdit(originalType, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceEdit(IType originalType, String newName) {
+ return this.xmlJavaClassRef.createReplaceEdit(originalType, newName);
+ }
+
// ********** misc **********
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 b5f4aa822c..2c99c33281 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
@@ -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.
@@ -9,10 +9,14 @@
*******************************************************************************/
package org.eclipse.jpt.core.internal.jpa1.context.persistence;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceXmlContextNode;
import org.eclipse.jpt.core.resource.persistence.XmlProperty;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* Straightforward implementation of the persistence unit property.
@@ -92,6 +96,20 @@ public class GenericPersistenceUnitProperty
}
+ // ********** refactoring **********
+
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ if (this.getValue() != null && this.getValue().equals(originalType.getFullyQualifiedName('.'))) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceTypeEdit(originalType, newName));
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceTypeEdit(IType originalType, String newName) {
+ return this.xmlProperty.createReplaceTypeEdit(originalType, newName);
+ }
+
+
// ********** misc **********
@Override
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 00b1d5be03..5de731c1a7 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.IType;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AssociationOverride;
import org.eclipse.jpt.core.context.AttributeMapping;
@@ -69,9 +70,13 @@ import org.eclipse.jpt.db.Table;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.Transformer;
+import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
+import org.eclipse.jpt.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -1027,7 +1032,43 @@ public abstract class AbstractOrmElementCollectionMapping2_0<T extends XmlElemen
public String getMetamodelFieldMapKeyTypeName() {
return MappingTools.getMetamodelFieldMapKeyTypeName(this);
}
-
+
+
+ //*********** refactoring ***********
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterable<ReplaceEdit> createReplaceTypeEdits(IType originalType, String newName) {
+ return new CompositeIterable<ReplaceEdit>(
+ super.createReplaceTypeEdits(originalType, newName),
+ this.createMapKeyClassReplaceTypeEdits(originalType, newName),
+ this.createTargetClassReplaceTypeEdits(originalType, newName));
+ }
+
+ protected Iterable<ReplaceEdit> createMapKeyClassReplaceTypeEdits(IType originalType, String newName) {
+ if (this.specifiedMapKeyClass != null) {
+ String originalName = originalType.getFullyQualifiedName('.');
+ if (this.resolvedMapKeyType != null && this.resolvedMapKeyType.isFor(originalName)) {
+ return new SingleElementIterable<ReplaceEdit>(this.createReplaceMapKeyClassEdit(originalType, newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
+ protected ReplaceEdit createReplaceMapKeyClassEdit(IType originalType, String newName) {
+ return this.resourceAttributeMapping.createReplaceMapKeyClassEdit(originalType, newName);
+ }
+
+ protected Iterable<ReplaceEdit> createTargetClassReplaceTypeEdits(IType originalType, String newName) {
+ if (this.specifiedTargetClass != null) {
+ String originalName = originalType.getFullyQualifiedName('.');
+ if (this.resolvedTargetType != null && this.resolvedTargetType.isFor(originalName)) {
+ return new SingleElementIterable<ReplaceEdit>(this.resourceAttributeMapping.createReplaceTargetClassEdit(originalType, newName));
+ }
+ }
+ return EmptyIterable.instance();
+ }
+
// ********** validation **********
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 0df873e22c..409b259542 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
@@ -30,6 +30,13 @@ 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_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/JpaRenameTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java
new file mode 100644
index 0000000000..fd70cc5ee6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java
@@ -0,0 +1,333 @@
+/*******************************************************************************
+ * 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.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 {
+
+ 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
+ public String getName() {
+ return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_PARTICIPANT_NAME;
+ }
+
+ @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.originalType = (IType) element;
+ this.addNestedTypes(this.originalType);
+ return true;
+ }
+
+ protected void addNestedType(IType renamedType) {
+ this.nestedTypes.add(renamedType);
+ this.addNestedTypes(renamedType);
+ }
+
+ private void addNestedTypes(IType renamedType) {
+ IType[] nestedTypes;
+ try {
+ nestedTypes = renamedType.getTypes();
+ }
+ catch (JavaModelException ex) {
+ JptCorePlugin.log(ex);
+ return;
+ }
+
+ for (IType nestedType : nestedTypes) {
+ this.addNestedType(nestedType);
+ }
+ }
+
+
+ //**************** 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;
+ }
+
+ @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;
+ }
+
+ /**
+ * 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;
+ }
+
+ 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);
+ }
+ 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();
+ }
+
+ private Iterable<ReplaceEdit> createPersistenceXmlReplaceOriginalTypeEdits(PersistenceUnit persistenceUnit) {
+ return persistenceUnit.createReplaceTypeEdits(this.originalType, this.getNewName());
+ }
+
+ 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);
+ }
+ }
+ );
+ }
+
+ protected String getNewName() {
+ String newName = getArguments().getNewName();
+ try {
+ if (this.originalType.isMember()) {
+ newName = this.originalType.getTypeQualifiedName().substring(0, this.originalType.getTypeQualifiedName().lastIndexOf('$')) + '$' + newName;
+ }
+ }
+ catch (JavaModelException e) {
+ JptCorePlugin.log(e);
+ }
+ return newName;
+ }
+
+ 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();
+ }
+
+ private Iterable<ReplaceEdit> createMappingFileReplaceOriginalTypeEdits(MappingFileRef mappingFileRef) {
+ return mappingFileRef.createReplaceTypeEdits(this.originalType, this.getNewName());
+ }
+
+ 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);
+ }
+ }
+ );
+ }
+
+ 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);
+ }
+
+ 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/resource/orm/AbstractXmlMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/AbstractXmlMultiRelationshipMapping.java
index 5444fc9c44..2ab9a3427e 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
@@ -18,12 +18,14 @@ import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.resource.orm.v2_0.JPA2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.OrmV2_0Package;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapKeyAttributeOverrideContainer_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlMultiRelationshipMapping_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlOrderable_2_0;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
@@ -1083,4 +1085,12 @@ public abstract class AbstractXmlMultiRelationshipMapping extends AbstractXmlRel
protected static Translator buildOrderColumnTranslator() {
return XmlOrderColumn.buildTranslator(JPA2_0.ORDER_COLUMN, OrmV2_0Package.eINSTANCE.getXmlOrderable_2_0_OrderColumn());
}
+
+
+ // ********** refactoring **********
+
+ public ReplaceEdit createReplaceMapKeyClassEdit(IType originalType, String newName) {
+ return getMapKeyClass().createReplaceEdit(originalType, 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 2f590a2bf7..f23098cd78 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
@@ -14,7 +14,9 @@ import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
@@ -378,5 +380,15 @@ public abstract class AbstractXmlRelationshipMapping extends AbstractXmlAttribut
protected static Translator buildCascadeTranslator() {
return CascadeType.buildTranslator(JPA.CASCADE, OrmPackage.eINSTANCE.getAbstractXmlRelationshipMapping_Cascade());
}
-
+
+
+ // ********** refactoring **********
+
+ public ReplaceEdit createReplaceTargetEntityEdit(IType originalType, String newName) {
+ String originalName = originalType.getElementName();
+ int nameIndex = this.targetEntity.lastIndexOf(originalName);
+ int offset = getAttributeNode(JPA.TARGET_ENTITY).getValueRegionStartOffset() + 1;
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), 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 322b3eab36..66e8fe17c5 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
@@ -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.
@@ -14,8 +14,10 @@ import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
/**
@@ -516,6 +518,16 @@ public abstract class AbstractXmlTypeMapping extends AbstractJpaEObject implemen
protected static Translator buildAttributesTranslator() {
return Attributes.buildTranslator();
- }
+ }
+
+
+ // ********** refactoring **********
+
+ public ReplaceEdit createReplaceTypeEdit(IType originalType, String newName) {
+ String originalName = originalType.getTypeQualifiedName();
+ int nameIndex = this.className.lastIndexOf(originalName);
+ int offset = getAttributeNode(JPA.CLASS).getValueRegionStartOffset() + 1; // +1 = opening double quote
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), 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 26cad878dc..edde3bc7e0 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
@@ -15,10 +15,12 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.utility.translators.SimpleTranslator;
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.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
/**
@@ -226,4 +228,12 @@ public class XmlClassReference extends AbstractJpaEObject implements JpaEObject
private static Translator buildClassTranslator() {
return new Translator(JPA.CLASS, OrmPackage.eINSTANCE.getXmlClassReference_ClassName(), Translator.DOM_ATTRIBUTE);
}
+
+ public ReplaceEdit createReplaceEdit(IType originalType, String newName) {
+ String originalName = originalType.getElementName();
+ int nameIndex = this.className.lastIndexOf(originalName);
+
+ int offset = getAttributeNode(JPA.CLASS).getValueRegionStartOffset() + 1;
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), 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 3103bc7640..9b4ef50ba3 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
@@ -21,7 +21,7 @@ import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
-import org.eclipse.jpt.core.internal.utility.translators.BooleanTranslator;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.utility.translators.EmptyTagBooleanTranslator;
import org.eclipse.jpt.core.internal.utility.translators.SimpleTranslator;
import org.eclipse.jpt.core.jpa2.MappingKeys2_0;
@@ -31,6 +31,7 @@ import org.eclipse.jpt.core.resource.orm.v2_0.XmlElementCollection_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapKeyAttributeOverrideContainer_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlOrderable_2_0;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.common.internal.emf.resource.Translator;
/**
@@ -1631,4 +1632,19 @@ public class XmlElementCollection extends AbstractXmlAttributeMapping implements
protected static Translator buildMapKeyAttributeOverrideTranslator() {
return XmlAttributeOverride.buildTranslator(JPA2_0.MAP_KEY_ATTRIBUTE_OVERRIDE, OrmV2_0Package.eINSTANCE.getXmlMapKeyAttributeOverrideContainer_2_0_MapKeyAttributeOverrides());
}
+
+
+ // ********** refactoring **********
+
+ public ReplaceEdit createReplaceTargetClassEdit(IType originalType, String newName) {
+ String originalName = originalType.getElementName();
+ int nameIndex = this.targetClass.lastIndexOf(originalName);
+ int offset = getAttributeNode(JPA2_0.TARGET_CLASS).getValueRegionStartOffset() + 1;
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
+ }
+
+ public ReplaceEdit createReplaceMapKeyClassEdit(IType originalType, String newName) {
+ return getMapKeyClass().createReplaceEdit(originalType, 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 e8a71a6ccc..18a6dc13a1 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
@@ -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.
@@ -9,7 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.core.resource.orm;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.text.edits.ReplaceEdit;
/**
* <!-- begin-user-doc -->
@@ -149,4 +151,9 @@ public interface XmlTypeMapping extends XmlAccessHolder
//TODO not happy with this, or the corresponding one in XmlAttributeMapping
String getMappingKey();
+
+
+ // ********** refactoring **********
+
+ ReplaceEdit createReplaceTypeEdit(IType originalType, String newName);
} // XmlTypeMapping
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 807ed320c7..c9e02be73b 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
@@ -14,9 +14,10 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.utility.translators.SimpleTranslator;
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;
/**
@@ -42,7 +43,7 @@ import org.eclipse.wst.common.internal.emf.resource.Translator;
* @extends JpaEObject
* @generated
*/
-public class XmlJavaClassRef extends AbstractJpaEObject implements JpaEObject
+public class XmlJavaClassRef extends AbstractJpaEObject
{
/**
* The default value of the '{@link #getJavaClass() <em>Java Class</em>}' attribute.
@@ -228,4 +229,14 @@ public class XmlJavaClassRef extends AbstractJpaEObject implements JpaEObject
PersistencePackage.eINSTANCE.getXmlJavaClassRef_JavaClass()
);
}
+
+
+ // *********** refactoring ***********
+
+ public ReplaceEdit createReplaceEdit(IType originalType, String newName) {
+ String originalName = originalType.getTypeQualifiedName();
+ int nameIndex = this.javaClass.lastIndexOf(originalName);
+ int offset = getTextNode().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 22e944c680..30d38b310b 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2006, 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,10 +14,13 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.utility.translators.SimpleTranslator;
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 -->
@@ -302,4 +305,16 @@ 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;
+ return new ReplaceEdit(offset + nameIndex, originalName.length(), newName);
+ }
+
}

Back to the top