[eclipse/xtext#1679] ported more code to java

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2020-03-21 16:36:21 +01:00
parent 5ac95444ee
commit 90d648b042
30 changed files with 347 additions and 773 deletions

View file

@ -1,16 +1,15 @@
/**
* Copyright (c) 2017 itemis AG (http://www.itemis.de) and others.
/*******************************************************************************
* Copyright (c) 2017, 2020 itemis AG (http://www.itemis.de) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
*
* SPDX-License-Identifier: EPL-2.0
*/
*******************************************************************************/
package org.eclipse.xtext.ide.tests.indentation;
import com.google.inject.Inject;
import org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider;
import org.eclipse.xtext.ide.tests.indentation.AbstractCompletePrefixProviderTest;
import org.eclipse.xtext.ide.tests.testlanguage.tests.IndentationAwareUiTestLanguageInjectorProvider;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
@ -21,13 +20,14 @@ import org.junit.runner.RunWith;
*/
@RunWith(XtextRunner.class)
@InjectWith(IndentationAwareUiTestLanguageInjectorProvider.class)
@SuppressWarnings("all")
public class CompletionPrefixProviderTest extends AbstractCompletePrefixProviderTest {
@Inject
private CompletionPrefixProvider testee;
@Override
public CompletionPrefixProvider getTestee() {
return this.testee;
}
}
@Inject
private CompletionPrefixProvider testee;
@Override
public CompletionPrefixProvider getTestee() {
return testee;
}
}

View file

@ -1,31 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017 itemis AG (http://www.itemis.de) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.indentation
import com.google.inject.Inject
import org.eclipse.xtext.ide.editor.contentassist.CompletionPrefixProvider
import org.eclipse.xtext.ide.tests.testlanguage.tests.IndentationAwareUiTestLanguageInjectorProvider
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.runner.RunWith
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
@RunWith(XtextRunner)
@InjectWith(IndentationAwareUiTestLanguageInjectorProvider)
class CompletionPrefixProviderTest extends AbstractCompletePrefixProviderTest {
@Inject CompletionPrefixProvider testee;
override getTestee() {
return testee
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.util;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.lsp4j.Position;
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
import org.eclipse.xtext.ide.util.PositionComparator;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.common.collect.Lists;
/**
* Test for the null-safe {@link PositionComparator}.
*
* @author akos.kitta - Initial contribution and API
*/
@RunWith(XtextRunner.class)
@InjectWith(TestLanguageIdeInjectorProvider.class)
public class PositionComparatorTest extends Assert {
@Inject
private PositionComparator comparator;
@Test
public void withoutNull() {
List<? extends Position> input = sort(Lists.newArrayList(new Position(2, 2), new Position(2, 1), new Position(1, 2), new Position(1, 1)));
assertEquals(1, input.get(0).getLine());
assertEquals(1, input.get(0).getCharacter());
assertEquals(1, input.get(1).getLine());
assertEquals(2, input.get(1).getCharacter());
assertEquals(2, input.get(2).getLine());
assertEquals(1, input.get(2).getCharacter());
assertEquals(2, input.get(3).getLine());
assertEquals(2, input.get(3).getCharacter());
}
@Test
public void withNull() {
List<? extends Position> input = sort(Lists.newArrayList(new Position(2, 2), null, new Position(1, 1)));
assertEquals(1, input.get(0).getLine());
assertEquals(1, input.get(0).getCharacter());
assertEquals(2, input.get(1).getLine());
assertEquals(2, input.get(1).getCharacter());
assertNull(IterableExtensions.last(input));
}
private List<? extends Position> sort(List<? extends Position> toSort) {
toSort.sort(comparator);
return toSort;
}
}

View file

@ -1,69 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.util
import java.util.List
import javax.inject.Inject
import org.eclipse.lsp4j.Position
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider
import org.eclipse.xtext.ide.util.PositionComparator
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
/**
* Test for the null-safe {@link PositionComparator}.
*
* @author akos.kitta - Initial contribution and API
*/
@RunWith(XtextRunner)
@InjectWith(TestLanguageIdeInjectorProvider)
class PositionComparatorTest extends Assert {
@Inject
PositionComparator comparator;
@Test
def void withoutNull() {
val input = newArrayList(new Position(2, 2), new Position(2, 1), new Position(1, 2), new Position(1, 1)).sort;
assertEquals(1, input.get(0).line);
assertEquals(1, input.get(0).character);
assertEquals(1, input.get(1).line);
assertEquals(2, input.get(1).character);
assertEquals(2, input.get(2).line);
assertEquals(1, input.get(2).character);
assertEquals(2, input.get(3).line);
assertEquals(2, input.get(3).character);
}
@Test
def void withNull() {
val input = newArrayList(new Position(2, 2), null, new Position(1, 1)).sort;
assertEquals(1, input.get(0).line);
assertEquals(1, input.get(0).character);
assertEquals(2, input.get(1).line);
assertEquals(2, input.get(1).character);
assertNull(input.last)
}
private def sort(List<? extends Position> toSort) {
toSort.sort(comparator);
return toSort;
}
}

View file

@ -62,7 +62,7 @@ Workflow {
generateStub = false
}
validator = {
generateXtendStub = true
generateStub = true
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
junitSupport = {
@ -86,7 +86,7 @@ Workflow {
generateStub = false
}
generator = {
generateXtendStub = true
generateStub = true
}
}
language = StandardLanguage {
@ -105,7 +105,7 @@ Workflow {
partialParsing = true
}
generator = {
generateXtendStub = true
generateStub = true
}
}
language = StandardLanguage {
@ -130,7 +130,7 @@ Workflow {
generateXtendStub = true
}
generator = {
generateXtendStub = true
generateStub = true
}
}
language = StandardLanguage {
@ -146,7 +146,7 @@ Workflow {
generateStub = false
}
generator = {
generateXtendStub = true
generateStub = true
}
}
}

View file

@ -1,22 +1,28 @@
/*******************************************************************************
* Copyright (c) 2018 TypeFox and others.
* Copyright (c) 2018, 2020 TypeFox and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.editor.syntaxcoloring
package org.eclipse.xtext.ide.tests.testlanguage.editor.syntaxcoloring;
import org.eclipse.xtext.ide.server.semanticHighlight.ISemanticHighlightingStyleToTokenMapper
import java.util.Collections;
import java.util.List;
import java.util.Set;
class SemanticHighlightingStyleToTokenMapper implements ISemanticHighlightingStyleToTokenMapper {
import org.eclipse.xtext.ide.server.semanticHighlight.ISemanticHighlightingStyleToTokenMapper;
override toScopes(String styleId) {
return #[styleId];
public class SemanticHighlightingStyleToTokenMapper implements ISemanticHighlightingStyleToTokenMapper {
@Override
public List<String> toScopes(String styleId) {
return Collections.singletonList(styleId);
}
override getAllStyleIds() {
@Override
public Set<String> getAllStyleIds() {
return SemanticHighlightingCalculatorImpl.STYLES;
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
/*
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -18,9 +18,18 @@ import org.eclipse.xtext.generator.IGeneratorContext;
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
@SuppressWarnings("all")
public class IndentationAwareUiTestLanguageGenerator extends AbstractGenerator {
@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
}
@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {
//
// @Override
// public String apply(Greeting greeting) {
// return greeting.getName();
// }
// });
// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", "));
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class IndentationAwareUiTestLanguageGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// fsa.generateFile('greetings.txt', 'People to greet: ' +
// resource.allContents
// .filter(Greeting)
// .map[name]
// .join(', '))
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
/*
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -18,9 +18,18 @@ import org.eclipse.xtext.generator.IGeneratorContext;
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
@SuppressWarnings("all")
public class PartialContentAssistTestLanguageGenerator extends AbstractGenerator {
@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
}
@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {
//
// @Override
// public String apply(Greeting greeting) {
// return greeting.getName();
// }
// });
// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", "));
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class PartialContentAssistTestLanguageGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// fsa.generateFile('greetings.txt', 'People to greet: ' +
// resource.allContents
// .filter(Greeting)
// .map[name]
// .join(', '))
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
/*
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -18,9 +18,18 @@ import org.eclipse.xtext.generator.IGeneratorContext;
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
@SuppressWarnings("all")
public class PartialSerializationTestLanguageGenerator extends AbstractGenerator {
@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
}
@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {
//
// @Override
// public String apply(Greeting greeting) {
// return greeting.getName();
// }
// });
// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", "));
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class PartialSerializationTestLanguageGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// fsa.generateFile('greetings.txt', 'People to greet: ' +
// resource.allContents
// .filter(Greeting)
// .map[name]
// .join(', '))
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
/*
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -18,9 +18,18 @@ import org.eclipse.xtext.generator.IGeneratorContext;
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
@SuppressWarnings("all")
public class RenameTestLanguageGenerator extends AbstractGenerator {
@Override
public void doGenerate(final Resource resource, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
}
@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {
//
// @Override
// public String apply(Greeting greeting) {
// return greeting.getName();
// }
// });
// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", "));
}
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class RenameTestLanguageGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// fsa.generateFile('greetings.txt', 'People to greet: ' +
// resource.allContents
// .filter(Greeting)
// .map[name]
// .join(', '))
}
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.ide;
import java.util.List;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.xtext.ide.server.ILanguageServerAccess;
import org.eclipse.xtext.ide.server.commands.IExecutableCommandService;
import org.eclipse.xtext.util.CancelIndicator;
import com.google.common.collect.Lists;
/**
* @author Christian Dietrich - Initial contribution and API
*/
public class TestLanguageExecutableCommandService implements IExecutableCommandService {
@Override
public List<String> initialize() {
return Lists.newArrayList("testlang.a", "testlang.b", "testlang.c");
}
@Override
public Object execute(ExecuteCommandParams params, ILanguageServerAccess access, CancelIndicator cancelIndicator) {
if ("testlang.a".equals(params.getCommand())) {
return "a";
} else if ("testlang.b".equals(params.getCommand())) {
return "b";
} else if ("testlang.c".equals(params.getCommand())) {
return "c";
}
return null;
}
}

View file

@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.ide
import org.eclipse.xtext.ide.server.commands.IExecutableCommandService
import org.eclipse.lsp4j.ExecuteCommandParams
import org.eclipse.xtext.ide.server.ILanguageServerAccess
import org.eclipse.xtext.util.CancelIndicator
/**
* @author Christian Dietrich - Initial contribution and API
*/
class TestLanguageExecutableCommandService implements IExecutableCommandService {
override initialize() {
#["testlang.a", "testlang.b", "testlang.c"]
}
override execute(ExecuteCommandParams params, ILanguageServerAccess access, CancelIndicator cancelIndicator) {
if (params.command == "testlang.a") {
return "a"
} else if (params.command == "testlang.b") {
return "b"
} else if (params.command == "testlang.c") {
return "c"
}
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2018, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.ide;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalCreator;
import org.eclipse.xtext.util.ReplaceRegion;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
/**
* @author Dennis Huebner - Initial contribution and API
*/
public class TestLanguageProposalCreator extends IdeContentProposalCreator {
@Override
public ContentAssistEntry createProposal(String proposal, String prefix, ContentAssistContext context, String kind,
Procedure1<? super ContentAssistEntry> init) {
ContentAssistEntry entry = super.createProposal(proposal, prefix, context, kind, init);
if (entry != null && kind == ContentAssistEntry.KIND_KEYWORD && "{".equals(proposal)) {
// just for testing purposes
entry.getTextReplacements().add(new ReplaceRegion(context.getOffset() + 1, 0, "}"));
}
return entry;
}
}

View file

@ -1,31 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.ide
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalCreator
import org.eclipse.xtext.util.ReplaceRegion
/**
* @author Dennis Huebner - Initial contribution and API
*/
class TestLanguageProposalCreator extends IdeContentProposalCreator {
override createProposal(String proposal, String prefix, ContentAssistContext context, String kind,
(ContentAssistEntry)=>void init) {
val entry = super.createProposal(proposal, prefix, context, kind, init)
if (entry !== null && kind == ContentAssistEntry.KIND_KEYWORD && proposal == '{') {
// just for testing purposes
entry.textReplacements += new ReplaceRegion(context.offset + 1, 0, '}')
}
entry
}
}

View file

@ -1,11 +1,11 @@
/**
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
/*******************************************************************************
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
*
* SPDX-License-Identifier: EPL-2.0
*/
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.scoping;
import com.google.inject.Inject;
@ -17,13 +17,14 @@ import org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter;
/**
* @author Moritz Eysholdt - Initial contribution and API
*/
@SuppressWarnings("all")
public class PartialSerializationTestLanguageValueConverter extends DefaultTerminalConverters {
@Inject
private QualifiedNameValueConverter fqnc;
@ValueConverter(rule = "QualifiedName")
public IValueConverter<String> QualifiedName() {
return this.fqnc;
}
@Inject
private QualifiedNameValueConverter fqnc;
@ValueConverter(rule="QualifiedName")
public IValueConverter<String> QualifiedName() {
return fqnc;
}
}

View file

@ -1,29 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.scoping
import com.google.inject.Inject
import org.eclipse.xtext.common.services.DefaultTerminalConverters
import org.eclipse.xtext.conversion.IValueConverter
import org.eclipse.xtext.conversion.ValueConverter
import org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter
/**
* @author Moritz Eysholdt - Initial contribution and API
*/
class PartialSerializationTestLanguageValueConverter extends DefaultTerminalConverters {
@Inject QualifiedNameValueConverter fqnc
@ValueConverter(rule="QualifiedName")
def IValueConverter<String> QualifiedName() {
return fqnc
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.server;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.nio.channels.Channels;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.launch.LSPLauncher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.xtext.ide.server.ServerModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author kosyakov - Initial contribution and API
*/
public class SocketServerLauncher {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new ServerModule());
LanguageServer languageServer = injector.getInstance(LanguageServer.class);
ServerSocketChannel serverSocket = ServerSocketChannel.open();
serverSocket.bind(new InetSocketAddress("localhost", 5007));
SocketChannel socketChannel = serverSocket.accept();
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(languageServer, Channels.newInputStream(socketChannel), Channels.newOutputStream(socketChannel), true, new PrintWriter(System.out));
launcher.startListening().get();
}
}

View file

@ -1,35 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.ide.tests.testlanguage.server
import com.google.inject.Guice
import java.io.PrintWriter
import java.net.InetSocketAddress
import java.nio.channels.Channels
import java.nio.channels.ServerSocketChannel
import org.eclipse.lsp4j.launch.LSPLauncher
import org.eclipse.lsp4j.services.LanguageServer
import org.eclipse.xtext.ide.server.ServerModule
/**
* @author kosyakov - Initial contribution and API
*/
class SocketServerLauncher {
def static void main(String[] args) {
val injector = Guice.createInjector(new ServerModule)
val languageServer = injector.getInstance(LanguageServer)
val serverSocket = ServerSocketChannel.open()
serverSocket.bind(new InetSocketAddress('localhost', 5007));
val socketChannel = serverSocket.accept()
val launcher = LSPLauncher.createServerLauncher(languageServer, Channels.newInputStream(socketChannel), Channels.newOutputStream(socketChannel), true, new PrintWriter(System.out));
launcher.startListening.get
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.validation;
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TestLanguagePackage;
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration;
import org.eclipse.xtext.validation.Check;
import static org.eclipse.xtext.xbase.lib.IterableExtensions.*;
/**
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
public class TestLanguageValidator extends AbstractTestLanguageValidator {
public static final String INVALID_NAME = "invalidName";
public static final String UNSORTED_MEMBERS = "unsorted_members";
public static final String MULTILINE_PROBLEM = "multiline_problem";
@Check
public void checkGreetingStartsWithCapital(TypeDeclaration type) {
if (!Character.isUpperCase(type.getName().charAt(0))) {
warning("Name should start with a capital",
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
INVALID_NAME);
}
}
@Check
public void checkMembersAreSorted(TypeDeclaration type) {
if (!sortBy(type.getMembers(), e -> e.getName()).equals(type.getMembers())) {
warning(
"Members should be in alphabetic order.",
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
UNSORTED_MEMBERS
);
}
}
@Check
public void checkWithMultilineError(TypeDeclaration type) {
if (type.getName().startsWith("Multiline")) {
warning("Test Validation to mark the whole type", null, MULTILINE_PROBLEM);
}
}
}

View file

@ -1,53 +0,0 @@
/*
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.validation
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TestLanguagePackage
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration
import org.eclipse.xtext.validation.Check
/**
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
class TestLanguageValidator extends AbstractTestLanguageValidator {
public static val INVALID_NAME = 'invalidName'
public static val UNSORTED_MEMBERS = 'unsorted_members'
public static val MULTILINE_PROBLEM = 'multiline_problem'
@Check
def checkGreetingStartsWithCapital(TypeDeclaration type) {
if (!Character.isUpperCase(type.name.charAt(0))) {
warning('Name should start with a capital',
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
INVALID_NAME)
}
}
@Check
def checkMembersAreSorted(TypeDeclaration type) {
if (type.members.sortBy[name] != type.members) {
warning(
'Members should be in alphabetic order.',
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
UNSORTED_MEMBERS
)
}
}
@Check
def checkWithMultilineError(TypeDeclaration type) {
if (type.name.startsWith("Multiline")) {
warning("Test Validation to mark the whole type", null, MULTILINE_PROBLEM)
}
}
}

View file

@ -1,29 +0,0 @@
/**
* Copyright (c) 2018 TypeFox and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.editor.syntaxcoloring;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.eclipse.xtext.ide.server.semanticHighlight.ISemanticHighlightingStyleToTokenMapper;
import org.eclipse.xtext.ide.tests.testlanguage.editor.syntaxcoloring.SemanticHighlightingCalculatorImpl;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
@SuppressWarnings("all")
public class SemanticHighlightingStyleToTokenMapper implements ISemanticHighlightingStyleToTokenMapper {
@Override
public List<String> toScopes(final String styleId) {
return Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(styleId));
}
@Override
public Set<String> getAllStyleIds() {
return SemanticHighlightingCalculatorImpl.STYLES;
}
}

View file

@ -1,51 +0,0 @@
/**
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.ide;
import com.google.common.base.Objects;
import java.util.Collections;
import java.util.List;
import org.eclipse.lsp4j.ExecuteCommandParams;
import org.eclipse.xtext.ide.server.ILanguageServerAccess;
import org.eclipse.xtext.ide.server.commands.IExecutableCommandService;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
/**
* @author Christian Dietrich - Initial contribution and API
*/
@SuppressWarnings("all")
public class TestLanguageExecutableCommandService implements IExecutableCommandService {
@Override
public List<String> initialize() {
return Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("testlang.a", "testlang.b", "testlang.c"));
}
@Override
public Object execute(final ExecuteCommandParams params, final ILanguageServerAccess access, final CancelIndicator cancelIndicator) {
String _command = params.getCommand();
boolean _equals = Objects.equal(_command, "testlang.a");
if (_equals) {
return "a";
} else {
String _command_1 = params.getCommand();
boolean _equals_1 = Objects.equal(_command_1, "testlang.b");
if (_equals_1) {
return "b";
} else {
String _command_2 = params.getCommand();
boolean _equals_2 = Objects.equal(_command_2, "testlang.c");
if (_equals_2) {
return "c";
}
}
}
return null;
}
}

View file

@ -1,40 +0,0 @@
/**
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.ide;
import com.google.common.base.Objects;
import java.util.ArrayList;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry;
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalCreator;
import org.eclipse.xtext.util.ReplaceRegion;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
/**
* @author Dennis Huebner - Initial contribution and API
*/
@SuppressWarnings("all")
public class TestLanguageProposalCreator extends IdeContentProposalCreator {
@Override
public ContentAssistEntry createProposal(final String proposal, final String prefix, final ContentAssistContext context, final String kind, final Procedure1<? super ContentAssistEntry> init) {
ContentAssistEntry _xblockexpression = null;
{
final ContentAssistEntry entry = super.createProposal(proposal, prefix, context, kind, init);
if ((((entry != null) && Objects.equal(kind, ContentAssistEntry.KIND_KEYWORD)) && Objects.equal(proposal, "{"))) {
ArrayList<ReplaceRegion> _textReplacements = entry.getTextReplacements();
int _offset = context.getOffset();
int _plus = (_offset + 1);
ReplaceRegion _replaceRegion = new ReplaceRegion(_plus, 0, "}");
_textReplacements.add(_replaceRegion);
}
_xblockexpression = entry;
}
return _xblockexpression;
}
}

View file

@ -1,50 +0,0 @@
/**
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.server;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.nio.channels.Channels;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.launch.LSPLauncher;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.xtext.ide.server.ServerModule;
import org.eclipse.xtext.xbase.lib.Exceptions;
/**
* @author kosyakov - Initial contribution and API
*/
@SuppressWarnings("all")
public class SocketServerLauncher {
public static void main(final String[] args) {
try {
ServerModule _serverModule = new ServerModule();
final Injector injector = Guice.createInjector(_serverModule);
final LanguageServer languageServer = injector.<LanguageServer>getInstance(LanguageServer.class);
final ServerSocketChannel serverSocket = ServerSocketChannel.open();
InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 5007);
serverSocket.bind(_inetSocketAddress);
final SocketChannel socketChannel = serverSocket.accept();
InputStream _newInputStream = Channels.newInputStream(socketChannel);
OutputStream _newOutputStream = Channels.newOutputStream(socketChannel);
PrintWriter _printWriter = new PrintWriter(System.out);
final Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(languageServer, _newInputStream, _newOutputStream, true, _printWriter);
launcher.startListening().get();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}

View file

@ -1,69 +0,0 @@
/**
* Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.testlanguage.validation;
import com.google.common.base.Objects;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Member;
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TestLanguagePackage;
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration;
import org.eclipse.xtext.ide.tests.testlanguage.validation.AbstractTestLanguageValidator;
import org.eclipse.xtext.validation.Check;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
/**
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
@SuppressWarnings("all")
public class TestLanguageValidator extends AbstractTestLanguageValidator {
public static final String INVALID_NAME = "invalidName";
public static final String UNSORTED_MEMBERS = "unsorted_members";
public static final String MULTILINE_PROBLEM = "multiline_problem";
@Check
public void checkGreetingStartsWithCapital(final TypeDeclaration type) {
boolean _isUpperCase = Character.isUpperCase(type.getName().charAt(0));
boolean _not = (!_isUpperCase);
if (_not) {
this.warning("Name should start with a capital",
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
TestLanguageValidator.INVALID_NAME);
}
}
@Check
public void checkMembersAreSorted(final TypeDeclaration type) {
final Function1<Member, String> _function = (Member it) -> {
return it.getName();
};
List<Member> _sortBy = IterableExtensions.<Member, String>sortBy(type.getMembers(), _function);
EList<Member> _members = type.getMembers();
boolean _notEquals = (!Objects.equal(_sortBy, _members));
if (_notEquals) {
this.warning(
"Members should be in alphabetic order.",
TestLanguagePackage.Literals.ABSTRACT_ELEMENT__NAME,
TestLanguageValidator.UNSORTED_MEMBERS);
}
}
@Check
public void checkWithMultilineError(final TypeDeclaration type) {
boolean _startsWith = type.getName().startsWith("Multiline");
if (_startsWith) {
this.warning("Test Validation to mark the whole type", null, TestLanguageValidator.MULTILINE_PROBLEM);
}
}
}

View file

@ -1,69 +0,0 @@
/**
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ide.tests.util;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.lsp4j.Position;
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
import org.eclipse.xtext.ide.util.PositionComparator;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test for the null-safe {@link PositionComparator}.
*
* @author akos.kitta - Initial contribution and API
*/
@RunWith(XtextRunner.class)
@InjectWith(TestLanguageIdeInjectorProvider.class)
@SuppressWarnings("all")
public class PositionComparatorTest extends Assert {
@Inject
private PositionComparator comparator;
@Test
public void withoutNull() {
Position _position = new Position(2, 2);
Position _position_1 = new Position(2, 1);
Position _position_2 = new Position(1, 2);
Position _position_3 = new Position(1, 1);
final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, _position_1, _position_2, _position_3));
Assert.assertEquals(1, input.get(0).getLine());
Assert.assertEquals(1, input.get(0).getCharacter());
Assert.assertEquals(1, input.get(1).getLine());
Assert.assertEquals(2, input.get(1).getCharacter());
Assert.assertEquals(2, input.get(2).getLine());
Assert.assertEquals(1, input.get(2).getCharacter());
Assert.assertEquals(2, input.get(3).getLine());
Assert.assertEquals(2, input.get(3).getCharacter());
}
@Test
public void withNull() {
Position _position = new Position(2, 2);
Position _position_1 = new Position(1, 1);
final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, null, _position_1));
Assert.assertEquals(1, input.get(0).getLine());
Assert.assertEquals(1, input.get(0).getCharacter());
Assert.assertEquals(2, input.get(1).getLine());
Assert.assertEquals(2, input.get(1).getCharacter());
Assert.assertNull(IterableExtensions.last(input));
}
private List<? extends Position> sort(final List<? extends Position> toSort) {
toSort.sort(this.comparator);
return toSort;
}
}