summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2013-01-10 11:36:15 (EST)
committerKaren Butzke2013-01-10 11:36:15 (EST)
commit92d98d72d1a904738bc870f8ce2820738db6fa0f (patch)
treef2d5dd52b4cadb91746c1d1851aedc5aec770fa5
parenta46bb1fd29fcc76d7dc37282dd69866a94cad07d (diff)
downloadwebtools.dali-92d98d72d1a904738bc870f8ce2820738db6fa0f.zip
webtools.dali-92d98d72d1a904738bc870f8ce2820738db6fa0f.tar.gz
webtools.dali-92d98d72d1a904738bc870f8ce2820738db6fa0f.tar.bz2
397606 - JPA Java Change Event Handler (Waiting) - limit the number of these jobs that are kicked off an then promptly ignored by each JpaProject - many are appearing when building the refactoring preview dialog, for every working copy created and discarded.
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java36
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java119
2 files changed, 136 insertions, 19 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 6279660..af991c9 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2013 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.
@@ -1250,6 +1250,12 @@ public abstract class AbstractJpaProject
/**
* We recurse back here from {@link #processJavaDeltaChildren(IJavaElementDelta)}.
+ *
+ * <br> <b>
+ * This code has been copied and modified in InternalJpaProjectManager, so make sure
+ * to make changes in both locations.
+ * </b>
+ * @see InternalJpaProjectManager#javaElementChanged(ElementChangedEvent)
*/
protected void processJavaDelta(IJavaElementDelta delta) {
switch (delta.getElement().getElementType()) {
@@ -1289,7 +1295,7 @@ public abstract class AbstractJpaProject
* {@link IJavaElementDelta#getKind() kind} is
* {@link IJavaElementDelta#CHANGED CHANGED}.)
*/
- protected boolean deltaFlagIsSet(IJavaElementDelta delta, int flag) {
+ protected static boolean deltaFlagIsSet(IJavaElementDelta delta, int flag) {
return (delta.getKind() == IJavaElementDelta.CHANGED) &&
BitTools.flagIsSet(delta.getFlags(), flag);
}
@@ -1306,7 +1312,7 @@ public abstract class AbstractJpaProject
this.processJavaDeltaChildren(delta);
// a classpath change can have pretty far-reaching effects...
- if (this.classpathHasChanged(delta)) {
+ if (classpathHasChanged(delta)) {
this.rebuild((IJavaProject) delta.getElement());
}
}
@@ -1376,8 +1382,8 @@ public abstract class AbstractJpaProject
* pre-condition:
* delta.getElement().getElementType() == IJavaElement.JAVA_PROJECT
*/
- protected boolean classpathHasChanged(IJavaElementDelta delta) {
- return this.deltaFlagIsSet(delta, IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED);
+ protected static boolean classpathHasChanged(IJavaElementDelta delta) {
+ return deltaFlagIsSet(delta, IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED);
}
protected void synchronizeWithJavaSource(Iterable<JavaResourceCompilationUnit> javaResourceCompilationUnits) {
@@ -1391,9 +1397,9 @@ public abstract class AbstractJpaProject
// process the Java package fragment root's package fragments
this.processJavaDeltaChildren(delta);
- if (this.classpathEntryHasBeenAdded(delta)) {
+ if (classpathEntryHasBeenAdded(delta)) {
// TODO bug 277218
- } else if (this.classpathEntryHasBeenRemoved(delta)) { // should be mutually-exclusive w/added (?)
+ } else if (classpathEntryHasBeenRemoved(delta)) { // should be mutually-exclusive w/added (?)
// TODO bug 277218
}
}
@@ -1402,16 +1408,16 @@ public abstract class AbstractJpaProject
* pre-condition:
* delta.getElement().getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT
*/
- protected boolean classpathEntryHasBeenAdded(IJavaElementDelta delta) {
- return this.deltaFlagIsSet(delta, IJavaElementDelta.F_ADDED_TO_CLASSPATH);
+ protected static boolean classpathEntryHasBeenAdded(IJavaElementDelta delta) {
+ return deltaFlagIsSet(delta, IJavaElementDelta.F_ADDED_TO_CLASSPATH);
}
/**
* pre-condition:
* delta.getElement().getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT
*/
- protected boolean classpathEntryHasBeenRemoved(IJavaElementDelta delta) {
- return this.deltaFlagIsSet(delta, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
+ protected static boolean classpathEntryHasBeenRemoved(IJavaElementDelta delta) {
+ return deltaFlagIsSet(delta, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
}
// ***** package fragment
@@ -1422,7 +1428,7 @@ public abstract class AbstractJpaProject
// ***** compilation unit
protected void processJavaCompilationUnitDelta(IJavaElementDelta delta) {
- if (this.javaCompilationUnitDeltaIsRelevant(delta)) {
+ if (javaCompilationUnitDeltaIsRelevant(delta)) {
ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement();
for (JavaResourceCompilationUnit jrcu : this.getCombinedJavaResourceCompilationUnits()) {
if (jrcu.getCompilationUnit().equals(compilationUnit)) {
@@ -1435,7 +1441,7 @@ public abstract class AbstractJpaProject
// ignore the java compilation unit's children
}
- protected boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) {
+ protected static boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) {
// ignore Java notification for ADDED or REMOVED;
// these are handled via resource notification
if (delta.getKind() != IJavaElementDelta.CHANGED) {
@@ -1453,7 +1459,7 @@ public abstract class AbstractJpaProject
// because the AST parser will log an exception for the missing file
if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_RESOURCE)) {
ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement();
- if ( ! this.compilationUnitResourceExists(compilationUnit)) {
+ if ( ! compilationUnitResourceExists(compilationUnit)) {
return false;
}
}
@@ -1461,7 +1467,7 @@ public abstract class AbstractJpaProject
return true;
}
- protected boolean compilationUnitResourceExists(ICompilationUnit compilationUnit) {
+ protected static boolean compilationUnitResourceExists(ICompilationUnit compilationUnit) {
try {
return compilationUnit.getCorrespondingResource().exists();
} catch (JavaModelException ex) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
index f926859..6855560 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/InternalJpaProjectManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2013 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.
@@ -34,6 +34,8 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.common.core.internal.JptCommonCoreMessages;
import org.eclipse.jpt.common.core.internal.utility.ProjectTools;
@@ -852,9 +854,11 @@ class InternalJpaProjectManager
// ********** Java element changed **********
/* CU private */ void javaElementChanged(ElementChangedEvent event) {
- JptJpaCorePlugin.instance().trace(TRACE_OPTION, "dispatch: Java element changed: {0}", event.getDelta()); //$NON-NLS-1$
- JavaChangeEventHandlerCommand command = new JavaChangeEventHandlerCommand(event);
- this.execute(command, JptCoreMessages.JAVA_CHANGE_EVENT_HANDLER_JOB_NAME, this.getWorkspaceRoot());
+ if (this.handleJavaElementChangedEvent(event)) {
+ JptJpaCorePlugin.instance().trace(TRACE_OPTION, "dispatch: Java element changed: {0}", event.getDelta()); //$NON-NLS-1$
+ JavaChangeEventHandlerCommand command = new JavaChangeEventHandlerCommand(event);
+ this.execute(command, JptCoreMessages.JAVA_CHANGE_EVENT_HANDLER_JOB_NAME, this.getWorkspaceRoot());
+ }
}
/* CU private */ class JavaChangeEventHandlerCommand
@@ -893,6 +897,113 @@ class InternalJpaProjectManager
}
}
+ /**
+ * Check to see if we should even handle this particular java event. If it
+ * needs to be handled then we will kick off our 'JPA Java Change Event Handler' job.
+ * If any change in the event needs to be handled, we short-circuit out and
+ * return true. Each JpaProject then makes the same checks to determine
+ * which changes are of concern. We are trying to limit the number
+ * of 'JPA Java Change Event Handler' jobs that are run.
+ * <br> <b>
+ * This code was copied and modified from AbstractJpaProject, so make sure
+ * to make changes in both locations.
+ * </b>
+ * @see AbstractJpaProject#processJavaDelta(IJavaElementDelta)
+ */
+ private boolean handleJavaElementChangedEvent(ElementChangedEvent event) {
+ return this.handleJavaDelta(event.getDelta());
+ }
+
+ /**
+ * We recurse back here from {@link #handleJavaDeltaChildren(IJavaElementDelta)}.
+ */
+ protected boolean handleJavaDelta(IJavaElementDelta delta) {
+ switch (delta.getElement().getElementType()) {
+ case IJavaElement.JAVA_MODEL :
+ return this.handleJavaModelDelta(delta);
+ case IJavaElement.JAVA_PROJECT :
+ return this.handleJavaProjectDelta(delta);
+ case IJavaElement.PACKAGE_FRAGMENT_ROOT :
+ return this.handleJavaPackageFragmentRootDelta(delta);
+ case IJavaElement.PACKAGE_FRAGMENT :
+ return this.processJavaPackageFragmentDelta(delta);
+ case IJavaElement.COMPILATION_UNIT :
+ return this.handleJavaCompilationUnitDelta(delta);
+ default :
+ break; // ignore the elements inside a compilation unit
+ }
+ return false;
+ }
+
+ protected boolean handleJavaDeltaChildren(IJavaElementDelta delta) {
+ for (IJavaElementDelta child : delta.getAffectedChildren()) {
+ if (this.handleJavaDelta(child)) { // recurse
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // ***** model
+ protected boolean handleJavaModelDelta(IJavaElementDelta delta) {
+ // process the Java model's projects
+ return this.handleJavaDeltaChildren(delta);
+ }
+
+ // ***** project
+ protected boolean handleJavaProjectDelta(IJavaElementDelta delta) {
+ // process the Java project's package fragment roots
+ boolean handle = this.handleJavaDeltaChildren(delta);
+ if (handle) {
+ //if any child needs to be handled, we're done
+ return handle;
+ }
+
+ // a classpath change can have pretty far-reaching effects...
+ if (AbstractJpaProject.classpathHasChanged(delta)) {
+ return true;
+ }
+ return false;
+ }
+
+ // ***** package fragment root
+ protected boolean handleJavaPackageFragmentRootDelta(IJavaElementDelta delta) {
+ // process the Java package fragment root's package fragments
+ boolean handle = this.handleJavaDeltaChildren(delta);
+ if (handle) {
+ //if any child needs to be handled, we're done
+ return handle;
+ }
+
+ if (AbstractJpaProject.classpathEntryHasBeenAdded(delta)) {
+ return true;
+ // TODO bug 277218
+ } else if (AbstractJpaProject.classpathEntryHasBeenRemoved(delta)) { // should be mutually-exclusive w/added (?)
+ return true;
+ // TODO bug 277218
+ }
+ return false;
+ }
+
+ // ***** package fragment
+ protected boolean processJavaPackageFragmentDelta(IJavaElementDelta delta) {
+ // process the java package fragment's compilation units
+ return this.handleJavaDeltaChildren(delta);
+ }
+
+ // ***** compilation unit
+ protected boolean handleJavaCompilationUnitDelta(IJavaElementDelta delta) {
+ if (this.javaCompilationUnitDeltaIsRelevant(delta)) {
+ return true;
+ }
+ // ignore the java compilation unit's children
+ return false;
+ }
+
+ protected boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) {
+ return AbstractJpaProject.javaCompilationUnitDeltaIsRelevant(delta);
+ }
+
// ********** support for modifying documents shared with the UI **********