diff options
author | kmoore | 2012-04-24 12:55:19 +0000 |
---|---|---|
committer | kmoore | 2012-04-24 12:55:19 +0000 |
commit | 96ca6e501d74bc83e2c200a44b0f4ab3645bdbc9 (patch) | |
tree | 13a18555ffc60d374818f75d1c80ccb9839d66c3 /jpa/plugins/org.eclipse.jpt.jpa.core | |
parent | bf75d6eed672c6df2e2bb9dddb409374c993f155 (diff) | |
download | webtools.dali-96ca6e501d74bc83e2c200a44b0f4ab3645bdbc9.tar.gz webtools.dali-96ca6e501d74bc83e2c200a44b0f4ab3645bdbc9.tar.xz webtools.dali-96ca6e501d74bc83e2c200a44b0f4ab3645bdbc9.zip |
370407 - more performance improvements for cleaning a project and refactoring classes
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core')
3 files changed, 51 insertions, 18 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java index e095505773..3bb886a67e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java @@ -12,6 +12,7 @@ package org.eclipse.jpt.jpa.core.internal; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,7 +48,6 @@ import org.eclipse.jpt.common.core.JptResourceModel; import org.eclipse.jpt.common.core.JptResourceModelListener; import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryTypeCache; import org.eclipse.jpt.common.core.internal.resource.java.source.SourceTypeCompilationUnit; -import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.common.core.internal.utility.command.NotifyingRepeatingJobCommandWrapper; import org.eclipse.jpt.common.core.internal.utility.command.RepeatingJobCommandWrapper; import org.eclipse.jpt.common.core.resource.ProjectResourceLocator; @@ -138,12 +138,14 @@ public abstract class AbstractJpaProject protected final JpaPlatform jpaPlatform; /** + * key - IFile associated with the JpaFile. + * value - the JpaFile * The JPA files associated with the JPA project: * persistence.xml * orm.xml * java */ - protected final Vector<JpaFile> jpaFiles = new Vector<JpaFile>(); + protected final Hashtable<IFile, JpaFile> jpaFiles = new Hashtable<IFile, JpaFile>(); /** * The "external" Java resource compilation units (source). Populated upon demand. @@ -521,7 +523,7 @@ public abstract class AbstractJpaProject // ********** JPA files ********** public Iterable<JpaFile> getJpaFiles() { - return new LiveCloneIterable<JpaFile>(this.jpaFiles); // read-only + return new LiveCloneIterable<JpaFile>(this.jpaFiles.values()); // read-only } public int getJpaFilesSize() { @@ -539,12 +541,7 @@ public abstract class AbstractJpaProject @Override public JpaFile getJpaFile(IFile file) { - for (JpaFile jpaFile : this.getJpaFiles()) { - if (jpaFile.getFile().equals(file)) { - return jpaFile; - } - } - return null; + return this.jpaFiles.get(file); } /** @@ -580,7 +577,7 @@ public abstract class AbstractJpaProject return null; } jpaFile.getResourceModel().addResourceModelListener(this.resourceModelListener); - this.jpaFiles.add(jpaFile); + this.jpaFiles.put(file, jpaFile); return jpaFile; } @@ -588,7 +585,7 @@ public abstract class AbstractJpaProject * <code>.java</code> or <code>.jar</code> */ protected boolean fileIsJavaRelated(IFile file) { - IContentType contentType = PlatformTools.getContentType(file); + IContentType contentType = getContentType(file); return (contentType != null) && this.contentTypeIsJavaRelated(contentType); } @@ -639,9 +636,10 @@ public abstract class AbstractJpaProject */ protected void removeJpaFile(JpaFile jpaFile) { jpaFile.getResourceModel().removeResourceModelListener(this.resourceModelListener); - if ( ! this.removeItemFromCollection(jpaFile, this.jpaFiles, JPA_FILES_COLLECTION)) { + if (this.jpaFiles.remove(jpaFile.getFile()) == null) { throw new IllegalArgumentException(jpaFile.toString()); } + this.fireItemRemoved(JPA_FILES_COLLECTION, jpaFile); } @@ -1705,7 +1703,7 @@ public abstract class AbstractJpaProject return this.addJpaFileMaybe(file); } - if (jpaFile.getContentType().equals(PlatformTools.getContentType(file))) { + if (jpaFile.getContentType().equals(getContentType(file))) { // content has not changed - ignore return false; } @@ -1782,7 +1780,7 @@ public abstract class AbstractJpaProject } protected boolean externalFileAdded(IFile file) { - IContentType contentType = PlatformTools.getContentType(file); + IContentType contentType = getContentType(file); if (contentType == null) { return false; } @@ -1796,7 +1794,7 @@ public abstract class AbstractJpaProject } protected boolean externalFileRemoved(IFile file) { - IContentType contentType = PlatformTools.getContentType(file); + IContentType contentType = getContentType(file); if (contentType == null) { return false; } @@ -1809,6 +1807,10 @@ public abstract class AbstractJpaProject return false; } + protected static IContentType getContentType(IFile file) { + return GenericJpaPlatform.getContentType(file); + } + protected void resolveExternalJavaTypes() { for (JavaResourceCompilationUnit jrcu : this.getExternalJavaResourceCompilationUnits()) { jrcu.resolveTypes(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java index 6a45d503d7..118f79e8a8 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/GenericJpaPlatform.java @@ -10,8 +10,11 @@ package org.eclipse.jpt.jpa.core.internal; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jpt.common.core.AnnotationProvider; +import org.eclipse.jpt.common.core.JptCommonCorePlugin; import org.eclipse.jpt.common.core.JptResourceModel; import org.eclipse.jpt.common.core.JptResourceType; import org.eclipse.jpt.common.core.internal.utility.PlatformTools; @@ -107,10 +110,38 @@ public class GenericJpaPlatform // ********** JPA file/resource models ********** public JpaFile buildJpaFile(JpaProject jpaProject, IFile file) { - IContentType contentType = PlatformTools.getContentType(file); + IContentType contentType = getContentType(file); return (contentType == null) ? null : this.buildJpaFile(jpaProject, file, contentType); } + //TODO make this a non-static method on JpaPlatform + //I have done this because our code PlatformTools.getContentType(IFile) opens an InputStream + //on the IFile in order to find the content type for our xml mapping files. This is expensive + //when called for every file in the project and is only needed for xml mapping files. For now + //I am attempting to find the content type just based on the file name first and short-circuiting + //if it is a .java or .class file. If we made this api on the JpaPlatform we could potentially + //check if it is XML content type and then only do the more expensive InputStream look-up + //in that case. Because we are extensible we can't be 100% certain that a "mapping file" + //has xml content type so we would allow this to be overridable. + public static IContentType getContentType(IFile file) { + IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(file.getName()); + if (contentType != null) { + if (contentType.equals(JptCommonCorePlugin.JAVA_SOURCE_CONTENT_TYPE)) { + return contentType; + } + if (contentType.equals(JAVA_CLASS_CONTENT_TYPE)) { + return contentType; + } + } + return PlatformTools.getContentType(file); + } + //TODO JptCommonCorePlugin.JAVA_CLASS_CONTENT_TYPE after API freeze + private static final IContentType JAVA_CLASS_CONTENT_TYPE = getContentType(JavaCore.PLUGIN_ID + ".javaClass");//$NON-NLS-1$ + + private static IContentType getContentType(String contentType) { + return Platform.getContentTypeManager().getContentType(contentType); + } + protected JpaFile buildJpaFile(JpaProject jpaProject, IFile file, IContentType contentType) { JptResourceModel resourceModel = this.buildResourceModel(jpaProject, file, contentType); return (resourceModel == null) ? null : this.jpaFactory.buildJpaFile(jpaProject, file, contentType, resourceModel); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java index 7ad6840b3b..a3ada7d411 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/refactoring/JpaDeletePackageOrFolderParticipant.java @@ -28,13 +28,13 @@ import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jpt.common.core.internal.utility.JDTTools; -import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; import org.eclipse.jpt.jpa.core.JpaProject; import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.jpa.core.internal.GenericJpaPlatform; import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant; import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments; import org.eclipse.ltk.core.refactoring.participants.RenameProcessor; @@ -178,7 +178,7 @@ public class JpaDeletePackageOrFolderParticipant @Override protected boolean accept(IFile file) { if (javaProject.isOnClasspath(file)) { - IContentType contentType = PlatformTools.getContentType(file); + IContentType contentType = GenericJpaPlatform.getContentType(file); return contentType != null && contentType.isKindOf(JptJpaCorePlugin.MAPPING_FILE_CONTENT_TYPE); } return false; |