Skip to content

Commit

Permalink
adapt Xtext to be supported by theia
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed Sep 14, 2021
1 parent 8481392 commit 50f55c7
Show file tree
Hide file tree
Showing 61 changed files with 101,262 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class RosGeneratorTest {

val fsa = new InMemoryFileSystemAccess
CIGenerator.doGenerate(model.eResource, fsa, new GeneratorContext)
Assert.assertTrue(fsa.textFiles.containsKey(CICustomOutputProvider::COM_OUTPUT + "test_node.componentinterface"))
Assert.assertTrue(fsa.textFiles.containsKey(CICustomOutputProvider::CM_CONFIGURATION + "test_node.componentinterface"))
Assert.assertEquals(
new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR, 'components', 'test_node.componentinterface'))).trim,
fsa.textFiles.get(CICustomOutputProvider::COM_OUTPUT + "test_node.componentinterface").toString.trim)
fsa.textFiles.get(CICustomOutputProvider::CM_CONFIGURATION + "test_node.componentinterface").toString.trim)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ 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.generator.IContextualOutputConfigurationProvider

/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
class RosRuntimeModule extends AbstractRosRuntimeModule {
override void configure(Binder binder) {

override void configure(Binder binder) {
super.configure(binder)
binder.bind(IOutputConfigurationProvider).to(CICustomOutputProvider).asEagerSingleton()
binder.bind(IContextualOutputConfigurationProvider).to(CICustomOutputProvider).asEagerSingleton()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,35 @@ import org.eclipse.xtext.generator.IOutputConfigurationProvider
import org.eclipse.xtext.generator.OutputConfiguration
import ros.Node
import ros.Package
import org.eclipse.xtext.generator.IContextualOutputConfigurationProvider

class CICustomOutputProvider implements IOutputConfigurationProvider {
public final static String COM_OUTPUT = "COM_OUTPUT"

class CICustomOutputProvider implements IOutputConfigurationProvider, IContextualOutputConfigurationProvider {
public final static String CM_CONFIGURATION = "CM_CONFIGURATION"
public final static String DEFAULT_OUTPUT = "DEFAULT_OUTPUT"

override Set<OutputConfiguration> getOutputConfigurations() {

var OutputConfiguration default_config = new OutputConfiguration(COM_OUTPUT)
default_config.setDescription("COM_OUTPUT");
default_config.setOutputDirectory("./components/");
var OutputConfiguration cm_config = new OutputConfiguration(CM_CONFIGURATION)
cm_config.setDescription("CM_CONFIGURATION");
cm_config.setOutputDirectory("./components/");
cm_config.setOverrideExistingResources(true);
cm_config.setCreateOutputDirectory(true);
cm_config.setCleanUpDerivedResources(false);
cm_config.setSetDerivedProperty(false);
var OutputConfiguration default_config = new OutputConfiguration(DEFAULT_OUTPUT)
default_config.setDescription("DEFAULT_OUTPUT");
default_config.setOutputDirectory("./src-gen/");
default_config.setOverrideExistingResources(true);
default_config.setCreateOutputDirectory(true);
default_config.setCleanUpDerivedResources(false);
default_config.setSetDerivedProperty(false);
return newHashSet(default_config)
return newHashSet(cm_config, default_config)
}

override Set<OutputConfiguration> getOutputConfigurations(Resource context) {
return getOutputConfigurations()
}

}

/**
Expand Down Expand Up @@ -57,7 +70,8 @@ class RosGenerator extends AbstractGenerator {
}
}
for (node : resource.allContents.toIterable.filter(Node)){
fsa.generateFile(node.getName()+".componentinterface",CICustomOutputProvider::COM_OUTPUT,compile(node,package_name,artifact_name))
fsa.generateFile(node.getName()+".componentinterface",CICustomOutputProvider::CM_CONFIGURATION,compile(node,package_name,artifact_name))

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,28 @@ Bundle-SymbolicName: de.fraunhofer.ipa.rossystem.xtext.ide; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: de.fraunhofer.ipa.rossystem.xtext,
de.fraunhofer.ipa.rossystem,
de.fraunhofer.ipa.ros.xtext,
de.fraunhofer.ipa.ros,
org.eclipse.xtext.ide,
org.eclipse.xtext.xbase.ide,
org.eclipse.sprotty,
org.eclipse.sprotty.layout,
org.eclipse.sprotty.server,
org.eclipse.sprotty.xtext,
org.eclipse.lsp4j,
org.eclipse.elk.graph,
com.google.gson,
org.objectweb.asm,
org.objectweb.asm.commons,
org.objectweb.asm.tree,
org.apache.log4j,
org.eclipse.elk.alg.common,
org.eclipse.elk.alg.layered,
org.eclipse.elk.core,
org.eclipse.lsp4j.jsonrpc,
org.antlr.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: de.fraunhofer.ipa.rossystem.ide.contentassist.antlr.internal,
de.fraunhofer.ipa.rossystem.ide.contentassist.antlr
de.fraunhofer.ipa.rossystem.ide.contentassist.antlr,
de.fraunhofer.ipa.ros.ide.contentassist.antlr,
de.fraunhofer.ipa.ros.ide.contentassist.antlr.internal
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
de.fraunhofer.ipa.rossystem.ide.RosSystemIdeSetup
de.fraunhofer.ipa.ros.ide.RosIdeSetup
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* generated by Xtext 2.24.0
*/
package de.fraunhofer.ipa.ros.ide;

import com.google.inject.Binder;
import com.google.inject.name.Names;
import de.fraunhofer.ipa.ros.ide.contentassist.antlr.RosParser;
import de.fraunhofer.ipa.ros.ide.contentassist.antlr.internal.InternalRosLexer;
import org.eclipse.xtext.ide.DefaultIdeModule;
import org.eclipse.xtext.ide.LexerIdeBindings;
import org.eclipse.xtext.ide.editor.contentassist.FQNPrefixMatcher;
import org.eclipse.xtext.ide.editor.contentassist.IPrefixMatcher;
import org.eclipse.xtext.ide.editor.contentassist.IProposalConflictHelper;
import org.eclipse.xtext.ide.editor.contentassist.antlr.AntlrProposalConflictHelper;
import org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser;
import org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer;
import org.eclipse.xtext.ide.refactoring.IRenameStrategy2;
import org.eclipse.xtext.ide.server.rename.IRenameService2;
import org.eclipse.xtext.ide.server.rename.RenameService2;

/**
* Manual modifications go to {@link RosIdeModule}.
*/
@SuppressWarnings("all")
public abstract class AbstractRosIdeModule extends DefaultIdeModule {

// contributed by org.eclipse.xtext.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment2
public void configureContentAssistLexer(Binder binder) {
binder.bind(Lexer.class)
.annotatedWith(Names.named(LexerIdeBindings.CONTENT_ASSIST))
.to(InternalRosLexer.class);
}

// contributed by org.eclipse.xtext.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment2
public Class<? extends IContentAssistParser> bindIContentAssistParser() {
return RosParser.class;
}

// contributed by org.eclipse.xtext.xtext.generator.parser.antlr.XtextAntlrGeneratorFragment2
public Class<? extends IProposalConflictHelper> bindIProposalConflictHelper() {
return AntlrProposalConflictHelper.class;
}

// contributed by org.eclipse.xtext.xtext.generator.exporting.QualifiedNamesFragment2
public Class<? extends IPrefixMatcher> bindIPrefixMatcher() {
return FQNPrefixMatcher.class;
}

// contributed by org.eclipse.xtext.xtext.generator.ui.refactoring.RefactorElementNameFragment2
public Class<? extends IRenameService2> bindIRenameService2() {
return RenameService2.class;
}

// contributed by org.eclipse.xtext.xtext.generator.ui.refactoring.RefactorElementNameFragment2
public Class<? extends IRenameStrategy2> bindIRenameStrategy2() {
return IRenameStrategy2.DefaultImpl.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* generated by Xtext 2.24.0
*/
package de.fraunhofer.ipa.ros.ide.contentassist.antlr;

import java.util.Collection;
import java.util.Collections;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement;
import org.eclipse.xtext.ide.editor.contentassist.antlr.internal.AbstractInternalContentAssistParser;
import org.eclipse.xtext.util.PolymorphicDispatcher;

public class PartialRosContentAssistParser extends RosParser {

private AbstractRule rule;

@Override
public void initializeFor(AbstractRule rule) {
this.rule = rule;
}

@Override
protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) {
if (rule == null || rule.eIsProxy())
return Collections.emptyList();
String methodName = "entryRule" + rule.getName();
PolymorphicDispatcher<Collection<FollowElement>> dispatcher =
new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser));
dispatcher.invoke();
return parser.getFollowElements();
}

}
Loading

0 comments on commit 50f55c7

Please sign in to comment.