aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-13 12:07:37 (EDT)
committersefftinge2009-03-13 12:07:37 (EDT)
commit1e1dcf3363de02701851bb5c6fb9acaf085b1488 (patch)
treeedd0de7a9ea23ebd432488d08ff383a21f63fed1
parentbd2c9d28d28d09fe4894c5b1343aeeb9d1f2ffd6 (diff)
downloadorg.eclipse.xtext-1e1dcf3363de02701851bb5c6fb9acaf085b1488.zip
org.eclipse.xtext-1e1dcf3363de02701851bb5c6fb9acaf085b1488.tar.gz
org.eclipse.xtext-1e1dcf3363de02701851bb5c6fb9acaf085b1488.tar.bz2
Fix: respect cancel status of validation job
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextResourceChecker.java14
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/XtextDocument.java10
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java3
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/utils/ValidationJob.java20
-rw-r--r--tests/org.eclipse.xtext.generator.tests/plugin.xml12
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/plugin.xml13
-rw-r--r--tests/org.eclipse.xtext.xtend.tests/plugin.xml14
7 files changed, 37 insertions, 49 deletions
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextResourceChecker.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextResourceChecker.java
index 793e0d6..777fd5f 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextResourceChecker.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/XtextResourceChecker.java
@@ -83,6 +83,8 @@ public class XtextResourceChecker {
if (!issues.isEmpty()) {
// update
for (Map<String, Object> map : issues) {
+ if (monitor.isCanceled())
+ return;
IMarker marker = file.createMarker(markerId);
Object lNr = map.get(IMarker.LINE_NUMBER);
String lineNR = "";
@@ -113,21 +115,31 @@ public class XtextResourceChecker {
* @param resource
* @return a {@link List} of {@link IMarker} attributes
*/
- public static List<Map<String, Object>> check(final Resource resource, Map<?, ?> context) {
+ public static List<Map<String, Object>> check(final Resource resource, Map<?, ?> context, IProgressMonitor monitor) {
List<Map<String, Object>> markers = new ArrayList<Map<String, Object>>();
try {
// Syntactical errors
// Collect EMF Resource Diagnostics
for (org.eclipse.emf.ecore.resource.Resource.Diagnostic error : resource.getErrors())
markers.add(markerFromXtextResourceDiagnostic(error, IMarker.SEVERITY_ERROR));
+
+ if (monitor.isCanceled())
+ return null;
+
for (org.eclipse.emf.ecore.resource.Resource.Diagnostic warning : resource.getWarnings())
markers.add(markerFromXtextResourceDiagnostic(warning, IMarker.SEVERITY_WARNING));
+
+ if (monitor.isCanceled())
+ return null;
+
boolean syntaxDiagFail = !markers.isEmpty();
logCheckStatus(resource, syntaxDiagFail, "Syntax");
for (EObject ele : resource.getContents()) {
try {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(ele, context);
+ if (monitor.isCanceled())
+ return null;
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
Map<String, Object> marker = markerFromEValidatorDiagnostic(childDiagnostic);
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/XtextDocument.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/XtextDocument.java
index e70df63..1721128 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/XtextDocument.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/model/XtextDocument.java
@@ -22,6 +22,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
@@ -233,8 +234,15 @@ public class XtextDocument extends Document implements IXtextDocument {
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(XtextDocument.class);
+ private final Object validationLock = new Object();
+ private Job validationJob;
private void checkAndUpdateMarkers() {
- new ValidationJob(this, file, CheckMode.FAST_ONLY,true).schedule();
+ synchronized(validationLock) {
+ if (validationJob != null)
+ validationJob.cancel();
+ validationJob = new ValidationJob(this, file, CheckMode.FAST_ONLY, true);
+ validationJob.schedule(250);
+ }
}
@SuppressWarnings("unchecked")
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java
index d8a09d2..4e4bf92 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/reconciler/XtextReconciler.java
@@ -172,6 +172,9 @@ public class XtextReconciler extends Job implements IReconciler {
@Override
protected IStatus run(IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
long start = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug("Preparing reconciliation.");
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/utils/ValidationJob.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/utils/ValidationJob.java
index 97cd05c..e6c5471 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/utils/ValidationJob.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/utils/ValidationJob.java
@@ -26,9 +26,7 @@ import org.eclipse.xtext.ui.core.editor.model.UnitOfWork;
import org.eclipse.xtext.validator.CheckMode;
/**
- *
* @author Dennis Hübner - Initial contribution and API
- *
*/
public final class ValidationJob extends Job {
private static final Logger log = Logger.getLogger(ValidationJob.class);
@@ -37,11 +35,11 @@ public final class ValidationJob extends Job {
private final IXtextDocument xtextDocument;
private final IFile iFile;
- private boolean deleteOldMarkers;
+ private final boolean deleteOldMarkers;
/**
* Constructs a ValidationJob with a specified {@link CheckMode}
- *
+ *
* @param xtextEditor
* @param checkMode
*/
@@ -52,7 +50,7 @@ public final class ValidationJob extends Job {
/**
* Constructs a ValidationJob with a specified {@link CheckMode}
- *
+ *
* @param xtextEditor
* @param checkMode
*/
@@ -63,7 +61,7 @@ public final class ValidationJob extends Job {
/**
* Constructs a ValidationJob with a specified {@link CheckMode}
- *
+ *
* @param xtextDocument
* @param iFile
* @param checkMode
@@ -79,7 +77,9 @@ public final class ValidationJob extends Job {
}
@Override
- protected IStatus run(IProgressMonitor monitor) {
+ protected IStatus run(final IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
log.debug("Starting Xtext Validation with CheckMode: " + checkMode);
if (iFile == null) { // file may be null, if it was opend from an
// IStorageEditorInput
@@ -88,10 +88,14 @@ public final class ValidationJob extends Job {
}
final List<Map<String, Object>> issues = xtextDocument.readOnly(new UnitOfWork<List<Map<String, Object>>>() {
public List<Map<String, Object>> exec(XtextResource resource) throws Exception {
- return XtextResourceChecker.check(resource, Collections.singletonMap(CheckMode.KEY, checkMode));
+ return XtextResourceChecker.check(resource, Collections.singletonMap(CheckMode.KEY, checkMode), monitor);
}
});
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
XtextResourceChecker.addMarkers(iFile, issues, deleteOldMarkers, monitor);
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
return Status.OK_STATUS;
}
} \ No newline at end of file
diff --git a/tests/org.eclipse.xtext.generator.tests/plugin.xml b/tests/org.eclipse.xtext.generator.tests/plugin.xml
index 8c5edd0..6eca85e 100644
--- a/tests/org.eclipse.xtext.generator.tests/plugin.xml
+++ b/tests/org.eclipse.xtext.generator.tests/plugin.xml
@@ -675,18 +675,6 @@
</extension>
- <extension
- point="org.eclipse.xtend.typesystem.emf.checks">
- <metaModel
- nsURI="http://www.eclipse.org/2008/tmf/xtext/TreeTestLanguage">
- <checkFile
- path="org/eclipse/xtext/testlanguages/TreeTestLanguageChecks.chk">
- </checkFile>
- </metaModel>
-
- </extension>
-
-
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri = "http://org.eclipse.xtext.valueconverter.Bug250313"
diff --git a/tests/org.eclipse.xtext.ui.common.tests/plugin.xml b/tests/org.eclipse.xtext.ui.common.tests/plugin.xml
index 655da78..3a79bf0 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/plugin.xml
+++ b/tests/org.eclipse.xtext.ui.common.tests/plugin.xml
@@ -367,19 +367,6 @@
</extension>
- <extension
- point="org.eclipse.xtend.typesystem.emf.checks">
- <metaModel
- nsURI="http://www.eclipse.org/2008/tmf/xtext/TreeTestLanguage">
- <checkFile
- path="org/eclipse/xtext/testlanguages/TreeTestLanguageChecks.chk">
- </checkFile>
- </metaModel>
-
- </extension>
-
-
-
<!-- adding resource factories -->
<extension
diff --git a/tests/org.eclipse.xtext.xtend.tests/plugin.xml b/tests/org.eclipse.xtext.xtend.tests/plugin.xml
index a38dea0..e1df604 100644
--- a/tests/org.eclipse.xtext.xtend.tests/plugin.xml
+++ b/tests/org.eclipse.xtext.xtend.tests/plugin.xml
@@ -319,20 +319,6 @@
</extension>
-
- <extension
- point="org.eclipse.xtend.typesystem.emf.checks">
- <metaModel
- nsURI="http://www.eclipse.org/2008/tmf/xtext/TreeTestLanguage">
- <checkFile
- path="org/eclipse/xtext/testlanguages/TreeTestLanguageChecks.chk">
- </checkFile>
- </metaModel>
-
- </extension>
-
-
-
<!-- adding resource factories -->
<extension