Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-05-25 18:53:52 -0400
committerHenrik Rentz-Reichert2012-05-25 18:53:52 -0400
commit177965c4f54f156684783f313acb1ab2ca99d321 (patch)
tree30c84d7f52bcac87ec68c7beb50654d9af367cc0
parent51ef62bc6f1d1d61e4ed2af2e14d81edcbf3274d (diff)
downloadorg.eclipse.etrice-177965c4f54f156684783f313acb1ab2ca99d321.tar.gz
org.eclipse.etrice-177965c4f54f156684783f313acb1ab2ca99d321.tar.xz
org.eclipse.etrice-177965c4f54f156684783f313acb1ab2ca99d321.zip
[core.room, core.room.ui, genmodel, abstractexec.behavior] validator and quickfix extension points and extension examples
preparations for abstract state machine execution
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/.classpath7
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/.gitignore2
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/.project28
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF14
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/build.properties5
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/plugin.xml25
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java66
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActionCodeAnalyzer.java83
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoQuickfix.java40
-rw-r--r--plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoValidator.java44
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullDiagnostician.java65
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullLogger.java37
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/GeneratorModelBuilder.java2
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/plugin.xml1
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/schema/quickfix.exsd109
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java15
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/IRoomQuickfixProvider.java12
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/QuickfixExtensionManager.java88
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickfixProvider.java24
-rw-r--r--plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.core.room/plugin.xml1
-rw-r--r--plugins/org.eclipse.etrice.core.room/schema/validation.exsd129
-rw-r--r--plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/validation/AbstractRoomJavaValidator.java2
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe24
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java19
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/IRoomValidator.java26
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java200
29 files changed, 1057 insertions, 5 deletions
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/.classpath b/plugins/org.eclipse.etrice.abstractexec.behavior/.classpath
new file mode 100644
index 000000000..8a8f1668c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/.gitignore b/plugins/org.eclipse.etrice.abstractexec.behavior/.gitignore
new file mode 100644
index 000000000..a25460a14
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/.gitignore
@@ -0,0 +1,2 @@
+bin
+.antlr-generator-3.2.0.jar \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/.project b/plugins/org.eclipse.etrice.abstractexec.behavior/.project
new file mode 100644
index 000000000..bc5cf1d2c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.abstractexec.behavior</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.abstractexec.behavior/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..08fa054b3
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed May 23 19:11:47 CEST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..06bec0601
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Abstract Execution for State Machines
+Bundle-SymbolicName: org.eclipse.etrice.abstractexec.behavior;singleton:=true
+Bundle-Version: 0.2.0.qualifier
+Bundle-Vendor: eTrice (Incubation)
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.eclipse.etrice.core.room;bundle-version="0.2.0",
+ org.eclipse.etrice.core.room.ui;bundle-version="0.2.0",
+ org.eclipse.etrice.core.genmodel;bundle-version="0.2.0",
+ org.eclipse.etrice.generator;bundle-version="0.2.0",
+ org.eclipse.emf.ecore;bundle-version="2.7.0",
+ org.eclipse.xtext;bundle-version="2.1.1",
+ org.eclipse.xtext.ui;bundle-version="2.1.1"
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/build.properties b/plugins/org.eclipse.etrice.abstractexec.behavior/build.properties
new file mode 100644
index 000000000..6f20375d6
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/plugin.xml b/plugins/org.eclipse.etrice.abstractexec.behavior/plugin.xml
new file mode 100644
index 000000000..07d46d86e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/plugin.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.etrice.core.room.validation">
+ <validator
+ class="org.eclipse.etrice.abstractexec.behavior.DemoValidator"
+ classToCheck="org.eclipse.etrice.core.room.ActorClass"
+ mode="FAST">
+ </validator>
+ <validator
+ class="org.eclipse.etrice.abstractexec.behavior.AbstractExecutionValidator"
+ classToCheck="org.eclipse.etrice.core.room.ActorClass"
+ mode="FAST">
+ </validator>
+ </extension>
+ <extension
+ point="org.eclipse.etrice.core.room.ui.quickfix">
+ <quickfixProvider
+ class="org.eclipse.etrice.abstractexec.behavior.DemoQuickfix"
+ code="demo_issue">
+ </quickfixProvider>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
new file mode 100644
index 000000000..9891e116e
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.genmodel.base.NullDiagnostician;
+import org.eclipse.etrice.core.genmodel.base.NullLogger;
+import org.eclipse.etrice.core.genmodel.builder.GeneratorModelBuilder;
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.core.validation.IRoomValidator;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * @author rentzhnr
+ *
+ */
+public class AbstractExecutionValidator implements IRoomValidator {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.validation.IRoomValidator#validate(org.eclipse.emf.ecore.EObject, org.eclipse.xtext.validation.ValidationMessageAcceptor)
+ */
+ @Override
+ public void validate(EObject object, ValidationMessageAcceptor messageAcceptor) {
+
+ if (!(object instanceof ActorClass))
+ return;
+
+ ActorClass ac = (ActorClass) object;
+
+ NullDiagnostician diagnostician = new NullDiagnostician();
+ GeneratorModelBuilder builder = new GeneratorModelBuilder(new NullLogger(), diagnostician);
+ ExpandedActorClass xpac = builder.createExpandedActorClass(ac);
+ if (xpac!=null && !diagnostician.isFailed()) {
+ boolean allProtocolsWithSemantics = true;
+ List<InterfaceItem> ifItems = RoomHelpers.getAllInterfaceItems(ac);
+ for (InterfaceItem item : ifItems) {
+ if (item.getProtocol().getSemantics()==null) {
+ allProtocolsWithSemantics = false;
+ break;
+ }
+ }
+
+ if (allProtocolsWithSemantics) {
+ // begin abstract execution on state machine of expanded actor class
+
+ ActionCodeAnalyzer analyzer = new ActionCodeAnalyzer(ac);
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActionCodeAnalyzer.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActionCodeAnalyzer.java
new file mode 100644
index 000000000..ac47532a7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActionCodeAnalyzer.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.MessageFromIf;
+import org.eclipse.etrice.core.room.RoomFactory;
+import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
+import org.eclipse.etrice.generator.base.DetailCodeTranslator;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ActionCodeAnalyzer {
+
+ private class Collector extends DefaultTranslationProvider {
+
+ private ArrayList<MessageFromIf> mifs = new ArrayList<MessageFromIf>();
+
+ public ArrayList<MessageFromIf> getMifs() {
+ return mifs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.base.DefaultTranslationProvider#getInterfaceItemMessageText(org.eclipse.etrice.core.room.InterfaceItem, org.eclipse.etrice.core.room.Message, java.util.ArrayList, java.lang.String, java.lang.String)
+ */
+ @Override
+ public String getInterfaceItemMessageText(InterfaceItem item,
+ Message msg, ArrayList<String> args, String index, String orig) {
+
+ MessageFromIf mif = RoomFactory.eINSTANCE.createMessageFromIf();
+ mif.setFrom(item);
+ mif.setMessage(msg);
+ mifs.add(mif);
+
+ return orig;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.generator.base.DefaultTranslationProvider#translateMembers()
+ */
+ @Override
+ public boolean translateMembers() {
+ return true;
+ }
+
+ // create a new list and leave previous unchanged
+ public void begin() {
+ mifs = new ArrayList<MessageFromIf>();
+ }
+ }
+
+ private Collector collector;
+ private DetailCodeTranslator translator;
+
+ public ActionCodeAnalyzer(ActorClass ac) {
+ collector = new Collector();
+ translator = new DetailCodeTranslator(ac, collector);
+ }
+
+ public List<MessageFromIf> analyze(DetailCode dc) {
+ collector.begin();
+ translator.translateDetailCode(dc);
+ return collector.getMifs();
+ }
+}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoQuickfix.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoQuickfix.java
new file mode 100644
index 000000000..900343e68
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoQuickfix.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior;
+
+import org.eclipse.etrice.core.ui.quickfix.IRoomQuickfixProvider;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.model.edit.IModification;
+import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
+import org.eclipse.xtext.validation.Issue;
+
+public class DemoQuickfix implements IRoomQuickfixProvider {
+
+ public DemoQuickfix() {
+ }
+
+ @Override
+ public void getResolution(final Issue issue, IssueResolutionAcceptor acceptor) {
+ // 3rd arg is image, check ImageHelper how this could work
+ acceptor.accept(issue, issue.getData()[0]+"_ac", "change actor class name to "+issue.getData()[0]+"_ac", null, new IModification() {
+ public void apply(IModificationContext context) throws BadLocationException {
+ IXtextDocument xtextDocument = context.getXtextDocument();
+// String firstLetter = xtextDocument.get(issue.getOffset(), 1);
+ xtextDocument.replace(issue.getOffset()+issue.getData()[0].length(), 0, "_ac");
+ }
+ });
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoValidator.java b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoValidator.java
new file mode 100644
index 000000000..ade8ace17
--- /dev/null
+++ b/plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoValidator.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.abstractexec.behavior;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.etrice.core.validation.IRoomValidator;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class DemoValidator implements IRoomValidator {
+
+ public static final String DEMO_ISSUE_CODE = "demo_issue";
+
+ // HOWTO: if validator is running in check mode NORMAL there are issues with marker updates
+ // the marker appears grayed and quick fixes aren't available
+
+ @Override
+ public void validate(EObject object,
+ ValidationMessageAcceptor messageAcceptor) {
+
+ if (!(object instanceof ActorClass))
+ return;
+
+ ActorClass ac = (ActorClass) object;
+ if (!ac.getName().endsWith("_ac"))
+ messageAcceptor.acceptWarning("ActorClass name must end with _ac", ac, RoomPackage.Literals.ROOM_CLASS__NAME, -1, DEMO_ISSUE_CODE, ac.getName());
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullDiagnostician.java b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullDiagnostician.java
new file mode 100644
index 000000000..be3595963
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullDiagnostician.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.genmodel.base;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class NullDiagnostician implements IDiagnostician {
+
+ private boolean failed = false;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician#warning(java.lang.String, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature)
+ */
+ @Override
+ public void warning(String msg, EObject source, EStructuralFeature feature) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician#warning(java.lang.String, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, int)
+ */
+ @Override
+ public void warning(String msg, EObject source, EStructuralFeature feature, int idx) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician#error(java.lang.String, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature)
+ */
+ @Override
+ public void error(String msg, EObject source, EStructuralFeature feature) {
+ error(msg, source, feature, -1);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician#error(java.lang.String, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EStructuralFeature, int)
+ */
+ @Override
+ public void error(String msg, EObject source, EStructuralFeature feature, int idx) {
+ failed = true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician#isFailed()
+ */
+ @Override
+ public boolean isFailed() {
+ return failed;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullLogger.java b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullLogger.java
new file mode 100644
index 000000000..da3c35b3c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullLogger.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.genmodel.base;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class NullLogger implements ILogger {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.base.ILogger#logInfo(java.lang.String)
+ */
+ @Override
+ public void logInfo(String text) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.core.genmodel.base.ILogger#logError(java.lang.String, org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ public void logError(String text, EObject obj) {
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/GeneratorModelBuilder.java b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/GeneratorModelBuilder.java
index 9617a8439..0a5ac46d0 100644
--- a/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/GeneratorModelBuilder.java
+++ b/plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/builder/GeneratorModelBuilder.java
@@ -1013,7 +1013,7 @@ public class GeneratorModelBuilder {
* @param ac - the original model class
* @return - the newly created expanded actor class
*/
- private ExpandedActorClass createExpandedActorClass(ActorClass ac) {
+ public ExpandedActorClass createExpandedActorClass(ActorClass ac) {
logger.logInfo("GeneratorModelBuilder: creating expanded actor class from "+ac.getName()
+" of "+((RoomModel)ac.eContainer()).getName());
diff --git a/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
index 20a47ce35..13bd0f1ce 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF
@@ -24,5 +24,6 @@ Export-Package: org.eclipse.etrice.core.ui,
org.eclipse.etrice.core.ui.contentassist.antlr,
org.eclipse.etrice.core.ui.editor,
org.eclipse.etrice.core.ui.linking,
- org.eclipse.etrice.core.ui.newwizard
-Bundle-Activator: org.eclipse.etrice.core.ui.internal.RoomActivator
+ org.eclipse.etrice.core.ui.newwizard,
+ org.eclipse.etrice.core.ui.quickfix
+Bundle-Activator: org.eclipse.etrice.core.ui.RoomUiActivator
diff --git a/plugins/org.eclipse.etrice.core.room.ui/plugin.xml b/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
index c9d1d69e8..c85abe78d 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.room.ui/plugin.xml
@@ -2,6 +2,7 @@
<?eclipse version="3.0"?>
<plugin>
+ <extension-point id="quickfix" name="Room Quickfix Provider" schema="schema/quickfix.exsd"/>
<extension
point="org.eclipse.ui.editors">
diff --git a/plugins/org.eclipse.etrice.core.room.ui/schema/quickfix.exsd b/plugins/org.eclipse.etrice.core.room.ui/schema/quickfix.exsd
new file mode 100644
index 000000000..c0e2ac7c8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/schema/quickfix.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.etrice.core.room.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.etrice.core.room.ui" id="quickfix" name="Room Quickfix Provider"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="quickfixProvider"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="quickfixProvider">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.etrice.core.ui.quickfix.IRoomQuickfixProvider"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="code" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java
new file mode 100644
index 000000000..99de52632
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java
@@ -0,0 +1,15 @@
+package org.eclipse.etrice.core.ui;
+
+import org.eclipse.etrice.core.ui.internal.RoomActivator;
+import org.eclipse.etrice.core.ui.quickfix.QuickfixExtensionManager;
+import org.osgi.framework.BundleContext;
+
+public class RoomUiActivator extends RoomActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+ QuickfixExtensionManager.getInstance().loadQuickfixExtensions();
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/IRoomQuickfixProvider.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/IRoomQuickfixProvider.java
new file mode 100644
index 000000000..decbbb840
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/IRoomQuickfixProvider.java
@@ -0,0 +1,12 @@
+package org.eclipse.etrice.core.ui.quickfix;
+
+import java.util.List;
+
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolution;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
+import org.eclipse.xtext.validation.Issue;
+
+public interface IRoomQuickfixProvider {
+
+ void getResolution(final Issue issue, IssueResolutionAcceptor acceptor);
+}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/QuickfixExtensionManager.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/QuickfixExtensionManager.java
new file mode 100644
index 000000000..701395099
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/QuickfixExtensionManager.java
@@ -0,0 +1,88 @@
+package org.eclipse.etrice.core.ui.quickfix;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
+import org.eclipse.xtext.validation.Issue;
+
+public class QuickfixExtensionManager {
+
+ private static final String IQUICKFIX_ID = "org.eclipse.etrice.core.room.ui.quickfix";
+ private static QuickfixExtensionManager instance = null;
+
+ private HashMap<String, ArrayList<IRoomQuickfixProvider>> code2provider = new HashMap<String, ArrayList<IRoomQuickfixProvider>>();
+
+ public static QuickfixExtensionManager getInstance() {
+ if (instance==null)
+ instance = new QuickfixExtensionManager();
+ return instance;
+ }
+
+ public void loadQuickfixExtensions() {
+ IConfigurationElement[] config = Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(IQUICKFIX_ID);
+
+ try {
+ for (IConfigurationElement e : config) {
+ final Object ext = e.createExecutableExtension("class");
+ if (ext instanceof IRoomQuickfixProvider) {
+ String code = e.getAttribute("code");
+ put(code, (IRoomQuickfixProvider) ext);
+ }
+ else {
+ System.out.println("QuickfixExtensionManager: unexpected extension");
+ }
+ }
+ } catch (CoreException ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+
+ public void getResolutions(Issue issue, IssueResolutionAcceptor acceptor) {
+ ArrayList<IRoomQuickfixProvider> list = code2provider.get(issue.getCode());
+ if (list!=null)
+ for (IRoomQuickfixProvider provider : list) {
+ executeExtension(provider, issue, acceptor);
+ }
+ }
+
+ public boolean hasResolutionFor(String issueCode) {
+ ArrayList<IRoomQuickfixProvider> list = code2provider.get(issueCode);
+ return list!=null && !list.isEmpty();
+ }
+
+ private void executeExtension(
+ final IRoomQuickfixProvider provider,
+ final Issue issue,
+ final IssueResolutionAcceptor acceptor) {
+
+ ISafeRunnable runnable = new ISafeRunnable() {
+ @Override
+ public void handleException(Throwable exception) {
+ System.out.println("Exception in IRoomValidator");
+ }
+
+ @Override
+ public void run() throws Exception {
+ provider.getResolution(issue, acceptor);
+ }
+ };
+ SafeRunner.run(runnable);
+ }
+
+ private void put(String code, IRoomQuickfixProvider ext) {
+ ArrayList<IRoomQuickfixProvider> list = code2provider.get(code);
+ if (list==null) {
+ list = new ArrayList<IRoomQuickfixProvider>();
+ code2provider.put(code, list);
+ }
+ list.add(ext);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickfixProvider.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickfixProvider.java
index c52b11d6d..7b911329e 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickfixProvider.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickfixProvider.java
@@ -12,7 +12,13 @@
package org.eclipse.etrice.core.ui.quickfix;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolution;
+import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor;
+import org.eclipse.xtext.validation.Issue;
public class RoomQuickfixProvider extends DefaultQuickfixProvider {
@@ -27,4 +33,22 @@ public class RoomQuickfixProvider extends DefaultQuickfixProvider {
// });
// }
+ @Override
+ public List<IssueResolution> getResolutions(Issue issue) {
+ List<IssueResolution> result = new ArrayList<IssueResolution>();
+
+ result.addAll(super.getResolutions(issue));
+
+ IssueResolutionAcceptor acceptor = getIssueResolutionAcceptorProvider().get();
+ QuickfixExtensionManager.getInstance().getResolutions(issue, acceptor);
+
+ result.addAll(acceptor.getIssueResolutions());
+
+ return result;
+ }
+
+ @Override
+ public boolean hasResolutionFor(String issueCode) {
+ return super.hasResolutionFor(issueCode) || QuickfixExtensionManager.getInstance().hasResolutionFor(issueCode);
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF
index ccdb91a8e..60fe5a2af 100644
--- a/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.core.room/META-INF/MANIFEST.MF
@@ -33,3 +33,4 @@ Export-Package: org.eclipse.etrice.core,
org.eclipse.etrice.core.services,
org.eclipse.etrice.core.validation,
org.eclipse.etrice.core.formatting
+Bundle-Activator: org.eclipse.etrice.core.RoomActivator
diff --git a/plugins/org.eclipse.etrice.core.room/plugin.xml b/plugins/org.eclipse.etrice.core.room/plugin.xml
index 14513883a..0f64f0332 100644
--- a/plugins/org.eclipse.etrice.core.room/plugin.xml
+++ b/plugins/org.eclipse.etrice.core.room/plugin.xml
@@ -2,6 +2,7 @@
<?eclipse version="3.0"?>
<plugin>
+ <extension-point id="validation" name="Room Validator" schema="schema/validation.exsd"/>
<extension point="org.eclipse.emf.ecore.generated_package">
<package
diff --git a/plugins/org.eclipse.etrice.core.room/schema/validation.exsd b/plugins/org.eclipse.etrice.core.room/schema/validation.exsd
new file mode 100644
index 000000000..1361f0e88
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/schema/validation.exsd
@@ -0,0 +1,129 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.etrice.core.room" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.etrice.core.room" id="org_eclipse_etrice_core_room_validation" name="Room Validator"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element ref="validator"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="validator">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.etrice.core.validation.IRoomValidator"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="mode" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="FAST">
+ </enumeration>
+ <enumeration value="NORMAL">
+ </enumeration>
+ <enumeration value="EXPENSIVE">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="classToCheck" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.EObject"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/validation/AbstractRoomJavaValidator.java b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/validation/AbstractRoomJavaValidator.java
index ebb459cf5..0ed09bf43 100644
--- a/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/validation/AbstractRoomJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.room/src-gen/org/eclipse/etrice/core/validation/AbstractRoomJavaValidator.java
@@ -7,7 +7,7 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
import org.eclipse.xtext.validation.ComposedChecks;
-@ComposedChecks(validators= {org.eclipse.xtext.validation.ImportUriValidator.class, org.eclipse.xtext.validation.NamesAreUniqueValidator.class})
+@ComposedChecks(validators= {org.eclipse.xtext.validation.ImportUriValidator.class, org.eclipse.xtext.validation.NamesAreUniqueValidator.class, org.eclipse.etrice.core.validation.ValidatorExtensionManager.class})
public class AbstractRoomJavaValidator extends AbstractDeclarativeValidator {
@Override
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2 b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
index cd3716b33..771fabb50 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/GenerateRoom.mwe2
@@ -85,8 +85,10 @@ Workflow {
fragment = validation.JavaValidatorFragment {
// HOWTO: use URI imports - configure validator
composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
-
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
+
+ // HOWTO: extension manager is added here (CAUTION: don't register with RoomPackage in the class since this makes it is called twice)
+ composedCheck = "org.eclipse.etrice.core.validation.ValidatorExtensionManager"
}
// scoping and exporting API
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java
new file mode 100644
index 000000000..e06b763c0
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java
@@ -0,0 +1,19 @@
+package org.eclipse.etrice.core;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.etrice.core.validation.ValidatorExtensionManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class RoomActivator extends Plugin implements BundleActivator {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+ ValidatorExtensionManager.Registry.getInstance().loadValidatorExtensions();
+ }
+}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/IRoomValidator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/IRoomValidator.java
new file mode 100644
index 000000000..b50fffebd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/IRoomValidator.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.validation;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public interface IRoomValidator {
+
+ void validate(EObject object, ValidationMessageAcceptor messageAcceptor);
+
+}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
new file mode 100644
index 000000000..76f99b71c
--- /dev/null
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * 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
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.validation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.RoomPackage;
+import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
+import org.eclipse.xtext.validation.Check;
+import org.eclipse.xtext.validation.CheckMode;
+import org.eclipse.xtext.validation.CheckType;
+import org.eclipse.xtext.validation.EValidatorRegistrar;
+import org.eclipse.xtext.validation.ValidationMessageAcceptor;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class ValidatorExtensionManager extends AbstractDeclarativeValidator {
+
+ public static class Registry {
+
+ private static final String PACKAGE = RoomPackage.class.getPackage().getName()+".";
+ private static final String IVALIDATOR_ID = "org.eclipse.etrice.core.room.validation";
+ private static Registry instance = null;
+ private HashMap<String, ArrayList<IRoomValidator>> fastClass2Ext = new HashMap<String, ArrayList<IRoomValidator>>();
+ private HashMap<String, ArrayList<IRoomValidator>> normalClass2Ext = new HashMap<String, ArrayList<IRoomValidator>>();
+ private HashMap<String, ArrayList<IRoomValidator>> expensiveClass2Ext = new HashMap<String, ArrayList<IRoomValidator>>();
+
+ public static Registry getInstance() {
+ if (instance==null)
+ instance = new Registry();
+
+ return instance;
+ }
+
+ public void loadValidatorExtensions() {
+ IConfigurationElement[] config = Platform.getExtensionRegistry()
+ .getConfigurationElementsFor(IVALIDATOR_ID);
+
+ // compute all sub classes for all classes of the Room package
+ HashMap<String, ArrayList<String>> cls2sub = new HashMap<String, ArrayList<String>>();
+ for (EClassifier cls : RoomPackage.eINSTANCE.getEClassifiers()) {
+ if (cls instanceof EClass) {
+ EList<EClass> superTypes = ((EClass) cls).getESuperTypes();
+ for (EClass sup : superTypes) {
+ put(sup.getName(), ((EClass) cls).getName(), cls2sub);
+ }
+ }
+ }
+
+ // now we add each extension to our maps
+ try {
+ for (IConfigurationElement e : config) {
+ final Object ext = e.createExecutableExtension("class");
+ if (ext instanceof IRoomValidator) {
+ String mode = e.getAttribute("mode");
+ String classToCheck = e.getAttribute("classToCheck");
+ if (classToCheck.startsWith(PACKAGE))
+ classToCheck = classToCheck.substring(PACKAGE.length());
+ EClassifier cls = RoomPackage.eINSTANCE.getEClassifier(classToCheck);
+ if (cls instanceof EClass) {
+ HashMap<String,ArrayList<IRoomValidator>> map = getMap(mode);
+ if (map!=null) {
+ put(map, ((EClass) cls).getName(), (IRoomValidator) ext);
+ ArrayList<String> subTypes = cls2sub.get(cls.getName());
+ if (subTypes!=null)
+ for (String type : subTypes) {
+ put(map, type, (IRoomValidator) ext);
+ }
+ }
+ }
+ }
+ else {
+ System.out.println("ValidatorExtensionManager: unexpected extension");
+ }
+ }
+ } catch (CoreException ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+
+ public void validate(EObject object, CheckMode checkMode,
+ ValidationMessageAcceptor messageAcceptor) {
+ HashSet<IRoomValidator> executed = new HashSet<IRoomValidator>();
+ if (checkMode.shouldCheck(CheckType.FAST))
+ validate(object, messageAcceptor, fastClass2Ext, executed);
+ if (checkMode.shouldCheck(CheckType.NORMAL))
+ validate(object, messageAcceptor, normalClass2Ext, executed);
+ if (checkMode.shouldCheck(CheckType.EXPENSIVE))
+ validate(object, messageAcceptor, expensiveClass2Ext, executed);
+ }
+
+ private void validate(EObject object,
+ ValidationMessageAcceptor messageAcceptor,
+ HashMap<String, ArrayList<IRoomValidator>> map, HashSet<IRoomValidator> executed) {
+ ArrayList<IRoomValidator> validators = map.get(object.eClass().getName());
+ if (validators!=null)
+ for (IRoomValidator validator : validators) {
+ if (!executed.contains(validator)) {
+ executed.add(validator);
+ executeExtension(validator, object, messageAcceptor);
+ }
+ }
+ }
+
+ private void put(String cls, String sub,
+ HashMap<String,ArrayList<String>> cls2sub) {
+
+ ArrayList<String> list = cls2sub.get(cls);
+ if (list==null) {
+ list = new ArrayList<String>();
+ cls2sub.put(cls, list);
+ }
+ list.add(sub);
+ }
+
+ private void put(HashMap<String, ArrayList<IRoomValidator>> map, String cls, IRoomValidator val) {
+ ArrayList<IRoomValidator> list = map.get(cls);
+ if (list==null) {
+ list = new ArrayList<IRoomValidator>();
+ map.put(cls, list);
+ }
+ list.add(val);
+ }
+
+ private HashMap<String, ArrayList<IRoomValidator>> getMap(String mode) {
+ if (mode.equals(CheckType.FAST.name()))
+ return fastClass2Ext;
+ else if (mode.equals(CheckType.NORMAL.name()))
+ return normalClass2Ext;
+ else if (mode.equals(CheckType.EXPENSIVE.name()))
+ return normalClass2Ext;
+ else
+ return null;
+ }
+
+ private void executeExtension(
+ final IRoomValidator validator,
+ final EObject object,
+ final ValidationMessageAcceptor messageAcceptor) {
+
+ ISafeRunnable runnable = new ISafeRunnable() {
+ @Override
+ public void handleException(Throwable exception) {
+ System.out.println("Exception in IRoomValidator");
+ }
+
+ @Override
+ public void run() throws Exception {
+ validator.validate(object, messageAcceptor);
+ }
+ };
+ SafeRunner.run(runnable);
+ }
+ }
+
+ public ValidatorExtensionManager() {
+
+ }
+
+ @Check
+ public void checkObject(EObject object) {
+ Registry.getInstance().validate(object, getCheckMode(), getMessageAcceptor());
+ }
+
+ @Override
+ public void register(EValidatorRegistrar registrar) {
+ // HOWTO: if this validator is registered for the RoomPackage then it is called twice
+ }
+
+// @Override
+// protected List<EPackage> getEPackages() {
+// List<EPackage> result = new ArrayList<EPackage>();
+// result.add(RoomPackage.eINSTANCE);
+// return result;
+// }
+
+}

Back to the top