summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2013-01-09 17:03:39 (EST)
committerKaren Butzke2013-01-09 17:19:46 (EST)
commitea8e1ddbea3b9e976f42acc07ebfe269ab66c4cf (patch)
tree28b0e9f2cd15f82e040b4340f754f4f2c5f96fc6
parent3ec1b412f486b758066382de22f0f41a7a554fa5 (diff)
downloadwebtools.dali-ea8e1ddbea3b9e976f42acc07ebfe269ab66c4cf.zip
webtools.dali-ea8e1ddbea3b9e976f42acc07ebfe269ab66c4cf.tar.gz
webtools.dali-ea8e1ddbea3b9e976f42acc07ebfe269ab66c4cf.tar.bz2
Bug 397606 - JPA Java Change Event Handler (Waiting) - limit the numberv201301092252
of these jobs that are kicked off and 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.java92
2 files changed, 109 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 5c3f539..e062424 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.
@@ -1254,6 +1254,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()) {
@@ -1293,7 +1299,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);
}
@@ -1310,7 +1316,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());
}
}
@@ -1380,8 +1386,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) {
@@ -1395,9 +1401,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
}
}
@@ -1406,16 +1412,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
@@ -1426,7 +1432,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)) {
@@ -1439,7 +1445,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) {
@@ -1457,7 +1463,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;
}
}
@@ -1465,7 +1471,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 d0e9801..97b40b1 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.
@@ -33,6 +33,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.command.CommandJobCommandAdapter;
@@ -770,9 +772,11 @@ public class InternalJpaProjectManager
// ********** Java element changed **********
/* CU private */ void javaElementChanged(ElementChangedEvent event) {
- debug("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)) {
+ debug("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
@@ -806,6 +810,86 @@ public 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
+ return this.handleJavaDeltaChildren(delta) ||
+ AbstractJpaProject.classpathHasChanged(delta);
+ }
+
+ // ***** package fragment root
+ protected boolean handleJavaPackageFragmentRootDelta(IJavaElementDelta delta) {
+ // process the Java package fragment root's package fragments
+ return this.handleJavaDeltaChildren(delta) ||
+ AbstractJpaProject.classpathEntryHasBeenAdded(delta) ||
+ AbstractJpaProject.classpathEntryHasBeenRemoved(delta);
+ }
+
+ // ***** 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) {
+ // ignore the java compilation unit's children
+ return AbstractJpaProject.javaCompilationUnitDeltaIsRelevant(delta);
+ }
+
// ********** support for modifying documents shared with the UI **********