Browse Source

abort notifications when one tirggers validation
set chemode for all check methods
create markers async

Andreas Muelder 9 years ago
parent
commit
cf6fd34f29

+ 4 - 0
plugins/org.yakindu.sct.domain.generic.editor/src/org/yakindu/sct/domain/generic/editor/GenericEditorModule.java

@@ -14,9 +14,11 @@ import org.eclipse.xtext.service.AbstractGenericModule;
 import org.eclipse.xtext.ui.editor.validation.MarkerCreator;
 import org.eclipse.xtext.ui.validation.MarkerTypeProvider;
 import org.eclipse.xtext.validation.IDiagnosticConverter;
+import org.eclipse.xtext.validation.IResourceValidator;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTDiagnosticConverterImpl;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTMarkerCreator;
 import org.yakindu.sct.model.sgraph.ui.validation.SCTMarkerTypeProvider;
+import org.yakindu.sct.model.stext.resource.SCTResourceValidatorImpl;
 import org.yakindu.sct.refactoring.proposals.RefactoringProposalProvider;
 import org.yakindu.sct.ui.editor.editor.proposals.SmartEditProposalProvider;
 import org.yakindu.sct.ui.editor.proposals.IEditProposalProvider;
@@ -39,6 +41,7 @@ public class GenericEditorModule extends AbstractGenericModule {
 				IEditProposalProvider.class);
 		proposalProviderBinder.addBinding().to(SmartEditProposalProvider.class);
 		proposalProviderBinder.addBinding().to(RefactoringProposalProvider.class);
+		binder.bind(IResourceValidator.class).to(SCTResourceValidatorImpl.class);
 	}
 
 	public Class<? extends ISCTPaletteFactory> bindISCTPaletteFactory() {
@@ -56,4 +59,5 @@ public class GenericEditorModule extends AbstractGenericModule {
 	public Class<? extends MarkerTypeProvider> bindMarkerTypeProvider() {
 		return SCTMarkerTypeProvider.class;
 	}
+
 }

+ 3 - 0
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/STextRuntimeModule.java

@@ -16,6 +16,7 @@ import org.eclipse.xtext.linking.ILinker;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
 import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
 import org.eclipse.xtext.validation.CompositeEValidator;
+import org.eclipse.xtext.validation.IResourceValidator;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
 import org.yakindu.base.types.typesystem.GenericTypeSystem;
 import org.yakindu.base.types.typesystem.ITypeSystem;
@@ -24,6 +25,7 @@ import org.yakindu.sct.model.stext.conversion.StextValueConverterService;
 import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
 import org.yakindu.sct.model.stext.naming.StextNameProvider;
 import org.yakindu.sct.model.stext.resource.SCTResourceDescriptionStrategy;
+import org.yakindu.sct.model.stext.resource.SCTResourceValidatorImpl;
 import org.yakindu.sct.model.stext.resource.StextResource;
 import org.yakindu.sct.model.stext.scoping.STextGlobalScopeProvider;
 
@@ -44,6 +46,7 @@ public class STextRuntimeModule extends org.yakindu.sct.model.stext.AbstractSTex
 	public void configure(Binder binder) {
 		super.configure(binder);
 		binder.bind(IDefaultResourceDescriptionStrategy.class).to(SCTResourceDescriptionStrategy.class);
+		binder.bind(IResourceValidator.class).to(SCTResourceValidatorImpl.class);
 	}
 	public Class<? extends org.eclipse.xtext.scoping.IGlobalScopeProvider> bindIGlobalScopeProvider() {
 		return STextGlobalScopeProvider.class;

+ 52 - 52
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -131,7 +131,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 	@Inject
 	private ContextPredicateProvider contextPredicateProvider;
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkContextElement(ElementReferenceExpression expression) {
 		Predicate<IEObjectDescription> predicate = contextPredicateProvider.calculateFilterPredicate(expression,
 				ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE);
@@ -144,24 +144,24 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkExpression(VariableDefinition expression) {
 		if (expression.getType() == null || expression.getType().eIsProxy())
 			return;
 		typeInferrer.infer(expression, this);
 	}
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkExpression(TimeEventSpec expression) {
 		typeInferrer.infer(expression, this);
 	}
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkExpression(Guard expression) {
 		typeInferrer.infer(expression, this);
 	}
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkNoAssignmentInGuard(Guard guard) {
 		TreeIterator<EObject> eAllContents = guard.eAllContents();
 		while (eAllContents.hasNext()) {
@@ -342,7 +342,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 
 	}
 
-	@Check(CheckType.FAST)
+	@Check(CheckType.NORMAL)
 	public void checkValueReferenedBeforeDefined(Scope scope) {
 		EList<Declaration> declarations = scope.getDeclarations();
 		Set<QualifiedName> defined = Sets.newHashSet();
@@ -376,7 +376,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	@Check(CheckType.FAST)
+	@Check(CheckType.NORMAL)
 	public void checkUnusedExit(final Exit exit) {
 		if (exit.getParentRegion().getComposite() instanceof org.yakindu.sct.model.sgraph.State
 				&& exit.getOutgoingTransitions().isEmpty()) {
@@ -459,7 +459,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	@Check(CheckType.FAST)
+	@Check(CheckType.NORMAL)
 	public void checkUnboundEntryPoints(final org.yakindu.sct.model.sgraph.State state) {
 		if (state.isComposite()) {
 			final List<Transition>[] transitions = STextValidationModelUtils
@@ -513,7 +513,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	@Check(CheckType.FAST)
+	@Check(CheckType.NORMAL)
 	public void checkTopLeveEntryIsDefaultEntry(final Entry entry) {
 		Region parentRegion = entry.getParentRegion();
 		EObject eContainer = parentRegion.eContainer();
@@ -582,18 +582,6 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	private String getVariableName(AssignmentExpression exp) {
-		Expression varRef = exp.getVarRef();
-		if (varRef instanceof ElementReferenceExpression
-				&& ((ElementReferenceExpression) varRef).getReference() instanceof Property) {
-			Property reference = (Property) ((ElementReferenceExpression) varRef).getReference();
-			return reference.getName();
-		} else if (varRef instanceof FeatureCall && ((FeatureCall) varRef).getFeature() instanceof Property) {
-			Property reference = (Property) ((FeatureCall) varRef).getFeature();
-			return reference.getName();
-		}
-		return null;
-	}
 
 	@Check(CheckType.FAST)
 	public void checkFeatureCall(FeatureCall call) {
@@ -673,26 +661,19 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	protected void checkElementReferenceEffect(ElementReferenceExpression refExp) {
-		if (!(refExp.getReference() instanceof Operation)) {
-			if (refExp.getReference() instanceof Property) {
-				error("Access to property '" + nameProvider.getFullyQualifiedName(refExp.getReference())
-						+ "' has no effect.", refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
-						FEATURE_CALL_HAS_NO_EFFECT);
-			} else if (refExp.getReference() instanceof Event) {
-				error("Access to event '" + nameProvider.getFullyQualifiedName(refExp.getReference())
-						+ "' has no effect.", refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
-						FEATURE_CALL_HAS_NO_EFFECT);
-			} else {
-				error("Access to feature '" + nameProvider.getFullyQualifiedName(refExp.getReference())
-						+ "' has no effect.", refExp,
-						ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
-						FEATURE_CALL_HAS_NO_EFFECT);
-			}
+	private String getVariableName(AssignmentExpression exp) {
+		Expression varRef = exp.getVarRef();
+		if (varRef instanceof ElementReferenceExpression
+				&& ((ElementReferenceExpression) varRef).getReference() instanceof Property) {
+			Property reference = (Property) ((ElementReferenceExpression) varRef).getReference();
+			return reference.getName();
+		} else if (varRef instanceof FeatureCall && ((FeatureCall) varRef).getFeature() instanceof Property) {
+			Property reference = (Property) ((FeatureCall) varRef).getFeature();
+			return reference.getName();
 		}
+		return null;
 	}
+	
 
 	@Check(CheckType.FAST)
 	public void checkEventDefinition(EventDefinition event) {
@@ -729,7 +710,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		}
 	}
 
-	@Check
+	@Check(CheckType.FAST)
 	public void checkChoiceWithoutDefaultTransition(final Choice choice) {
 		boolean found = false;
 		for (Transition transition : choice.getOutgoingTransitions()) {
@@ -742,8 +723,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 			warning(CHOICE_ONE_OUTGOING_DEFAULT_TRANSITION, SGraphPackage.Literals.VERTEX__OUTGOING_TRANSITIONS);
 	}
 
-	// TODO Extract TypesValidator
-	@Check
+	@Check(CheckType.FAST)
 	public void checkAnnotationTarget(final AnnotatableElement element) {
 		EList<Annotation> annotations = element.getAnnotations();
 		for (Annotation annotation : annotations) {
@@ -761,9 +741,38 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 			}
 		}
 	}
+	
+	@Check(CheckType.FAST)
+	public void checkImportExists(Import importDef) {
+		String namespace = importDef.getImportedNamespace();
+		if (resolver.getPackageForNamespace(getResource(importDef), namespace) == null) {
+			error("The import " + namespace + " cannot be resolved.", importDef,
+					StextPackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORT_NOT_RESOLVED);
+		}
+	}
 
-	protected boolean isDefault(Trigger trigger) {
+	protected void checkElementReferenceEffect(ElementReferenceExpression refExp) {
+		if (!(refExp.getReference() instanceof Operation)) {
+			if (refExp.getReference() instanceof Property) {
+				error("Access to property '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+				+ "' has no effect.", refExp,
+				ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+				FEATURE_CALL_HAS_NO_EFFECT);
+			} else if (refExp.getReference() instanceof Event) {
+				error("Access to event '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+				+ "' has no effect.", refExp,
+				ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+				FEATURE_CALL_HAS_NO_EFFECT);
+			} else {
+				error("Access to feature '" + nameProvider.getFullyQualifiedName(refExp.getReference())
+				+ "' has no effect.", refExp,
+				ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE, INSIGNIFICANT_INDEX,
+				FEATURE_CALL_HAS_NO_EFFECT);
+			}
+		}
+	}
 
+	protected boolean isDefault(Trigger trigger) {
 		return trigger == null || trigger instanceof DefaultTrigger
 				|| ((trigger instanceof ReactionTrigger) && ((ReactionTrigger) trigger).getTriggers().size() == 0
 						&& ((ReactionTrigger) trigger).getGuard() == null);
@@ -833,15 +842,6 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 		return result;
 	}
 
-	@Check(CheckType.FAST)
-	public void checkImportExists(Import importDef) {
-		String namespace = importDef.getImportedNamespace();
-		if (resolver.getPackageForNamespace(getResource(importDef), namespace) == null) {
-			error("The import " + namespace + " cannot be resolved.", importDef,
-					StextPackage.Literals.IMPORT__IMPORTED_NAMESPACE, IMPORT_NOT_RESOLVED);
-		}
-	}
-
 	protected Resource getResource(EObject context) {
 		final ContextElementAdapter provider = (ContextElementAdapter) EcoreUtil.getExistingAdapter(context.eResource(),
 				ContextElementAdapter.class);

+ 6 - 3
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/ResourceSetValidationListener.java

@@ -43,15 +43,18 @@ public class ResourceSetValidationListener extends ResourceSetListenerImpl {
 				EObject eObject = (EObject) notification.getNotifier();
 				if (eObject.eClass().getEPackage() == SGraphPackage.eINSTANCE) {
 					validationJob.cancel();
-					if (liveValidationEnabled())
+					if (liveValidationEnabled()) {
 						validationJob.schedule(DELAY);
+						break;
+					}
 				} else
 					for (EClass eClass : eObject.eClass().getEAllSuperTypes()) {
 						if (SGraphPackage.eINSTANCE == eClass.getEPackage()) {
 							validationJob.cancel();
-							if (liveValidationEnabled())
+							if (liveValidationEnabled()) {
 								validationJob.schedule(DELAY);
-							return;
+								return;
+							}
 						}
 					}
 			}

+ 20 - 9
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/validation/SCTValidationJob.java

@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.emf.common.util.WrappedException;
@@ -56,7 +57,6 @@ public class SCTValidationJob extends Job implements IMarkerType {
 
 	private Resource resource;
 
-	
 	/**
 	 * Wrappes the {@link IResourceValidator} validate within a
 	 * {@link RunnableWithResult} to execute within a read only transaction
@@ -81,9 +81,13 @@ public class SCTValidationJob extends Job implements IMarkerType {
 		}
 
 		public void run() {
-			List<Issue> result = validator.validate(resource, checkMode, indicator);
-			setResult(result);
-			setStatus(Status.OK_STATUS);
+			try {
+				List<Issue> result = validator.validate(resource, checkMode, indicator);
+				setResult(result);
+				setStatus(Status.OK_STATUS);
+			} catch (OperationCanceledException ex) {
+				setStatus(Status.CANCEL_STATUS);
+			}
 		}
 	}
 
@@ -94,6 +98,7 @@ public class SCTValidationJob extends Job implements IMarkerType {
 
 	@Override
 	public IStatus run(final IProgressMonitor monitor) {
+//		long t = System.currentTimeMillis();
 		try {
 			if (!resource.isLoaded())
 				return Status.CANCEL_STATUS;
@@ -103,7 +108,7 @@ public class SCTValidationJob extends Job implements IMarkerType {
 			if (monitor.isCanceled())
 				return Status.CANCEL_STATUS;
 			TransactionalValidationRunner runner = new TransactionalValidationRunner(validator, resource,
-					CheckMode.ALL, new CancelIndicator() {
+					CheckMode.FAST_ONLY, new CancelIndicator() {
 						public boolean isCanceled() {
 							return monitor.isCanceled();
 
@@ -112,7 +117,12 @@ public class SCTValidationJob extends Job implements IMarkerType {
 			TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
 			if (editingDomain == null)
 				return Status.CANCEL_STATUS;
-			editingDomain.runExclusive(runner);
+			try {
+				editingDomain.runExclusive(runner);
+			} catch (Throwable ex) {
+				//Since xtext 2.8 this may throw an OperationCanceledError
+				return Status.CANCEL_STATUS;
+			}
 			final List<Issue> issues = runner.getResult();
 			if (issues == null)
 				return Status.CANCEL_STATUS;
@@ -123,6 +133,7 @@ public class SCTValidationJob extends Job implements IMarkerType {
 			ex.printStackTrace();
 			return new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID, ex.getMessage());
 		}
+//		System.out.println("Validation took " + (System.currentTimeMillis() - t));
 		return Status.OK_STATUS;
 	}
 
@@ -131,7 +142,7 @@ public class SCTValidationJob extends Job implements IMarkerType {
 	 * problem markers // will flicker otherwise
 	 */
 	private void refreshMarkers(final IFile target, final List<Issue> issues, final IProgressMonitor monitor) {
-		PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
 			public void run() {
 				try {
 					target.deleteMarkers(SCT_MARKER_TYPE, true, IResource.DEPTH_ZERO);
@@ -152,8 +163,8 @@ public class SCTValidationJob extends Job implements IMarkerType {
 	 */
 	protected void relinkModel(final IProgressMonitor monitor, final AbstractSCTResource eResource)
 			throws ExecutionException {
-		AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(
-				TransactionUtil.getEditingDomain(eResource), "", null) {
+		AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(TransactionUtil.getEditingDomain(eResource),
+				"", null) {
 			@Override
 			protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
 					throws ExecutionException {