diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring')
14 files changed, 0 insertions, 2623 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java deleted file mode 100644 index 1eca9a11a7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaDeleteTypeParticipant.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * 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.HashSet; -import java.util.Map; -import java.util.Set; -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.IJavaProject; -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.FilteringIterable; -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.DeleteParticipant; -import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker; -import org.eclipse.text.edits.DeleteEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.TextEdit; - - -public abstract class AbstractJpaDeleteTypeParticipant - extends DeleteParticipant -{ - - /** - * Store all the types that are going to be deleted including nestedTypes. - */ - protected final Set<IType> allTypes; - - /** - * Store the persistence.xml DeleteEdits in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<DeleteEdit>> persistenceXmlDeleteEdits; - - /** - * Store the mapping file DeleteEdits in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<DeleteEdit>> mappingFilePersistentTypeDeleteEdits; - - protected AbstractJpaDeleteTypeParticipant() { - super(); - this.allTypes = new HashSet<IType>(); - this.persistenceXmlDeleteEdits = new HashMap<IFile, Iterable<DeleteEdit>>(); - this.mappingFilePersistentTypeDeleteEdits = new HashMap<IFile, Iterable<DeleteEdit>>(); - } - - /** - * Nested types are not added to the deleteParticipant when the parent is deleted. - * We must handle them in case they are mapped. - */ - protected void addType(IType type) { - this.allTypes.add(type); - this.addNestedTypes(type); - } - - private void addNestedTypes(IType type) { - IType[] nestedTypes; - try { - nestedTypes = type.getTypes(); - } - catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return; - } - - for (IType nestedType : nestedTypes) { - this.addType(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 DeleteEdits 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 + 2); - sm.subTask(this.getCheckConditionsSubTaskName()); - ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); - IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory(); - - for (JpaProject jpaProject : jpaProjectManager.getJpaProjects()) { - this.createDeleteEdits(sm.newChild(10), jpaProject); - } - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - for (IFile file : this.persistenceXmlDeleteEdits.keySet()) { - deltaFactory.change(file); - } - sm.worked(1); - for (IFile file : this.mappingFilePersistentTypeDeleteEdits.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_DELETE_TYPE_REFACTORING_SUB_TASK_NAME; - } - - @Override - public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { - if (this.persistenceXmlDeleteEdits.isEmpty() && this.mappingFilePersistentTypeDeleteEdits.isEmpty()) { - return null; - } - SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlDeleteEdits.size() + this.mappingFilePersistentTypeDeleteEdits.size()); - sm.subTask(this.getCreateChangeSubTaskName()); - CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_DELETE_TYPE_REFACTORING_CHANGE_NAME); - for (IFile persistenceXmlFile : this.persistenceXmlDeleteEdits.keySet()) { - this.addPersistenceXmlDeleteTypeChange(persistenceXmlFile, compositeChange); - sm.worked(1); - } - for (IFile mappingFile : this.mappingFilePersistentTypeDeleteEdits.keySet()) { - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - this.addMappingFileDeleteTypeChange(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_DELETE_TYPE_REFACTORING_SUB_TASK_NAME; - } - - protected void createDeleteEdits(IProgressMonitor monitor, JpaProject jpaProject) throws OperationCanceledException { - PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject); - if (persistenceUnit == null) { - return; - } - SubMonitor sm = SubMonitor.convert(monitor, 1 + persistenceUnit.mappingFileRefsSize()); - Iterable<DeleteEdit> persistenceXmlDeleteEdits = this.createPersistenceXmlDeleteEdits(persistenceUnit); - if (!CollectionTools.isEmpty(persistenceXmlDeleteEdits)) { - this.persistenceXmlDeleteEdits.put(jpaProject.getPersistenceXmlResource().getFile(), persistenceXmlDeleteEdits); - } - sm.worked(1); - for (MappingFileRef mappingFileRef : CollectionTools.iterable(persistenceUnit.mappingFileRefs())) { - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - Iterable<DeleteEdit> mappingFileDeleteEdits = this.createMappingFileDeleteTypeEdits(mappingFileRef); - if (!CollectionTools.isEmpty(mappingFileDeleteEdits)) { - this.mappingFilePersistentTypeDeleteEdits.put((IFile) mappingFileRef.getMappingFile().getResource(), mappingFileDeleteEdits); - } - sm.worked(1); - } - } - - protected Iterable<DeleteEdit> createPersistenceXmlDeleteEdits(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<DeleteEdit>( - new TransformationIterable<IType, Iterable<DeleteEdit>>(this.getTypesOnClasspath(persistenceUnit.getJpaProject())) { - @Override - protected Iterable<DeleteEdit> transform(IType type) { - return persistenceUnit.createDeleteTypeEdits(type); - } - } - ); - } - - protected Iterable<IType> getTypesOnClasspath(final JpaProject jpaProject) { - final IJavaProject javaProject = jpaProject.getJavaProject(); - return new FilteringIterable<IType>(this.allTypes) { - @Override - protected boolean accept(IType type) { - return javaProject.isOnClasspath(type); - } - }; - } - - protected void addPersistenceXmlDeleteTypeChange(IFile persistenceXmlFile, CompositeChange compositeChange) { - Iterable<DeleteEdit> deleteTypeEdits = this.persistenceXmlDeleteEdits.get(persistenceXmlFile); - - TextChange textChange = getTextChange(persistenceXmlFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_DELETE_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, deleteTypeEdits); - } - - private Iterable<DeleteEdit> createMappingFileDeleteTypeEdits(final MappingFileRef mappingFileRef) { - return new CompositeIterable<DeleteEdit>( - new TransformationIterable<IType, Iterable<DeleteEdit>>(this.getTypesOnClasspath(mappingFileRef.getJpaProject())) { - @Override - protected Iterable<DeleteEdit> transform(IType type) { - return mappingFileRef.createDeleteTypeEdits(type); - } - } - ); - } - - protected void addMappingFileDeleteTypeChange(IFile mappingFile, CompositeChange compositeChange) { - Iterable<DeleteEdit> deleteTypeEdits = this.mappingFilePersistentTypeDeleteEdits.get(mappingFile); - - TextChange textChange = getTextChange(mappingFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_DELETE_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME, mappingFile); - MultiTextEdit multiTextEdit = new MultiTextEdit(); - textChange.setEdit(multiTextEdit); - compositeChange.add(textChange); - } - this.addEdits(textChange, deleteTypeEdits); - } - - 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/AbstractJpaMoveJavaElementParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java deleted file mode 100644 index 894661ceb8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaMoveJavaElementParticipant.java +++ /dev/null @@ -1,291 +0,0 @@ -/******************************************************************************* - * 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.jdt.core.IJavaProject; -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.FilteringIterable; -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.ISharableParticipant; -import org.eclipse.ltk.core.refactoring.participants.MoveArguments; -import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; -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 AbstractJpaMoveJavaElementParticipant - extends MoveParticipant implements ISharableParticipant { - - /** - * Store the {@link IJavaElements}s to be moved and their corresponding {@link MoveArguments} - */ - protected final Map<IJavaElement, MoveArguments> originalJavaElements; - - /** - * 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 AbstractJpaMoveJavaElementParticipant() { - super(); - this.originalJavaElements = new HashMap<IJavaElement, MoveArguments>(); - 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.addElement(element, getArguments()); - return true; - } - - - //****************ISharableParticipant implementation ***************** - /** - * This is used when multiple mapping files are deleted. - * RefactoringParticipant#initialize(Object) is called for the first deleted IFile. - * RefactoringParticipant#getArguments() only applies to the first deleted IFile - */ - public void addElement(Object element, RefactoringArguments arguments) { - this.originalJavaElements.put((IJavaElement) element, (MoveArguments) arguments); - } - - protected MoveArguments getArguments(IJavaElement element) { - return this.originalJavaElements.get(element); - } - - //**************** 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.createPersistenceUnitReplaceEditsCheckClasspath(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> createPersistenceUnitReplaceEditsCheckClasspath(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<ReplaceEdit>( - new TransformationIterable<IJavaElement, Iterable<ReplaceEdit>>(this.getElementsOnClasspath(persistenceUnit.getJpaProject())) { - @Override - protected Iterable<ReplaceEdit> transform(IJavaElement javaElement) { - return createPersistenceXmlReplaceEdits(persistenceUnit, javaElement, getArguments(javaElement).getDestination()); - } - } - ); - } - - protected Iterable<IJavaElement> getElementsOnClasspath(final JpaProject jpaProject) { - final IJavaProject javaProject = jpaProject.getJavaProject(); - return new FilteringIterable<IJavaElement>(this.originalJavaElements.keySet()) { - @Override - protected boolean accept(IJavaElement javaElement) { - return javaProject.isOnClasspath(javaElement); - } - }; - } - - protected abstract Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit, IJavaElement javaElement, Object destination); - - 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(); - - - private Iterable<ReplaceEdit> createMappingFileReplaceEditsCheckClasspath(final MappingFileRef mappingFileRef) { - return new CompositeIterable<ReplaceEdit>( - new TransformationIterable<IJavaElement, Iterable<ReplaceEdit>>(this.getElementsOnClasspath(mappingFileRef.getJpaProject())) { - @Override - protected Iterable<ReplaceEdit> transform(IJavaElement javaElement) { - return createMappingFileReplaceEdits(mappingFileRef, javaElement, getArguments(javaElement).getDestination()); - } - } - ); - } - - protected abstract Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef, IJavaElement javaElement, Object destination); - - - 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/AbstractJpaRenameJavaElementParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java deleted file mode 100644 index b21ef88d77..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/AbstractJpaRenameJavaElementParticipant.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 6972076869..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaCoreRefactoringMessages.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * 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.osgi.util.NLS; - -/** - * Localized messages used by Dali core. - */ -public class JpaCoreRefactoringMessages { - - public static String JPA_DELETE_TYPE_REFACTORING_PARTICIPANT_NAME; - public static String JPA_DELETE_PACKAGE_OR_FOLDER_REFACTORING_PARTICIPANT_NAME; - public static String JPA_DELETE_TYPE_REFACTORING_CHANGE_NAME; - public static String JPA_DELETE_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - public static String JPA_DELETE_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME; - public static String JPA_DELETE_TYPE_REFACTORING_SUB_TASK_NAME; - - public static String JPA_DELETE_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME; - public static String JPA_DELETE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME; - public static String JPA_DELETE_MAPPING_FILE_REFACTORING_CHANGE_NAME; - public static String JPA_DELETE_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - - 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_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; - public static String JPA_RENAME_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - - public static String JPA_MOVE_TYPE_REFACTORING_PARTICIPANT_NAME; - public static String JPA_MOVE_TYPE_REFACTORING_CHANGE_NAME; - public static String JPA_MOVE_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - public static String JPA_MOVE_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME; - public static String JPA_MOVE_TYPE_REFACTORING_SUB_TASK_NAME; - - public static String JPA_MOVE_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME; - public static String JPA_MOVE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME; - public static String JPA_MOVE_MAPPING_FILE_REFACTORING_CHANGE_NAME; - public static String JPA_MOVE_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - - public static String JPA_MOVE_FOLDER_REFACTORING_PARTICIPANT_NAME; - public static String JPA_MOVE_FOLDER_REFACTORING_CHANGE_NAME; - public static String JPA_MOVE_FOLDER_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - public static String JPA_MOVE_FOLDER_REFACTORING_SUB_TASK_NAME; - - private static final String BUNDLE_NAME = "jpa_core_refactoring"; //$NON-NLS-1$ - private static final Class<?> BUNDLE_CLASS = JpaCoreRefactoringMessages.class; - static { - NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS); - } - - private JpaCoreRefactoringMessages() { - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteMappingFileParticipant.java deleted file mode 100644 index fe3cf25933..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteMappingFileParticipant.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * 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.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.CompositeIterable; -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.DeleteArguments; -import org.eclipse.ltk.core.refactoring.participants.DeleteParticipant; -import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; -import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker; -import org.eclipse.text.edits.DeleteEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.TextEdit; - -/** - * Participant in the delete refactoring of {@link IFile}s with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE}. - * If the deleted mapping file is listed in a persistence.xml file of any JpaProject - * then a Change object is created that will delete that reference from the file. - */ -public class JpaDeleteMappingFileParticipant - extends DeleteParticipant - implements ISharableParticipant -{ - - /** - * Store the {@link IFile}s to be deleted with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE} - * and their corresponding {@link DeleteArguments} - */ - protected final Map<IFile, DeleteArguments> mappingFiles; - - /** - * Store the persistence.xml DeleteEdits in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<DeleteEdit>> persistenceXmlMappingFileDeleteEdits; - - public JpaDeleteMappingFileParticipant() { - super(); - this.mappingFiles = new HashMap<IFile, DeleteArguments>(); - this.persistenceXmlMappingFileDeleteEdits = new HashMap<IFile, Iterable<DeleteEdit>>(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_DELETE_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME; - } - - @Override - protected boolean initialize(Object element) { - this.addElement(element, getArguments()); - return true; - } - - - //****************ISharableParticipant implementation ***************** - /** - * This is used when multiple mapping files are deleted. - * RefactoringParticipant#initialize(Object) is called for the first deleted IFile. - * RefactoringParticipant#getArguments() only applies to the first deleted IFile - */ - public void addElement(Object element, RefactoringArguments arguments) { - this.mappingFiles.put((IFile) element, (DeleteArguments) arguments); - } - - - //**************** 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 DeleteEdits 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_DELETE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME); - ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); - IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory(); - - for (JpaProject jpaProject : JptCorePlugin.getJpaProjectManager().getJpaProjects()) { - this.createDeleteEdits(jpaProject); - sm.worked(10); - } - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - for (IFile persistenceXmlFile : this.persistenceXmlMappingFileDeleteEdits.keySet()) { - deltaFactory.change(persistenceXmlFile); - } - sm.worked(1); - - return null; - } - - protected void createDeleteEdits(JpaProject jpaProject) throws OperationCanceledException { - PersistenceUnit persistenceUnit = getPersistenceUnit(jpaProject); - if (persistenceUnit == null) { - return; - } - Iterable<DeleteEdit> classRefDeleteEdits = this.createSpecifiedMappingFileRefDeleteEdits(persistenceUnit); - if (!CollectionTools.isEmpty(classRefDeleteEdits)) { - this.persistenceXmlMappingFileDeleteEdits.put(jpaProject.getPersistenceXmlResource().getFile(), classRefDeleteEdits); - } - } - - @Override - public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { - if (this.persistenceXmlMappingFileDeleteEdits.isEmpty()) { - return null; - } - SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlMappingFileDeleteEdits.size()); - sm.subTask(JpaCoreRefactoringMessages.JPA_DELETE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME); - CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_DELETE_MAPPING_FILE_REFACTORING_CHANGE_NAME); - for (IFile persistenceXmlFile : this.persistenceXmlMappingFileDeleteEdits.keySet()) { - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - this.addPersistenceXmlDeleteMappingFileChange(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<DeleteEdit> createSpecifiedMappingFileRefDeleteEdits(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<DeleteEdit>( - new TransformationIterable<IFile, Iterable<DeleteEdit>>(this.mappingFiles.keySet()) { - @Override - protected Iterable<DeleteEdit> transform(IFile file) { - return persistenceUnit.createDeleteMappingFileEdits(file); - } - } - ); - } - - protected void addPersistenceXmlDeleteMappingFileChange(IFile persistenceXmlFile, CompositeChange compositeChange) { - TextChange textChange = getTextChange(persistenceXmlFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_DELETE_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME, persistenceXmlFile); - MultiTextEdit multiTextEdit = new MultiTextEdit(); - textChange.setEdit(multiTextEdit); - compositeChange.add(textChange); - } - Iterable<DeleteEdit> mappingFileDeleteEdits = this.persistenceXmlMappingFileDeleteEdits.get(persistenceXmlFile); - this.addEdits(textChange, mappingFileDeleteEdits); - } - - 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/JpaDeletePackageOrFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java deleted file mode 100644 index b1703b485e..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * 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.HashSet; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.utility.PlatformTools; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -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 - extends AbstractJpaDeleteTypeParticipant - implements ISharableParticipant -{ - - /** - * The folders that are going to be deleted. - * Only folders which are not also IPackageFragments or IPackageFragmentRoots are added to this collection. - */ - protected final Collection<IFolder> folders; - - /** - * The IPackageFragments that are going to be deleted. - */ - protected final Collection<IPackageFragment> packageFragments; - - public JpaDeletePackageOrFolderParticipant() { - super(); - this.folders = new ArrayList<IFolder>(); - this.packageFragments = new ArrayList<IPackageFragment>(); - } - - //**************** RefactoringParticipant implementation ***************** - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_DELETE_PACKAGE_OR_FOLDER_REFACTORING_PARTICIPANT_NAME; - } - - @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; - } - - //**************** ISharableParticipant implementation ***************** - /** - * This is used when multiple IPackageFraments/IFolders are deleted. - * RefactoringParticipant#initialize(Object) is called for the first deleted IPackageFragment/IFolder. - * RefactoringParticipant#getArguments() only applies to the first deleted IPackageFragment/IFolder - */ - public void addElement(Object element, RefactoringArguments arguments) { - if (element instanceof IFolder) { - IJavaElement javaElement = JavaCore.create((IFolder) element); - if (javaElement != null) { - if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { - this.addPackageFragmentRoot((IPackageFragmentRoot) javaElement); - } - else { - this.addPackageFragment((IPackageFragment) javaElement); - } - } - else { - this.addFolder((IFolder) element); - } - } - else { - this.addPackageFragment((IPackageFragment) element); - } - } - - protected void addFolder(IFolder folder) { - this.folders.add(folder); - } - - protected void addPackageFragmentRoot(IPackageFragmentRoot root) { - if (JDTTools.packageFragmentRootIsSourceFolder(root)) { - IJavaElement[] children = JDTTools.getJDTChildren(root); - for (IJavaElement child : children) { - this.addPackageFragment((IPackageFragment) child); - } - } - } - - protected void addPackageFragment(IPackageFragment packageFragment) { - this.packageFragments.add(packageFragment); - Collection<IType> allDeletedTypes = new HashSet<IType>(); - addAffectedTypes(allDeletedTypes, packageFragment); - for (IType deletedType : allDeletedTypes) { - this.addType(deletedType); - } - } - - //nestedTypes are handled in AbstractJpaDeleteTypeParticipant - static void addAffectedTypes(Collection<IType> types, IPackageFragment fragment) { - try { - if (fragment.containsJavaResources()) { - ICompilationUnit[] cunits = fragment.getCompilationUnits(); - IType type = null; - for (int i = 0; i < cunits.length; i++) { - type = cunits[i].findPrimaryType(); - if (type == null) { - continue; - } - types.add(type); - } - } - } - catch (JavaModelException ex) { - JptCorePlugin.log(ex); - } - } - - /** - * Add mapping file delete edits here, super.createPersistenceXmlDeleteEdits() is - * called to add the type delete edits. - */ - @Override - @SuppressWarnings("unchecked") - protected Iterable<DeleteEdit> createPersistenceXmlDeleteEdits(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<DeleteEdit>( - super.createPersistenceXmlDeleteEdits(persistenceUnit), - new CompositeIterable<DeleteEdit>( - new TransformationIterable<IFile, Iterable<DeleteEdit>>(this.getMappingFilesOnClasspath(persistenceUnit.getJpaProject())) { - @Override - protected Iterable<DeleteEdit> transform(IFile file) { - return persistenceUnit.createDeleteMappingFileEdits(file); - } - } - ) - ); - } - - @SuppressWarnings("unchecked") - protected Iterable<IFile> getMappingFilesOnClasspath(final JpaProject jpaProject) { - final IJavaProject javaProject = jpaProject.getJavaProject(); - return new FilteringIterable<IFile>(new CompositeIterable<IFile>( - getPossibleMappingFilesInFolders(), - getPossibleMappingFilesInPackageFragments())) - { - @Override - protected boolean accept(IFile file) { - return javaProject.isOnClasspath(file) - && PlatformTools.getContentType(file).isKindOf(JptCorePlugin.MAPPING_FILE_CONTENT_TYPE); - } - }; - } - - protected Iterable<IFile> getPossibleMappingFilesInFolders() { - Collection<IFile> files = new ArrayList<IFile>(); - FolderResourceProxyVisitor visitor = new FolderResourceProxyVisitor(files); - for (IFolder folder : this.folders) { - visitor.visitFolder(folder); - } - return files; - } - - protected Iterable<IFile> getPossibleMappingFilesInPackageFragments() { - return new CompositeIterable<IFile>( - new TransformationIterable<IPackageFragment, Iterable<IFile>>(this.packageFragments) { - @Override - protected Iterable<IFile> transform(IPackageFragment packageFragment) { - return getNonJavaFiles(packageFragment); - } - } - ); - } - - protected static Iterable<IFile> getNonJavaFiles(IPackageFragment packageFragment) { - Collection<IFile> files = new ArrayList<IFile>(); - Object[] resources = getNonJavaResources(packageFragment); - for (Object resource : resources) { - if (resource instanceof IFile) { - files.add((IFile) resource); - } - } - return files; - } - - protected static Object[] getNonJavaResources(IPackageFragment packageFragment) { - try { - return packageFragment.getNonJavaResources(); - } - catch (JavaModelException e) { - JptCorePlugin.log(e); - return EMPTY_OBJECT_ARRAY; - } - } - - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - protected class FolderResourceProxyVisitor implements IResourceProxyVisitor { - private Collection<IFile> files; - protected FolderResourceProxyVisitor(Collection<IFile> files) { - super(); - this.files = files; - } - protected void visitFolder(IFolder folder) { - try { - folder.accept(this, IResource.NONE); - } catch (CoreException ex) { - // shouldn't happen - we don't throw any CoreExceptions - throw new RuntimeException(ex); - } - } - public boolean visit(IResourceProxy resource) { - switch (resource.getType()) { - case IResource.FOLDER : - return true; // visit children - case IResource.FILE : - this.files.add((IFile) resource.requestResource()); - return false; // no children - default : - return false; // no children - } - } - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteTypeParticipant.java deleted file mode 100644 index e0b7fd8dba..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaDeleteTypeParticipant.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * 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.IType; -import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; - -public class JpaDeleteTypeParticipant - extends AbstractJpaDeleteTypeParticipant - implements ISharableParticipant -{ - - public JpaDeleteTypeParticipant() { - super(); - } - - @Override - protected boolean initialize(Object element) { - this.addElement(element, getArguments()); - return true; - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_DELETE_TYPE_REFACTORING_PARTICIPANT_NAME; - } - - - //****************ISharableParticipant implementation ***************** - - /** - * This is used when multiple ITypes are deleted. - * RefactoringParticipant#initialize(Object) is called for the first deleted IType. - * RefactoringParticipant#getArguments() only applies to the first deleted IType - */ - public void addElement(Object element, RefactoringArguments arguments) { - this.addType((IType) element); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveFolderParticipant.java deleted file mode 100644 index e933786fe7..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveFolderParticipant.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * 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.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jdt.core.IJavaProject; -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.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -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.ISharableParticipant; -import org.eclipse.ltk.core.refactoring.participants.MoveArguments; -import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; -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 move refactoring of {@link IFolders}s. - * Any mapping file references in the persistence.xml will be updated to reflect the new location. - */ -public class JpaMoveFolderParticipant - extends MoveParticipant - implements ISharableParticipant -{ - - /** - * Store the {@link IFolder}s to be moved and their corresponding MoveArguments - */ - protected final Map<IFolder, MoveArguments> originalFolders; - - /** - * Store the persistence.xml ReplaceEdit in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlReplaceEdits; - - public JpaMoveFolderParticipant() { - super(); - this.originalFolders = new HashMap<IFolder, MoveArguments>(); - this.persistenceXmlReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_MOVE_FOLDER_REFACTORING_PARTICIPANT_NAME; - } - - @Override - protected boolean initialize(Object element) { - if (!getArguments().getUpdateReferences()) { - return false; - } - this.addElement(element, getArguments()); - return true; - } - - //****************ISharableParticipant implementation ***************** - - /** - * This is used when multiple folders are moved. - * RefactoringParticipant#initialize(Object) is called for the first moved IFolder. - * RefactoringParticipant#getArguments() only applies to the first moved IFolder. - */ - public void addElement(Object element, RefactoringArguments arguments) { - this.originalFolders.put((IFolder) element, (MoveArguments) arguments); - } - - protected MoveArguments getArguments(IFolder element) { - return this.originalFolders.get(element); - } - - - //**************** 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_MOVE_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.createPersistenceUnitReplaceEditsCheckClasspath(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_MOVE_FOLDER_REFACTORING_SUB_TASK_NAME); - CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_MOVE_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; - } - - protected Iterable<ReplaceEdit> createPersistenceUnitReplaceEditsCheckClasspath(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<ReplaceEdit>( - new TransformationIterable<IFolder, Iterable<ReplaceEdit>>(this.getOriginalFoldersOnClasspath(persistenceUnit.getJpaProject())) { - @Override - protected Iterable<ReplaceEdit> transform(IFolder folder) { - return createPersistenceUnitReplaceEdits(persistenceUnit, folder, (IContainer) getArguments(folder).getDestination()); - } - } - ); - } - - protected Iterable<IFolder> getOriginalFoldersOnClasspath(final JpaProject jpaProject) { - final IJavaProject javaProject = jpaProject.getJavaProject(); - return new FilteringIterable<IFolder>(this.originalFolders.keySet()) { - @Override - protected boolean accept(IFolder folder) { - return javaProject.isOnClasspath(folder); - } - }; - } - - protected Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(PersistenceUnit persistenceUnit, IFolder folder, IContainer destination) { - IProject project = destination.getProject(); - IPath fullPath = destination.getFullPath().append(folder.getName()); - IPath runtimePath = JptCorePlugin.getResourceLocator(project).getRuntimePath(project, fullPath); - return persistenceUnit.createMoveFolderEdits(folder, runtimePath); - } - - protected void addPersistenceXmlRenameChange(IFile persistenceXmlFile, CompositeChange compositeChange) { - TextChange textChange = getTextChange(persistenceXmlFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_MOVE_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/JpaMoveMappingFileParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveMappingFileParticipant.java deleted file mode 100644 index 1133f581fe..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveMappingFileParticipant.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * 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.IProject; -import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jdt.core.IJavaProject; -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.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.FilteringIterable; -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.ISharableParticipant; -import org.eclipse.ltk.core.refactoring.participants.MoveArguments; -import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; -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 IFile}s with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE}. - * 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 JpaMoveMappingFileParticipant - extends MoveParticipant - implements ISharableParticipant -{ - - /** - * Store the {@link IFile}s to be renamed with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE} - * and their corresponding {@link MoveArguments} - */ - protected final Map<IFile, MoveArguments> originalMappingFiles; - - /** - * Store the persistence.xml ReplaceEdit in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlMappingFileReplaceEdits; - - public JpaMoveMappingFileParticipant() { - super(); - this.originalMappingFiles = new HashMap<IFile, MoveArguments>(); - this.persistenceXmlMappingFileReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_MOVE_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME; - } - - @Override - protected boolean initialize(Object element) { - if (!getArguments().getUpdateReferences()) { - return false; - } - this.addElement(element, getArguments()); - return true; - } - - //****************ISharableParticipant implementation ***************** - - /** - * This is used when multiple mapping files are deleted. - * RefactoringParticipant#initialize(Object) is called for the first deleted IFile. - * RefactoringParticipant#getArguments() only applies to the first deleted IFile - */ - public void addElement(Object element, RefactoringArguments arguments) { - this.originalMappingFiles.put((IFile) element, (MoveArguments) arguments); - } - - protected MoveArguments getArguments(IFile element) { - return this.originalMappingFiles.get(element); - } - - - //**************** 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_MOVE_MAPPING_FILE_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.persistenceXmlMappingFileReplaceEdits.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.createPersistenceUnitReplaceEditsCheckClasspath(persistenceUnit); - if (!CollectionTools.isEmpty(replaceEdits)) { - this.persistenceXmlMappingFileReplaceEdits.put(jpaProject.getPersistenceXmlResource().getFile(), replaceEdits); - } - } - - @Override - public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { - if (this.persistenceXmlMappingFileReplaceEdits.isEmpty()) { - return null; - } - SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlMappingFileReplaceEdits.size()); - sm.subTask(JpaCoreRefactoringMessages.JPA_MOVE_MAPPING_FILE_REFACTORING_SUB_TASK_NAME); - CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_MOVE_MAPPING_FILE_REFACTORING_CHANGE_NAME); - for (IFile persistenceXmlFile : this.persistenceXmlMappingFileReplaceEdits.keySet()) { - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - this.addPersistenceXmlRenameMappingFileChange(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; - } - - - protected Iterable<ReplaceEdit> createPersistenceUnitReplaceEditsCheckClasspath(final PersistenceUnit persistenceUnit) { - return new CompositeIterable<ReplaceEdit>( - new TransformationIterable<IFile, Iterable<ReplaceEdit>>(this.getOriginalFoldersOnClasspath(persistenceUnit.getJpaProject())) { - @Override - protected Iterable<ReplaceEdit> transform(IFile mappingFile) { - return createPersistenceUnitReplaceEdits(persistenceUnit, mappingFile, (IFolder) getArguments(mappingFile).getDestination()); - } - } - ); - } - - protected Iterable<IFile> getOriginalFoldersOnClasspath(final JpaProject jpaProject) { - final IJavaProject javaProject = jpaProject.getJavaProject(); - return new FilteringIterable<IFile>(this.originalMappingFiles.keySet()) { - @Override - protected boolean accept(IFile file) { - return javaProject.isOnClasspath(file); - } - }; - } - - private Iterable<ReplaceEdit> createPersistenceUnitReplaceEdits(PersistenceUnit persistenceUnit, IFile mappingFile, IFolder destination) { - IProject project = destination.getProject(); - IPath fullPath = destination.getFullPath(); - IPath runtimePath = JptCorePlugin.getResourceLocator(project).getRuntimePath(project, fullPath); - return persistenceUnit.createMoveMappingFileEdits(mappingFile, runtimePath); - } - - protected void addPersistenceXmlRenameMappingFileChange(IFile persistenceXmlFile, CompositeChange compositeChange) { - TextChange textChange = getTextChange(persistenceXmlFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_MOVE_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME, persistenceXmlFile); - MultiTextEdit multiTextEdit = new MultiTextEdit(); - textChange.setEdit(multiTextEdit); - compositeChange.add(textChange); - } - Iterable<ReplaceEdit> mappingFileReplaceEdits = this.persistenceXmlMappingFileReplaceEdits.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/JpaMoveTypeParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveTypeParticipant.java deleted file mode 100644 index 96f9b0bb26..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaMoveTypeParticipant.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * 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.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; -import org.eclipse.text.edits.ReplaceEdit; - -public class JpaMoveTypeParticipant - extends AbstractJpaMoveJavaElementParticipant { - - public JpaMoveTypeParticipant() { - super(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_MOVE_TYPE_REFACTORING_PARTICIPANT_NAME; - } - - @Override - public void addElement(Object element, RefactoringArguments arguments) { - super.addElement(element, arguments); - this.addNestedTypes((IType) element, arguments); - } - - protected void addNestedType(IType renamedType, RefactoringArguments arguments) { - super.addElement(renamedType, arguments); - this.addNestedTypes(renamedType, arguments); - } - - private void addNestedTypes(IType renamedType, RefactoringArguments arguments) { - IType[] nestedTypes; - try { - nestedTypes = renamedType.getTypes(); - } - catch (JavaModelException ex) { - JptCorePlugin.log(ex); - return; - } - - for (IType nestedType : nestedTypes) { - this.addNestedType(nestedType, arguments); - } - } - - - //**************** AbstractJpaRenameJavaElementParticipant implementation ***************** - - @Override - protected Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit, IJavaElement javaElement, Object destination) { - IType type = (IType) javaElement; - if (((IJavaElement) destination).getElementType() == IJavaElement.PACKAGE_FRAGMENT) { - return persistenceUnit.createMoveTypeEdits(type, (IPackageFragment) destination); - } - return persistenceUnit.createRenameTypeEdits(type, getNewNameForNestedType(type, (IType) destination)); - } - - @Override - protected Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef, IJavaElement javaElement, Object destination) { - IType type = (IType) javaElement; - if (((IJavaElement) destination).getElementType() == IJavaElement.PACKAGE_FRAGMENT) { - return mappingFileRef.createMoveTypeEdits(type, (IPackageFragment) destination); - } - return mappingFileRef.createRenameTypeEdits(type, getNewNameForNestedType(type, (IType) destination)); - } - - protected String getNewNameForNestedType(IType nestedType, IType destination) { - return nestedType.getTypeQualifiedName('$').replaceFirst(nestedType.getDeclaringType().getElementName(), destination.getElementName()); - } - - protected IPackageFragment getNewPackage() { - return (IPackageFragment) getArguments().getDestination(); - } - - @Override - protected String getCheckConditionsSubTaskName() { - return JpaCoreRefactoringMessages.JPA_MOVE_TYPE_REFACTORING_SUB_TASK_NAME; - } - - @Override - protected String getCreateChangeSubTaskName() { - return JpaCoreRefactoringMessages.JPA_MOVE_TYPE_REFACTORING_SUB_TASK_NAME; - } - - @Override - protected String getCompositeChangeName() { - return JpaCoreRefactoringMessages.JPA_MOVE_TYPE_REFACTORING_CHANGE_NAME; - } - - @Override - protected String getPersistenceXmlChangeName() { - return JpaCoreRefactoringMessages.JPA_MOVE_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - } - - @Override - protected String getMappingFileChangeName() { - return JpaCoreRefactoringMessages.JPA_MOVE_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/refactoring/JpaRenameFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java deleted file mode 100644 index 9a50ebd17d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameFolderParticipant.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * 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.createRenameFolderEdits(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 deleted file mode 100644 index 68d08148cc..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameMappingFileParticipant.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * 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.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.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 IFile}s with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE}. - * 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 JpaRenameMappingFileParticipant - extends RenameParticipant -{ - - /** - * Store the {@link IFile}s to be renamed with content type {@link JptCorePlugin#MAPPING_FILE_CONTENT_TYPE} - */ - - protected IFile originalMappingFile; - - /** - * Store the persistence.xml ReplaceEdit in the checkConditions() call - * to avoid duplicated effort in createChange(). - */ - protected final Map<IFile, Iterable<ReplaceEdit>> persistenceXmlMappingFileReplaceEdits; - - public JpaRenameMappingFileParticipant() { - super(); - this.persistenceXmlMappingFileReplaceEdits = new HashMap<IFile, Iterable<ReplaceEdit>>(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_RENAME_MAPPING_FILE_REFACTORING_PARTICIPANT_NAME; - } - - @Override - protected boolean initialize(Object element) { - if (!getArguments().getUpdateReferences()) { - return false; - } - this.originalMappingFile = (IFile) 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_MAPPING_FILE_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.persistenceXmlMappingFileReplaceEdits.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.createMappingFileRefReplaceEdits(persistenceUnit); - if (!CollectionTools.isEmpty(replaceEdits)) { - this.persistenceXmlMappingFileReplaceEdits.put(jpaProject.getPersistenceXmlResource().getFile(), replaceEdits); - } - } - - @Override - public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { - if (this.persistenceXmlMappingFileReplaceEdits.isEmpty()) { - return null; - } - SubMonitor sm = SubMonitor.convert(monitor, this.persistenceXmlMappingFileReplaceEdits.size()); - sm.subTask(JpaCoreRefactoringMessages.JPA_RENAME_MAPPING_FILE_REFACTORING_SUB_TASK_NAME); - CompositeChange compositeChange = new CompositeChange(JpaCoreRefactoringMessages.JPA_RENAME_MAPPING_FILE_REFACTORING_CHANGE_NAME); - for (IFile persistenceXmlFile : this.persistenceXmlMappingFileReplaceEdits.keySet()) { - if (sm.isCanceled()) { - throw new OperationCanceledException(); - } - this.addPersistenceXmlRenameMappingFileChange(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> createMappingFileRefReplaceEdits(final PersistenceUnit persistenceUnit) { - return persistenceUnit.createRenameMappingFileEdits(this.originalMappingFile, getArguments().getNewName()); - } - - protected void addPersistenceXmlRenameMappingFileChange(IFile persistenceXmlFile, CompositeChange compositeChange) { - TextChange textChange = getTextChange(persistenceXmlFile); - if (textChange == null) { - textChange = new TextFileChange(JpaCoreRefactoringMessages.JPA_RENAME_MAPPING_FILE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME, persistenceXmlFile); - MultiTextEdit multiTextEdit = new MultiTextEdit(); - textChange.setEdit(multiTextEdit); - compositeChange.add(textChange); - } - Iterable<ReplaceEdit> mappingFileReplaceEdits = this.persistenceXmlMappingFileReplaceEdits.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/JpaRenamePackageParticipant.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java deleted file mode 100644 index cff31cf88d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenamePackageParticipant.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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.createRenamePackageEdits(this.getOriginalPackage(), this.getNewName()); - } - - @Override - protected Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef) { - return mappingFileRef.createRenamePackageEdits(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 deleted file mode 100644 index 0668838912..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/refactoring/JpaRenameTypeParticipant.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * 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 org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.text.edits.ReplaceEdit; - -//TODO RenameTypeArguments.updateSimilarDeclarations() - http://www.eclipse.org/jdt/ui/r3_2/RenameType.html -public class JpaRenameTypeParticipant - extends AbstractJpaRenameJavaElementParticipant { - - protected final Collection<IType> nestedTypes; - - public JpaRenameTypeParticipant() { - super(); - this.nestedTypes = new ArrayList<IType>(); - } - - @Override - public String getName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_PARTICIPANT_NAME; - } - - protected IType getOriginalType() { - return (IType) super.getOriginalJavaElement(); - } - - @Override - protected boolean initialize(Object element) { - boolean initialize = super.initialize(element); - if (initialize) { - this.addNestedTypes(this.getOriginalType()); - return true; - } - return false; - } - - 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); - } - } - - - //**************** AbstractJpaRenameJavaElementParticipant implementation ***************** - - @SuppressWarnings("unchecked") - @Override - protected Iterable<ReplaceEdit> createPersistenceXmlReplaceEdits(PersistenceUnit persistenceUnit) { - return new CompositeIterable<ReplaceEdit>( - this.createPersistenceXmlReplaceOriginalTypeEdits(persistenceUnit), - this.createPersistenceXmlReplaceNestedTypeEdits(persistenceUnit)); - } - - private Iterable<ReplaceEdit> createPersistenceXmlReplaceOriginalTypeEdits(PersistenceUnit persistenceUnit) { - return persistenceUnit.createRenameTypeEdits(this.getOriginalType(), 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.createRenameTypeEdits(nestedType, newName); - } - } - ); - } - - @SuppressWarnings("unchecked") - @Override - protected Iterable<ReplaceEdit> createMappingFileReplaceEdits(MappingFileRef mappingFileRef) { - return new CompositeIterable<ReplaceEdit>( - this.createMappingFileReplaceOriginalTypeEdits(mappingFileRef), - this.createMappingFileReplaceNestedTypeEdits(mappingFileRef)); - } - - private Iterable<ReplaceEdit> createMappingFileReplaceOriginalTypeEdits(MappingFileRef mappingFileRef) { - return mappingFileRef.createRenameTypeEdits(this.getOriginalType(), 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.createRenameTypeEdits(nestedType, newName); - } - } - ); - } - - protected String getNewName() { - String newName = getArguments().getNewName(); - try { - if (this.getOriginalType().isMember()) { - newName = this.getOriginalType().getTypeQualifiedName().substring(0, this.getOriginalType().getTypeQualifiedName().lastIndexOf('$')) + '$' + newName; - } - } - catch (JavaModelException e) { - JptCorePlugin.log(e); - } - return newName; - } - - protected String getNewNameForNestedType(IType nestedType) { - return nestedType.getTypeQualifiedName('$').replaceFirst(this.getOriginalType().getElementName(), getArguments().getNewName()); - } - - @Override - protected String getCheckConditionsSubTaskName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME; - } - - @Override - protected String getCreateChangeSubTaskName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_SUB_TASK_NAME; - } - - @Override - protected String getCompositeChangeName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_NAME; - } - - @Override - protected String getPersistenceXmlChangeName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_PERSISTENCE_XML_NAME; - } - - @Override - protected String getMappingFileChangeName() { - return JpaCoreRefactoringMessages.JPA_RENAME_TYPE_REFACTORING_CHANGE_MAPPING_FILE_NAME; - } -}
\ No newline at end of file |