|
|
|
|
Re: Gets proposal for a position [message #1741093 is a reply to message #1741086] |
Tue, 23 August 2016 04:31 |
|
i did just some playaround: btw. why do you want to do this?
@RunWith(XtextRunner)
@InjectWith(MyDslIdeInjectorProvider)
class MyDslParsingTest{
static class MyDslIdeInjectorProvider extends MyDslInjectorProvider {
override protected internalCreateInjector() {
return new MyDslStandaloneSetup() {
@Override
override Injector createInjector() {
return Guice.createInjector(createRuntimeModule(), new MyDslIdeModule);
}
}.createInjectorAndDoEMFRegistration();
}
}
val List<ExecutorService> executorServices = newArrayList
@Inject
ParseHelper<Model> parseHelper
@Inject Provider<ContentAssistContextFactory> contextFactoryProvider
@Inject IdeContentProposalProvider proposalProvider
ExecutorService executorService
new() {
executorService = Executors.newCachedThreadPool => [executorServices += it]
}
@Test
def void loadModel() {
val model = '''
Hello Xtext!
'''
val result = parseHelper.parse(model)
Assert.assertNotNull(result)
val contexts = (result.eResource as XtextResource).getContexts(new TextRegion(6,0), 6)
val a = new IIdeContentProposalAcceptor {
override accept(ContentAssistEntry e, int prio) {
println(e.toString)
}
override canAcceptMoreProposals() {
true
}
}
proposalProvider.createProposals(contexts, a)
}
def ContentAssistContext[] getContexts(XtextResource resource, ITextRegion selection, int caretOffset) {
val text = resource.parseResult.rootNode.text
if (caretOffset > text.length)
return #[]
val contextFactory = contextFactoryProvider.get() => [it.pool = executorService]
contextFactory.create(text, selection, caretOffset, resource)
}
@After
def void tearDown() {
executorServices.forEach[shutdown()]
executorServices.clear()
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Gets proposal for a position [message #1741112 is a reply to message #1741093] |
Tue, 23 August 2016 07:49 |
Michael Müller Messages: 20 Registered: August 2016 |
Junior Member |
|
|
Christian Dietrich wrote on Tue, 23 August 2016 04:31i did just some playaround: btw. why do you want to do this?
Thanks a lot. I will try that.
I would like to integrate xText with Vaadin. I just need a Textfield (not a whole Editor) with auto completion or suggestion support. Additionally i need the parsing and error handling.
So the user enter "Hel" and now there is a suggestion to use the keyword "Hello"
@Test
def void loadModel() {
val model = '''
Hel
'''
val result = parseHelper.parse(model)
Assert.assertNotNull(result)
val contexts = (result.eResource as XtextResource).getContexts(new TextRegion(3,0), 6)
val a = new IIdeContentProposalAcceptor {
override accept(ContentAssistEntry e, int prio) {
println(e.toString)
}
override canAcceptMoreProposals() {
true
}
}
proposalProvider.createProposals(contexts, a)
}
[Updated on: Tue, 23 August 2016 08:36] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Gets proposal for a position [message #1741149 is a reply to message #1741146] |
Tue, 23 August 2016 11:03 |
|
well that was you abusing parsehelper
/*
* generated by Xtext 2.10.0
*/
package org.xtext.example.mydsl5.tests
import com.google.inject.Guice
import com.google.inject.Inject
import com.google.inject.Injector
import com.google.inject.Provider
import java.util.List
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import org.eclipse.emf.common.util.URI
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.eclipse.xtext.resource.FileExtensionProvider
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.util.ITextRegion
import org.eclipse.xtext.util.StringInputStream
import org.eclipse.xtext.util.TextRegion
import org.junit.After
import org.junit.Test
import org.junit.runner.RunWith
import org.xtext.example.mydsl5.MyDslStandaloneSetup
import org.xtext.example.mydsl5.ide.MyDslIdeModule
import org.xtext.example.mydsl5.myDsl.Model
@RunWith(XtextRunner)
@InjectWith(MyDslIdeInjectorProvider)
class MyDslParsingTest{
static class MyDslIdeInjectorProvider extends MyDslInjectorProvider {
override protected internalCreateInjector() {
return new MyDslStandaloneSetup() {
@Override
override Injector createInjector() {
return Guice.createInjector(createRuntimeModule(), new MyDslIdeModule);
}
}.createInjectorAndDoEMFRegistration();
}
}
val List<ExecutorService> executorServices = newArrayList
@Inject Provider<ContentAssistContextFactory> contextFactoryProvider
@Inject IdeContentProposalProvider proposalProvider
ExecutorService executorService
@Inject
Provider<XtextResourceSet> rsp
@Inject
extension FileExtensionProvider
new() {
executorService = Executors.newCachedThreadPool => [executorServices += it]
}
@Test
def void loadModel() {
val model = '''
Hel
'''
val rs = rsp.get
val resource = rs.createResource(URI.createURI("demo." + primaryFileExtension)) as XtextResource
resource.load(new StringInputStream(model), null)
val contexts = resource.getContexts(new TextRegion(3,0), 3)
val a = new IIdeContentProposalAcceptor {
override accept(ContentAssistEntry e, int prio) {
println(e.toString)
}
override canAcceptMoreProposals() {
true
}
}
proposalProvider.createProposals(contexts, a)
}
def ContentAssistContext[] getContexts(XtextResource resource, ITextRegion selection, int caretOffset) {
val text = resource.parseResult.rootNode.text
if (caretOffset > text.length)
return #[]
val contextFactory = contextFactoryProvider.get() => [it.pool = executorService]
contextFactory.create(text, selection, caretOffset, resource)
}
@After
def void tearDown() {
executorServices.forEach[shutdown()]
executorServices.clear()
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03048 seconds