Skip to content

Commit

Permalink
Add customized qualified name for cross references for specifications…
Browse files Browse the repository at this point in the history
…, e.g., TopicSpec
  • Loading branch information
ipa-nhg committed Jun 1, 2023
1 parent de87909 commit a7896fd
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,4 +20,12 @@ class RosRuntimeModule extends AbstractRosRuntimeModule {
binder.bind(IOutputConfigurationProvider).to(CICustomOutputProvider).asEagerSingleton()
}

override Class<? extends IScopeProvider> bindIScopeProvider() {
return RosSP
}

override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return RosQNP
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends IScopeProvider> bindIScopeProvider() {
return RosSP
}

override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return RosQNP
}

}

0 comments on commit a7896fd

Please sign in to comment.