From a7896fdaeb2dd0446d8206ae2d2f92cc1fe0c02e Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Thu, 1 Jun 2023 14:43:01 +0200 Subject: [PATCH] Add customized qualified name for cross references for specifications, e.g., TopicSpec --- .../src/de/fraunhofer/ipa/ros/RosQNP.xtend | 29 +++++++++++++++++++ .../fraunhofer/ipa/ros/RosRuntimeModule.xtend | 12 +++++++- .../de/fraunhofer/ipa/ros/scoping/RosSP.xtend | 23 +++++++++++++++ .../ipa/ros2/Ros2RuntimeModule.xtend | 14 +++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosQNP.xtend create mode 100644 plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/scoping/RosSP.xtend diff --git a/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosQNP.xtend b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosQNP.xtend new file mode 100644 index 000000000..f7bf8c1cd --- /dev/null +++ b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosQNP.xtend @@ -0,0 +1,29 @@ +package de.fraunhofer.ipa.ros; + +import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider +import org.eclipse.emf.ecore.EObject +import ros.TopicSpec +import ros.ServiceSpec +import ros.ActionSpec + +class RosQNP extends DefaultDeclarativeQualifiedNameProvider{ + + override getFullyQualifiedName(EObject obj) { + if (obj instanceof TopicSpec) { + val topic_spec_name = obj.name + val pkg_name = obj.package.name + return getConverter().toQualifiedName(pkg_name + "/msg/" + topic_spec_name); + } + if (obj instanceof ServiceSpec) { + val service_spec_name = obj.name + val pkg_name = obj.package.name + return getConverter().toQualifiedName(pkg_name + "/srv/" + service_spec_name); + } + if (obj instanceof ActionSpec) { + val action_spec_name = obj.name + val pkg_name = obj.package.name + return getConverter().toQualifiedName(pkg_name + "/action/" + action_spec_name); + } + return super.qualifiedName(obj); + } +} diff --git a/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosRuntimeModule.xtend b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosRuntimeModule.xtend index 64d3578c0..fb17fd257 100644 --- a/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosRuntimeModule.xtend +++ b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/RosRuntimeModule.xtend @@ -5,8 +5,10 @@ package de.fraunhofer.ipa.ros import com.google.inject.Binder import de.fraunhofer.ipa.ros.generator.CICustomOutputProvider -import org.eclipse.xtext.conversion.IValueConverterService import org.eclipse.xtext.generator.IOutputConfigurationProvider +import org.eclipse.xtext.scoping.IScopeProvider +import de.fraunhofer.ipa.ros.scoping.RosSP +import org.eclipse.xtext.naming.IQualifiedNameProvider /** * Use this class to register components to be used at runtime / without the Equinox extension registry. @@ -18,4 +20,12 @@ class RosRuntimeModule extends AbstractRosRuntimeModule { binder.bind(IOutputConfigurationProvider).to(CICustomOutputProvider).asEagerSingleton() } + override Class bindIScopeProvider() { + return RosSP + } + + override Class bindIQualifiedNameProvider() { + return RosQNP + } + } diff --git a/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/scoping/RosSP.xtend b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/scoping/RosSP.xtend new file mode 100644 index 000000000..571aaade7 --- /dev/null +++ b/plugins/de.fraunhofer.ipa.ros.xtext/src/de/fraunhofer/ipa/ros/scoping/RosSP.xtend @@ -0,0 +1,23 @@ +package de.fraunhofer.ipa.ros.scoping + +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.EReference +import org.eclipse.xtext.EcoreUtil2 +import org.eclipse.xtext.scoping.Scopes +import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider +import ros.RosPackage +import ros.SpecBase + +class RosSP extends AbstractDeclarativeScopeProvider { + + override getScope(EObject context, EReference reference) { + if (context instanceof SpecBase) { + if (reference == RosPackage.Literals.SPEC_BASE) { + val candidates = EcoreUtil2.getAllContentsOfType(context.package, SpecBase); + return Scopes.scopeFor(candidates) + } + } + return super.getScope(context, reference); + } + +} \ No newline at end of file diff --git a/plugins/de.fraunhofer.ipa.ros2.xtext/src/de/fraunhofer/ipa/ros2/Ros2RuntimeModule.xtend b/plugins/de.fraunhofer.ipa.ros2.xtext/src/de/fraunhofer/ipa/ros2/Ros2RuntimeModule.xtend index fd6401132..517c849e2 100644 --- a/plugins/de.fraunhofer.ipa.ros2.xtext/src/de/fraunhofer/ipa/ros2/Ros2RuntimeModule.xtend +++ b/plugins/de.fraunhofer.ipa.ros2.xtext/src/de/fraunhofer/ipa/ros2/Ros2RuntimeModule.xtend @@ -3,9 +3,23 @@ */ package de.fraunhofer.ipa.ros2 +import org.eclipse.xtext.scoping.IGlobalScopeProvider +import de.fraunhofer.ipa.ros.RosQNP +import org.eclipse.xtext.naming.IQualifiedNameProvider +import org.eclipse.xtext.scoping.IScopeProvider +import de.fraunhofer.ipa.ros.scoping.RosSP /** * Use this class to register components to be used at runtime / without the Equinox extension registry. */ class Ros2RuntimeModule extends AbstractRos2RuntimeModule { + + override Class bindIScopeProvider() { + return RosSP + } + + override Class bindIQualifiedNameProvider() { + return RosQNP + } + }