From 177965c4f54f156684783f313acb1ab2ca99d321 Mon Sep 17 00:00:00 2001 From: Henrik Rentz-Reichert Date: Sat, 26 May 2012 00:53:52 +0200 Subject: [core.room, core.room.ui, genmodel, abstractexec.behavior] validator and quickfix extension points and extension examples preparations for abstract state machine execution --- .../.classpath | 7 + .../.gitignore | 2 + .../.project | 28 +++ .../.settings/org.eclipse.jdt.core.prefs | 8 + .../META-INF/MANIFEST.MF | 14 ++ .../build.properties | 5 + .../plugin.xml | 25 +++ .../behavior/AbstractExecutionValidator.java | 66 +++++++ .../abstractexec/behavior/ActionCodeAnalyzer.java | 83 +++++++++ .../etrice/abstractexec/behavior/DemoQuickfix.java | 40 +++++ .../abstractexec/behavior/DemoValidator.java | 44 +++++ .../core/genmodel/base/NullDiagnostician.java | 65 +++++++ .../etrice/core/genmodel/base/NullLogger.java | 37 ++++ .../genmodel/builder/GeneratorModelBuilder.java | 2 +- .../META-INF/MANIFEST.MF | 5 +- plugins/org.eclipse.etrice.core.room.ui/plugin.xml | 1 + .../schema/quickfix.exsd | 109 +++++++++++ .../eclipse/etrice/core/ui/RoomUiActivator.java | 15 ++ .../core/ui/quickfix/IRoomQuickfixProvider.java | 12 ++ .../core/ui/quickfix/QuickfixExtensionManager.java | 88 +++++++++ .../core/ui/quickfix/RoomQuickfixProvider.java | 24 +++ .../META-INF/MANIFEST.MF | 1 + plugins/org.eclipse.etrice.core.room/plugin.xml | 1 + .../schema/validation.exsd | 129 +++++++++++++ .../core/validation/AbstractRoomJavaValidator.java | 2 +- .../src/org/eclipse/etrice/core/GenerateRoom.mwe2 | 4 +- .../src/org/eclipse/etrice/core/RoomActivator.java | 19 ++ .../etrice/core/validation/IRoomValidator.java | 26 +++ .../core/validation/ValidatorExtensionManager.java | 200 +++++++++++++++++++++ 29 files changed, 1057 insertions(+), 5 deletions(-) create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/.classpath create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/.gitignore create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/.project create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/META-INF/MANIFEST.MF create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/build.properties create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/plugin.xml create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/AbstractExecutionValidator.java create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/ActionCodeAnalyzer.java create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoQuickfix.java create mode 100644 plugins/org.eclipse.etrice.abstractexec.behavior/src/org/eclipse/etrice/abstractexec/behavior/DemoValidator.java create mode 100644 plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullDiagnostician.java create mode 100644 plugins/org.eclipse.etrice.core.genmodel/src/org/eclipse/etrice/core/genmodel/base/NullLogger.java create mode 100644 plugins/org.eclipse.etrice.core.room.ui/schema/quickfix.exsd create mode 100644 plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/RoomUiActivator.java create mode 100644 plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/IRoomQuickfixProvider.java create mode 100644 plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/QuickfixExtensionManager.java create mode 100644 plugins/org.eclipse.etrice.core.room/schema/validation.exsd create mode 100644 plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java create mode 100644 plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/IRoomValidator.java create mode 100644 plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidatorExtensionManager.java 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 @@ + + + + + + + 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 @@ + + + org.eclipse.etrice.abstractexec.behavior + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + 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 @@ + + + + + + + + + + + + + + + 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 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 mifs = new ArrayList(); + + public ArrayList 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 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(); + } + } + + private Collector collector; + private DetailCodeTranslator translator; + + public ActionCodeAnalyzer(ActorClass ac) { + collector = new Collector(); + translator = new DetailCodeTranslator(ac, collector); + } + + public List 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 @@ + 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 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + 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> code2provider = new HashMap>(); + + 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 list = code2provider.get(issue.getCode()); + if (list!=null) + for (IRoomQuickfixProvider provider : list) { + executeExtension(provider, issue, acceptor); + } + } + + public boolean hasResolutionFor(String issueCode) { + ArrayList 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 list = code2provider.get(code); + if (list==null) { + list = new ArrayList(); + 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 getResolutions(Issue issue) { + List result = new ArrayList(); + + 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 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + 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> fastClass2Ext = new HashMap>(); + private HashMap> normalClass2Ext = new HashMap>(); + private HashMap> expensiveClass2Ext = new HashMap>(); + + 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> cls2sub = new HashMap>(); + for (EClassifier cls : RoomPackage.eINSTANCE.getEClassifiers()) { + if (cls instanceof EClass) { + EList 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> map = getMap(mode); + if (map!=null) { + put(map, ((EClass) cls).getName(), (IRoomValidator) ext); + ArrayList 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 executed = new HashSet(); + 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> map, HashSet executed) { + ArrayList 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> cls2sub) { + + ArrayList list = cls2sub.get(cls); + if (list==null) { + list = new ArrayList(); + cls2sub.put(cls, list); + } + list.add(sub); + } + + private void put(HashMap> map, String cls, IRoomValidator val) { + ArrayList list = map.get(cls); + if (list==null) { + list = new ArrayList(); + map.put(cls, list); + } + list.add(val); + } + + private HashMap> 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 getEPackages() { +// List result = new ArrayList(); +// result.add(RoomPackage.eINSTANCE); +// return result; +// } + +} -- cgit v1.2.3