浏览代码

Enabled Xtext Based Validation Rules

Andreas Mülder 14 年之前
父节点
当前提交
6121b8e38e

+ 2 - 1
plugins/org.yakindu.sct.model.stext/META-INF/MANIFEST.MF

@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.xtext;visibility:=reexport,
  org.antlr.runtime,
  org.eclipse.xtext.common.types,
  org.yakindu.sct.model.sgraph,
- de.itemis.xtext.utils.gmf
+ de.itemis.xtext.utils.gmf,
+ org.eclipse.gmf.runtime.emf.core;bundle-version="1.4.1"
 Import-Package: org.apache.commons.logging,
  org.apache.log4j,
  org.eclipse.xtext.builder.builderState,

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

@@ -11,7 +11,10 @@
  */
 package org.yakindu.sct.model.stext.validation;
 
+import java.util.Map;
+
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.xtext.validation.Check;
 import org.eclipse.xtext.validation.CheckType;
 import org.yakindu.sct.model.sgraph.Declaration;
@@ -31,6 +34,8 @@ import org.yakindu.sct.model.stext.stext.SimpleScope;
 import org.yakindu.sct.model.stext.stext.StatechartDefinition;
 import org.yakindu.sct.model.stext.stext.StextPackage;
 
+import de.itemis.xtext.utils.gmf.resource.InjectMembersResource;
+
 /**
  * Several validations for nonsensical expressions.
  * 
@@ -112,4 +117,13 @@ public class STextJavaValidator extends AbstractSTextJavaValidator {
 		}
 		return false;
 	}
+
+	@Override
+	protected String getCurrentLanguage(Map<Object, Object> context,
+			EObject eObject) {
+		Resource resource = eObject.eResource();
+		if (resource instanceof InjectMembersResource)
+			return ((InjectMembersResource) resource).getLanguageName();
+		return super.getCurrentLanguage(context, eObject);
+	}
 }

+ 16 - 9
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -55,18 +55,25 @@ public class StatechartDiagramEditor extends BreadcrumbDiagramEditor implements
 				new ResourceSetListenerImpl() {
 					@Override
 					public void resourceSetChanged(ResourceSetChangeEvent event) {
-						Display.getDefault().asyncExec(new Runnable() {
-							public void run() {
-								if (getDiagram() != null) {
-									ValidationAction.validate(
-											getDiagramEditPart(), getDiagram());
-								}
-							}
-						});
-
+						validate();
 					}
 				});
 	}
+	protected void validate() {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				if (getDiagram() != null) {
+					ValidationAction.validate(
+							getDiagramEditPart(), getDiagram());
+				}
+			}
+		});
+	}
+	@Override
+	protected void sanityCheckState(IEditorInput input) {
+		super.sanityCheckState(input);
+		validate();
+	}
 
 	public void gotoMarker(IMarker marker) {
 		MarkerNavigationService.getInstance().gotoMarker(this, marker);

+ 4 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/validation/GMFMarkerUtil.java

@@ -56,7 +56,7 @@ public final class GMFMarkerUtil {
 			return;
 		}
 		View view = findNotationView(diagram, semanticTarget);
-		if(view == null)
+		if (view == null)
 			return;
 		String uriFragment = view.eResource().getURIFragment(view);
 
@@ -77,6 +77,9 @@ public final class GMFMarkerUtil {
 				return (View) eObject;
 			}
 		}
+		if (semanticElement.eContainer() != null) {
+			return findNotationView(diagram, semanticElement.eContainer());
+		}
 		return null;
 
 	}

+ 2 - 3
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/validation/ValidationAction.java

@@ -44,7 +44,7 @@ public class ValidationAction implements IMarkerType {
 				e.printStackTrace();
 			}
 		}
-
+		
 		// // Ecore constraints
 		Diagnostic diagnostic = Diagnostician.INSTANCE.validate(view
 				.getElement());
@@ -55,7 +55,7 @@ public class ValidationAction implements IMarkerType {
 					DIAGRAM_MARKER_TYPE, (EObject) child.getData().get(0));
 		}
 
-		// Diagnosticans from the InkectMembersResoruce
+		// Diagnosticans from the InjectMembersResoruce
 		if (view.eResource() instanceof InjectMembersResource) {
 			InjectMembersResource resource = (InjectMembersResource) view
 					.eResource();
@@ -66,7 +66,6 @@ public class ValidationAction implements IMarkerType {
 						XTEXT_MARKER_TYPE, (EObject) child.getData().get(0));
 			}
 		}
-
 	}
 
 }