Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2019-08-26 08:47:17 -0400
committerJuergen Haug2019-08-26 08:47:17 -0400
commita53edb84d9bf41a5c874f874474f9f91725377ed (patch)
treec4dc25a0c44cd7aa12910581f1255e03796ea438
parent3db28f8c02d066d107e343baf958712bc35fc9eb (diff)
downloadorg.eclipse.etrice-a53edb84d9bf41a5c874f874474f9f91725377ed.tar.gz
org.eclipse.etrice-a53edb84d9bf41a5c874f874474f9f91725377ed.tar.xz
org.eclipse.etrice-a53edb84d9bf41a5c874f874474f9f91725377ed.zip
added RoomModel template with correct namespace + minor improvements
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java45
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickFixProviderXtend.xtend5
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml5
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/build.gradle3
-rw-r--r--tests/org.eclipse.etrice.generator.common.tests/models/Bug541775_NoInitialTransition.room32
6 files changed, 80 insertions, 13 deletions
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 487790597..0babd26b1 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,7 +24,8 @@ Require-Bundle: org.eclipse.etrice.core.fsm.ui;bundle-version="2.0.0",
org.eclipse.help,
com.google.inject,
org.eclipse.etrice.expressions.ui,
- org.eclipse.etrice.ui.behavior.fsm;bundle-version="2.0.0"
+ org.eclipse.etrice.ui.behavior.fsm;bundle-version="2.0.0",
+ org.eclipse.etrice.generator.base;bundle-version="2.0.0"
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.etrice.core.ui,
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
index 8ef81fe69..433722e3a 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
@@ -16,10 +16,12 @@ package org.eclipse.etrice.core.ui.contentassist;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.common.base.AnnotationType;
import org.eclipse.etrice.core.common.ui.contentassist.ImportModelAssist;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
@@ -39,12 +41,17 @@ import org.eclipse.etrice.core.services.RoomGrammarAccess;
import org.eclipse.etrice.core.ui.util.UIExpressionUtil;
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider;
import org.eclipse.etrice.expressions.ui.contentassist.RoomExpressionProposalProvider;
+import org.eclipse.etrice.generator.base.io.IModelPath;
+import org.eclipse.etrice.generator.base.io.IModelPathProvider;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.Assignment;
-import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.CrossReference;
+import org.eclipse.xtext.Keyword;
import org.eclipse.xtext.RuleCall;
+import org.eclipse.xtext.formatting.IWhitespaceInformationProvider;
+import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
@@ -57,14 +64,36 @@ import com.google.inject.Inject;
*/
public class RoomProposalProvider extends AbstractRoomProposalProvider {
- @Inject
- protected RoomHelpers roomHelpers;
+ @Inject protected RoomHelpers roomHelpers;
+ @Inject protected RoomNameProvider roomNameProvider;
+ @Inject protected RoomGrammarAccess grammar;
+ @Inject protected IModelPathProvider modelPathProvider;
+ @Inject protected IWhitespaceInformationProvider whiteSpaceInfo;
- @Inject
- protected RoomNameProvider roomNameProvider;
-
- @Inject
- protected RoomGrammarAccess grammar;
+ @Override
+ public void complete_RoomModel(EObject model, RuleCall ruleCall, ContentAssistContext context,
+ ICompletionProposalAcceptor acceptor) {
+ Resource resource = context.getResource();
+ if(model == null || model.eContents().isEmpty()) {
+ IModelPath modelPath = modelPathProvider.get(resource);
+ Optional<QualifiedName> modelPathFQN = modelPath.getQualifiedName(resource.getURI());
+ String modelName = modelPathFQN.map(fqn -> fqn.toString()).orElse(resource.getURI().trimFileExtension().lastSegment());
+
+ String lineSep = whiteSpaceInfo.getLineSeparatorInformation(resource.getURI()).getLineSeparator();
+ String indent = whiteSpaceInfo.getIndentationInformation(resource.getURI()).getIndentString();
+
+ String proposalStr = "RoomModel " + modelName + " {" + lineSep + lineSep + indent + "import etrice.api.types.*" + lineSep + lineSep + indent + lineSep + "}";
+ ICompletionProposal proposal = createCompletionProposal(proposalStr, "RoomModel - empty template", null, context);
+ if(proposal instanceof ConfigurableCompletionProposal) {
+ ConfigurableCompletionProposal configProposal = (ConfigurableCompletionProposal) proposal;
+ configProposal.setSelectionStart(proposalStr.length() - (lineSep + "}").length());
+ configProposal.setSelectionLength(1);
+ }
+ acceptor.accept(proposal);
+ } else {
+ super.complete_RoomModel(model, ruleCall, context, acceptor);
+ }
+ }
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickFixProviderXtend.xtend b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickFixProviderXtend.xtend
index cf7179eb4..ddac4bdcc 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickFixProviderXtend.xtend
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/quickfix/RoomQuickFixProviderXtend.xtend
@@ -23,11 +23,14 @@ import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
import org.eclipse.xtext.validation.Issue
import org.eclipse.etrice.core.room.RoomPackage
+import org.eclipse.etrice.core.common.base.BasePackage
class RoomQuickFixProviderXtend extends RoomQuickfixProvider {
@Inject ImportHelpers importHelpers
+ val static importQuickFixClasses = #{RoomPackage.Literals.ROOM_CLASS, BasePackage.Literals.ANNOTATION_TYPE}
+
// override xtext linking issues
override getResolutionsForLinkingIssue(Issue issue) {
val xtextDocument = modificationContextFactory.createModificationContext(issue).getXtextDocument
@@ -47,7 +50,7 @@ class RoomQuickFixProviderXtend extends RoomQuickfixProvider {
val target = resource.getEObject(issue.uriToProblem.fragment)
val reference = getUnresolvedEReference(issue, target)
- if(reference !== null && RoomPackage.Literals.ROOM_CLASS.isSuperTypeOf(reference.EReferenceType)) {
+ if(reference !== null && importQuickFixClasses.exists[it.isSuperTypeOf(reference.EReferenceType)]) {
createLinkingImports(issue, issueString, resource, reference.EReferenceType, false, acceptor);
}
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml b/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
index a9d220009..6249d0c39 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
+++ b/plugins/org.eclipse.etrice.core.room.ui/templates/templates.xml
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
- <template autoinsert="true" context="org.eclipse.etrice.core.Room.RoomModel"
+ <!-- RoomModel template here cannot compute the namespace, use RoomProposalProvider instead -->
+ <!-->template autoinsert="true" context="org.eclipse.etrice.core.Room.RoomModel"
deleted="false" description="model skeleton" enabled="true" id="model"
name="RoomModel"
>RoomModel ${RoomModel1} {
@@ -17,7 +18,7 @@
ActorClass ${ActorClass1} {
}
-}${cursor}</template>
+}${cursor}</template-->
<template autoinsert="true" context="org.eclipse.etrice.core.Room.ActorClass"
deleted="false" description="actor class skeleton" enabled="true"
diff --git a/tests/org.eclipse.etrice.generator.common.tests/build.gradle b/tests/org.eclipse.etrice.generator.common.tests/build.gradle
index 685efc007..06fd90738 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/build.gradle
+++ b/tests/org.eclipse.etrice.generator.common.tests/build.gradle
@@ -24,12 +24,13 @@ def tests = [
choicePointTestExtended: ['models/ChoicePointTestExtended.room', genericPhysical],
dataDrivenTest: ['models/DataDrivenTest.room', genericPhysical],
/* enumTest: ['models/EnumTest.room', genericPhysical], not supported in c++ */
- compileTest: ['models/CompileTest.room', genericPhysical, 'models/StatemachineInterfaceTest.room', 'models/StatemachineInterfaceInheritedTest.room', 'models/StatemachineInterfaceTest.room', 'models/ContinuationTransitionTest.room', 'models/Bug541775_NoInitialTransition.room'],
+ compileTest: ['models/CompileTest.room', genericPhysical, 'models/StatemachineInterfaceTest.room', 'models/StatemachineInterfaceInheritedTest.room', 'models/StatemachineInterfaceTest.room', 'models/ContinuationTransitionTest.room'],
handlerTest: ['models/HandlerTest.room', genericPhysical],
operationInheritanceTest: ['models/OperationInheritanceTest.room', genericPhysical],
pingPongThreadTest: ['models/PingPongThreadTest.etmap', 'models/PingPongThreadTest.room'],
pingPongThreadReplPortTest: ['models/PingPongThreadReplPortTest.etmap', 'models/PingPongThreadReplPortTest.room'],
+ bug541775Test: ['models/Bug541775_NoInitialTransition.room', genericPhysical],
]
tests.each { name, models ->
diff --git a/tests/org.eclipse.etrice.generator.common.tests/models/Bug541775_NoInitialTransition.room b/tests/org.eclipse.etrice.generator.common.tests/models/Bug541775_NoInitialTransition.room
index cdeb83a8d..630944b2f 100644
--- a/tests/org.eclipse.etrice.generator.common.tests/models/Bug541775_NoInitialTransition.room
+++ b/tests/org.eclipse.etrice.generator.common.tests/models/Bug541775_NoInitialTransition.room
@@ -1,11 +1,15 @@
RoomModel Bug541775_NoInitialTransition {
+ import etrice.api.annotations.TestInstance
+ import etrice.api.types.int32
+
ProtocolClass PDummy {
incoming {
Message in1
}
}
+ // generate and compile this actor
abstract ActorClass ANoInitialTransition {
Structure {
Port p1: PDummy
@@ -21,4 +25,32 @@ RoomModel Bug541775_NoInitialTransition {
}
}
}
+
+ ActorClass AInitialTransition extends ANoInitialTransition {
+ @TestInstance
+ Structure {
+ Attribute caseId: int32
+ }
+ Behavior {
+ ctor '''
+ caseId = etUnit_openAll("log", "Bug541775Test", "org.eclipse.etrice.generator.common.tests.Bug541775", "Bug541775_case");
+ '''
+ dtor '''
+ etUnit_closeAll(caseId);
+ '''
+ StateMachine {
+ State state0 {
+ subgraph {
+ State state0
+ Transition init: initial -> state0
+ }
+ }
+ Transition init0: initial -> state0 {
+ action '''
+ etUnit_testFinished(caseId);
+ '''
+ }
+ }
+ }
+ }
} \ No newline at end of file

Back to the top