mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Merge pull request #1610 from eclipse/cdx2j
[eclipse/xtext#1837] converted xtend 2 java
This commit is contained in:
commit
150fb7cc6d
73 changed files with 5810 additions and 14842 deletions
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* 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.editor.contentassist;
|
||||
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.TestLanguageGrammarAccess;
|
||||
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;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
public class ContentAssistContextFactoryTest {
|
||||
@Inject
|
||||
private ContentAssistContextTestHelper contentAssistContextTestHelper;
|
||||
|
||||
@Inject
|
||||
private ContentAssistContextFactory factory;
|
||||
|
||||
@Inject
|
||||
private TestLanguageGrammarAccess grammar;
|
||||
|
||||
@Test
|
||||
public void testSimple1() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument(
|
||||
"type Foo <|>{\n" +
|
||||
" int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Keyword: TypeDeclaration:'extends'\n" +
|
||||
" Keyword: TypeDeclaration:'{'\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple2() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument(
|
||||
"type Foo {\n" +
|
||||
" <|>int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: TypeDeclaration:members+= *\n" +
|
||||
" RuleCall: TypeDeclaration:members+=Member\n" +
|
||||
" RuleCall: Member:Property\n" +
|
||||
" Assignment: Property:type= \n" +
|
||||
" RuleCall: Property:type=Type\n" +
|
||||
" RuleCall: Type:TypeReference\n" +
|
||||
" Assignment: TypeReference:typeRef= \n" +
|
||||
" RuleCall: Type:PrimitiveType\n" +
|
||||
" Assignment: PrimitiveType:name= \n" +
|
||||
" Keyword: PrimitiveType:name='string'\n" +
|
||||
" Keyword: PrimitiveType:name='int'\n" +
|
||||
" Keyword: PrimitiveType:name='boolean'\n" +
|
||||
" Keyword: PrimitiveType:name='void'\n" +
|
||||
" RuleCall: Member:Operation\n" +
|
||||
" Keyword: Operation:'op'\n" +
|
||||
" Keyword: TypeDeclaration:'}'\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeginning() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument(
|
||||
"<|>type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: Model:elements+= *\n" +
|
||||
" RuleCall: Model:elements+=AbstractElement\n" +
|
||||
" RuleCall: AbstractElement:PackageDeclaration\n" +
|
||||
" Keyword: PackageDeclaration:'package'\n" +
|
||||
" RuleCall: AbstractElement:TypeDeclaration\n" +
|
||||
" Keyword: TypeDeclaration:'type'\n" +
|
||||
" RuleCall: <AbstractElement not contained in AbstractRule!>:Model\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPoint() throws Exception {
|
||||
contentAssistContextTestHelper.setEntryPoint(grammar.getPropertyRule());
|
||||
contentAssistContextTestHelper.setDocument("int <|>bar");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: Type:arrayDiemensions+= \n" +
|
||||
" Keyword: Type:arrayDiemensions+='['\n" +
|
||||
" Assignment: Property:name= \n" +
|
||||
" RuleCall: Property:name=ID\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPointBeginning() throws Exception {
|
||||
contentAssistContextTestHelper.setEntryPoint(grammar.getPropertyRule());
|
||||
contentAssistContextTestHelper.setDocument("<|>int bar");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: Property:type= \n" +
|
||||
" RuleCall: Property:type=Type\n" +
|
||||
" RuleCall: Type:TypeReference\n" +
|
||||
" Assignment: TypeReference:typeRef= \n" +
|
||||
" RuleCall: Type:PrimitiveType\n" +
|
||||
" Assignment: PrimitiveType:name= \n" +
|
||||
" Keyword: PrimitiveType:name='string'\n" +
|
||||
" Keyword: PrimitiveType:name='int'\n" +
|
||||
" Keyword: PrimitiveType:name='boolean'\n" +
|
||||
" Keyword: PrimitiveType:name='void'\n" +
|
||||
" RuleCall: <AbstractElement not contained in AbstractRule!>:Type\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
}
|
|
@ -1,131 +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.editor.contentassist
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.TestLanguageGrammarAccess
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import static extension org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider)
|
||||
class ContentAssistContextFactoryTest {
|
||||
|
||||
@Inject extension ContentAssistContextTestHelper
|
||||
@Inject ContentAssistContextFactory factory
|
||||
@Inject TestLanguageGrammarAccess grammar
|
||||
|
||||
@Test def void testSimple1() throws Exception {
|
||||
document = '''
|
||||
type Foo <|>{
|
||||
int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Keyword: TypeDeclaration:'extends'
|
||||
Keyword: TypeDeclaration:'{'
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testSimple2() throws Exception {
|
||||
document = '''
|
||||
type Foo {
|
||||
<|>int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: TypeDeclaration:members+= *
|
||||
RuleCall: TypeDeclaration:members+=Member
|
||||
RuleCall: Member:Property
|
||||
Assignment: Property:type=
|
||||
RuleCall: Property:type=Type
|
||||
RuleCall: Type:TypeReference
|
||||
Assignment: TypeReference:typeRef=
|
||||
RuleCall: Type:PrimitiveType
|
||||
Assignment: PrimitiveType:name=
|
||||
Keyword: PrimitiveType:name='string'
|
||||
Keyword: PrimitiveType:name='int'
|
||||
Keyword: PrimitiveType:name='boolean'
|
||||
Keyword: PrimitiveType:name='void'
|
||||
RuleCall: Member:Operation
|
||||
Keyword: Operation:'op'
|
||||
Keyword: TypeDeclaration:'}'
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testBeginning() throws Exception {
|
||||
document = '''
|
||||
<|>type Foo {
|
||||
int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: Model:elements+= *
|
||||
RuleCall: Model:elements+=AbstractElement
|
||||
RuleCall: AbstractElement:PackageDeclaration
|
||||
Keyword: PackageDeclaration:'package'
|
||||
RuleCall: AbstractElement:TypeDeclaration
|
||||
Keyword: TypeDeclaration:'type'
|
||||
RuleCall: <AbstractElement not contained in AbstractRule!>:Model
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testCustomEntryPoint() throws Exception {
|
||||
entryPoint = grammar.propertyRule
|
||||
document = '''
|
||||
int <|>bar
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: Type:arrayDiemensions+=
|
||||
Keyword: Type:arrayDiemensions+='['
|
||||
Assignment: Property:name=
|
||||
RuleCall: Property:name=ID
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testCustomEntryPointBeginning() throws Exception {
|
||||
entryPoint = grammar.propertyRule
|
||||
document = '''
|
||||
<|>int bar
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: Property:type=
|
||||
RuleCall: Property:type=Type
|
||||
RuleCall: Type:TypeReference
|
||||
Assignment: TypeReference:typeRef=
|
||||
RuleCall: Type:PrimitiveType
|
||||
Assignment: PrimitiveType:name=
|
||||
Keyword: PrimitiveType:name='string'
|
||||
Keyword: PrimitiveType:name='int'
|
||||
Keyword: PrimitiveType:name='boolean'
|
||||
Keyword: PrimitiveType:name='void'
|
||||
RuleCall: <AbstractElement not contained in AbstractRule!>:Type
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import org.eclipse.xtext.resource.XtextResourceSet
|
|||
import org.eclipse.xtext.testing.validation.ValidationTestHelper
|
||||
import org.eclipse.xtext.util.StringInputStream
|
||||
import org.eclipse.xtext.util.TextRegion
|
||||
import org.eclipse.xtend2.lib.StringConcatenation
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
|
@ -56,7 +57,8 @@ class ContentAssistContextTestHelper {
|
|||
factory.pool = Executors.newCachedThreadPool
|
||||
val ctxs = factory.create(doc, new TextRegion(0, 0), offset, res)
|
||||
val f = new GrammarElementTitleSwitch().showAssignments.showQualified.showRule
|
||||
return '''
|
||||
val result = new StringConcatenation("\n")
|
||||
result.append('''
|
||||
«FOR ctx : ctxs.indexed»
|
||||
context«ctx.key» {
|
||||
«FOR ele:ctx.value.firstSetGrammarElements»
|
||||
|
@ -64,6 +66,7 @@ class ContentAssistContextTestHelper {
|
|||
«ENDFOR»
|
||||
}
|
||||
«ENDFOR»
|
||||
'''
|
||||
''')
|
||||
result.toString
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* 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.editor.contentassist;
|
||||
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.PartialContentAssistTestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.PartialContentAssistTestLanguageGrammarAccess;
|
||||
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;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(PartialContentAssistTestLanguageIdeInjectorProvider.class)
|
||||
public class PartialContentAssistTestLanguageContextFactoryTest {
|
||||
@Inject
|
||||
private ContentAssistContextTestHelper contentAssistContextTestHelper;
|
||||
|
||||
@Inject
|
||||
private ContentAssistContextFactory factory;
|
||||
|
||||
@Inject
|
||||
private PartialContentAssistTestLanguageGrammarAccess grammar;
|
||||
|
||||
@Test
|
||||
public void testConfig() {
|
||||
Assert.assertTrue(factory instanceof PartialContentAssistContextFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple1() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument("type Foo <|>{\n" +
|
||||
" int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals("context0 {\n" +
|
||||
" Keyword: TypeDeclaration:'extends'\n" +
|
||||
" Keyword: TypeDeclaration:'{'\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple2() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument("type Foo {\n" +
|
||||
" <|>int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: TypeDeclaration:properties+= *\n" +
|
||||
" RuleCall: TypeDeclaration:properties+=Property\n" +
|
||||
" Assignment: Property:type= \n" +
|
||||
" Keyword: Property:type='int'\n" +
|
||||
" Keyword: Property:type='bool'\n" +
|
||||
" Keyword: TypeDeclaration:'}'\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeginning() throws Exception {
|
||||
contentAssistContextTestHelper.setDocument("<|>type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Keyword: TypeDeclaration:'type'\n" +
|
||||
" RuleCall: <AbstractElement not contained in AbstractRule!>:TypeDeclaration\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPoint() throws Exception {
|
||||
contentAssistContextTestHelper.setEntryPoint(grammar.getPropertyRule());
|
||||
contentAssistContextTestHelper.setDocument("int <|>bar");
|
||||
Assert.assertEquals("context0 {\n" +
|
||||
" Assignment: Property:name= \n" +
|
||||
" RuleCall: Property:name=ID\n" +
|
||||
"}\n".toString(),
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPointBeginning() throws Exception {
|
||||
contentAssistContextTestHelper.setEntryPoint(grammar.getPropertyRule());
|
||||
contentAssistContextTestHelper.setDocument("<|>int bar");
|
||||
Assert.assertEquals(
|
||||
"context0 {\n" +
|
||||
" Assignment: Property:type= \n" +
|
||||
" Keyword: Property:type='int'\n" +
|
||||
" Keyword: Property:type='bool'\n" +
|
||||
" RuleCall: <AbstractElement not contained in AbstractRule!>:Property\n" +
|
||||
"}\n",
|
||||
contentAssistContextTestHelper.firstSetGrammarElementsToString(factory));
|
||||
}
|
||||
}
|
|
@ -1,112 +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.editor.contentassist
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.PartialContentAssistTestLanguageIdeInjectorProvider
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.PartialContentAssistTestLanguageGrammarAccess
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import static extension org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(PartialContentAssistTestLanguageIdeInjectorProvider)
|
||||
class PartialContentAssistTestLanguageContextFactoryTest {
|
||||
|
||||
@Inject extension ContentAssistContextTestHelper
|
||||
@Inject ContentAssistContextFactory factory
|
||||
@Inject PartialContentAssistTestLanguageGrammarAccess grammar
|
||||
|
||||
@Test def void testConfig() {
|
||||
assertTrue(factory instanceof PartialContentAssistContextFactory)
|
||||
}
|
||||
|
||||
@Test def void testSimple1() throws Exception {
|
||||
document = '''
|
||||
type Foo <|>{
|
||||
int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Keyword: TypeDeclaration:'extends'
|
||||
Keyword: TypeDeclaration:'{'
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testSimple2() throws Exception {
|
||||
document = '''
|
||||
type Foo {
|
||||
<|>int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: TypeDeclaration:properties+= *
|
||||
RuleCall: TypeDeclaration:properties+=Property
|
||||
Assignment: Property:type=
|
||||
Keyword: Property:type='int'
|
||||
Keyword: Property:type='bool'
|
||||
Keyword: TypeDeclaration:'}'
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testBeginning() throws Exception {
|
||||
document = '''
|
||||
<|>type Foo {
|
||||
int bar
|
||||
}
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Keyword: TypeDeclaration:'type'
|
||||
RuleCall: <AbstractElement not contained in AbstractRule!>:TypeDeclaration
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testCustomEntryPoint() throws Exception {
|
||||
entryPoint = grammar.propertyRule
|
||||
document = '''
|
||||
int <|>bar
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: Property:name=
|
||||
RuleCall: Property:name=ID
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
@Test def void testCustomEntryPointBeginning() throws Exception {
|
||||
entryPoint = grammar.propertyRule
|
||||
document = '''
|
||||
<|>int bar
|
||||
'''
|
||||
'''
|
||||
context0 {
|
||||
Assignment: Property:type=
|
||||
Keyword: Property:type='int'
|
||||
Keyword: Property:type='bool'
|
||||
RuleCall: <AbstractElement not contained in AbstractRule!>:Property
|
||||
}
|
||||
'''.toString.assertEquals(factory.firstSetGrammarElementsToString)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
public class CodeActionTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testCodeAction() {
|
||||
testCodeAction((TestCodeActionConfiguration it) -> {
|
||||
String model =
|
||||
"type foo {\n" +
|
||||
" \n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
// contains quickfix and edit command
|
||||
String expectedCodeActions =
|
||||
"title : Change element name to first upper\n" +
|
||||
"kind : quickfix\n" +
|
||||
"command : \n" +
|
||||
"codes : invalidName\n" +
|
||||
"edit : changes :\n" +
|
||||
" MyModel.testlang : Foo [[0, 5] .. [0, 8]]\n" +
|
||||
"documentChanges : \n" +
|
||||
"command : my.textedit.command\n" +
|
||||
"title : Make \'foo\' upper case (Command)\n" +
|
||||
"args : \n" +
|
||||
" changes :\n" +
|
||||
" MyModel.testlang : Foo [[0, 5] .. [0, 8]]\n" +
|
||||
" documentChanges : \n";
|
||||
it.setExpectedCodeActions(expectedCodeActions);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSemanticCodeAction() {
|
||||
testCodeAction((TestCodeActionConfiguration it) -> {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
" String ccc\n" +
|
||||
" String aaa\n" +
|
||||
"}\n" +
|
||||
"type String {}\n";
|
||||
it.setModel(model);
|
||||
String expectedCodeActions =
|
||||
"title : Sort Members\n" +
|
||||
"kind : \n" +
|
||||
"command : \n" +
|
||||
"codes : unsorted_members\n" +
|
||||
"edit : changes :\n" +
|
||||
" MyModel.testlang : \n" +
|
||||
" String aaa\n" +
|
||||
" [[0, 10] .. [0, 10]]\n" +
|
||||
" \n" +
|
||||
" [[1, 11] .. [3, 0]]\n" +
|
||||
"documentChanges : \n";
|
||||
it.setExpectedCodeActions(expectedCodeActions);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,72 +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.server
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
class CodeActionTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testCodeAction() {
|
||||
testCodeAction [
|
||||
model = '''
|
||||
type foo {
|
||||
|
||||
}
|
||||
'''
|
||||
// contains quickfix and edit command
|
||||
expectedCodeActions = '''
|
||||
title : Change element name to first upper
|
||||
kind : quickfix
|
||||
command :
|
||||
codes : invalidName
|
||||
edit : changes :
|
||||
MyModel.testlang : Foo [[0, 5] .. [0, 8]]
|
||||
documentChanges :
|
||||
command : my.textedit.command
|
||||
title : Make 'foo' upper case (Command)
|
||||
args :
|
||||
changes :
|
||||
MyModel.testlang : Foo [[0, 5] .. [0, 8]]
|
||||
documentChanges :
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testSemanticCodeAction() {
|
||||
testCodeAction [
|
||||
model = '''
|
||||
type Foo {
|
||||
String ccc
|
||||
String aaa
|
||||
}
|
||||
type String {}
|
||||
'''
|
||||
expectedCodeActions = '''
|
||||
title : Sort Members
|
||||
kind :
|
||||
command :
|
||||
codes : unsorted_members
|
||||
edit : changes :
|
||||
MyModel.testlang :
|
||||
String aaa
|
||||
[[0, 10] .. [0, 10]]
|
||||
|
||||
[[1, 11] .. [3, 0]]
|
||||
documentChanges :
|
||||
'''
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.xtext.testing.TestCompletionConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
public class CompletionTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testCompletion_01() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
it.setModel("");
|
||||
String expectedCompletionItems =
|
||||
"package -> package [[0, 0] .. [0, 0]]\n" +
|
||||
"type -> type [[0, 0] .. [0, 0]]\n" +
|
||||
"Sample Snippet -> type ${1|A,B,C|} {\n" +
|
||||
" \n" +
|
||||
"} [[0, 0] .. [0, 0]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_02() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
it.setModel("type ");
|
||||
it.setColumn(5);
|
||||
String expectedCompletionItems = "name (ID) -> name [[0, 5] .. [0, 5]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_03() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model =
|
||||
"type Foo {}\n" +
|
||||
"type Bar {}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(1);
|
||||
it.setColumn("type Bar {".length());
|
||||
String expectedCompletionItems =
|
||||
"Bar (TypeDeclaration) -> Bar [[1, 10] .. [1, 10]]\n" +
|
||||
"Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]\n" +
|
||||
"boolean -> boolean [[1, 10] .. [1, 10]]\n" +
|
||||
"int -> int [[1, 10] .. [1, 10]]\n" +
|
||||
"op -> op [[1, 10] .. [1, 10]]\n" +
|
||||
"string -> string [[1, 10] .. [1, 10]]\n" +
|
||||
"void -> void [[1, 10] .. [1, 10]]\n" +
|
||||
"} -> } [[1, 10] .. [1, 10]]\n" +
|
||||
"{ -> { [[1, 9] .. [1, 10]]\n" +
|
||||
" + } [[1, 11] .. [1, 11]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_04() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(1);
|
||||
it.setColumn(" Fo".length());
|
||||
String expectedCompletionItems =
|
||||
"Foo (TypeDeclaration) -> Foo [[1, 4] .. [1, 6]]\n" +
|
||||
"[ -> [ [[1, 6] .. [1, 6]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_05() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model =
|
||||
"type Foo {}\n" +
|
||||
"type foo {}\n" +
|
||||
"type Boo {}\n" +
|
||||
"type boo {}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(1);
|
||||
it.setColumn("type Bar {".length());
|
||||
String expectedCompletionItems = "Boo (TypeDeclaration) -> Boo [[1, 10] .. [1, 10]]\n" +
|
||||
"boo (TypeDeclaration) -> boo [[1, 10] .. [1, 10]]\n" +
|
||||
"Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]\n" +
|
||||
"foo (TypeDeclaration) -> foo [[1, 10] .. [1, 10]]\n" +
|
||||
"boolean -> boolean [[1, 10] .. [1, 10]]\n" +
|
||||
"int -> int [[1, 10] .. [1, 10]]\n" +
|
||||
"op -> op [[1, 10] .. [1, 10]]\n" +
|
||||
"string -> string [[1, 10] .. [1, 10]]\n" +
|
||||
"void -> void [[1, 10] .. [1, 10]]\n" +
|
||||
"} -> } [[1, 10] .. [1, 10]]\n" +
|
||||
"{ -> { [[1, 9] .. [1, 10]]\n" +
|
||||
" + } [[1, 11] .. [1, 11]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
withKind = true;
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model = "type Foo {}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(1);
|
||||
it.setColumn(0);
|
||||
String expectedCompletionItems =
|
||||
"(Keyword) package -> package [[1, 0] .. [1, 0]]\n" +
|
||||
"(Keyword) type -> type [[1, 0] .. [1, 0]]\n" +
|
||||
"(Snippet|Snippet) Sample Snippet -> type ${1|A,B,C|} {\n" +
|
||||
" \n" +
|
||||
"} [[1, 0] .. [1, 0]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
withKind = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_AdditionalEdits_01() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model = "type Foo \n";
|
||||
it.setModel(model);
|
||||
it.setLine(0);
|
||||
it.setColumn("type Foo ".length());
|
||||
String expectedCompletionItems =
|
||||
"extends -> extends [[0, 9] .. [0, 9]]\n" +
|
||||
"{ -> { [[0, 9] .. [0, 9]]\n" +
|
||||
" + } [[1, 0] .. [1, 0]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_AdditionalEdits_02() {
|
||||
testCompletion((TestCompletionConfiguration it) -> {
|
||||
String model = "type Foo \n";
|
||||
it.setModel(model);
|
||||
it.setLine(0);
|
||||
it.setColumn("type Foo ".length());
|
||||
String expectedCompletionItems = "extends -> extends [[0, 9] .. [0, 9]]\n" +
|
||||
"{ -> { [[0, 9] .. [0, 9]]\n" +
|
||||
" + } [[0, 10] .. [0, 10]]\n";
|
||||
it.setExpectedCompletionItems(expectedCompletionItems);
|
||||
});
|
||||
}
|
||||
|
||||
private boolean withKind = false;
|
||||
|
||||
@Override
|
||||
protected String _toExpectation(CompletionItem it) {
|
||||
if (withKind) {
|
||||
return "(" + it.getKind() + (it.getInsertTextFormat() != null ? "|" + it.getInsertTextFormat() : "") + ") "
|
||||
+ super._toExpectation(it);
|
||||
} else {
|
||||
return super._toExpectation(it);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.server
|
||||
|
||||
import org.junit.Test
|
||||
import org.eclipse.lsp4j.CompletionItem
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class CompletionTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testCompletion_01() {
|
||||
testCompletion [
|
||||
model = ''
|
||||
expectedCompletionItems = '''
|
||||
package -> package [[0, 0] .. [0, 0]]
|
||||
type -> type [[0, 0] .. [0, 0]]
|
||||
Sample Snippet -> type ${1|A,B,C|} {
|
||||
|
||||
} [[0, 0] .. [0, 0]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_02() {
|
||||
testCompletion [
|
||||
model = 'type '
|
||||
column = 5
|
||||
expectedCompletionItems = '''
|
||||
name (ID) -> name [[0, 5] .. [0, 5]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_03() {
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo {}
|
||||
type Bar {}
|
||||
'''
|
||||
line = 1
|
||||
column = 'type Bar {'.length
|
||||
expectedCompletionItems = '''
|
||||
Bar (TypeDeclaration) -> Bar [[1, 10] .. [1, 10]]
|
||||
Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]
|
||||
boolean -> boolean [[1, 10] .. [1, 10]]
|
||||
int -> int [[1, 10] .. [1, 10]]
|
||||
op -> op [[1, 10] .. [1, 10]]
|
||||
string -> string [[1, 10] .. [1, 10]]
|
||||
void -> void [[1, 10] .. [1, 10]]
|
||||
} -> } [[1, 10] .. [1, 10]]
|
||||
{ -> { [[1, 9] .. [1, 10]]
|
||||
+ } [[1, 11] .. [1, 11]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_04() {
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
line = 1
|
||||
column = ' Fo'.length
|
||||
expectedCompletionItems = '''
|
||||
Foo (TypeDeclaration) -> Foo [[1, 4] .. [1, 6]]
|
||||
[ -> [ [[1, 6] .. [1, 6]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_05() {
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo {}
|
||||
type foo {}
|
||||
type Boo {}
|
||||
type boo {}
|
||||
'''
|
||||
line = 1
|
||||
column = 'type Bar {'.length
|
||||
expectedCompletionItems = '''
|
||||
Boo (TypeDeclaration) -> Boo [[1, 10] .. [1, 10]]
|
||||
boo (TypeDeclaration) -> boo [[1, 10] .. [1, 10]]
|
||||
Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]
|
||||
foo (TypeDeclaration) -> foo [[1, 10] .. [1, 10]]
|
||||
boolean -> boolean [[1, 10] .. [1, 10]]
|
||||
int -> int [[1, 10] .. [1, 10]]
|
||||
op -> op [[1, 10] .. [1, 10]]
|
||||
string -> string [[1, 10] .. [1, 10]]
|
||||
void -> void [[1, 10] .. [1, 10]]
|
||||
} -> } [[1, 10] .. [1, 10]]
|
||||
{ -> { [[1, 9] .. [1, 10]]
|
||||
+ } [[1, 11] .. [1, 11]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testSnippet() {
|
||||
withKind = true
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo {}
|
||||
|
||||
'''
|
||||
line = 1
|
||||
column = 0
|
||||
expectedCompletionItems = '''
|
||||
(Keyword) package -> package [[1, 0] .. [1, 0]]
|
||||
(Keyword) type -> type [[1, 0] .. [1, 0]]
|
||||
(Snippet|Snippet) Sample Snippet -> type ${1|A,B,C|} {
|
||||
|
||||
} [[1, 0] .. [1, 0]]
|
||||
'''
|
||||
]
|
||||
withKind = false
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_AdditionalEdits_01() {
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo
|
||||
'''
|
||||
line = 0
|
||||
column = 'type Foo '.length
|
||||
expectedCompletionItems = '''
|
||||
extends -> extends [[0, 9] .. [0, 9]]
|
||||
{ -> { [[0, 9] .. [0, 9]]
|
||||
+ } [[1, 0] .. [1, 0]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCompletion_AdditionalEdits_02() {
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo
|
||||
'''
|
||||
line = 0
|
||||
column = 'type Foo '.length
|
||||
expectedCompletionItems = '''
|
||||
extends -> extends [[0, 9] .. [0, 9]]
|
||||
{ -> { [[0, 9] .. [0, 9]]
|
||||
+ } [[0, 10] .. [0, 10]]
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
var withKind = false;
|
||||
|
||||
protected override dispatch String toExpectation(CompletionItem it) '''
|
||||
«IF withKind»(«kind»«IF insertTextFormat !== null»|«insertTextFormat»«ENDIF») «ENDIF»«label»«IF !detail.nullOrEmpty» («detail»)«ENDIF»«IF textEdit !== null» -> «textEdit.toExpectation»«IF !additionalTextEdits.nullOrEmpty» + «additionalTextEdits.map[toExpectation].join(' + ')»«ENDIF»«ELSEIF insertText !== null && insertText != label» -> «insertText»«ENDIF»
|
||||
'''
|
||||
}
|
|
@ -118,7 +118,9 @@ public class DocumentHighlightTest extends AbstractTestLangLanguageServerTest {
|
|||
" }\n}";
|
||||
cfg.setModel(model);
|
||||
cfg.setLine(1);
|
||||
cfg.setColumn("\top fo".length());
|
||||
cfg.setColumn(
|
||||
" op fo".length()
|
||||
);
|
||||
cfg.setExpectedDocumentHighlight("W [[1, 4] .. [1, 7]] | R [[3, 2] .. [3, 5]]");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.xtext.testing.DocumentSymbolConfiguraiton;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
public class DocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testDocumentSymbol_01() {
|
||||
testDocumentSymbol((DocumentSymbolConfiguraiton it) -> {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
String expectedSymbols =
|
||||
"symbol \"Foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[0, 5] .. [0, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 5] .. [1, 8]]\n" +
|
||||
" container: \"Foo\"\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar.int\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 1] .. [1, 4]]\n" +
|
||||
" container: \"Foo.bar\"\n" +
|
||||
"}\n" +
|
||||
"symbol \"Bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[3, 5] .. [3, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Bar.foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[4, 5] .. [4, 8]]\n" +
|
||||
" container: \"Bar\"\n" +
|
||||
"}\n";
|
||||
it.setExpectedSymbols(
|
||||
expectedSymbols);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,57 +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.server
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class DocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testDocumentSymbol_01() {
|
||||
testDocumentSymbol[
|
||||
model = '''
|
||||
type Foo {
|
||||
int bar
|
||||
}
|
||||
type Bar {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
expectedSymbols = '''
|
||||
symbol "Foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[0, 5] .. [0, 8]]
|
||||
}
|
||||
symbol "Foo.bar" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 5] .. [1, 8]]
|
||||
container: "Foo"
|
||||
}
|
||||
symbol "Foo.bar.int" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 1] .. [1, 4]]
|
||||
container: "Foo.bar"
|
||||
}
|
||||
symbol "Bar" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[3, 5] .. [3, 8]]
|
||||
}
|
||||
symbol "Bar.foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[4, 5] .. [4, 8]]
|
||||
container: "Bar"
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,205 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author efftinge - Initial contribution and API
|
||||
*/
|
||||
public class DocumentTest {
|
||||
@Test
|
||||
public void testOffSet() {
|
||||
String model =
|
||||
"hello world\n" +
|
||||
"foo\n" +
|
||||
"bar\n";
|
||||
Document document = new Document(1, model);
|
||||
Assert.assertEquals(0, document.getOffSet(position(0, 0)));
|
||||
Assert.assertEquals(11, document.getOffSet(position(0, 11)));
|
||||
try {
|
||||
document.getOffSet(position(0, 12));
|
||||
Assert.fail();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
Assert.assertEquals(12, document.getOffSet(position(1, 0)));
|
||||
Assert.assertEquals(13, document.getOffSet(position(1, 1)));
|
||||
Assert.assertEquals(14, document.getOffSet(position(1, 2)));
|
||||
Assert.assertEquals(16, document.getOffSet(position(2, 0)));
|
||||
Assert.assertEquals(19, document.getOffSet(position(2, 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffSet_empty() {
|
||||
Document document = new Document(1, "");
|
||||
Assert.assertEquals(0, document.getOffSet(position(0, 0)));
|
||||
try {
|
||||
document.getOffSet(position(0, 12));
|
||||
Assert.fail();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_01() {
|
||||
String model =
|
||||
"hello world\n" +
|
||||
"foo\n" +
|
||||
"bar\n";
|
||||
Document document = new Document(1, model);
|
||||
String expectedModelAfterChange =
|
||||
"hello world\n" +
|
||||
"bar\n";
|
||||
Assert.assertEquals(expectedModelAfterChange,
|
||||
document.applyTextDocumentChanges(Lists.newArrayList(change(position(1, 0), position(2, 0), "")))
|
||||
.getContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_02() {
|
||||
String model =
|
||||
"hello world\n" +
|
||||
"foo\n" +
|
||||
"bar\n";
|
||||
Document document = new Document(1, model);
|
||||
String expectedModelAfterChange =
|
||||
"hello world\n" +
|
||||
"future\n" +
|
||||
"bar\n";
|
||||
Assert.assertEquals(expectedModelAfterChange,
|
||||
document.applyTextDocumentChanges(Lists.newArrayList(change(position(1, 1), position(1, 3), "uture")))
|
||||
.getContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_03() {
|
||||
String model =
|
||||
"hello world\n" +
|
||||
"foo\n" +
|
||||
"bar";
|
||||
Document document = new Document(1, model);
|
||||
Assert.assertEquals("",
|
||||
document.applyTextDocumentChanges(Lists.newArrayList(change(position(0, 0), position(2, 3), "")))
|
||||
.getContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyTextDocumentChanges_04() {
|
||||
String model =
|
||||
"foo\n" +
|
||||
"bar\n";
|
||||
Document changedDocument = new Document(1, model)
|
||||
.applyTextDocumentChanges(Lists.newArrayList(change(position(0, 3), position(0, 3), "b"),
|
||||
change(position(0, 4), position(0, 4), "a"), change(position(0, 5), position(0, 5), "r")));
|
||||
String expectedModelAfterChange =
|
||||
"foobar\n" +
|
||||
"bar\n";
|
||||
Assert.assertEquals(expectedModelAfterChange, changedDocument.getContents());
|
||||
Assert.assertEquals(2, changedDocument.getVersion().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_nonIncrementalChange() {
|
||||
String model =
|
||||
"hello world\n" +
|
||||
"foo\n" +
|
||||
"bar";
|
||||
Document document = new Document(1, model);
|
||||
Assert.assertEquals(" foo ",
|
||||
document.applyChanges(Lists.newArrayList(textEdit(null, null, " foo "))).getContents());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testGetLineContent_negative() {
|
||||
new Document(1, "").getLineContent(-1);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testGetLineContent_exceeds() {
|
||||
String model =
|
||||
"aaa\n" +
|
||||
"bbb\n" +
|
||||
"ccc";
|
||||
new Document(1, model).getLineContent(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent_empty() {
|
||||
Assert.assertEquals("", new Document(1, "").getLineContent(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent() {
|
||||
String model =
|
||||
"aaa\n" +
|
||||
"bbb\n" +
|
||||
"ccc";
|
||||
Assert.assertEquals("bbb", new Document(1, model).getLineContent(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent_windows_line_endings() {
|
||||
String model =
|
||||
"aaa\r\n" +
|
||||
"bbb\r\n" +
|
||||
"ccc";
|
||||
Assert.assertEquals("bbb", new Document(1, model).getLineContent(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_empty() {
|
||||
Assert.assertEquals(1, new Document(1, "").getLineCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_single() {
|
||||
Assert.assertEquals(1, new Document(1, "aaa bbb ccc").getLineCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_multi() {
|
||||
String model =
|
||||
"aaa\n" +
|
||||
"bbb\n" +
|
||||
"ccc";
|
||||
Assert.assertEquals(3, new Document(1, model).getLineCount());
|
||||
}
|
||||
|
||||
private TextDocumentContentChangeEvent change(Position startPos, Position endPos, String newText) {
|
||||
TextDocumentContentChangeEvent textDocumentContentChangeEvent = new TextDocumentContentChangeEvent();
|
||||
if (startPos != null) {
|
||||
textDocumentContentChangeEvent.setRange(new Range(startPos, endPos));
|
||||
}
|
||||
textDocumentContentChangeEvent.setText(newText);
|
||||
return textDocumentContentChangeEvent;
|
||||
}
|
||||
|
||||
private TextEdit textEdit(Position startPos, Position endPos, String newText) {
|
||||
TextEdit textEdit = new TextEdit();
|
||||
if (startPos != null) {
|
||||
textEdit.setRange(new Range(startPos, endPos));
|
||||
}
|
||||
textEdit.setNewText(newText);
|
||||
return textEdit;
|
||||
}
|
||||
|
||||
private Position position(int l, int c) {
|
||||
return new Position(l, c);
|
||||
}
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2019 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.server
|
||||
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.Range
|
||||
import org.eclipse.lsp4j.TextEdit
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent
|
||||
|
||||
/**
|
||||
* @author efftinge - Initial contribution and API
|
||||
*/
|
||||
class DocumentTest {
|
||||
|
||||
@Test def void testOffSet() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar
|
||||
'''.normalize) => [
|
||||
assertEquals(0, getOffSet(position(0,0)))
|
||||
assertEquals(11, getOffSet(position(0,11)))
|
||||
try {
|
||||
getOffSet(position(0, 12))
|
||||
fail()
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
//expected
|
||||
}
|
||||
assertEquals(12, getOffSet(position(1,0)))
|
||||
assertEquals(13, getOffSet(position(1,1)))
|
||||
assertEquals(14, getOffSet(position(1,2)))
|
||||
assertEquals(16, getOffSet(position(2,0)))
|
||||
assertEquals(19, getOffSet(position(2,3)))
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testOffSet_empty() {
|
||||
new Document(1, "") => [
|
||||
assertEquals(0, getOffSet(position(0,0)))
|
||||
try {
|
||||
getOffSet(position(0, 12))
|
||||
fail()
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
//expected
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testUpdate_01() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar
|
||||
'''.normalize) => [
|
||||
assertEquals('''
|
||||
hello world
|
||||
bar
|
||||
'''.normalize, applyTextDocumentChanges(#[
|
||||
change(position(1,0), position(2,0), "")
|
||||
]).contents)
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testUpdate_02() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar
|
||||
'''.normalize) => [
|
||||
assertEquals('''
|
||||
hello world
|
||||
future
|
||||
bar
|
||||
'''.normalize, applyTextDocumentChanges(#[
|
||||
change(position(1,1), position(1,3), "uture")
|
||||
]).contents)
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testUpdate_03() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar'''.normalize) => [
|
||||
assertEquals('', applyTextDocumentChanges(#[
|
||||
change(position(0,0), position(2,3), "")
|
||||
]).contents)
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testApplyTextDocumentChanges_04() {
|
||||
new Document(1, '''
|
||||
foo
|
||||
bar
|
||||
'''.normalize).applyTextDocumentChanges(#[
|
||||
change(position(0,3), position(0,3), "b"),
|
||||
change(position(0,4), position(0,4), "a"),
|
||||
change(position(0,5), position(0,5), "r")
|
||||
])
|
||||
=> [
|
||||
assertEquals('''
|
||||
foobar
|
||||
bar
|
||||
'''.normalize, contents)
|
||||
assertEquals(2, version)
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testUpdate_nonIncrementalChange() {
|
||||
new Document(1, '''
|
||||
hello world
|
||||
foo
|
||||
bar'''.normalize) => [
|
||||
assertEquals(' foo ', applyChanges(#[
|
||||
textEdit(null, null, " foo ")
|
||||
]).contents)
|
||||
]
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException) def void testGetLineContent_negative() {
|
||||
new Document(1, '').getLineContent(-1);
|
||||
}
|
||||
|
||||
@Test(expected=IndexOutOfBoundsException) def void testGetLineContent_exceeds() {
|
||||
new Document(1, '''
|
||||
aaa
|
||||
bbb
|
||||
ccc''').getLineContent(3);
|
||||
}
|
||||
|
||||
@Test def void testGetLineContent_empty() {
|
||||
assertEquals('', new Document(1, '').getLineContent(0));
|
||||
}
|
||||
|
||||
@Test def void testGetLineContent() {
|
||||
assertEquals('bbb', new Document(1, '''
|
||||
aaa
|
||||
bbb
|
||||
ccc''').getLineContent(1));
|
||||
}
|
||||
|
||||
@Test def void testGetLineContent_windows_line_endings() {
|
||||
assertEquals('bbb', new Document(1, "aaa\r\nbbb\r\nccc").getLineContent(1));
|
||||
}
|
||||
|
||||
@Test def void testGetLineCount_empty() {
|
||||
assertEquals(1, new Document(1, '').lineCount);
|
||||
}
|
||||
|
||||
@Test def void testGetLineCount_single() {
|
||||
assertEquals(1, new Document(1, 'aaa bbb ccc').lineCount);
|
||||
}
|
||||
|
||||
@Test def void testGetLineCount_multi() {
|
||||
assertEquals(3, new Document(1, '''
|
||||
aaa
|
||||
bbb
|
||||
ccc''').lineCount);
|
||||
}
|
||||
|
||||
private def change(Position startPos, Position endPos, String newText) {
|
||||
new TextDocumentContentChangeEvent => [
|
||||
if (startPos !== null) {
|
||||
range = new Range => [
|
||||
start = startPos
|
||||
end = endPos
|
||||
]
|
||||
}
|
||||
it.text = newText
|
||||
]
|
||||
}
|
||||
|
||||
private def textEdit(Position startPos, Position endPos, String newText) {
|
||||
new TextEdit => [
|
||||
if (startPos !== null) {
|
||||
range = new Range => [
|
||||
start = startPos
|
||||
end = endPos
|
||||
]
|
||||
}
|
||||
it.newText = newText
|
||||
]
|
||||
}
|
||||
|
||||
private def normalize(CharSequence s) {
|
||||
return s.toString.replaceAll("\r", "")
|
||||
}
|
||||
|
||||
private def position(int l, int c) {
|
||||
new Position => [line=l character=c]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2020 itemis AG (http://www.itemis.com) 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.FormattingOptions;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtext.ide.server.formatting.FormattingService;
|
||||
import org.eclipse.xtext.testing.FormattingConfiguration;
|
||||
import org.eclipse.xtext.testing.RangeFormattingConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Tests for {@link FormattingService}
|
||||
*
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
public class FormattingTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testFormattingService() {
|
||||
testFormatting((FormattingConfiguration it) -> {
|
||||
it.setModel("type Foo{int bar} type Bar{Foo foo}");
|
||||
String expectedText =
|
||||
"type Foo{\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar{\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setExpectedText(expectedText);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattingService_02() {
|
||||
testFormatting(it -> it.setOptions(new FormattingOptions(4, true)), (FormattingConfiguration it) -> {
|
||||
it.setModel("type Foo{int bar} type Bar{Foo foo}");
|
||||
String expectedText =
|
||||
"type Foo{\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar{\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setExpectedText(expectedText);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattingClosedFile() {
|
||||
testFormatting((FormattingConfiguration it) -> {
|
||||
it.setFilesInScope(ImmutableMap.<String, CharSequence>builder()
|
||||
.put("foo.testlang", "type Foo{int bar} type Bar{Foo foo}").build());
|
||||
String expectedText =
|
||||
"type Foo{\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar{\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setExpectedText(expectedText);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRangeFormattingService() {
|
||||
testRangeFormatting((RangeFormattingConfiguration it) -> {
|
||||
it.setModel("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setRange(new Range(new Position(0, 0), new Position(0, 17)));
|
||||
String expectedText =
|
||||
"type Foo{\n" +
|
||||
" int bar\n" +
|
||||
"} type Bar{Foo foo}";
|
||||
it.setExpectedText(expectedText);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRangeFormattingService_02() {
|
||||
testRangeFormatting(it -> it.setOptions(new FormattingOptions(4, true)), (RangeFormattingConfiguration it) -> {
|
||||
it.setModel("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setRange(new Range(new Position(0, 0), new Position(0, 17)));
|
||||
String expectedText =
|
||||
"type Foo{\n" +
|
||||
" int bar\n" +
|
||||
"} type Bar{Foo foo}";
|
||||
it.setExpectedText(expectedText);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 itemis AG (http://www.itemis.com) 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.server
|
||||
|
||||
import org.eclipse.lsp4j.FormattingOptions
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.Range
|
||||
import org.eclipse.xtext.ide.server.formatting.FormattingService
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Tests for {@link FormattingService}
|
||||
*
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
class FormattingTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test def void testFormattingService() {
|
||||
testFormatting [
|
||||
model = '''type Foo{int bar} type Bar{Foo foo}'''
|
||||
expectedText = '''
|
||||
type Foo{
|
||||
int bar
|
||||
}
|
||||
type Bar{
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testFormattingService_02() {
|
||||
testFormatting([
|
||||
options = new FormattingOptions(4, true)
|
||||
]) [
|
||||
model = '''type Foo{int bar} type Bar{Foo foo}'''
|
||||
expectedText = '''
|
||||
type Foo{
|
||||
int bar
|
||||
}
|
||||
type Bar{
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testFormattingClosedFile() {
|
||||
testFormatting [
|
||||
it.filesInScope = #{
|
||||
'foo.testlang' -> '''type Foo{int bar} type Bar{Foo foo}'''
|
||||
}
|
||||
expectedText = '''
|
||||
type Foo{
|
||||
int bar
|
||||
}
|
||||
type Bar{
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testRangeFormattingService() {
|
||||
testRangeFormatting [
|
||||
model = '''type Foo{int bar} type Bar{Foo foo}'''
|
||||
range = new Range => [
|
||||
start = new Position(0,0)
|
||||
end = new Position(0,17)
|
||||
]
|
||||
expectedText = '''
|
||||
type Foo{
|
||||
int bar
|
||||
} type Bar{Foo foo}'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test def void testRangeFormattingService_02() {
|
||||
testRangeFormatting([
|
||||
options = new FormattingOptions(4, true)
|
||||
]) [
|
||||
model = '''type Foo{int bar} type Bar{Foo foo}'''
|
||||
range = new Range => [
|
||||
start = new Position(0,0)
|
||||
end = new Position(0,17)
|
||||
]
|
||||
expectedText = '''
|
||||
type Foo{
|
||||
int bar
|
||||
} type Bar{Foo foo}'''
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.DocumentSymbolCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.xtext.testing.DocumentSymbolConfiguraiton;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HierarchicalDocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
private static final Procedure1<? super InitializeParams> INITIALIZER = (InitializeParams it) -> {
|
||||
ClientCapabilities clientCapabilities = new ClientCapabilities();
|
||||
DocumentSymbolCapabilities documentSymbolCapabilities = new DocumentSymbolCapabilities();
|
||||
documentSymbolCapabilities.setHierarchicalDocumentSymbolSupport(true);
|
||||
TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
textDocumentClientCapabilities.setDocumentSymbol(documentSymbolCapabilities);
|
||||
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
|
||||
it.setCapabilities(clientCapabilities);
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testDocumentSymbol_01() {
|
||||
testDocumentSymbol((DocumentSymbolConfiguraiton it) -> {
|
||||
it.setInitializer(HierarchicalDocumentSymbolTest.INITIALIZER);
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
String expectedSymbols =
|
||||
"symbol \"Foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" range: [[0, 0] .. [2, 1]]\n" +
|
||||
" selectionRange: [[0, 5] .. [0, 8]]\n" +
|
||||
" details: \n" +
|
||||
" deprecated: false\n" +
|
||||
" children: [\n" +
|
||||
" symbol \"Foo.bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" range: [[1, 1] .. [1, 8]]\n" +
|
||||
" selectionRange: [[1, 5] .. [1, 8]]\n" +
|
||||
" details: \n" +
|
||||
" deprecated: false\n" +
|
||||
" children: [\n" +
|
||||
" symbol \"Foo.bar.int\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" range: [[1, 1] .. [1, 4]]\n" +
|
||||
" selectionRange: [[1, 1] .. [1, 4]]\n" +
|
||||
" details: \n" +
|
||||
" deprecated: false\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" range: [[3, 0] .. [5, 1]]\n" +
|
||||
" selectionRange: [[3, 5] .. [3, 8]]\n" +
|
||||
" details: \n" +
|
||||
" deprecated: false\n" +
|
||||
" children: [\n" +
|
||||
" symbol \"Bar.foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" range: [[4, 1] .. [4, 8]]\n" +
|
||||
" selectionRange: [[4, 5] .. [4, 8]]\n" +
|
||||
" details: \n" +
|
||||
" deprecated: false\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}\n";
|
||||
it.setExpectedSymbols(expectedSymbols);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,86 +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.server
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities
|
||||
import org.eclipse.lsp4j.DocumentSymbolCapabilities
|
||||
import org.eclipse.lsp4j.InitializeParams
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities
|
||||
import org.junit.Test
|
||||
|
||||
class HierarchicalDocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
static val (InitializeParams)=>void INITIALIZER = [
|
||||
capabilities = new ClientCapabilities() => [
|
||||
textDocument = new TextDocumentClientCapabilities() => [
|
||||
documentSymbol = new DocumentSymbolCapabilities() => [
|
||||
it.hierarchicalDocumentSymbolSupport = true;
|
||||
];
|
||||
];
|
||||
];
|
||||
];
|
||||
|
||||
@Test
|
||||
def void testDocumentSymbol_01() {
|
||||
testDocumentSymbol[
|
||||
initializer = INITIALIZER
|
||||
model = '''
|
||||
type Foo {
|
||||
int bar
|
||||
}
|
||||
type Bar {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
expectedSymbols = '''
|
||||
symbol "Foo" {
|
||||
kind: 7
|
||||
range: [[0, 0] .. [2, 1]]
|
||||
selectionRange: [[0, 5] .. [0, 8]]
|
||||
details:
|
||||
deprecated: false
|
||||
children: [
|
||||
symbol "Foo.bar" {
|
||||
kind: 7
|
||||
range: [[1, 1] .. [1, 8]]
|
||||
selectionRange: [[1, 5] .. [1, 8]]
|
||||
details:
|
||||
deprecated: false
|
||||
children: [
|
||||
symbol "Foo.bar.int" {
|
||||
kind: 7
|
||||
range: [[1, 1] .. [1, 4]]
|
||||
selectionRange: [[1, 1] .. [1, 4]]
|
||||
details:
|
||||
deprecated: false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
symbol "Bar" {
|
||||
kind: 7
|
||||
range: [[3, 0] .. [5, 1]]
|
||||
selectionRange: [[3, 5] .. [3, 8]]
|
||||
details:
|
||||
deprecated: false
|
||||
children: [
|
||||
symbol "Bar.foo" {
|
||||
kind: 7
|
||||
range: [[4, 1] .. [4, 8]]
|
||||
selectionRange: [[4, 5] .. [4, 8]]
|
||||
details:
|
||||
deprecated: false
|
||||
}
|
||||
]
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.xtext.testing.HoverTestConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
public class HoverTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testHover_01() {
|
||||
testHover((HoverTestConfiguration it) -> {
|
||||
String model =
|
||||
"/**\n" +
|
||||
" * Some documentation.\n" +
|
||||
" */\n" +
|
||||
"type Foo {\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(3);
|
||||
it.setColumn("type F".length());
|
||||
String expectedHover =
|
||||
"[[3, 5] .. [3, 8]]\n" +
|
||||
"kind: markdown\n" +
|
||||
"value: Some documentation.\n";
|
||||
it.setExpectedHover(expectedHover);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_02() {
|
||||
testHover((HoverTestConfiguration it) -> {
|
||||
String model =
|
||||
"/**\n" +
|
||||
" * Some documentation.\n" +
|
||||
" */\n" +
|
||||
"type Foo {}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(3);
|
||||
it.setColumn("{".length());
|
||||
String expectedHover =
|
||||
"kind: markdown\n" +
|
||||
"value: \n";
|
||||
it.setExpectedHover(expectedHover);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_03() {
|
||||
testHover((HoverTestConfiguration it) -> {
|
||||
String model =
|
||||
"/**\n" +
|
||||
" * Some documentation.\n" +
|
||||
" */\n" +
|
||||
"type Foo {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(4);
|
||||
it.setColumn(" F".length());
|
||||
String expectedHover =
|
||||
"[[4, 1] .. [4, 4]]\n" +
|
||||
"kind: markdown\n" +
|
||||
"value: Some documentation.\n";
|
||||
it.setExpectedHover(expectedHover);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_04() {
|
||||
testHover((HoverTestConfiguration it) -> {
|
||||
String model =
|
||||
"/**\n" +
|
||||
" * Some documentation.\n" +
|
||||
" */\n" +
|
||||
"type Foo {\n" +
|
||||
"}\n" +
|
||||
"type Bar extends Foo {\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setLine(5);
|
||||
it.setColumn("type Bar extends F".length());
|
||||
String expectedHover =
|
||||
"[[5, 17] .. [5, 20]]\n" +
|
||||
"kind: markdown\n" +
|
||||
"value: Some documentation.\n";
|
||||
it.setExpectedHover(expectedHover);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_05() {
|
||||
testHover((HoverTestConfiguration it) -> {
|
||||
String otherModel =
|
||||
"/**\n" +
|
||||
" * Some documentation.\n" +
|
||||
" */\n" +
|
||||
"type Foo {\n" +
|
||||
"}\n";
|
||||
it.setFilesInScope(
|
||||
ImmutableMap.<String, CharSequence>builder().put("MyModel2." + fileExtension, otherModel).build());
|
||||
String model =
|
||||
"type Bar extends Foo {\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setColumn("type Bar extends F".length());
|
||||
String expectedHover =
|
||||
"[[0, 17] .. [0, 20]]\n" +
|
||||
"kind: markdown\n" +
|
||||
"value: Some documentation.\n";
|
||||
it.setExpectedHover(expectedHover);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.server
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class HoverTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testHover_01() {
|
||||
testHover[
|
||||
model = '''
|
||||
/**
|
||||
* Some documentation.
|
||||
*/
|
||||
type Foo {
|
||||
}
|
||||
'''
|
||||
line = 3
|
||||
column = 'type F'.length
|
||||
expectedHover = '''
|
||||
[[3, 5] .. [3, 8]]
|
||||
kind: markdown
|
||||
value: Some documentation.
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testHover_02() {
|
||||
testHover[
|
||||
model = '''
|
||||
/**
|
||||
* Some documentation.
|
||||
*/
|
||||
type Foo {}
|
||||
'''
|
||||
line = 3
|
||||
column = '{'.length
|
||||
expectedHover = '''
|
||||
kind: markdown
|
||||
value:
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testHover_03() {
|
||||
testHover[
|
||||
model = '''
|
||||
/**
|
||||
* Some documentation.
|
||||
*/
|
||||
type Foo {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
line = 4
|
||||
column = ' F'.length
|
||||
expectedHover = '''
|
||||
[[4, 1] .. [4, 4]]
|
||||
kind: markdown
|
||||
value: Some documentation.
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testHover_04() {
|
||||
testHover[
|
||||
model = '''
|
||||
/**
|
||||
* Some documentation.
|
||||
*/
|
||||
type Foo {
|
||||
}
|
||||
type Bar extends Foo {
|
||||
}
|
||||
'''
|
||||
line = 5
|
||||
column = 'type Bar extends F'.length
|
||||
expectedHover = '''
|
||||
[[5, 17] .. [5, 20]]
|
||||
kind: markdown
|
||||
value: Some documentation.
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testHover_05() {
|
||||
testHover[
|
||||
filesInScope = #{
|
||||
('MyModel2.' + fileExtension) -> '''
|
||||
/**
|
||||
* Some documentation.
|
||||
*/
|
||||
type Foo {
|
||||
}
|
||||
'''
|
||||
}
|
||||
model = '''
|
||||
type Bar extends Foo {
|
||||
}
|
||||
'''
|
||||
column = 'type Bar extends F'.length
|
||||
expectedHover = '''
|
||||
[[0, 17] .. [0, 20]]
|
||||
kind: markdown
|
||||
value: Some documentation.
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
/**
|
||||
* Copyright (c) 2019, 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.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.ide.server.UriExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class PrepareRenameTest extends AbstractTestLangLanguageServerTest {
|
||||
@Inject
|
||||
private UriExtensions uriExtensions;
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_missing_file_null() throws Exception {
|
||||
String uri = uriExtensions.toUriString(new File("missing." + fileExtension).toURI().normalize());
|
||||
initializeWithPrepareSupport();
|
||||
RenameParams params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), "Does not matter");
|
||||
Assert.assertNull(languageServer.rename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_missing_file_null() throws Exception {
|
||||
String uri = uriExtensions.toUriString(new File("missing." + fileExtension).toURI().normalize());
|
||||
initializeWithPrepareSupport();
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 5));
|
||||
Assert.assertNull(languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_missing_file_exception() throws Exception {
|
||||
String uri = uriExtensions.toUriString(new File("missing." + fileExtension).toURI().normalize());
|
||||
initialize();
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 5));
|
||||
try {
|
||||
Assert.assertNull(languageServer.prepareRename(params).get());
|
||||
Assert.fail("Expected an error.");
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(Throwables.getRootCause(e) instanceof FileNotFoundException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_invalid_error() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
String uri = writeFile("my-type-invalid.testlang", model);
|
||||
initialize();
|
||||
RenameParams params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), "Does not matter");
|
||||
try {
|
||||
languageServer.rename(params).get();
|
||||
Assert.fail(
|
||||
"Expected an expcetion when trying to rename document but got a valid workspace edit instead: «workspaceEdit»");
|
||||
} catch (Exception e) {
|
||||
Throwable rootCause = Throwables.getRootCause(e);
|
||||
Assert.assertTrue(rootCause instanceof ResponseErrorException);
|
||||
ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
|
||||
Assert.assertTrue(error.getData().toString().contains("No element found at position"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_invalid_null() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
String uri = writeFile("my-type-invalid.testlang", model);
|
||||
initializeWithPrepareSupport();
|
||||
RenameParams params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), "Does not matter");
|
||||
Assert.assertNull(languageServer.rename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_before_ok() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
String uri = writeFile(
|
||||
"my-type-valid.testlang",
|
||||
model);
|
||||
initializeWithPrepareSupport();
|
||||
RenameParams params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 13), "YourType");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
" my-type-valid.testlang : foo.bar.YourType [[2, 4] .. [2, 18]]\n" +
|
||||
" YourType [[4, 7] .. [4, 13]]\n" +
|
||||
"documentChanges : \n";
|
||||
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_before_nok() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
initializeWithPrepareSupport();
|
||||
String uri = writeFile("my-type-valid.testlang", model);
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 11));
|
||||
Assert.assertNull(languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_start_ok() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
initializeWithPrepareSupport();
|
||||
String uri = writeFile("my-type-valid.testlang", model);
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 12));
|
||||
Range range = languageServer.prepareRename(params).get().getLeft();
|
||||
assertEquals("MyType", new Document(0, model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_in_ok() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
initializeWithPrepareSupport();
|
||||
String uri = writeFile("my-type-valid.testlang", model);
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 14));
|
||||
Range range = languageServer.prepareRename(params).get().getLeft();
|
||||
assertEquals("MyType", new Document(0, model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_end_ok() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
initializeWithPrepareSupport();
|
||||
String uri = writeFile("my-type-valid.testlang", model);
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18));
|
||||
Range range = languageServer.prepareRename(params).get().getLeft();
|
||||
assertEquals("MyType", new Document(0, model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_end_null() throws Exception {
|
||||
String model =
|
||||
"package foo.bar {\n" +
|
||||
" type A {\n" +
|
||||
" foo.bar.MyType bar\n" +
|
||||
" }\n" +
|
||||
" type MyType { }\n" +
|
||||
"}\n";
|
||||
initialize();
|
||||
String uri = writeFile("my-type-valid.testlang", model);
|
||||
PrepareRenameParams params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18));
|
||||
Assert.assertNull(languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
private InitializeResult initializeWithPrepareSupport() {
|
||||
return super.initialize((InitializeParams params) -> {
|
||||
ClientCapabilities clientCapabilities = new ClientCapabilities();
|
||||
WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
|
||||
clientCapabilities.setWorkspace(workspaceClientCapabilities);
|
||||
TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
|
||||
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
|
||||
params.setCapabilities(clientCapabilities);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2019 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.server
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import org.eclipse.lsp4j.ClientCapabilities
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.RenameCapabilities
|
||||
import org.eclipse.lsp4j.RenameParams
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.eclipse.xtext.ide.server.UriExtensions
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import java.io.FileNotFoundException
|
||||
import org.eclipse.lsp4j.PrepareRenameParams
|
||||
|
||||
class PrepareRenameTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Inject
|
||||
extension UriExtensions
|
||||
|
||||
@Test
|
||||
def void testRenameFqn_missing_file_null() throws Exception {
|
||||
val uri = new File('''missing.«fileExtension»''').toURI.normalize.toUriString
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), 'Does not matter')
|
||||
assertNull(languageServer.rename(params).get)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_missing_file_null() throws Exception {
|
||||
val uri = new File('''missing.«fileExtension»''').toURI.normalize.toUriString
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 5))
|
||||
assertNull(languageServer.prepareRename(params).get)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_missing_file_exception() throws Exception {
|
||||
val uri = new File('''missing.«fileExtension»''').toURI.normalize.toUriString
|
||||
initialize()
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 5))
|
||||
try {
|
||||
assertNull(languageServer.prepareRename(params).get)
|
||||
fail('Expected an error.')
|
||||
} catch (Exception e) {
|
||||
assertTrue(Throwables.getRootCause(e) instanceof FileNotFoundException)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameFqn_invalid_error() throws Exception {
|
||||
val uri = 'my-type-invalid.testlang'.writeFile('''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
''')
|
||||
initialize()
|
||||
|
||||
val params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), 'Does not matter')
|
||||
try {
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
fail('''Expected an expcetion when trying to rename document but got a valid workspace edit instead: «workspaceEdit»''')
|
||||
} catch (Exception e) {
|
||||
val rootCause = Throwables.getRootCause(e)
|
||||
assertTrue(rootCause instanceof ResponseErrorException)
|
||||
val error = (rootCause as ResponseErrorException).responseError
|
||||
assertTrue(error.data.toString.contains('No element found at position'))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameFqn_invalid_null() throws Exception {
|
||||
val uri = 'my-type-invalid.testlang'.writeFile('''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
''')
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 5), 'Does not matter')
|
||||
assertNull(languageServer.rename(params).get)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameFqn_before_ok() throws Exception {
|
||||
val uri = 'my-type-valid.testlang'.writeFile('''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
''')
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val params = new RenameParams(new TextDocumentIdentifier(uri), new Position(2, 13), 'YourType')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
my-type-valid.testlang : foo.bar.YourType [[2, 4] .. [2, 18]]
|
||||
YourType [[4, 7] .. [4, 13]]
|
||||
documentChanges :
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_before_nok() throws Exception {
|
||||
val model = '''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
'''
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val uri = 'my-type-valid.testlang'.writeFile(model)
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 11))
|
||||
assertNull(languageServer.prepareRename(params).get)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_start_ok() throws Exception {
|
||||
val model = '''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
'''
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val uri = 'my-type-valid.testlang'.writeFile(model)
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 12))
|
||||
val range = languageServer.prepareRename(params).get.getLeft
|
||||
assertEquals('MyType', new Document(0, model).getSubstring(range))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_in_ok() throws Exception {
|
||||
val model = '''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
'''
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val uri = 'my-type-valid.testlang'.writeFile(model)
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 14))
|
||||
val range = languageServer.prepareRename(params).get.getLeft
|
||||
assertEquals('MyType', new Document(0, model).getSubstring(range))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_end_ok() throws Exception {
|
||||
val model = '''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
'''
|
||||
initializeWithPrepareSupport()
|
||||
|
||||
val uri = 'my-type-valid.testlang'.writeFile(model)
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18))
|
||||
val range = languageServer.prepareRename(params).get.getLeft
|
||||
assertEquals('MyType', new Document(0, model).getSubstring(range))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPrepareRenameFqn_end_null() throws Exception {
|
||||
val model = '''
|
||||
package foo.bar {
|
||||
type A {
|
||||
foo.bar.MyType bar
|
||||
}
|
||||
type MyType { }
|
||||
}
|
||||
'''
|
||||
initialize()
|
||||
|
||||
val uri = 'my-type-valid.testlang'.writeFile(model)
|
||||
|
||||
val params = new PrepareRenameParams(new TextDocumentIdentifier(uri), new Position(2, 18))
|
||||
assertNull(languageServer.prepareRename(params).get)
|
||||
}
|
||||
|
||||
private def initializeWithPrepareSupport() {
|
||||
initialize[
|
||||
capabilities = new ClientCapabilities => [
|
||||
textDocument = new TextDocumentClientCapabilities => [
|
||||
rename = new RenameCapabilities => [
|
||||
prepareSupport = true
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* Copyright (c) 2019, 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.PrepareRenameResult;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
public class RenamePositionTest extends AbstractLanguageServerTest {
|
||||
public RenamePositionTest() {
|
||||
super("renametl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeginningOfFile() {
|
||||
renameAndFail("type Test", new Position(0, 0), "No element found at position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameNameAtEndOfFile() throws Exception {
|
||||
String model = "type Test";
|
||||
renameWithSuccess(model, new Position(0, model.length()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondBeginningOfFile() {
|
||||
renameAndFail("type Test", new Position(-1, 0), "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeyondLine() {
|
||||
String model =
|
||||
"type Test\n" +
|
||||
"{}\n";
|
||||
renameAndFail(model, new Position(0, 11), "Invalid document position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondEndOfFile() {
|
||||
String model = "type Test";
|
||||
renameAndFail(model, new Position(0, model.length()+ 1), "Invalid document position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAtBraceAfterIdentifier() throws Exception {
|
||||
String model = "type Test{}";
|
||||
renameWithSuccess(model, new Position(0, model.indexOf("{")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAtBrace() {
|
||||
String model = "type Test{}";
|
||||
renameAndFail(model, new Position(0, model.indexOf("}")), "No element found at position");
|
||||
}
|
||||
|
||||
protected void renameAndFail(String model, Position position, String messageFragment) {
|
||||
String modelFile = writeFile("MyType.testlang", model);
|
||||
initialize();
|
||||
try {
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
|
||||
Either<Range, PrepareRenameResult> prepareRenameResult = languageServer
|
||||
.prepareRename(new PrepareRenameParams(identifier, position)).get();
|
||||
Assert.assertNull("expected null result got " + prepareRenameResult + " instead", prepareRenameResult);
|
||||
RenameParams renameParams = new RenameParams(new TextDocumentIdentifier(modelFile), position, "Tescht");
|
||||
languageServer.rename(renameParams).get();
|
||||
Assert.fail("Rename should have failed");
|
||||
} catch (Exception exc) {
|
||||
Throwable rootCause = Throwables.getRootCause(exc);
|
||||
Assert.assertTrue(rootCause instanceof ResponseErrorException);
|
||||
ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
|
||||
Assert.assertTrue(error.getData().toString().contains(messageFragment));
|
||||
}
|
||||
}
|
||||
|
||||
protected void renameWithSuccess(String model, Position position) throws Exception {
|
||||
String modelFile = writeFile("MyType.testlang", model);
|
||||
initialize((InitializeParams params) -> {
|
||||
ClientCapabilities clientCapabilities = new ClientCapabilities();
|
||||
TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
|
||||
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
|
||||
params.setCapabilities(clientCapabilities);
|
||||
});
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
Assert.assertNotNull(range);
|
||||
assertEquals(new Document(Integer.valueOf(0), model).getSubstring(range), "Test");
|
||||
RenameParams params = new RenameParams(identifier, position, "Tescht");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
" MyType.testlang : Tescht [[0, 5] .. [0, 9]]\n" +
|
||||
"documentChanges : \n";
|
||||
assertEquals(expectation.toString(),
|
||||
toExpectation(workspaceEdit));
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2019 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.server
|
||||
|
||||
import com.google.common.base.Throwables
|
||||
import org.eclipse.lsp4j.ClientCapabilities
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.PrepareRenameParams
|
||||
import org.eclipse.lsp4j.RenameCapabilities
|
||||
import org.eclipse.lsp4j.RenameParams
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
class RenamePositionTest extends AbstractLanguageServerTest {
|
||||
|
||||
new() {
|
||||
super('renametl')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameBeginningOfFile() {
|
||||
renameAndFail('type Test', new Position(0, 0), 'No element found at position')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameNameAtEndOfFile() {
|
||||
val model = 'type Test'
|
||||
renameWithSuccess(model, new Position(0, model.length))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testBeyondBeginningOfFile() {
|
||||
renameAndFail('type Test', new Position(-1, 0), '')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameBeyondLine() {
|
||||
renameAndFail('''
|
||||
type Test
|
||||
{}
|
||||
''', new Position(0, 11), 'Invalid document position')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testBeyondEndOfFile() {
|
||||
val model = 'type Test'
|
||||
renameAndFail(model, new Position(0, model.length + 1), 'Invalid document position')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAtBraceAfterIdentifier() {
|
||||
val model = 'type Test{}'
|
||||
renameWithSuccess(model, new Position(0, model.indexOf('{')))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAtBrace() {
|
||||
val model = 'type Test{}'
|
||||
renameAndFail(model, new Position(0, model.indexOf('}')), 'No element found at position')
|
||||
}
|
||||
|
||||
protected def void renameAndFail(String model, Position position, String messageFragment) {
|
||||
val modelFile = 'MyType.testlang'.writeFile(model)
|
||||
initialize
|
||||
try {
|
||||
val identifier = new TextDocumentIdentifier(modelFile)
|
||||
val prepareRenameResult = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get
|
||||
assertNull('''expected null result got «prepareRenameResult» instead''', prepareRenameResult)
|
||||
val renameParams = new RenameParams(new TextDocumentIdentifier(modelFile), position, 'Tescht')
|
||||
languageServer.rename(renameParams).get
|
||||
fail('Rename should have failed')
|
||||
} catch (Exception exc) {
|
||||
val rootCause = Throwables.getRootCause(exc)
|
||||
assertTrue(rootCause instanceof ResponseErrorException)
|
||||
val error = (rootCause as ResponseErrorException).responseError
|
||||
assertTrue(error.data.toString.contains(messageFragment))
|
||||
}
|
||||
}
|
||||
|
||||
protected def renameWithSuccess(String model, Position position) {
|
||||
val modelFile = 'MyType.testlang'.writeFile(model)
|
||||
initialize [
|
||||
capabilities = new ClientCapabilities => [
|
||||
textDocument = new TextDocumentClientCapabilities => [
|
||||
rename = new RenameCapabilities => [
|
||||
prepareSupport = true
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
val identifier = new TextDocumentIdentifier(modelFile)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertNotNull(range)
|
||||
assertEquals(new Document(0, model).getSubstring(range), 'Test')
|
||||
val params = new RenameParams(identifier, position, 'Tescht')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
MyType.testlang : Tescht [[0, 5] .. [0, 9]]
|
||||
documentChanges :
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
public class RenameTest extends AbstractTestLangLanguageServerTest {
|
||||
private String firstFile;
|
||||
|
||||
private String secondFile;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String first =
|
||||
"type Test {\n" +
|
||||
" Test foo\n" +
|
||||
"}\n";
|
||||
firstFile = writeFile("MyType1.testlang", first);
|
||||
String second =
|
||||
"type Test2 {\n" +
|
||||
" Test foo\n" +
|
||||
"}\n";
|
||||
secondFile = writeFile("MyType2.testlang", second);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeforeDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnReference() throws Exception {
|
||||
doTest(firstFile, new Position(1, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterReference() throws Exception {
|
||||
doTest(firstFile, new Position(1, 8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnReferenceInOtherFile() throws Exception {
|
||||
doTest(secondFile, new Position(1, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterReferenceInOtherFile() throws Exception {
|
||||
doTest(secondFile, new Position(1, 8));
|
||||
}
|
||||
|
||||
protected void doTest(String fileName, Position position) throws Exception {
|
||||
RenameParams params = new RenameParams(new TextDocumentIdentifier(fileName), position, "Tescht");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expected =
|
||||
"changes :\n" +
|
||||
" MyType1.testlang : Tescht [[0, 5] .. [0, 9]]\n" +
|
||||
" Tescht [[1, 4] .. [1, 8]]\n" +
|
||||
" MyType2.testlang : Tescht [[1, 4] .. [1, 8]]\n" +
|
||||
"documentChanges : \n";
|
||||
assertEquals(expected, toExpectation(workspaceEdit));
|
||||
}
|
||||
}
|
|
@ -1,90 +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.server
|
||||
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.RenameParams
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier
|
||||
import org.junit.Test
|
||||
import org.junit.Before
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
class RenameTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
String firstFile
|
||||
String secondFile
|
||||
|
||||
@Before
|
||||
def void setUp() {
|
||||
val first = '''
|
||||
type Test {
|
||||
Test foo
|
||||
}
|
||||
'''
|
||||
firstFile = 'MyType1.testlang'.writeFile(first)
|
||||
val second = '''
|
||||
type Test2 {
|
||||
Test foo
|
||||
}
|
||||
'''
|
||||
secondFile = 'MyType2.testlang'.writeFile(second)
|
||||
initialize
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameBeforeDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 5))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameOnDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 6))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAfterDeclaration() throws Exception {
|
||||
doTest(firstFile, new Position(0, 8))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameOnReference() throws Exception {
|
||||
doTest(firstFile, new Position(1, 5))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAfterReference() throws Exception {
|
||||
doTest(firstFile, new Position(1, 8))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameOnReferenceInOtherFile() throws Exception {
|
||||
doTest(secondFile, new Position(1, 5))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAfterReferenceInOtherFile() throws Exception {
|
||||
doTest(secondFile, new Position(1,8))
|
||||
}
|
||||
|
||||
protected def doTest(String fileName, Position position) throws Exception {
|
||||
val params = new RenameParams(new TextDocumentIdentifier(fileName), position, 'Tescht')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
MyType1.testlang : Tescht [[0, 5] .. [0, 9]]
|
||||
Tescht [[1, 4] .. [1, 8]]
|
||||
MyType2.testlang : Tescht [[1, 4] .. [1, 8]]
|
||||
documentChanges :
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
public class RenameTest2 extends AbstractLanguageServerTest {
|
||||
public RenameTest2() {
|
||||
super("fileawaretestlanguage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameSelfRef() throws Exception {
|
||||
String model =
|
||||
"package foo\n" +
|
||||
"\n" +
|
||||
"element Foo {\n" +
|
||||
" ref Foo\n" +
|
||||
"}\n";
|
||||
String file = writeFile("foo/Foo.fileawaretestlanguage", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(2, 9);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("Foo", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "Bar");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.fileawaretestlanguage <1> : Bar [[2, 8] .. [2, 11]]\n" +
|
||||
" Bar [[3, 5] .. [3, 8]]\n";
|
||||
assertEquals(
|
||||
expectation
|
||||
.toString(),
|
||||
toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameContainer() throws Exception {
|
||||
String model =
|
||||
"package foo\n" +
|
||||
"\n" +
|
||||
"element Foo {\n" +
|
||||
" element Bar {\n" +
|
||||
" }\n" +
|
||||
" ref foo.Foo.Bar\n" +
|
||||
" ref Foo.Bar\n" +
|
||||
" ref Bar\n" +
|
||||
"}\n";
|
||||
String file = writeFile("foo/Foo.fileawaretestlanguage", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(2, 9);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("Foo", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "Baz");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.fileawaretestlanguage <1> : Baz [[2, 8] .. [2, 11]]\n" +
|
||||
" Bar [[5, 5] .. [5, 16]]\n" +
|
||||
" Bar [[6, 5] .. [6, 12]]\n";
|
||||
assertEquals(
|
||||
expectation
|
||||
.toString(),
|
||||
toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InitializeResult initialize() {
|
||||
return super.initialize((InitializeParams params) -> {
|
||||
ClientCapabilities clientCapabilities = new ClientCapabilities();
|
||||
WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
|
||||
WorkspaceEditCapabilities workspaceEditCapabilities = new WorkspaceEditCapabilities();
|
||||
workspaceEditCapabilities.setDocumentChanges(true);
|
||||
workspaceClientCapabilities.setWorkspaceEdit(workspaceEditCapabilities);
|
||||
clientCapabilities.setWorkspace(workspaceClientCapabilities);
|
||||
TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
|
||||
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
|
||||
params.setCapabilities(clientCapabilities);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,104 +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.server
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.PrepareRenameParams
|
||||
import org.eclipse.lsp4j.RenameCapabilities
|
||||
import org.eclipse.lsp4j.RenameParams
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
class RenameTest2 extends AbstractLanguageServerTest {
|
||||
|
||||
new() {
|
||||
super('fileawaretestlanguage')
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameSelfRef() throws Exception {
|
||||
val model = '''
|
||||
package foo
|
||||
|
||||
element Foo {
|
||||
ref Foo
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.fileawaretestlanguage'.writeFile(model)
|
||||
initialize
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(2, 9)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('Foo', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'Bar')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.fileawaretestlanguage <1> : Bar [[2, 8] .. [2, 11]]
|
||||
Bar [[3, 5] .. [3, 8]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameContainer() throws Exception {
|
||||
val model = '''
|
||||
package foo
|
||||
|
||||
element Foo {
|
||||
element Bar {
|
||||
}
|
||||
ref foo.Foo.Bar
|
||||
ref Foo.Bar
|
||||
ref Bar
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.fileawaretestlanguage'.writeFile(model)
|
||||
initialize
|
||||
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(2, 9)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('Foo', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'Baz')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.fileawaretestlanguage <1> : Baz [[2, 8] .. [2, 11]]
|
||||
Bar [[5, 5] .. [5, 16]]
|
||||
Bar [[6, 5] .. [6, 12]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
override protected initialize() {
|
||||
super.initialize([params | params.capabilities = new ClientCapabilities => [
|
||||
workspace = new WorkspaceClientCapabilities => [
|
||||
workspaceEdit = new WorkspaceEditCapabilities => [
|
||||
documentChanges = true
|
||||
]
|
||||
]
|
||||
textDocument = new TextDocumentClientCapabilities => [
|
||||
rename = new RenameCapabilities => [
|
||||
prepareSupport = true
|
||||
]
|
||||
]
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* Copyright (c) 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
public class RenameTest3 extends AbstractLanguageServerTest {
|
||||
public RenameTest3() {
|
||||
super("renametl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAutoQuote() throws Exception {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
"}\n" +
|
||||
"";
|
||||
String file = writeFile("foo/Foo.renametl", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(0, 6);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("Foo", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "type");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]\n" +
|
||||
"";
|
||||
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameQuoted() throws Exception {
|
||||
String model =
|
||||
"type ^type {\n" +
|
||||
"}\n" +
|
||||
"";
|
||||
String file = writeFile("foo/Foo.renametl", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(0, 6);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("^type", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "Foo");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]\n" +
|
||||
"";
|
||||
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAutoQuoteRef() throws Exception {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"type Bar extends Foo {\n" +
|
||||
"}\n" +
|
||||
"";
|
||||
String file = writeFile("foo/Foo.renametl", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(3, 18);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("Foo", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "type");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]\n" +
|
||||
" ^type [[3, 17] .. [3, 20]]\n" +
|
||||
"";
|
||||
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameQuotedRef() throws Exception {
|
||||
String model =
|
||||
"type ^type {\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"type Bar extends ^type {\n" +
|
||||
"}\n" +
|
||||
"";
|
||||
String file = writeFile("foo/Foo.renametl", model);
|
||||
initialize();
|
||||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
Position position = new Position(3, 19);
|
||||
Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
|
||||
assertEquals("^type", new Document(0, model).getSubstring(range));
|
||||
RenameParams params = new RenameParams(identifier, position, "Foo");
|
||||
WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
|
||||
String expectation =
|
||||
"changes :\n" +
|
||||
"documentChanges : \n" +
|
||||
" Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]\n" +
|
||||
" Foo [[3, 17] .. [3, 22]]\n" +
|
||||
"";
|
||||
assertEquals(expectation.toString(), toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InitializeResult initialize() {
|
||||
return super.initialize((InitializeParams params) -> {
|
||||
ClientCapabilities clientCapabilities = new ClientCapabilities();
|
||||
WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
|
||||
WorkspaceEditCapabilities workspaceEditCapabilities = new WorkspaceEditCapabilities();
|
||||
workspaceEditCapabilities.setDocumentChanges(true);
|
||||
workspaceClientCapabilities.setWorkspaceEdit(workspaceEditCapabilities);
|
||||
clientCapabilities.setWorkspace(workspaceClientCapabilities);
|
||||
TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
|
||||
clientCapabilities.setTextDocument(textDocumentClientCapabilities);
|
||||
params.setCapabilities(clientCapabilities);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 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.server
|
||||
|
||||
import org.eclipse.lsp4j.Position
|
||||
import org.eclipse.lsp4j.RenameParams
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier
|
||||
import org.junit.Test
|
||||
import org.eclipse.lsp4j.PrepareRenameParams
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.eclipse.lsp4j.ClientCapabilities
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities
|
||||
import org.eclipse.lsp4j.RenameCapabilities
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
class RenameTest3 extends AbstractLanguageServerTest {
|
||||
|
||||
new() {
|
||||
super("renametl")
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAutoQuote() throws Exception {
|
||||
val model = '''
|
||||
type Foo {
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.renametl'.writeFile(model)
|
||||
initialize
|
||||
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(0, 6)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('Foo', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'type')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameQuoted() throws Exception {
|
||||
val model = '''
|
||||
type ^type {
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.renametl'.writeFile(model)
|
||||
initialize
|
||||
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(0, 6)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('^type', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'Foo')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameAutoQuoteRef() throws Exception {
|
||||
val model = '''
|
||||
type Foo {
|
||||
}
|
||||
|
||||
type Bar extends Foo {
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.renametl'.writeFile(model)
|
||||
initialize
|
||||
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(3, 18)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('Foo', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'type')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]
|
||||
^type [[3, 17] .. [3, 20]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testRenameQuotedRef() throws Exception {
|
||||
val model = '''
|
||||
type ^type {
|
||||
}
|
||||
|
||||
type Bar extends ^type {
|
||||
}
|
||||
'''
|
||||
val file = 'foo/Foo.renametl'.writeFile(model)
|
||||
initialize
|
||||
|
||||
val identifier = new TextDocumentIdentifier(file)
|
||||
val position = new Position(3, 19)
|
||||
val range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get.getLeft
|
||||
assertEquals('^type', new Document(0, model).getSubstring(range))
|
||||
val params = new RenameParams(identifier, position, 'Foo')
|
||||
val workspaceEdit = languageServer.rename(params).get
|
||||
assertEquals('''
|
||||
changes :
|
||||
documentChanges :
|
||||
Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]
|
||||
Foo [[3, 17] .. [3, 22]]
|
||||
'''.toString, toExpectation(workspaceEdit))
|
||||
}
|
||||
|
||||
override protected initialize() {
|
||||
super.initialize([ params |
|
||||
params.capabilities = new ClientCapabilities => [
|
||||
workspace = new WorkspaceClientCapabilities => [
|
||||
workspaceEdit = new WorkspaceEditCapabilities => [
|
||||
documentChanges = true
|
||||
]
|
||||
]
|
||||
textDocument = new TextDocumentClientCapabilities => [
|
||||
rename = new RenameCapabilities => [
|
||||
prepareSupport = true
|
||||
]
|
||||
]
|
||||
]
|
||||
])
|
||||
}
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.signatureHelp.SignatureHelpServiceImpl;
|
||||
import org.eclipse.xtext.testing.SignatureHelpConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Class for testing the the {@link SignatureHelpService signature help service}
|
||||
* implementation.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
* @see SignatureHelpServiceImpl
|
||||
*/
|
||||
public class SignatureHelpTest extends AbstractTestLangLanguageServerTest {
|
||||
private static int LINE_NUMBER = 12;
|
||||
|
||||
@Test
|
||||
public void singleArgsExactMatchAfterTriggerChar() {
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel("type A { op foo(a: A) { } } type Main { op main() { foo() } }");
|
||||
it.setLine(0);
|
||||
it.setColumn("type A { op foo(a: A) { } } type Main { op main() { foo(".length());
|
||||
it.setExpectedSignatureHelp("A.foo(a: A): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noArgsExactMatch() {
|
||||
String testMe = "foo()";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(".length());
|
||||
it.setExpectedSignatureHelp(
|
||||
"A.foo(): void | A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | <empty>");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstArgExactMatch() {
|
||||
String testMe = "foo(1)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1".length());
|
||||
it.setExpectedSignatureHelp(
|
||||
"A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secondArgExactMatch() {
|
||||
String testMe = "foo(1, 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, 2".length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thirdArgExactMatch() {
|
||||
String testMe = "foo(1, 2, 3)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, 2, 3".length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleArgWithLeadingWhitespace() {
|
||||
String testMe = "foo( 1)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo( 1".length());
|
||||
it.setExpectedSignatureHelp(
|
||||
"A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleArgWithTrailingWhitespace() {
|
||||
String testMe = "foo(1 )";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1 ".length());
|
||||
it.setExpectedSignatureHelp(
|
||||
"A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceBeforeFirstArg_ExpectFirstArg() {
|
||||
String testMe = "foo( 1, 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo( 1".length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceBeforeComma_ExpectFirstArg() {
|
||||
String testMe = "foo( 1 , 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo( 1 ".length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceAtComma_ExpectFirstArg() {
|
||||
String testMe = "foo( 1 , 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo( 1 ,".length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsAtComma() {
|
||||
String testMe = "foo(1, 2, 3)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, 2,".length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsAtCommaIncomplete() {
|
||||
String testMe = "foo(1, 2,)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, 2,".length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithCommentAtCommaIncomplete() {
|
||||
String testMe = "foo(1, /*,*/ 2,)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, /*,*/ 2,".length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeOperationCall() {
|
||||
String testMe = "foo(1, 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo".length());
|
||||
it.setExpectedSignatureHelp("<empty>");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterOperationCall() {
|
||||
String testMe = "foo(1, 2)";
|
||||
testSignatureHelp((SignatureHelpConfiguration it) -> {
|
||||
it.setModel(getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
it.setColumn("foo(1, 2)".length());
|
||||
it.setExpectedSignatureHelp("<empty>");
|
||||
});
|
||||
}
|
||||
|
||||
private String getModel(CharSequence method) {
|
||||
return "type A { \n" +
|
||||
" op foo() { } \n" +
|
||||
" op foo(a: A): string { }\n" +
|
||||
"}\n" +
|
||||
"type B { \n" +
|
||||
" op foo(a: A, b: B): int { }\n" +
|
||||
"}\n" +
|
||||
"type C { \n" +
|
||||
" op foo(a: A, b: B, c: C): void { }\n" +
|
||||
"}\n" +
|
||||
"type Test { \n" +
|
||||
" op main() {\n" +
|
||||
method+"\n" + // this is not properly formatted, but neither was is xtend
|
||||
" }\n" +
|
||||
"}\n";
|
||||
}
|
||||
}
|
|
@ -1,207 +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.server
|
||||
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.signatureHelp.SignatureHelpServiceImpl
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Class for testing the the {@link SignatureHelpService signature help service} implementation.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
* @see SignatureHelpServiceImpl
|
||||
*/
|
||||
class SignatureHelpTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
static val LINE_NUMBER = 12;
|
||||
|
||||
@Test
|
||||
def void singleArgsExactMatchAfterTriggerChar() {
|
||||
testSignatureHelp[
|
||||
model = '''type A { op foo(a: A) { } } type Main { op main() { foo() } }'''
|
||||
line = 0;
|
||||
column = '''type A { op foo(a: A) { } } type Main { op main() { foo('''.length;
|
||||
expectedSignatureHelp = 'A.foo(a: A): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void noArgsExactMatch() {
|
||||
val testMe = '''foo()''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo('''.length;
|
||||
expectedSignatureHelp = 'A.foo(): void | A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | <empty>'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void firstArgExactMatch() {
|
||||
val testMe = '''foo(1)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1'''.length;
|
||||
expectedSignatureHelp = 'A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void secondArgExactMatch() {
|
||||
val testMe = '''foo(1, 2)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, 2'''.length;
|
||||
expectedSignatureHelp = 'B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void thirdArgExactMatch() {
|
||||
val testMe = '''foo(1, 2, 3)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, 2, 3'''.length;
|
||||
expectedSignatureHelp = 'C.foo(a: A, b: B, c: C): void | c: C'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void singleArgWithLeadingWhitespace() {
|
||||
val testMe = '''foo( 1)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo( 1'''.length;
|
||||
expectedSignatureHelp = 'A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void singleArgWithTrailingWhitespace() {
|
||||
val testMe = '''foo(1 )''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1 '''.length;
|
||||
expectedSignatureHelp = 'A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsWithLeadingWhitespaceBeforeFirstArg_ExpectFirstArg() {
|
||||
val testMe = '''foo( 1, 2)'''
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo( 1'''.length;
|
||||
expectedSignatureHelp = 'B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsWithLeadingWhitespaceBeforeComma_ExpectFirstArg() {
|
||||
val testMe = '''foo( 1 , 2)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo( 1 '''.length;
|
||||
expectedSignatureHelp = 'B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsWithLeadingWhitespaceAtComma_ExpectFirstArg() {
|
||||
val testMe = '''foo( 1 , 2)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo( 1 ,'''.length;
|
||||
expectedSignatureHelp = 'B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsAtComma() {
|
||||
val testMe = '''foo(1, 2, 3)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, 2,'''.length;
|
||||
expectedSignatureHelp = 'C.foo(a: A, b: B, c: C): void | c: C'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsAtCommaIncomplete() {
|
||||
val testMe = '''foo(1, 2,)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, 2,'''.length;
|
||||
expectedSignatureHelp = 'C.foo(a: A, b: B, c: C): void | c: C'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void multipleArgsWithCommentAtCommaIncomplete() {
|
||||
val testMe = '''foo(1, /*,*/ 2,)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, /*,*/ 2,'''.length;
|
||||
expectedSignatureHelp = 'C.foo(a: A, b: B, c: C): void | c: C'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void beforeOperationCall() {
|
||||
val testMe = '''foo(1, 2)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo'''.length;
|
||||
expectedSignatureHelp = '<empty>'
|
||||
];
|
||||
}
|
||||
|
||||
@Test
|
||||
def void afterOperationCall() {
|
||||
val testMe = '''foo(1, 2)''';
|
||||
testSignatureHelp[
|
||||
model = getModel(testMe)
|
||||
line = LINE_NUMBER;
|
||||
column = '''foo(1, 2)'''.length;
|
||||
expectedSignatureHelp = '<empty>'
|
||||
];
|
||||
}
|
||||
|
||||
private def String getModel(CharSequence method) '''
|
||||
type A {
|
||||
op foo() { }
|
||||
op foo(a: A): string { }
|
||||
}
|
||||
type B {
|
||||
op foo(a: A, b: B): int { }
|
||||
}
|
||||
type C {
|
||||
op foo(a: A, b: B, c: C): void { }
|
||||
}
|
||||
type Test {
|
||||
op main() {
|
||||
«method»
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import org.eclipse.xtext.testing.WorkspaceSymbolConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
public class WorkspaceSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testSymbol_01() {
|
||||
testSymbol((WorkspaceSymbolConfiguration it) -> {
|
||||
String model =
|
||||
"type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setQuery("F");
|
||||
String expectedSymbols =
|
||||
"symbol \"Foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[0, 5] .. [0, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 5] .. [1, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar.int\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 1] .. [1, 4]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Bar.foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[4, 5] .. [4, 8]]\n" +
|
||||
"}\n";
|
||||
it.setExpectedSymbols(expectedSymbols);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSymbol_02() {
|
||||
testSymbol((WorkspaceSymbolConfiguration it) -> {
|
||||
String model = "type Foo {\n" +
|
||||
" int bar\n" +
|
||||
"}\n" +
|
||||
"type Bar {\n" +
|
||||
" Foo foo\n" +
|
||||
"}\n";
|
||||
it.setModel(model);
|
||||
it.setQuery("oO");
|
||||
String expectedSymbols = "symbol \"Foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[0, 5] .. [0, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 5] .. [1, 8]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Foo.bar.int\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[1, 1] .. [1, 4]]\n" +
|
||||
"}\n" +
|
||||
"symbol \"Bar.foo\" {\n" +
|
||||
" kind: 7\n" +
|
||||
" location: MyModel.testlang [[4, 5] .. [4, 8]]\n" +
|
||||
"}\n" +
|
||||
"";
|
||||
it.setExpectedSymbols(expectedSymbols);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,84 +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.server
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
class WorkspaceSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
|
||||
@Test
|
||||
def void testSymbol_01() {
|
||||
testSymbol[
|
||||
model = '''
|
||||
type Foo {
|
||||
int bar
|
||||
}
|
||||
type Bar {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
query = 'F'
|
||||
expectedSymbols = '''
|
||||
symbol "Foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[0, 5] .. [0, 8]]
|
||||
}
|
||||
symbol "Foo.bar" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 5] .. [1, 8]]
|
||||
}
|
||||
symbol "Foo.bar.int" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 1] .. [1, 4]]
|
||||
}
|
||||
symbol "Bar.foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[4, 5] .. [4, 8]]
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testSymbol_02() {
|
||||
testSymbol[
|
||||
model = '''
|
||||
type Foo {
|
||||
int bar
|
||||
}
|
||||
type Bar {
|
||||
Foo foo
|
||||
}
|
||||
'''
|
||||
query = 'oO'
|
||||
expectedSymbols = '''
|
||||
symbol "Foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[0, 5] .. [0, 8]]
|
||||
}
|
||||
symbol "Foo.bar" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 5] .. [1, 8]]
|
||||
}
|
||||
symbol "Foo.bar.int" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[1, 1] .. [1, 4]]
|
||||
}
|
||||
symbol "Bar.foo" {
|
||||
kind: 7
|
||||
location: MyModel.testlang [[4, 5] .. [4, 8]]
|
||||
}
|
||||
'''
|
||||
]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
/**
|
||||
* 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.signatureHelp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.lsp4j.ParameterInformation;
|
||||
import org.eclipse.lsp4j.SignatureHelp;
|
||||
import org.eclipse.lsp4j.SignatureHelpParams;
|
||||
import org.eclipse.lsp4j.SignatureInformation;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType;
|
||||
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.testLanguage.TypeReference;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Signature help service implementation for the test language.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
public class SignatureHelpServiceImpl implements ISignatureHelpService {
|
||||
private static final String OPENING_CHAR = "(";
|
||||
|
||||
private static final String CLOSING_CHAR = ")";
|
||||
|
||||
private static final String SEPARATOR_CHAR = ",";
|
||||
|
||||
/**
|
||||
* Shared comparator singleton to compare {@link SignatureInformation
|
||||
* signature information} instances based on the number of parameters first,
|
||||
* then the parameter labels lexicographically.
|
||||
*/
|
||||
private static final Comparator<SignatureInformation> SIGNATURE_INFO_ORDERING = (Comparator<SignatureInformation>) (
|
||||
SignatureInformation left, SignatureInformation right) -> {
|
||||
int result = left.getParameters().size()- right.getParameters().size();
|
||||
if (result == 0) {
|
||||
int i = 0;
|
||||
int size = left.getParameters().size();
|
||||
while (i < size) {
|
||||
result = left.getParameters().get(i).getLabel().getLeft()
|
||||
.compareTo(right.getParameters().get(i).getLabel().getLeft());
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
@Inject
|
||||
private EObjectAtOffsetHelper offsetHelper;
|
||||
|
||||
@Inject
|
||||
private IScopeProvider scopeProvider;
|
||||
|
||||
@Override
|
||||
public SignatureHelp getSignatureHelp(Document document, XtextResource resource, SignatureHelpParams params,
|
||||
CancelIndicator cancelIndicator) {
|
||||
int offset = document.getOffSet(params.getPosition());
|
||||
Preconditions.checkNotNull(resource, "resource");
|
||||
Preconditions.checkArgument(offset >= 0, "offset >= 0. Was: " + offset);
|
||||
EObject object = offsetHelper.resolveContainedElementAt(resource, offset);
|
||||
if (object instanceof OperationCall) {
|
||||
String operationName = getOperationName((OperationCall) object);
|
||||
if (!Strings.isNullOrEmpty(operationName)) {
|
||||
return getSignatureHelp((OperationCall) object, operationName, offset);
|
||||
}
|
||||
}
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
|
||||
private SignatureHelp getSignatureHelp(OperationCall call, String operationName, int offset) {
|
||||
// If the offset exceeds either the opening or the closing characters'
|
||||
// offset we should not
|
||||
// provide signature help at all.
|
||||
|
||||
List<Integer> separatorIndices = new ArrayList<>();
|
||||
for (INode node : NodeModelUtils.getNode(call).getChildren()) {
|
||||
String text = node.getText();
|
||||
if (SignatureHelpServiceImpl.OPENING_CHAR.equals(text) && node.getOffset() >= offset) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
} else {
|
||||
if (SignatureHelpServiceImpl.CLOSING_CHAR.equals(text) && node.getOffset() < offset) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
} else {
|
||||
if (SignatureHelpServiceImpl.SEPARATOR_CHAR.equals(text)) {
|
||||
separatorIndices.add(node.getOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Here we will distinguish between three different AST states:
|
||||
// 1. Valid state: when the number of parameter separators equals with
|
||||
// the number of (parameters - 1)
|
||||
// and each separator is surrounded by two parameters.
|
||||
// 2. Broken recoverable state: the number of parameters equals with the
|
||||
// number of separators and the
|
||||
// last separator offset is greater than the last parameter (offset +
|
||||
// length) and each separator is
|
||||
// surrounded by two parameters. Expect the last separator.
|
||||
// 3. Broken inconsistent state: non of the above cases.
|
||||
int paramCount = call.getParams().size();
|
||||
int separatorCount = separatorIndices.size();
|
||||
if (separatorCount+ 1 == paramCount || separatorCount == paramCount) {
|
||||
List<INode> paramNodes = NodeModelUtils.findNodesForFeature(call,
|
||||
TestLanguagePackage.Literals.OPERATION__PARAMS);
|
||||
// Parameter count could be greater than separator count.
|
||||
for (int i = 0; i < separatorCount; i++) {
|
||||
INode paramNode = paramNodes.get(i);
|
||||
// If separator is not after a parameter, signature help
|
||||
// should not be provided.
|
||||
if (paramNode.getOffset()+ paramNode.getLength() > separatorIndices.get(i).intValue()) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
final int currentParameter;
|
||||
if (paramCount != 0) {
|
||||
if (separatorIndices.contains(offset)) {
|
||||
currentParameter = separatorIndices.indexOf(offset)+ 2;
|
||||
} else {
|
||||
// Here we can execute a binary search for sure, because the
|
||||
// nodes where visited in order.
|
||||
currentParameter = -Collections.binarySearch(separatorIndices, offset);
|
||||
}
|
||||
} else {
|
||||
currentParameter = 0;
|
||||
}
|
||||
Iterable<Operation> visibleOperations = Iterables.filter(getVisibleOperationsWithName(call, operationName),
|
||||
it -> currentParameter <= it.getParams().size());
|
||||
int paramOffset = separatorIndices.contains(offset) ? 2 : 1;
|
||||
final Integer activeParamIndex;
|
||||
if (paramCount == 0) {
|
||||
Iterable<Integer> paramSize = Iterables.transform(visibleOperations, it -> it.getParams().size());
|
||||
// If on declaration-side no no-args exists, propose the first
|
||||
// parameter on use-side.
|
||||
if (!Iterables.any(paramSize, it -> it.intValue() == 0)
|
||||
&& Iterables.any(visibleOperations, it -> !it.getParams().isEmpty())) {
|
||||
activeParamIndex = 0;
|
||||
} else {
|
||||
activeParamIndex = null;
|
||||
}
|
||||
} else {
|
||||
activeParamIndex = currentParameter - paramOffset;
|
||||
}
|
||||
SignatureHelp signatureHelp = new SignatureHelp();
|
||||
signatureHelp.setActiveParameter(activeParamIndex);
|
||||
signatureHelp.setActiveSignature(0);
|
||||
signatureHelp.setSignatures(IterableExtensions
|
||||
.sortWith(IterableExtensions.toList(Iterables.transform(visibleOperations, (Operation operation) -> {
|
||||
SignatureInformation signatureInformation = new SignatureInformation(getLabel(operation));
|
||||
signatureInformation.setParameters(
|
||||
Lists.transform(operation.getParams(), (Parameter param) -> new ParameterInformation(
|
||||
param.getName() + ": " + getLabel(param.getType()))));
|
||||
return signatureInformation;
|
||||
})), SignatureHelpServiceImpl.SIGNATURE_INFO_ORDERING));
|
||||
return signatureHelp;
|
||||
}
|
||||
|
||||
private Iterable<Operation> getVisibleOperationsWithName(EObject object, String name) {
|
||||
return Iterables.filter(Iterables.transform(
|
||||
Iterables.filter(Iterables.filter(
|
||||
scopeProvider.getScope(object, TestLanguagePackage.Literals.OPERATION_CALL__OPERATION)
|
||||
.getAllElements(),
|
||||
(IEObjectDescription it) -> it.getEClass() == TestLanguagePackage.Literals.OPERATION),
|
||||
(IEObjectDescription it) -> Objects.equal(it.getQualifiedName().getLastSegment(), name)),
|
||||
IEObjectDescription::getEObjectOrProxy), Operation.class);
|
||||
}
|
||||
|
||||
private String getOperationName(OperationCall call) {
|
||||
INode firstNode = Iterables.getFirst(
|
||||
NodeModelUtils.findNodesForFeature(call, TestLanguagePackage.Literals.OPERATION_CALL__OPERATION), null);
|
||||
if (firstNode != null) {
|
||||
return firstNode.getText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getLabel(EObject it) {
|
||||
if (it instanceof Operation) {
|
||||
Operation it1 = (Operation) it;
|
||||
return EcoreUtil2.getContainerOfType(it1, TypeDeclaration.class).getName() + "." + it1.getName() + "("
|
||||
+ Joiner.on(", ")
|
||||
.join(Iterables.transform(it1.getParams(),
|
||||
(Parameter p) -> p.getName() + ": " + getLabel(p.getType())))
|
||||
+ "): " + (it1.getReturnType() == null ? "void" : getLabel(it1.getReturnType()));
|
||||
} else if (it instanceof PrimitiveType) {
|
||||
return ((PrimitiveType) it).getName();
|
||||
} else if (it instanceof TypeReference) {
|
||||
return ((TypeReference) it).getTypeRef().getName();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.asList(it).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,195 +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.signatureHelp
|
||||
|
||||
import com.google.common.base.Preconditions
|
||||
import com.google.inject.Inject
|
||||
import java.util.Arrays
|
||||
import java.util.Comparator
|
||||
import java.util.List
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.lsp4j.ParameterInformation
|
||||
import org.eclipse.lsp4j.SignatureHelp
|
||||
import org.eclipse.lsp4j.SignatureHelpParams
|
||||
import org.eclipse.lsp4j.SignatureInformation
|
||||
import org.eclipse.xtext.EcoreUtil2
|
||||
import org.eclipse.xtext.ide.server.Document
|
||||
import org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType
|
||||
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.testLanguage.TypeReference
|
||||
import org.eclipse.xtext.nodemodel.INode
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.eclipse.xtext.scoping.IScopeProvider
|
||||
import org.eclipse.xtext.util.CancelIndicator
|
||||
|
||||
/**
|
||||
* Signature help service implementation for the test language.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
class SignatureHelpServiceImpl implements ISignatureHelpService {
|
||||
|
||||
static val OPENING_CHAR = '(';
|
||||
|
||||
static val CLOSING_CHAR = ')';
|
||||
|
||||
static val SEPARATOR_CHAR = ',';
|
||||
|
||||
/**
|
||||
* Shared comparator singleton to compare {@link SignatureInformation signature information} instances
|
||||
* based on the number of parameters first, then the parameter labels lexicographically.
|
||||
*/
|
||||
static val Comparator<SignatureInformation> SIGNATURE_INFO_ORDERING = [ left, right |
|
||||
var result = left.parameters.size - right.parameters.size;
|
||||
if (result === 0) {
|
||||
for (var i = 0, var size = left.parameters.size; i < size; i++) {
|
||||
result = left.parameters.get(i).label.getLeft().compareTo(right.parameters.get(i).label.getLeft());
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
];
|
||||
|
||||
@Inject
|
||||
EObjectAtOffsetHelper offsetHelper;
|
||||
|
||||
@Inject
|
||||
IScopeProvider scopeProvider;
|
||||
|
||||
extension TestLanguagePackage = TestLanguagePackage.eINSTANCE;
|
||||
|
||||
override getSignatureHelp(Document document, XtextResource resource, SignatureHelpParams params, CancelIndicator cancelIndicator) {
|
||||
val offset = document.getOffSet(params.position)
|
||||
|
||||
Preconditions.checkNotNull(resource, "resource");
|
||||
Preconditions.checkArgument(offset >= 0, "offset >= 0. Was: " + offset);
|
||||
|
||||
val object = offsetHelper.resolveContainedElementAt(resource, offset);
|
||||
if (object instanceof OperationCall) {
|
||||
val operationName = object.operationName;
|
||||
if (!operationName.nullOrEmpty) {
|
||||
return getSignatureHelp(object, operationName, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
private def getSignatureHelp(OperationCall call, String operationName, int offset) {
|
||||
|
||||
// If the offset exceeds either the opening or the closing characters' offset we should not
|
||||
// provide signature help at all.
|
||||
val List<Integer> separatorIndices = newArrayList();
|
||||
|
||||
for (INode node : NodeModelUtils.getNode(call).getChildren()) {
|
||||
val text = node.text;
|
||||
if (OPENING_CHAR == text && node.offset >= offset) {
|
||||
return EMPTY;
|
||||
} else if (CLOSING_CHAR == text && node.offset < offset) {
|
||||
return EMPTY;
|
||||
} else if (SEPARATOR_CHAR == text) {
|
||||
separatorIndices.add(node.offset);
|
||||
}
|
||||
}
|
||||
|
||||
// Here we will distinguish between three different AST states:
|
||||
// 1. Valid state: when the number of parameter separators equals with the number of (parameters - 1)
|
||||
// and each separator is surrounded by two parameters.
|
||||
// 2. Broken recoverable state: the number of parameters equals with the number of separators and the
|
||||
//last separator offset is greater than the last parameter (offset + length) and each separator is
|
||||
// surrounded by two parameters. Expect the last separator.
|
||||
// 3. Broken inconsistent state: non of the above cases.
|
||||
val paramCount = call.params.size;
|
||||
val separatorCount = separatorIndices.size;
|
||||
|
||||
if ((separatorCount + 1) === paramCount || separatorCount === paramCount) {
|
||||
val paramNodes = NodeModelUtils.findNodesForFeature(call, operation_Params);
|
||||
// Parameter count could be greater than separator count.
|
||||
for (var i = 0; i < separatorCount; i++) {
|
||||
val paramNode = paramNodes.get(i);
|
||||
// If separator is not after a parameter, signature help should not be provided.
|
||||
if (paramNode.offset + paramNode.length > separatorIndices.get(i)) {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
val currentParameter = if (paramCount === 0) {
|
||||
0;
|
||||
} else if (separatorIndices.contains(offset)) {
|
||||
separatorIndices.indexOf(offset) + 2
|
||||
} else {
|
||||
// Here we can execute a binary search for sure, because the nodes where visited in order.
|
||||
-Arrays.binarySearch(separatorIndices, offset);
|
||||
}
|
||||
|
||||
val visibleOperations = call.getVisibleOperationsWithName(operationName).filter [
|
||||
currentParameter <= params.size
|
||||
]
|
||||
|
||||
val paramOffset = if (separatorIndices.contains(offset)) 2 else 1;
|
||||
val Integer activeParamIndex = if (paramCount === 0) {
|
||||
val paramSize = visibleOperations.map[params.size];
|
||||
// If on declaration-side no no-args exists, propose the first parameter on use-side.
|
||||
if (!paramSize.exists[it === 0] && visibleOperations.exists[!params.empty]) 0 else null;
|
||||
} else {
|
||||
currentParameter - paramOffset
|
||||
}
|
||||
return new SignatureHelp => [
|
||||
activeParameter = activeParamIndex
|
||||
activeSignature = 0;
|
||||
signatures = visibleOperations.map [ operation |
|
||||
new SignatureInformation => [
|
||||
label = operation.label;
|
||||
parameters = operation.params.map [ param |
|
||||
new ParameterInformation => [
|
||||
label = '''«param.name»: «param.type.label»'''
|
||||
];
|
||||
];
|
||||
];
|
||||
].toList.sortWith(SIGNATURE_INFO_ORDERING);
|
||||
]
|
||||
}
|
||||
|
||||
private def getVisibleOperationsWithName(EObject object, String name) {
|
||||
return scopeProvider.getScope(object, operationCall_Operation)
|
||||
.allElements
|
||||
.filter[EClass == operation]
|
||||
.filter [qualifiedName.lastSegment == name]
|
||||
.map[EObjectOrProxy]
|
||||
.filter(Operation);
|
||||
}
|
||||
|
||||
private def getOperationName(OperationCall call) {
|
||||
return NodeModelUtils.findNodesForFeature(call, operationCall_Operation).head?.text;
|
||||
}
|
||||
|
||||
private dispatch def String getLabel(Operation it) {
|
||||
return '''«EcoreUtil2.getContainerOfType(it, TypeDeclaration).name».«name»(«FOR p : params SEPARATOR ', '»«p.name»: «p.type.label»«ENDFOR»): «IF returnType === null»void«ELSE»«returnType.label»«ENDIF»''';
|
||||
}
|
||||
|
||||
private dispatch def String getLabel(TypeReference it) {
|
||||
return typeRef.name;
|
||||
}
|
||||
|
||||
private dispatch def String getLabel(PrimitiveType it) {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,247 +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.editor.contentassist;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.tests.editor.contentassist.ContentAssistContextTestHelper;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.TestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.TestLanguageGrammarAccess;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(TestLanguageIdeInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class ContentAssistContextFactoryTest {
|
||||
@Inject
|
||||
@Extension
|
||||
private ContentAssistContextTestHelper _contentAssistContextTestHelper;
|
||||
|
||||
@Inject
|
||||
private ContentAssistContextFactory factory;
|
||||
|
||||
@Inject
|
||||
private TestLanguageGrammarAccess grammar;
|
||||
|
||||
@Test
|
||||
public void testSimple1() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo <|>{");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'extends\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'{\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple2() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("<|>int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: TypeDeclaration:members+= *");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: TypeDeclaration:members+=Member");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Member:Property");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:type= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Property:type=Type");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Type:TypeReference");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: TypeReference:typeRef= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Type:PrimitiveType");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: PrimitiveType:name= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'string\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'int\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'boolean\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'void\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Member:Operation");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Operation:\'op\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'}\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeginning() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("<|>type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Model:elements+= *");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Model:elements+=AbstractElement");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: AbstractElement:PackageDeclaration");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PackageDeclaration:\'package\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: AbstractElement:TypeDeclaration");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'type\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: <AbstractElement not contained in AbstractRule!>:Model");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPoint() throws Exception {
|
||||
this._contentAssistContextTestHelper.setEntryPoint(this.grammar.getPropertyRule());
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("int <|>bar");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Type:arrayDiemensions+= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Type:arrayDiemensions+=\'[\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:name= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Property:name=ID");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPointBeginning() throws Exception {
|
||||
this._contentAssistContextTestHelper.setEntryPoint(this.grammar.getPropertyRule());
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("<|>int bar");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:type= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Property:type=Type");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Type:TypeReference");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: TypeReference:typeRef= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Type:PrimitiveType");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: PrimitiveType:name= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'string\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'int\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'boolean\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: PrimitiveType:name=\'void\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: <AbstractElement not contained in AbstractRule!>:Type");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
}
|
|
@ -76,40 +76,46 @@ public class ContentAssistContextTestHelper {
|
|||
}
|
||||
|
||||
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) throws Exception {
|
||||
final int offset = this.document.indexOf(this.cursor);
|
||||
Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
|
||||
final String doc = this.document.replace(this.cursor, "");
|
||||
final XtextResource res = this.parse(doc);
|
||||
factory.setPool(Executors.newCachedThreadPool());
|
||||
TextRegion _textRegion = new TextRegion(0, 0);
|
||||
final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
|
||||
final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
String _xblockexpression = null;
|
||||
{
|
||||
Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs)));
|
||||
for(final Pair<Integer, ContentAssistContext> ctx : _indexed) {
|
||||
_builder.append("context");
|
||||
Integer _key = ctx.getKey();
|
||||
_builder.append(_key);
|
||||
_builder.append(" {");
|
||||
_builder.newLineIfNotEmpty();
|
||||
{
|
||||
ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
|
||||
for(final AbstractElement ele : _firstSetGrammarElements) {
|
||||
_builder.append("\t");
|
||||
String _name = ele.eClass().getName();
|
||||
_builder.append(_name, "\t");
|
||||
_builder.append(": ");
|
||||
String _apply = f.apply(ele);
|
||||
_builder.append(_apply, "\t");
|
||||
_builder.newLineIfNotEmpty();
|
||||
final int offset = this.document.indexOf(this.cursor);
|
||||
Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
|
||||
final String doc = this.document.replace(this.cursor, "");
|
||||
final XtextResource res = this.parse(doc);
|
||||
factory.setPool(Executors.newCachedThreadPool());
|
||||
TextRegion _textRegion = new TextRegion(0, 0);
|
||||
final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
|
||||
final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
|
||||
final StringConcatenation result = new StringConcatenation("\n");
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
{
|
||||
Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>)Conversions.doWrapArray(ctxs)));
|
||||
for(final Pair<Integer, ContentAssistContext> ctx : _indexed) {
|
||||
_builder.append("context");
|
||||
Integer _key = ctx.getKey();
|
||||
_builder.append(_key);
|
||||
_builder.append(" {");
|
||||
_builder.newLineIfNotEmpty();
|
||||
{
|
||||
ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
|
||||
for(final AbstractElement ele : _firstSetGrammarElements) {
|
||||
_builder.append("\t");
|
||||
String _name = ele.eClass().getName();
|
||||
_builder.append(_name, "\t");
|
||||
_builder.append(": ");
|
||||
String _apply = f.apply(ele);
|
||||
_builder.append(_apply, "\t");
|
||||
_builder.newLineIfNotEmpty();
|
||||
}
|
||||
}
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
}
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
}
|
||||
result.append(_builder);
|
||||
_xblockexpression = result.toString();
|
||||
}
|
||||
return _builder.toString();
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
@Pure
|
||||
|
|
|
@ -1,181 +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.editor.contentassist;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.editor.contentassist.antlr.PartialContentAssistContextFactory;
|
||||
import org.eclipse.xtext.ide.tests.editor.contentassist.ContentAssistContextTestHelper;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.PartialContentAssistTestLanguageIdeInjectorProvider;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.services.PartialContentAssistTestLanguageGrammarAccess;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(PartialContentAssistTestLanguageIdeInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class PartialContentAssistTestLanguageContextFactoryTest {
|
||||
@Inject
|
||||
@Extension
|
||||
private ContentAssistContextTestHelper _contentAssistContextTestHelper;
|
||||
|
||||
@Inject
|
||||
private ContentAssistContextFactory factory;
|
||||
|
||||
@Inject
|
||||
private PartialContentAssistTestLanguageGrammarAccess grammar;
|
||||
|
||||
@Test
|
||||
public void testConfig() {
|
||||
Assert.assertTrue((this.factory instanceof PartialContentAssistContextFactory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple1() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo <|>{");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'extends\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'{\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple2() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("<|>int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: TypeDeclaration:properties+= *");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: TypeDeclaration:properties+=Property");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:type= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Property:type=\'int\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Property:type=\'bool\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'}\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeginning() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("<|>type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: TypeDeclaration:\'type\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: <AbstractElement not contained in AbstractRule!>:TypeDeclaration");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPoint() throws Exception {
|
||||
this._contentAssistContextTestHelper.setEntryPoint(this.grammar.getPropertyRule());
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("int <|>bar");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:name= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: Property:name=ID");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEntryPointBeginning() throws Exception {
|
||||
this._contentAssistContextTestHelper.setEntryPoint(this.grammar.getPropertyRule());
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("<|>int bar");
|
||||
_builder.newLine();
|
||||
this._contentAssistContextTestHelper.setDocument(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("context0 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Assignment: Property:type= ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Property:type=\'int\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Keyword: Property:type=\'bool\'");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("RuleCall: <AbstractElement not contained in AbstractRule!>:Property");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(_builder_1.toString(), this._contentAssistContextTestHelper.firstSetGrammarElementsToString(this.factory));
|
||||
}
|
||||
}
|
|
@ -1,117 +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.server;
|
||||
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class CodeActionTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testCodeAction() {
|
||||
final Procedure1<AbstractLanguageServerTest.TestCodeActionConfiguration> _function = (AbstractLanguageServerTest.TestCodeActionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("title : Change element name to first upper");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("kind : quickfix");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("command : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("codes : invalidName");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("edit : changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("MyModel.testlang : Foo [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("command : my.textedit.command");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("title : Make \'foo\' upper case (Command)");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("args : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("MyModel.testlang : Foo [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCodeActions(_builder_1.toString());
|
||||
};
|
||||
this.testCodeAction(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSemanticCodeAction() {
|
||||
final Procedure1<AbstractLanguageServerTest.TestCodeActionConfiguration> _function = (AbstractLanguageServerTest.TestCodeActionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("String ccc");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("String aaa");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type String {}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("title : Sort Members");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("kind : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("command : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("codes : unsorted_members");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("edit : changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("MyModel.testlang : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("String aaa");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("[[0, 10] .. [0, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("[[1, 11] .. [3, 0]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCodeActions(_builder_1.toString());
|
||||
};
|
||||
this.testCodeAction(_function);
|
||||
}
|
||||
}
|
|
@ -1,392 +0,0 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.eclipse.lsp4j.CodeAction;
|
||||
import org.eclipse.lsp4j.CodeLens;
|
||||
import org.eclipse.lsp4j.Command;
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.eclipse.lsp4j.DocumentHighlight;
|
||||
import org.eclipse.lsp4j.DocumentHighlightKind;
|
||||
import org.eclipse.lsp4j.DocumentSymbol;
|
||||
import org.eclipse.lsp4j.Hover;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.eclipse.lsp4j.MarkupContent;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.ResourceOperation;
|
||||
import org.eclipse.lsp4j.SemanticHighlightingInformation;
|
||||
import org.eclipse.lsp4j.SignatureHelp;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.TextDocumentEdit;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.TestCompletionConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.StringExtensions;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class CompletionTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testCompletion_01() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
it.setModel("");
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package -> package [[0, 0] .. [0, 0]]");
|
||||
_builder.newLine();
|
||||
_builder.append("type -> type [[0, 0] .. [0, 0]]");
|
||||
_builder.newLine();
|
||||
_builder.append("Sample Snippet -> type ${1|A,B,C|} {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.newLine();
|
||||
_builder.append("} [[0, 0] .. [0, 0]]");
|
||||
_builder.newLine();
|
||||
it.setExpectedCompletionItems(_builder.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_02() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
it.setModel("type ");
|
||||
it.setColumn(5);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("name (ID) -> name [[0, 5] .. [0, 5]]");
|
||||
_builder.newLine();
|
||||
it.setExpectedCompletionItems(_builder.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_03() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar {}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(1);
|
||||
it.setColumn("type Bar {".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Bar (TypeDeclaration) -> Bar [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("boolean -> boolean [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("int -> int [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("op -> op [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("string -> string [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("void -> void [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("} -> } [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("{ -> { [[1, 9] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("+ } [[1, 11] .. [1, 11]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_04() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(1);
|
||||
it.setColumn(" Fo".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Foo (TypeDeclaration) -> Foo [[1, 4] .. [1, 6]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("[ -> [ [[1, 6] .. [1, 6]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_05() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
_builder.append("type foo {}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Boo {}");
|
||||
_builder.newLine();
|
||||
_builder.append("type boo {}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(1);
|
||||
it.setColumn("type Bar {".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Boo (TypeDeclaration) -> Boo [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("boo (TypeDeclaration) -> boo [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Foo (TypeDeclaration) -> Foo [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("foo (TypeDeclaration) -> foo [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("boolean -> boolean [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("int -> int [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("op -> op [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("string -> string [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("void -> void [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("} -> } [[1, 10] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("{ -> { [[1, 9] .. [1, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("+ } [[1, 11] .. [1, 11]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
this.withKind = true;
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(1);
|
||||
it.setColumn(0);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("(Keyword) package -> package [[1, 0] .. [1, 0]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("(Keyword) type -> type [[1, 0] .. [1, 0]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("(Snippet|Snippet) Sample Snippet -> type ${1|A,B,C|} {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("} [[1, 0] .. [1, 0]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
this.withKind = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_AdditionalEdits_01() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo ");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(0);
|
||||
it.setColumn("type Foo ".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("extends -> extends [[0, 9] .. [0, 9]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("{ -> { [[0, 9] .. [0, 9]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("+ } [[1, 0] .. [1, 0]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompletion_AdditionalEdits_02() {
|
||||
final Procedure1<TestCompletionConfiguration> _function = (TestCompletionConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo ");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(0);
|
||||
it.setColumn("type Foo ".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("extends -> extends [[0, 9] .. [0, 9]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("{ -> { [[0, 9] .. [0, 9]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("+ } [[0, 10] .. [0, 10]]");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedCompletionItems(_builder_1.toString());
|
||||
};
|
||||
this.testCompletion(_function);
|
||||
}
|
||||
|
||||
private boolean withKind = false;
|
||||
|
||||
@Override
|
||||
protected String _toExpectation(final CompletionItem it) {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
{
|
||||
if (this.withKind) {
|
||||
_builder.append("(");
|
||||
CompletionItemKind _kind = it.getKind();
|
||||
_builder.append(_kind);
|
||||
{
|
||||
InsertTextFormat _insertTextFormat = it.getInsertTextFormat();
|
||||
boolean _tripleNotEquals = (_insertTextFormat != null);
|
||||
if (_tripleNotEquals) {
|
||||
_builder.append("|");
|
||||
InsertTextFormat _insertTextFormat_1 = it.getInsertTextFormat();
|
||||
_builder.append(_insertTextFormat_1);
|
||||
}
|
||||
}
|
||||
_builder.append(") ");
|
||||
}
|
||||
}
|
||||
String _label = it.getLabel();
|
||||
_builder.append(_label);
|
||||
{
|
||||
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it.getDetail());
|
||||
boolean _not = (!_isNullOrEmpty);
|
||||
if (_not) {
|
||||
_builder.append(" (");
|
||||
String _detail = it.getDetail();
|
||||
_builder.append(_detail);
|
||||
_builder.append(")");
|
||||
}
|
||||
}
|
||||
{
|
||||
TextEdit _textEdit = it.getTextEdit();
|
||||
boolean _tripleNotEquals_1 = (_textEdit != null);
|
||||
if (_tripleNotEquals_1) {
|
||||
_builder.append(" -> ");
|
||||
String _expectation = this.toExpectation(it.getTextEdit());
|
||||
_builder.append(_expectation);
|
||||
{
|
||||
boolean _isNullOrEmpty_1 = IterableExtensions.isNullOrEmpty(it.getAdditionalTextEdits());
|
||||
boolean _not_1 = (!_isNullOrEmpty_1);
|
||||
if (_not_1) {
|
||||
_builder.append(" + ");
|
||||
final Function1<TextEdit, String> _function = (TextEdit it_1) -> {
|
||||
return this.toExpectation(it_1);
|
||||
};
|
||||
String _join = IterableExtensions.join(ListExtensions.<TextEdit, String>map(it.getAdditionalTextEdits(), _function), " + ");
|
||||
_builder.append(_join);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (((it.getInsertText() != null) && (!Objects.equal(it.getInsertText(), it.getLabel())))) {
|
||||
_builder.append(" -> ");
|
||||
String _insertText = it.getInsertText();
|
||||
_builder.append(_insertText);
|
||||
}
|
||||
}
|
||||
}
|
||||
_builder.newLineIfNotEmpty();
|
||||
return _builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toExpectation(final Object it) {
|
||||
if (it instanceof Integer) {
|
||||
return _toExpectation((Integer)it);
|
||||
} else if (it instanceof List) {
|
||||
return _toExpectation((List<?>)it);
|
||||
} else if (it instanceof DocumentHighlightKind) {
|
||||
return _toExpectation((DocumentHighlightKind)it);
|
||||
} else if (it instanceof String) {
|
||||
return _toExpectation((String)it);
|
||||
} else if (it instanceof VersionedTextDocumentIdentifier) {
|
||||
return _toExpectation((VersionedTextDocumentIdentifier)it);
|
||||
} else if (it instanceof Pair) {
|
||||
return _toExpectation((Pair<SemanticHighlightingInformation, List<List<String>>>)it);
|
||||
} else if (it == null) {
|
||||
return _toExpectation((Void)null);
|
||||
} else if (it instanceof Map) {
|
||||
return _toExpectation((Map<Object, Object>)it);
|
||||
} else if (it instanceof CodeAction) {
|
||||
return _toExpectation((CodeAction)it);
|
||||
} else if (it instanceof CodeLens) {
|
||||
return _toExpectation((CodeLens)it);
|
||||
} else if (it instanceof Command) {
|
||||
return _toExpectation((Command)it);
|
||||
} else if (it instanceof CompletionItem) {
|
||||
return _toExpectation((CompletionItem)it);
|
||||
} else if (it instanceof DocumentHighlight) {
|
||||
return _toExpectation((DocumentHighlight)it);
|
||||
} else if (it instanceof DocumentSymbol) {
|
||||
return _toExpectation((DocumentSymbol)it);
|
||||
} else if (it instanceof Hover) {
|
||||
return _toExpectation((Hover)it);
|
||||
} else if (it instanceof Location) {
|
||||
return _toExpectation((Location)it);
|
||||
} else if (it instanceof MarkupContent) {
|
||||
return _toExpectation((MarkupContent)it);
|
||||
} else if (it instanceof Position) {
|
||||
return _toExpectation((Position)it);
|
||||
} else if (it instanceof Range) {
|
||||
return _toExpectation((Range)it);
|
||||
} else if (it instanceof ResourceOperation) {
|
||||
return _toExpectation((ResourceOperation)it);
|
||||
} else if (it instanceof SignatureHelp) {
|
||||
return _toExpectation((SignatureHelp)it);
|
||||
} else if (it instanceof SymbolInformation) {
|
||||
return _toExpectation((SymbolInformation)it);
|
||||
} else if (it instanceof TextDocumentEdit) {
|
||||
return _toExpectation((TextDocumentEdit)it);
|
||||
} else if (it instanceof TextEdit) {
|
||||
return _toExpectation((TextEdit)it);
|
||||
} else if (it instanceof WorkspaceEdit) {
|
||||
return _toExpectation((WorkspaceEdit)it);
|
||||
} else if (it instanceof Either) {
|
||||
return _toExpectation((Either<?, ?>)it);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " +
|
||||
Arrays.<Object>asList(it).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,105 +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.server;
|
||||
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.DocumentSymbolConfiguraiton;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class DocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testDocumentSymbol_01() {
|
||||
final Procedure1<DocumentSymbolConfiguraiton> _function = (DocumentSymbolConfiguraiton it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("symbol \"Foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 5] .. [1, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("container: \"Foo\"");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar.int\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 1] .. [1, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("container: \"Foo.bar\"");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[3, 5] .. [3, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Bar.foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[4, 5] .. [4, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("container: \"Bar\"");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedSymbols(_builder_1.toString());
|
||||
};
|
||||
this.testDocumentSymbol(_function);
|
||||
}
|
||||
}
|
|
@ -1,295 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2019 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.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author efftinge - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class DocumentTest {
|
||||
@Test
|
||||
public void testOffSet() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("hello world");
|
||||
_builder.newLine();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(Integer.valueOf(1), _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
|
||||
Assert.assertEquals(11, it.getOffSet(this.position(0, 11)));
|
||||
try {
|
||||
it.getOffSet(this.position(0, 12));
|
||||
Assert.fail();
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof IndexOutOfBoundsException) {
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(12, it.getOffSet(this.position(1, 0)));
|
||||
Assert.assertEquals(13, it.getOffSet(this.position(1, 1)));
|
||||
Assert.assertEquals(14, it.getOffSet(this.position(1, 2)));
|
||||
Assert.assertEquals(16, it.getOffSet(this.position(2, 0)));
|
||||
Assert.assertEquals(19, it.getOffSet(this.position(2, 3)));
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffSet_empty() {
|
||||
Document _document = new Document(Integer.valueOf(1), "");
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
|
||||
try {
|
||||
it.getOffSet(this.position(0, 12));
|
||||
Assert.fail();
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof IndexOutOfBoundsException) {
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_01() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("hello world");
|
||||
_builder.newLine();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(Integer.valueOf(1), _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("hello world");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("bar");
|
||||
_builder_1.newLine();
|
||||
TextDocumentContentChangeEvent _change = this.change(this.position(1, 0), this.position(2, 0), "");
|
||||
Assert.assertEquals(this.normalize(_builder_1), it.applyTextDocumentChanges(
|
||||
Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_02() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("hello world");
|
||||
_builder.newLine();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(Integer.valueOf(1), _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("hello world");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("future");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("bar");
|
||||
_builder_1.newLine();
|
||||
TextDocumentContentChangeEvent _change = this.change(this.position(1, 1), this.position(1, 3), "uture");
|
||||
Assert.assertEquals(this.normalize(_builder_1), it.applyTextDocumentChanges(
|
||||
Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_03() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("hello world");
|
||||
_builder.newLine();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(Integer.valueOf(1), _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
TextDocumentContentChangeEvent _change = this.change(this.position(0, 0), this.position(2, 3), "");
|
||||
Assert.assertEquals("", it.applyTextDocumentChanges(
|
||||
Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyTextDocumentChanges_04() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
_builder.newLine();
|
||||
String _normalize = this.normalize(_builder);
|
||||
TextDocumentContentChangeEvent _change = this.change(this.position(0, 3), this.position(0, 3), "b");
|
||||
TextDocumentContentChangeEvent _change_1 = this.change(this.position(0, 4), this.position(0, 4), "a");
|
||||
TextDocumentContentChangeEvent _change_2 = this.change(this.position(0, 5), this.position(0, 5), "r");
|
||||
Document _applyTextDocumentChanges = new Document(Integer.valueOf(1), _normalize).applyTextDocumentChanges(
|
||||
Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change, _change_1, _change_2)));
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foobar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("bar");
|
||||
_builder_1.newLine();
|
||||
Assert.assertEquals(this.normalize(_builder_1), it.getContents());
|
||||
Assert.assertEquals(2, (it.getVersion()).intValue());
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_applyTextDocumentChanges, _function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_nonIncrementalChange() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("hello world");
|
||||
_builder.newLine();
|
||||
_builder.append("foo");
|
||||
_builder.newLine();
|
||||
_builder.append("bar");
|
||||
String _normalize = this.normalize(_builder);
|
||||
Document _document = new Document(Integer.valueOf(1), _normalize);
|
||||
final Procedure1<Document> _function = (Document it) -> {
|
||||
TextEdit _textEdit = this.textEdit(null, null, " foo ");
|
||||
Assert.assertEquals(" foo ", it.applyChanges(
|
||||
Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_textEdit))).getContents());
|
||||
};
|
||||
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testGetLineContent_negative() {
|
||||
new Document(Integer.valueOf(1), "").getLineContent((-1));
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testGetLineContent_exceeds() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("aaa");
|
||||
_builder.newLine();
|
||||
_builder.append("bbb");
|
||||
_builder.newLine();
|
||||
_builder.append("ccc");
|
||||
new Document(Integer.valueOf(1), _builder.toString()).getLineContent(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent_empty() {
|
||||
Assert.assertEquals("", new Document(Integer.valueOf(1), "").getLineContent(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("aaa");
|
||||
_builder.newLine();
|
||||
_builder.append("bbb");
|
||||
_builder.newLine();
|
||||
_builder.append("ccc");
|
||||
Assert.assertEquals("bbb", new Document(Integer.valueOf(1), _builder.toString()).getLineContent(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineContent_windows_line_endings() {
|
||||
Assert.assertEquals("bbb", new Document(Integer.valueOf(1), "aaa\r\nbbb\r\nccc").getLineContent(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_empty() {
|
||||
Assert.assertEquals(1, new Document(Integer.valueOf(1), "").getLineCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_single() {
|
||||
Assert.assertEquals(1, new Document(Integer.valueOf(1), "aaa bbb ccc").getLineCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineCount_multi() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("aaa");
|
||||
_builder.newLine();
|
||||
_builder.append("bbb");
|
||||
_builder.newLine();
|
||||
_builder.append("ccc");
|
||||
Assert.assertEquals(3, new Document(Integer.valueOf(1), _builder.toString()).getLineCount());
|
||||
}
|
||||
|
||||
private TextDocumentContentChangeEvent change(final Position startPos, final Position endPos, final String newText) {
|
||||
TextDocumentContentChangeEvent _textDocumentContentChangeEvent = new TextDocumentContentChangeEvent();
|
||||
final Procedure1<TextDocumentContentChangeEvent> _function = (TextDocumentContentChangeEvent it) -> {
|
||||
if ((startPos != null)) {
|
||||
Range _range = new Range();
|
||||
final Procedure1<Range> _function_1 = (Range it_1) -> {
|
||||
it_1.setStart(startPos);
|
||||
it_1.setEnd(endPos);
|
||||
};
|
||||
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
|
||||
it.setRange(_doubleArrow);
|
||||
}
|
||||
it.setText(newText);
|
||||
};
|
||||
return ObjectExtensions.<TextDocumentContentChangeEvent>operator_doubleArrow(_textDocumentContentChangeEvent, _function);
|
||||
}
|
||||
|
||||
private TextEdit textEdit(final Position startPos, final Position endPos, final String newText) {
|
||||
TextEdit _textEdit = new TextEdit();
|
||||
final Procedure1<TextEdit> _function = (TextEdit it) -> {
|
||||
if ((startPos != null)) {
|
||||
Range _range = new Range();
|
||||
final Procedure1<Range> _function_1 = (Range it_1) -> {
|
||||
it_1.setStart(startPos);
|
||||
it_1.setEnd(endPos);
|
||||
};
|
||||
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
|
||||
it.setRange(_doubleArrow);
|
||||
}
|
||||
it.setNewText(newText);
|
||||
};
|
||||
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function);
|
||||
}
|
||||
|
||||
private String normalize(final CharSequence s) {
|
||||
return s.toString().replaceAll("\r", "");
|
||||
}
|
||||
|
||||
private Position position(final int l, final int c) {
|
||||
Position _position = new Position();
|
||||
final Procedure1<Position> _function = (Position it) -> {
|
||||
it.setLine(l);
|
||||
it.setCharacter(c);
|
||||
};
|
||||
return ObjectExtensions.<Position>operator_doubleArrow(_position, _function);
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016 itemis AG (http://www.itemis.com) 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.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.eclipse.lsp4j.DocumentFormattingParams;
|
||||
import org.eclipse.lsp4j.DocumentRangeFormattingParams;
|
||||
import org.eclipse.lsp4j.FormattingOptions;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.formatting.FormattingService;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.FormattingConfiguration;
|
||||
import org.eclipse.xtext.testing.RangeFormattingConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link FormattingService}
|
||||
*
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FormattingTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testFormattingService() {
|
||||
final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Foo{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("int bar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("type Bar{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Foo foo");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedText(_builder_1.toString());
|
||||
};
|
||||
this.testFormatting(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattingService_02() {
|
||||
final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
|
||||
FormattingOptions _formattingOptions = new FormattingOptions(4, true);
|
||||
it.setOptions(_formattingOptions);
|
||||
};
|
||||
final Procedure1<FormattingConfiguration> _function_1 = (FormattingConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Foo{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("int bar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("type Bar{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo foo");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedText(_builder_1.toString());
|
||||
};
|
||||
this.testFormatting(_function, _function_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattingClosedFile() {
|
||||
final Procedure1<FormattingConfiguration> _function = (FormattingConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo{int bar} type Bar{Foo foo}");
|
||||
Pair<String, String> _mappedTo = Pair.<String, String>of("foo.testlang", _builder.toString());
|
||||
it.setFilesInScope(Collections.<String, CharSequence>unmodifiableMap(CollectionLiterals.<String, CharSequence>newHashMap(_mappedTo)));
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Foo{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("int bar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("type Bar{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("Foo foo");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedText(_builder_1.toString());
|
||||
};
|
||||
this.testFormatting(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRangeFormattingService() {
|
||||
final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setModel(_builder.toString());
|
||||
Range _range = new Range();
|
||||
final Procedure1<Range> _function_1 = (Range it_1) -> {
|
||||
Position _position = new Position(0, 0);
|
||||
it_1.setStart(_position);
|
||||
Position _position_1 = new Position(0, 17);
|
||||
it_1.setEnd(_position_1);
|
||||
};
|
||||
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
|
||||
it.setRange(_doubleArrow);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Foo{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("int bar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("} type Bar{Foo foo}");
|
||||
it.setExpectedText(_builder_1.toString());
|
||||
};
|
||||
this.testRangeFormatting(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRangeFormattingService_02() {
|
||||
final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
|
||||
FormattingOptions _formattingOptions = new FormattingOptions(4, true);
|
||||
it.setOptions(_formattingOptions);
|
||||
};
|
||||
final Procedure1<RangeFormattingConfiguration> _function_1 = (RangeFormattingConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo{int bar} type Bar{Foo foo}");
|
||||
it.setModel(_builder.toString());
|
||||
Range _range = new Range();
|
||||
final Procedure1<Range> _function_2 = (Range it_1) -> {
|
||||
Position _position = new Position(0, 0);
|
||||
it_1.setStart(_position);
|
||||
Position _position_1 = new Position(0, 17);
|
||||
it_1.setEnd(_position_1);
|
||||
};
|
||||
Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_2);
|
||||
it.setRange(_doubleArrow);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Foo{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("int bar");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("} type Bar{Foo foo}");
|
||||
it.setExpectedText(_builder_1.toString());
|
||||
};
|
||||
this.testRangeFormatting(_function, _function_1);
|
||||
}
|
||||
}
|
|
@ -1,187 +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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.DocumentSymbolCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.DocumentSymbolConfiguraiton;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class HierarchicalDocumentSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
private static final Procedure1<? super InitializeParams> INITIALIZER = ((Procedure1<InitializeParams>) (InitializeParams it) -> {
|
||||
ClientCapabilities _clientCapabilities = new ClientCapabilities();
|
||||
final Procedure1<ClientCapabilities> _function = (ClientCapabilities it_1) -> {
|
||||
TextDocumentClientCapabilities _textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
final Procedure1<TextDocumentClientCapabilities> _function_1 = (TextDocumentClientCapabilities it_2) -> {
|
||||
DocumentSymbolCapabilities _documentSymbolCapabilities = new DocumentSymbolCapabilities();
|
||||
final Procedure1<DocumentSymbolCapabilities> _function_2 = (DocumentSymbolCapabilities it_3) -> {
|
||||
it_3.setHierarchicalDocumentSymbolSupport(Boolean.valueOf(true));
|
||||
};
|
||||
DocumentSymbolCapabilities _doubleArrow = ObjectExtensions.<DocumentSymbolCapabilities>operator_doubleArrow(_documentSymbolCapabilities, _function_2);
|
||||
it_2.setDocumentSymbol(_doubleArrow);
|
||||
};
|
||||
TextDocumentClientCapabilities _doubleArrow = ObjectExtensions.<TextDocumentClientCapabilities>operator_doubleArrow(_textDocumentClientCapabilities, _function_1);
|
||||
it_1.setTextDocument(_doubleArrow);
|
||||
};
|
||||
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function);
|
||||
it.setCapabilities(_doubleArrow);
|
||||
});
|
||||
|
||||
@Test
|
||||
public void testDocumentSymbol_01() {
|
||||
final Procedure1<DocumentSymbolConfiguraiton> _function = (DocumentSymbolConfiguraiton it) -> {
|
||||
it.setInitializer(HierarchicalDocumentSymbolTest.INITIALIZER);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("symbol \"Foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("range: [[0, 0] .. [2, 1]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("selectionRange: [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("details: ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("deprecated: false");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("children: [");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("symbol \"Foo.bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("range: [[1, 1] .. [1, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("selectionRange: [[1, 5] .. [1, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("details: ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("deprecated: false");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("children: [");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("symbol \"Foo.bar.int\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("range: [[1, 1] .. [1, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("selectionRange: [[1, 1] .. [1, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("details: ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("deprecated: false");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("range: [[3, 0] .. [5, 1]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("selectionRange: [[3, 5] .. [3, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("details: ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("deprecated: false");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("children: [");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("symbol \"Bar.foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("range: [[4, 1] .. [4, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("selectionRange: [[4, 5] .. [4, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("details: ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("deprecated: false");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedSymbols(_builder_1.toString());
|
||||
};
|
||||
this.testDocumentSymbol(_function);
|
||||
}
|
||||
}
|
|
@ -1,188 +0,0 @@
|
|||
/**
|
||||
* 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.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.HoverTestConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class HoverTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testHover_01() {
|
||||
final Procedure1<HoverTestConfiguration> _function = (HoverTestConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/**");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Some documentation.");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(3);
|
||||
it.setColumn("type F".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("[[3, 5] .. [3, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("kind: markdown");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("value: Some documentation.");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedHover(_builder_1.toString());
|
||||
};
|
||||
this.testHover(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_02() {
|
||||
final Procedure1<HoverTestConfiguration> _function = (HoverTestConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/**");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Some documentation.");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("type Foo {}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(3);
|
||||
it.setColumn("{".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("kind: markdown");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("value: ");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedHover(_builder_1.toString());
|
||||
};
|
||||
this.testHover(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_03() {
|
||||
final Procedure1<HoverTestConfiguration> _function = (HoverTestConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/**");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Some documentation.");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(4);
|
||||
it.setColumn("\tF".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("[[4, 1] .. [4, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("kind: markdown");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("value: Some documentation.");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedHover(_builder_1.toString());
|
||||
};
|
||||
this.testHover(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_04() {
|
||||
final Procedure1<HoverTestConfiguration> _function = (HoverTestConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/**");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Some documentation.");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar extends Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(5);
|
||||
it.setColumn("type Bar extends F".length());
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("[[5, 17] .. [5, 20]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("kind: markdown");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("value: Some documentation.");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedHover(_builder_1.toString());
|
||||
};
|
||||
this.testHover(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHover_05() {
|
||||
final Procedure1<HoverTestConfiguration> _function = (HoverTestConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/**");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Some documentation.");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
Pair<String, String> _mappedTo = Pair.<String, String>of(("MyModel2." + this.fileExtension), _builder.toString());
|
||||
it.setFilesInScope(Collections.<String, CharSequence>unmodifiableMap(CollectionLiterals.<String, CharSequence>newHashMap(_mappedTo)));
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Bar extends Foo {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setModel(_builder_1.toString());
|
||||
it.setColumn("type Bar extends F".length());
|
||||
StringConcatenation _builder_2 = new StringConcatenation();
|
||||
_builder_2.append("[[0, 17] .. [0, 20]]");
|
||||
_builder_2.newLine();
|
||||
_builder_2.append("kind: markdown");
|
||||
_builder_2.newLine();
|
||||
_builder_2.append("value: Some documentation.");
|
||||
_builder_2.newLine();
|
||||
it.setExpectedHover(_builder_2.toString());
|
||||
};
|
||||
this.testHover(_function);
|
||||
}
|
||||
}
|
|
@ -1,368 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2019 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.server;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.ide.server.UriExtensions;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class PrepareRenameTest extends AbstractTestLangLanguageServerTest {
|
||||
@Inject
|
||||
@Extension
|
||||
private UriExtensions _uriExtensions;
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_missing_file_null() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("missing.");
|
||||
_builder.append(this.fileExtension);
|
||||
final String uri = this._uriExtensions.toUriString(new File(_builder.toString()).toURI().normalize());
|
||||
this.initializeWithPrepareSupport();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 5);
|
||||
final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Does not matter");
|
||||
Assert.assertNull(this.languageServer.rename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_missing_file_null() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("missing.");
|
||||
_builder.append(this.fileExtension);
|
||||
final String uri = this._uriExtensions.toUriString(new File(_builder.toString()).toURI().normalize());
|
||||
this.initializeWithPrepareSupport();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 5);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
Assert.assertNull(this.languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_missing_file_exception() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("missing.");
|
||||
_builder.append(this.fileExtension);
|
||||
final String uri = this._uriExtensions.toUriString(new File(_builder.toString()).toURI().normalize());
|
||||
this.initialize();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 5);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
try {
|
||||
Assert.assertNull(this.languageServer.prepareRename(params).get());
|
||||
Assert.fail("Expected an error.");
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Exception) {
|
||||
final Exception e = (Exception)_t;
|
||||
Throwable _rootCause = Throwables.getRootCause(e);
|
||||
Assert.assertTrue((_rootCause instanceof FileNotFoundException));
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_invalid_error() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String uri = this.writeFile("my-type-invalid.testlang", _builder);
|
||||
this.initialize();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 5);
|
||||
final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Does not matter");
|
||||
try {
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Expected an expcetion when trying to rename document but got a valid workspace edit instead: ");
|
||||
_builder_1.append(workspaceEdit);
|
||||
Assert.fail(_builder_1.toString());
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Exception) {
|
||||
final Exception e = (Exception)_t;
|
||||
final Throwable rootCause = Throwables.getRootCause(e);
|
||||
Assert.assertTrue((rootCause instanceof ResponseErrorException));
|
||||
final ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
|
||||
Assert.assertTrue(error.getData().toString().contains("No element found at position"));
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_invalid_null() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String uri = this.writeFile("my-type-invalid.testlang", _builder);
|
||||
this.initializeWithPrepareSupport();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 5);
|
||||
final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Does not matter");
|
||||
Assert.assertNull(this.languageServer.rename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameFqn_before_ok() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", _builder);
|
||||
this.initializeWithPrepareSupport();
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 13);
|
||||
final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "YourType");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("my-type-valid.testlang : foo.bar.YourType [[2, 4] .. [2, 18]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("YourType [[4, 7] .. [4, 13]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_before_nok() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
this.initializeWithPrepareSupport();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", model);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 11);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
Assert.assertNull(this.languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_start_ok() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
this.initializeWithPrepareSupport();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", model);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 12);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
final Range range = this.languageServer.prepareRename(params).get().getLeft();
|
||||
this.assertEquals("MyType", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_in_ok() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
this.initializeWithPrepareSupport();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", model);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 14);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
final Range range = this.languageServer.prepareRename(params).get().getLeft();
|
||||
this.assertEquals("MyType", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_end_ok() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
this.initializeWithPrepareSupport();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", model);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 18);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
final Range range = this.languageServer.prepareRename(params).get().getLeft();
|
||||
this.assertEquals("MyType", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareRenameFqn_end_null() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo.bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type A {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("foo.bar.MyType bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("type MyType { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
this.initialize();
|
||||
final String uri = this.writeFile("my-type-valid.testlang", model);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
|
||||
Position _position = new Position(2, 18);
|
||||
final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
|
||||
Assert.assertNull(this.languageServer.prepareRename(params).get());
|
||||
}
|
||||
|
||||
private InitializeResult initializeWithPrepareSupport() {
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
|
||||
ClientCapabilities _clientCapabilities = new ClientCapabilities();
|
||||
final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it_1) -> {
|
||||
TextDocumentClientCapabilities _textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
final Procedure1<TextDocumentClientCapabilities> _function_2 = (TextDocumentClientCapabilities it_2) -> {
|
||||
RenameCapabilities _renameCapabilities = new RenameCapabilities();
|
||||
final Procedure1<RenameCapabilities> _function_3 = (RenameCapabilities it_3) -> {
|
||||
it_3.setPrepareSupport(Boolean.valueOf(true));
|
||||
};
|
||||
RenameCapabilities _doubleArrow = ObjectExtensions.<RenameCapabilities>operator_doubleArrow(_renameCapabilities, _function_3);
|
||||
it_2.setRename(_doubleArrow);
|
||||
};
|
||||
TextDocumentClientCapabilities _doubleArrow = ObjectExtensions.<TextDocumentClientCapabilities>operator_doubleArrow(_textDocumentClientCapabilities, _function_2);
|
||||
it_1.setTextDocument(_doubleArrow);
|
||||
};
|
||||
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
|
||||
it.setCapabilities(_doubleArrow);
|
||||
};
|
||||
return this.initialize(_function);
|
||||
}
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2019 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.server;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.PrepareRenameResult;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RenamePositionTest extends AbstractLanguageServerTest {
|
||||
public RenamePositionTest() {
|
||||
super("renametl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeginningOfFile() {
|
||||
Position _position = new Position(0, 0);
|
||||
this.renameAndFail("type Test", _position, "No element found at position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameNameAtEndOfFile() {
|
||||
final String model = "type Test";
|
||||
int _length = model.length();
|
||||
Position _position = new Position(0, _length);
|
||||
this.renameWithSuccess(model, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondBeginningOfFile() {
|
||||
Position _position = new Position((-1), 0);
|
||||
this.renameAndFail("type Test", _position, "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeyondLine() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Test");
|
||||
_builder.newLine();
|
||||
_builder.append("{}");
|
||||
_builder.newLine();
|
||||
Position _position = new Position(0, 11);
|
||||
this.renameAndFail(_builder.toString(), _position, "Invalid document position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeyondEndOfFile() {
|
||||
final String model = "type Test";
|
||||
int _length = model.length();
|
||||
int _plus = (_length + 1);
|
||||
Position _position = new Position(0, _plus);
|
||||
this.renameAndFail(model, _position, "Invalid document position");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAtBraceAfterIdentifier() {
|
||||
final String model = "type Test{}";
|
||||
int _indexOf = model.indexOf("{");
|
||||
Position _position = new Position(0, _indexOf);
|
||||
this.renameWithSuccess(model, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAtBrace() {
|
||||
final String model = "type Test{}";
|
||||
int _indexOf = model.indexOf("}");
|
||||
Position _position = new Position(0, _indexOf);
|
||||
this.renameAndFail(model, _position, "No element found at position");
|
||||
}
|
||||
|
||||
protected void renameAndFail(final String model, final Position position, final String messageFragment) {
|
||||
final String modelFile = this.writeFile("MyType.testlang", model);
|
||||
this.initialize();
|
||||
try {
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Either<Range, PrepareRenameResult> prepareRenameResult = this.languageServer.prepareRename(_prepareRenameParams).get();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("expected null result got ");
|
||||
_builder.append(prepareRenameResult);
|
||||
_builder.append(" instead");
|
||||
Assert.assertNull(_builder.toString(), prepareRenameResult);
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(modelFile);
|
||||
final RenameParams renameParams = new RenameParams(_textDocumentIdentifier, position, "Tescht");
|
||||
this.languageServer.rename(renameParams).get();
|
||||
Assert.fail("Rename should have failed");
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Exception) {
|
||||
final Exception exc = (Exception)_t;
|
||||
final Throwable rootCause = Throwables.getRootCause(exc);
|
||||
Assert.assertTrue((rootCause instanceof ResponseErrorException));
|
||||
final ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
|
||||
Assert.assertTrue(error.getData().toString().contains(messageFragment));
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void renameWithSuccess(final String model, final Position position) {
|
||||
try {
|
||||
final String modelFile = this.writeFile("MyType.testlang", model);
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
|
||||
ClientCapabilities _clientCapabilities = new ClientCapabilities();
|
||||
final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it_1) -> {
|
||||
TextDocumentClientCapabilities _textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
final Procedure1<TextDocumentClientCapabilities> _function_2 = (TextDocumentClientCapabilities it_2) -> {
|
||||
RenameCapabilities _renameCapabilities = new RenameCapabilities();
|
||||
final Procedure1<RenameCapabilities> _function_3 = (RenameCapabilities it_3) -> {
|
||||
it_3.setPrepareSupport(Boolean.valueOf(true));
|
||||
};
|
||||
RenameCapabilities _doubleArrow = ObjectExtensions.<RenameCapabilities>operator_doubleArrow(_renameCapabilities, _function_3);
|
||||
it_2.setRename(_doubleArrow);
|
||||
};
|
||||
TextDocumentClientCapabilities _doubleArrow = ObjectExtensions.<TextDocumentClientCapabilities>operator_doubleArrow(_textDocumentClientCapabilities, _function_2);
|
||||
it_1.setTextDocument(_doubleArrow);
|
||||
};
|
||||
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
|
||||
it.setCapabilities(_doubleArrow);
|
||||
};
|
||||
this.initialize(_function);
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
Assert.assertNotNull(range);
|
||||
this.assertEquals(new Document(Integer.valueOf(0), model).getSubstring(range), "Test");
|
||||
final RenameParams params = new RenameParams(identifier, position, "Tescht");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("changes :");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("MyType.testlang : Tescht [[0, 5] .. [0, 9]]");
|
||||
_builder.newLine();
|
||||
_builder.append("documentChanges : ");
|
||||
_builder.newLine();
|
||||
this.assertEquals(_builder.toString(), this.toExpectation(workspaceEdit));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +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.server;
|
||||
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RenameTest extends AbstractTestLangLanguageServerTest {
|
||||
private String firstFile;
|
||||
|
||||
private String secondFile;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Test {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("Test foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String first = _builder.toString();
|
||||
this.firstFile = this.writeFile("MyType1.testlang", first);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type Test2 {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Test foo");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String second = _builder_1.toString();
|
||||
this.secondFile = this.writeFile("MyType2.testlang", second);
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameBeforeDeclaration() throws Exception {
|
||||
Position _position = new Position(0, 5);
|
||||
this.doTest(this.firstFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnDeclaration() throws Exception {
|
||||
Position _position = new Position(0, 6);
|
||||
this.doTest(this.firstFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterDeclaration() throws Exception {
|
||||
Position _position = new Position(0, 8);
|
||||
this.doTest(this.firstFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnReference() throws Exception {
|
||||
Position _position = new Position(1, 5);
|
||||
this.doTest(this.firstFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterReference() throws Exception {
|
||||
Position _position = new Position(1, 8);
|
||||
this.doTest(this.firstFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameOnReferenceInOtherFile() throws Exception {
|
||||
Position _position = new Position(1, 5);
|
||||
this.doTest(this.secondFile, _position);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAfterReferenceInOtherFile() throws Exception {
|
||||
Position _position = new Position(1, 8);
|
||||
this.doTest(this.secondFile, _position);
|
||||
}
|
||||
|
||||
protected void doTest(final String fileName, final Position position) throws Exception {
|
||||
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileName);
|
||||
final RenameParams params = new RenameParams(_textDocumentIdentifier, position, "Tescht");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("changes :");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("MyType1.testlang : Tescht [[0, 5] .. [0, 9]]");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Tescht [[1, 4] .. [1, 8]]");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("MyType2.testlang : Tescht [[1, 4] .. [1, 8]]");
|
||||
_builder.newLine();
|
||||
_builder.append("documentChanges : ");
|
||||
_builder.newLine();
|
||||
this.assertEquals(_builder.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
}
|
|
@ -1,162 +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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RenameTest2 extends AbstractLanguageServerTest {
|
||||
public RenameTest2() {
|
||||
super("fileawaretestlanguage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameSelfRef() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("element Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("ref Foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.fileawaretestlanguage", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(2, 9);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "Bar");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.fileawaretestlanguage <1> : Bar [[2, 8] .. [2, 11]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Bar [[3, 5] .. [3, 8]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameContainer() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("package foo");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("element Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("element Bar {");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("ref foo.Foo.Bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("ref Foo.Bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("ref Bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.fileawaretestlanguage", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(2, 9);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "Baz");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.fileawaretestlanguage <1> : Baz [[2, 8] .. [2, 11]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Bar [[5, 5] .. [5, 16]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Bar [[6, 5] .. [6, 12]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InitializeResult initialize() {
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams params) -> {
|
||||
ClientCapabilities _clientCapabilities = new ClientCapabilities();
|
||||
final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it) -> {
|
||||
WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
|
||||
final Procedure1<WorkspaceClientCapabilities> _function_2 = (WorkspaceClientCapabilities it_1) -> {
|
||||
WorkspaceEditCapabilities _workspaceEditCapabilities = new WorkspaceEditCapabilities();
|
||||
final Procedure1<WorkspaceEditCapabilities> _function_3 = (WorkspaceEditCapabilities it_2) -> {
|
||||
it_2.setDocumentChanges(Boolean.valueOf(true));
|
||||
};
|
||||
WorkspaceEditCapabilities _doubleArrow = ObjectExtensions.<WorkspaceEditCapabilities>operator_doubleArrow(_workspaceEditCapabilities, _function_3);
|
||||
it_1.setWorkspaceEdit(_doubleArrow);
|
||||
};
|
||||
WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_2);
|
||||
it.setWorkspace(_doubleArrow);
|
||||
TextDocumentClientCapabilities _textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
final Procedure1<TextDocumentClientCapabilities> _function_3 = (TextDocumentClientCapabilities it_1) -> {
|
||||
RenameCapabilities _renameCapabilities = new RenameCapabilities();
|
||||
final Procedure1<RenameCapabilities> _function_4 = (RenameCapabilities it_2) -> {
|
||||
it_2.setPrepareSupport(Boolean.valueOf(true));
|
||||
};
|
||||
RenameCapabilities _doubleArrow_1 = ObjectExtensions.<RenameCapabilities>operator_doubleArrow(_renameCapabilities, _function_4);
|
||||
it_1.setRename(_doubleArrow_1);
|
||||
};
|
||||
TextDocumentClientCapabilities _doubleArrow_1 = ObjectExtensions.<TextDocumentClientCapabilities>operator_doubleArrow(_textDocumentClientCapabilities, _function_3);
|
||||
it.setTextDocument(_doubleArrow_1);
|
||||
};
|
||||
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
|
||||
params.setCapabilities(_doubleArrow);
|
||||
};
|
||||
return super.initialize(_function);
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 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.server;
|
||||
|
||||
import org.eclipse.lsp4j.ClientCapabilities;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
import org.eclipse.lsp4j.PrepareRenameParams;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.RenameCapabilities;
|
||||
import org.eclipse.lsp4j.RenameParams;
|
||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.eclipse.lsp4j.WorkspaceClientCapabilities;
|
||||
import org.eclipse.lsp4j.WorkspaceEdit;
|
||||
import org.eclipse.lsp4j.WorkspaceEditCapabilities;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.testing.AbstractLanguageServerTest;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RenameTest3 extends AbstractLanguageServerTest {
|
||||
public RenameTest3() {
|
||||
super("renametl");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAutoQuote() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.renametl", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(0, 6);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "type");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameQuoted() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type ^type {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.renametl", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(0, 6);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("^type", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "Foo");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameAutoQuoteRef() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar extends Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.renametl", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(3, 18);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "type");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("^type [[3, 17] .. [3, 20]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameQuotedRef() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type ^type {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar extends ^type {");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
final String model = _builder.toString();
|
||||
final String file = this.writeFile("foo/Foo.renametl", model);
|
||||
this.initialize();
|
||||
final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
|
||||
final Position position = new Position(3, 19);
|
||||
PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
|
||||
final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
|
||||
this.assertEquals("^type", new Document(Integer.valueOf(0), model).getSubstring(range));
|
||||
final RenameParams params = new RenameParams(identifier, position, "Foo");
|
||||
final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("changes :");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("documentChanges : ");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("Foo [[3, 17] .. [3, 22]]");
|
||||
_builder_1.newLine();
|
||||
this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InitializeResult initialize() {
|
||||
final Procedure1<InitializeParams> _function = (InitializeParams params) -> {
|
||||
ClientCapabilities _clientCapabilities = new ClientCapabilities();
|
||||
final Procedure1<ClientCapabilities> _function_1 = (ClientCapabilities it) -> {
|
||||
WorkspaceClientCapabilities _workspaceClientCapabilities = new WorkspaceClientCapabilities();
|
||||
final Procedure1<WorkspaceClientCapabilities> _function_2 = (WorkspaceClientCapabilities it_1) -> {
|
||||
WorkspaceEditCapabilities _workspaceEditCapabilities = new WorkspaceEditCapabilities();
|
||||
final Procedure1<WorkspaceEditCapabilities> _function_3 = (WorkspaceEditCapabilities it_2) -> {
|
||||
it_2.setDocumentChanges(Boolean.valueOf(true));
|
||||
};
|
||||
WorkspaceEditCapabilities _doubleArrow = ObjectExtensions.<WorkspaceEditCapabilities>operator_doubleArrow(_workspaceEditCapabilities, _function_3);
|
||||
it_1.setWorkspaceEdit(_doubleArrow);
|
||||
};
|
||||
WorkspaceClientCapabilities _doubleArrow = ObjectExtensions.<WorkspaceClientCapabilities>operator_doubleArrow(_workspaceClientCapabilities, _function_2);
|
||||
it.setWorkspace(_doubleArrow);
|
||||
TextDocumentClientCapabilities _textDocumentClientCapabilities = new TextDocumentClientCapabilities();
|
||||
final Procedure1<TextDocumentClientCapabilities> _function_3 = (TextDocumentClientCapabilities it_1) -> {
|
||||
RenameCapabilities _renameCapabilities = new RenameCapabilities();
|
||||
final Procedure1<RenameCapabilities> _function_4 = (RenameCapabilities it_2) -> {
|
||||
it_2.setPrepareSupport(Boolean.valueOf(true));
|
||||
};
|
||||
RenameCapabilities _doubleArrow_1 = ObjectExtensions.<RenameCapabilities>operator_doubleArrow(_renameCapabilities, _function_4);
|
||||
it_1.setRename(_doubleArrow_1);
|
||||
};
|
||||
TextDocumentClientCapabilities _doubleArrow_1 = ObjectExtensions.<TextDocumentClientCapabilities>operator_doubleArrow(_textDocumentClientCapabilities, _function_3);
|
||||
it.setTextDocument(_doubleArrow_1);
|
||||
};
|
||||
ClientCapabilities _doubleArrow = ObjectExtensions.<ClientCapabilities>operator_doubleArrow(_clientCapabilities, _function_1);
|
||||
params.setCapabilities(_doubleArrow);
|
||||
};
|
||||
return super.initialize(_function);
|
||||
}
|
||||
}
|
|
@ -1,307 +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.server;
|
||||
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.signatureHelp.SignatureHelpServiceImpl;
|
||||
import org.eclipse.xtext.testing.SignatureHelpConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Class for testing the the {@link SignatureHelpService signature help service} implementation.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
* @see SignatureHelpServiceImpl
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class SignatureHelpTest extends AbstractTestLangLanguageServerTest {
|
||||
private static final int LINE_NUMBER = 12;
|
||||
|
||||
@Test
|
||||
public void singleArgsExactMatchAfterTriggerChar() {
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type A { op foo(a: A) { } } type Main { op main() { foo() } }");
|
||||
it.setModel(_builder.toString());
|
||||
it.setLine(0);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("type A { op foo(a: A) { } } type Main { op main() { foo(");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("A.foo(a: A): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noArgsExactMatch() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo()");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("A.foo(): void | A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | <empty>");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstArgExactMatch() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secondArgExactMatch() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, 2");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void thirdArgExactMatch() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2, 3)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, 2, 3");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleArgWithLeadingWhitespace() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo( 1)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo( 1");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleArgWithTrailingWhitespace() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1 )");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1 ");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("A.foo(a: A): string | B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceBeforeFirstArg_ExpectFirstArg() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo( 1, 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo( 1");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceBeforeComma_ExpectFirstArg() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo( 1 , 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo( 1 ");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | a: A");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithLeadingWhitespaceAtComma_ExpectFirstArg() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo( 1 , 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo( 1 ,");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("B.foo(a: A, b: B): int | C.foo(a: A, b: B, c: C): void | b: B");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsAtComma() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2, 3)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, 2,");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsAtCommaIncomplete() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2,)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, 2,");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleArgsWithCommentAtCommaIncomplete() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, /*,*/ 2,)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, /*,*/ 2,");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("C.foo(a: A, b: B, c: C): void | c: C");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beforeOperationCall() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("<empty>");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterOperationCall() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo(1, 2)");
|
||||
final String testMe = _builder.toString();
|
||||
final Procedure1<SignatureHelpConfiguration> _function = (SignatureHelpConfiguration it) -> {
|
||||
it.setModel(this.getModel(testMe));
|
||||
it.setLine(SignatureHelpTest.LINE_NUMBER);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("foo(1, 2)");
|
||||
it.setColumn(_builder_1.length());
|
||||
it.setExpectedSignatureHelp("<empty>");
|
||||
};
|
||||
this.testSignatureHelp(_function);
|
||||
}
|
||||
|
||||
private String getModel(final CharSequence method) {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type A { ");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("op foo() { } ");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("op foo(a: A): string { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type B { ");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("op foo(a: A, b: B): int { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type C { ");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("op foo(a: A, b: B, c: C): void { }");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Test { ");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("op main() {");
|
||||
_builder.newLine();
|
||||
_builder.append(method);
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.append(" ");
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
return _builder.toString();
|
||||
}
|
||||
}
|
|
@ -1,153 +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.server;
|
||||
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest;
|
||||
import org.eclipse.xtext.testing.WorkspaceSymbolConfiguration;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class WorkspaceSymbolTest extends AbstractTestLangLanguageServerTest {
|
||||
@Test
|
||||
public void testSymbol_01() {
|
||||
final Procedure1<WorkspaceSymbolConfiguration> _function = (WorkspaceSymbolConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setQuery("F");
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("symbol \"Foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 5] .. [1, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar.int\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 1] .. [1, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Bar.foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[4, 5] .. [4, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedSymbols(_builder_1.toString());
|
||||
};
|
||||
this.testSymbol(_function);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSymbol_02() {
|
||||
final Procedure1<WorkspaceSymbolConfiguration> _function = (WorkspaceSymbolConfiguration it) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("type Foo {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("int bar");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
_builder.append("type Bar {");
|
||||
_builder.newLine();
|
||||
_builder.append("\t");
|
||||
_builder.append("Foo foo");
|
||||
_builder.newLine();
|
||||
_builder.append("}");
|
||||
_builder.newLine();
|
||||
it.setModel(_builder.toString());
|
||||
it.setQuery("oO");
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("symbol \"Foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[0, 5] .. [0, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 5] .. [1, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Foo.bar.int\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[1, 1] .. [1, 4]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("symbol \"Bar.foo\" {");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("kind: 7");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("\t");
|
||||
_builder_1.append("location: MyModel.testlang [[4, 5] .. [4, 8]]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
it.setExpectedSymbols(_builder_1.toString());
|
||||
};
|
||||
this.testSymbol(_function);
|
||||
}
|
||||
}
|
|
@ -1,328 +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.signatureHelp;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.lsp4j.ParameterInformation;
|
||||
import org.eclipse.lsp4j.SignatureHelp;
|
||||
import org.eclipse.lsp4j.SignatureHelpParams;
|
||||
import org.eclipse.lsp4j.SignatureInformation;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.ide.server.Document;
|
||||
import org.eclipse.xtext.ide.server.signatureHelp.ISignatureHelpService;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Operation;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.OperationCall;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Parameter;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.PrimitiveType;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TestLanguagePackage;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.Type;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeDeclaration;
|
||||
import org.eclipse.xtext.ide.tests.testlanguage.testLanguage.TypeReference;
|
||||
import org.eclipse.xtext.nodemodel.BidiIterable;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
|
||||
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.StringExtensions;
|
||||
|
||||
/**
|
||||
* Signature help service implementation for the test language.
|
||||
*
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class SignatureHelpServiceImpl implements ISignatureHelpService {
|
||||
private static final String OPENING_CHAR = "(";
|
||||
|
||||
private static final String CLOSING_CHAR = ")";
|
||||
|
||||
private static final String SEPARATOR_CHAR = ",";
|
||||
|
||||
/**
|
||||
* Shared comparator singleton to compare {@link SignatureInformation signature information} instances
|
||||
* based on the number of parameters first, then the parameter labels lexicographically.
|
||||
*/
|
||||
private static final Comparator<SignatureInformation> SIGNATURE_INFO_ORDERING = ((Comparator<SignatureInformation>) (SignatureInformation left, SignatureInformation right) -> {
|
||||
int _size = left.getParameters().size();
|
||||
int _size_1 = right.getParameters().size();
|
||||
int result = (_size - _size_1);
|
||||
if ((result == 0)) {
|
||||
int i = 0;
|
||||
int size = left.getParameters().size();
|
||||
boolean _while = (i < size);
|
||||
while (_while) {
|
||||
{
|
||||
result = left.getParameters().get(i).getLabel().getLeft().compareTo(right.getParameters().get(i).getLabel().getLeft());
|
||||
if ((result != 0)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
_while = (i < size);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
@Inject
|
||||
private EObjectAtOffsetHelper offsetHelper;
|
||||
|
||||
@Inject
|
||||
private IScopeProvider scopeProvider;
|
||||
|
||||
@Extension
|
||||
private TestLanguagePackage _testLanguagePackage = TestLanguagePackage.eINSTANCE;
|
||||
|
||||
@Override
|
||||
public SignatureHelp getSignatureHelp(final Document document, final XtextResource resource, final SignatureHelpParams params, final CancelIndicator cancelIndicator) {
|
||||
final int offset = document.getOffSet(params.getPosition());
|
||||
Preconditions.<XtextResource>checkNotNull(resource, "resource");
|
||||
Preconditions.checkArgument((offset >= 0), ("offset >= 0. Was: " + Integer.valueOf(offset)));
|
||||
final EObject object = this.offsetHelper.resolveContainedElementAt(resource, offset);
|
||||
if ((object instanceof OperationCall)) {
|
||||
final String operationName = this.getOperationName(((OperationCall)object));
|
||||
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(operationName);
|
||||
boolean _not = (!_isNullOrEmpty);
|
||||
if (_not) {
|
||||
return this.getSignatureHelp(((OperationCall)object), operationName, offset);
|
||||
}
|
||||
}
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
|
||||
private SignatureHelp getSignatureHelp(final OperationCall call, final String operationName, final int offset) {
|
||||
final List<Integer> separatorIndices = CollectionLiterals.<Integer>newArrayList();
|
||||
BidiIterable<INode> _children = NodeModelUtils.getNode(call).getChildren();
|
||||
for (final INode node : _children) {
|
||||
{
|
||||
final String text = node.getText();
|
||||
if ((Objects.equal(SignatureHelpServiceImpl.OPENING_CHAR, text) && (node.getOffset() >= offset))) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
} else {
|
||||
if ((Objects.equal(SignatureHelpServiceImpl.CLOSING_CHAR, text) && (node.getOffset() < offset))) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
} else {
|
||||
boolean _equals = Objects.equal(SignatureHelpServiceImpl.SEPARATOR_CHAR, text);
|
||||
if (_equals) {
|
||||
separatorIndices.add(Integer.valueOf(node.getOffset()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
final int paramCount = call.getParams().size();
|
||||
final int separatorCount = separatorIndices.size();
|
||||
if ((((separatorCount + 1) == paramCount) || (separatorCount == paramCount))) {
|
||||
final List<INode> paramNodes = NodeModelUtils.findNodesForFeature(call, this._testLanguagePackage.getOperation_Params());
|
||||
for (int i = 0; (i < separatorCount); i++) {
|
||||
{
|
||||
final INode paramNode = paramNodes.get(i);
|
||||
int _offset = paramNode.getOffset();
|
||||
int _length = paramNode.getLength();
|
||||
int _plus = (_offset + _length);
|
||||
Integer _get = separatorIndices.get(i);
|
||||
boolean _greaterThan = (_plus > (_get).intValue());
|
||||
if (_greaterThan) {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ISignatureHelpService.EMPTY;
|
||||
}
|
||||
int _xifexpression = (int) 0;
|
||||
if ((paramCount == 0)) {
|
||||
_xifexpression = 0;
|
||||
} else {
|
||||
int _xifexpression_1 = (int) 0;
|
||||
boolean _contains = separatorIndices.contains(Integer.valueOf(offset));
|
||||
if (_contains) {
|
||||
int _indexOf = separatorIndices.indexOf(Integer.valueOf(offset));
|
||||
_xifexpression_1 = (_indexOf + 2);
|
||||
} else {
|
||||
int _binarySearch = Arrays.binarySearch(((int[])Conversions.unwrapArray(separatorIndices, int.class)), offset);
|
||||
_xifexpression_1 = (-_binarySearch);
|
||||
}
|
||||
_xifexpression = _xifexpression_1;
|
||||
}
|
||||
final int currentParameter = _xifexpression;
|
||||
final Function1<Operation, Boolean> _function = (Operation it) -> {
|
||||
int _size = it.getParams().size();
|
||||
return Boolean.valueOf((currentParameter <= _size));
|
||||
};
|
||||
final Iterable<Operation> visibleOperations = IterableExtensions.<Operation>filter(this.getVisibleOperationsWithName(call, operationName), _function);
|
||||
int _xifexpression_2 = (int) 0;
|
||||
boolean _contains_1 = separatorIndices.contains(Integer.valueOf(offset));
|
||||
if (_contains_1) {
|
||||
_xifexpression_2 = 2;
|
||||
} else {
|
||||
_xifexpression_2 = 1;
|
||||
}
|
||||
final int paramOffset = _xifexpression_2;
|
||||
Integer _xifexpression_3 = null;
|
||||
if ((paramCount == 0)) {
|
||||
Integer _xblockexpression = null;
|
||||
{
|
||||
final Function1<Operation, Integer> _function_1 = (Operation it) -> {
|
||||
return Integer.valueOf(it.getParams().size());
|
||||
};
|
||||
final Iterable<Integer> paramSize = IterableExtensions.<Operation, Integer>map(visibleOperations, _function_1);
|
||||
Integer _xifexpression_4 = null;
|
||||
if (((!IterableExtensions.<Integer>exists(paramSize, ((Function1<Integer, Boolean>) (Integer it) -> {
|
||||
return Boolean.valueOf(((it).intValue() == 0));
|
||||
}))) && IterableExtensions.<Operation>exists(visibleOperations, ((Function1<Operation, Boolean>) (Operation it) -> {
|
||||
boolean _isEmpty = it.getParams().isEmpty();
|
||||
return Boolean.valueOf((!_isEmpty));
|
||||
})))) {
|
||||
_xifexpression_4 = Integer.valueOf(0);
|
||||
} else {
|
||||
_xifexpression_4 = null;
|
||||
}
|
||||
_xblockexpression = _xifexpression_4;
|
||||
}
|
||||
_xifexpression_3 = _xblockexpression;
|
||||
} else {
|
||||
_xifexpression_3 = Integer.valueOf((currentParameter - paramOffset));
|
||||
}
|
||||
final Integer activeParamIndex = _xifexpression_3;
|
||||
SignatureHelp _signatureHelp = new SignatureHelp();
|
||||
final Procedure1<SignatureHelp> _function_1 = (SignatureHelp it) -> {
|
||||
it.setActiveParameter(activeParamIndex);
|
||||
it.setActiveSignature(Integer.valueOf(0));
|
||||
final Function1<Operation, SignatureInformation> _function_2 = (Operation operation) -> {
|
||||
SignatureInformation _signatureInformation = new SignatureInformation();
|
||||
final Procedure1<SignatureInformation> _function_3 = (SignatureInformation it_1) -> {
|
||||
it_1.setLabel(this.getLabel(operation));
|
||||
final Function1<Parameter, ParameterInformation> _function_4 = (Parameter param) -> {
|
||||
ParameterInformation _parameterInformation = new ParameterInformation();
|
||||
final Procedure1<ParameterInformation> _function_5 = (ParameterInformation it_2) -> {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
String _name = param.getName();
|
||||
_builder.append(_name);
|
||||
_builder.append(": ");
|
||||
String _label = this.getLabel(param.getType());
|
||||
_builder.append(_label);
|
||||
it_2.setLabel(_builder.toString());
|
||||
};
|
||||
return ObjectExtensions.<ParameterInformation>operator_doubleArrow(_parameterInformation, _function_5);
|
||||
};
|
||||
it_1.setParameters(ListExtensions.<Parameter, ParameterInformation>map(operation.getParams(), _function_4));
|
||||
};
|
||||
return ObjectExtensions.<SignatureInformation>operator_doubleArrow(_signatureInformation, _function_3);
|
||||
};
|
||||
it.setSignatures(IterableExtensions.<SignatureInformation>sortWith(IterableExtensions.<SignatureInformation>toList(IterableExtensions.<Operation, SignatureInformation>map(visibleOperations, _function_2)), SignatureHelpServiceImpl.SIGNATURE_INFO_ORDERING));
|
||||
};
|
||||
return ObjectExtensions.<SignatureHelp>operator_doubleArrow(_signatureHelp, _function_1);
|
||||
}
|
||||
|
||||
private Iterable<Operation> getVisibleOperationsWithName(final EObject object, final String name) {
|
||||
final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
|
||||
EClass _eClass = it.getEClass();
|
||||
EClass _operation = this._testLanguagePackage.getOperation();
|
||||
return Boolean.valueOf(Objects.equal(_eClass, _operation));
|
||||
};
|
||||
final Function1<IEObjectDescription, Boolean> _function_1 = (IEObjectDescription it) -> {
|
||||
String _lastSegment = it.getQualifiedName().getLastSegment();
|
||||
return Boolean.valueOf(Objects.equal(_lastSegment, name));
|
||||
};
|
||||
final Function1<IEObjectDescription, EObject> _function_2 = (IEObjectDescription it) -> {
|
||||
return it.getEObjectOrProxy();
|
||||
};
|
||||
return Iterables.<Operation>filter(IterableExtensions.<IEObjectDescription, EObject>map(IterableExtensions.<IEObjectDescription>filter(IterableExtensions.<IEObjectDescription>filter(this.scopeProvider.getScope(object, this._testLanguagePackage.getOperationCall_Operation()).getAllElements(), _function), _function_1), _function_2), Operation.class);
|
||||
}
|
||||
|
||||
private String getOperationName(final OperationCall call) {
|
||||
INode _head = IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(call, this._testLanguagePackage.getOperationCall_Operation()));
|
||||
String _text = null;
|
||||
if (_head!=null) {
|
||||
_text=_head.getText();
|
||||
}
|
||||
return _text;
|
||||
}
|
||||
|
||||
private String _getLabel(final Operation it) {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
String _name = EcoreUtil2.<TypeDeclaration>getContainerOfType(it, TypeDeclaration.class).getName();
|
||||
_builder.append(_name);
|
||||
_builder.append(".");
|
||||
String _name_1 = it.getName();
|
||||
_builder.append(_name_1);
|
||||
_builder.append("(");
|
||||
{
|
||||
EList<Parameter> _params = it.getParams();
|
||||
boolean _hasElements = false;
|
||||
for(final Parameter p : _params) {
|
||||
if (!_hasElements) {
|
||||
_hasElements = true;
|
||||
} else {
|
||||
_builder.appendImmediate(", ", "");
|
||||
}
|
||||
String _name_2 = p.getName();
|
||||
_builder.append(_name_2);
|
||||
_builder.append(": ");
|
||||
String _label = this.getLabel(p.getType());
|
||||
_builder.append(_label);
|
||||
}
|
||||
}
|
||||
_builder.append("): ");
|
||||
{
|
||||
Type _returnType = it.getReturnType();
|
||||
boolean _tripleEquals = (_returnType == null);
|
||||
if (_tripleEquals) {
|
||||
_builder.append("void");
|
||||
} else {
|
||||
String _label_1 = this.getLabel(it.getReturnType());
|
||||
_builder.append(_label_1);
|
||||
}
|
||||
}
|
||||
return _builder.toString();
|
||||
}
|
||||
|
||||
private String _getLabel(final TypeReference it) {
|
||||
return it.getTypeRef().getName();
|
||||
}
|
||||
|
||||
private String _getLabel(final PrimitiveType it) {
|
||||
return it.getName();
|
||||
}
|
||||
|
||||
private String getLabel(final EObject it) {
|
||||
if (it instanceof Operation) {
|
||||
return _getLabel((Operation)it);
|
||||
} else if (it instanceof PrimitiveType) {
|
||||
return _getLabel((PrimitiveType)it);
|
||||
} else if (it instanceof TypeReference) {
|
||||
return _getLabel((TypeReference)it);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " +
|
||||
Arrays.<Object>asList(it).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 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.serializer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider;
|
||||
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(XtextInjectorProvider.class)
|
||||
public class GrammarConstraintProviderFeatureTest {
|
||||
@Inject
|
||||
private ValidationTestHelper validator;
|
||||
|
||||
@Inject
|
||||
private ParseHelper<Grammar> parser;
|
||||
|
||||
@Inject
|
||||
private IGrammarConstraintProvider constraintProvider;
|
||||
|
||||
@Test
|
||||
public void simple() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: val=ID; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val[1,1]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optional() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: {Rule} val=ID?; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val[0,1]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: val=ID+; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val[1,*]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionalMulti() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: {Rule} val=ID*; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val[0,*]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoToThree() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: val+=ID val+=ID val+=ID?; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val[2,3]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoDoubleLoop() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: {Rule} (val1+=ID val2+=ID)*; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val1[0,*]\n" +
|
||||
" val2[0,*]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroToThree() throws Exception {
|
||||
String actual = this.toFeatureInfo("Rule: (val1+=ID | val2+=ID | val3+=ID) (val1+=ID | val2+=ID) val1+=ID; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val1[1,3]\n" +
|
||||
" val2[0,2]\n" +
|
||||
" val3[0,1]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unordered() throws Exception {
|
||||
String actual = toFeatureInfo("Rule: val1+=ID & val2+=ID; \n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val1[0,*]\n" +
|
||||
" val2[0,*]\n}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complex1() throws Exception {
|
||||
String actual = toFeatureInfo(
|
||||
"Rule: 'a' val1+=ID 'b'\n" +
|
||||
" (\n" +
|
||||
" ('c' val2+=ID)?\n" +
|
||||
" & ('d' val3+=ID)?\n" +
|
||||
" & ('e' val4+=ID)?\n" +
|
||||
" )\n" +
|
||||
" ('f' val5+=ID*)?\n" +
|
||||
" ('g' val6+=ID*)?\n" +
|
||||
" 'h';\n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val1[1,1]\n" +
|
||||
" val2[0,*]\n" +
|
||||
" val3[0,*]\n" +
|
||||
" val4[0,*]\n" +
|
||||
" val5[0,*]\n" +
|
||||
" val6[0,*]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complex2() throws Exception {
|
||||
String actual = this
|
||||
.toFeatureInfo(
|
||||
"Rule: {Rule} (val1+=ID | 'a')\n" +
|
||||
" (val2+=ID & 'b')\n" +
|
||||
" ('c' | val1+=ID);\n");
|
||||
String expected =
|
||||
"Rule_Rule{\n" +
|
||||
" val1[0,2]\n" +
|
||||
" val2[0,*]\n" +
|
||||
"}\n";
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public void assertEquals(String expected, String actual) {
|
||||
if (expected != null) {
|
||||
expected = expected.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
if (actual != null) {
|
||||
actual = actual.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public String toFeatureInfo(CharSequence grammarString) throws Exception {
|
||||
Grammar grammar = parser.parse(
|
||||
"grammar org.eclipse.xtext.serializer.GrammarConstraintProviderFeatureTestLanguage with org.eclipse.xtext.common.Terminals\n" +
|
||||
"\n" +
|
||||
"generate GrammarConstraintProviderFeatureTest 'http://www.eclipse.org/2010/tmf/xtext/GrammarConstraintProviderFeatureTestLanguage'\n" +
|
||||
"\n" +
|
||||
grammarString);
|
||||
validator.assertNoErrors(grammar);
|
||||
List<IConstraint> constraints = Lists.transform(constraintProvider.getConstraints(grammar).values(),
|
||||
it -> it.getValue());
|
||||
return Joiner.on("\n").join(Lists.transform(constraints, (IConstraint c) -> {
|
||||
return c.getName() + "{\n "
|
||||
+ Joiner.on("\n ").join(Lists.transform(Arrays.asList(c.getFeatures()), f -> asString(f))) + "\n}";
|
||||
})) + "\n";
|
||||
}
|
||||
|
||||
public String asString(IGrammarConstraintProvider.IFeatureInfo it) {
|
||||
String upper = null;
|
||||
if (it.getUpperBound() == IGrammarConstraintProvider.MAX) {
|
||||
upper = "*";
|
||||
} else {
|
||||
upper = Integer.toString(it.getUpperBound());
|
||||
}
|
||||
return it.getFeature().getName() + "[" + it.getLowerBound() + "," + upper + "]";
|
||||
}
|
||||
}
|
|
@ -1,199 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2017 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.serializer
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider
|
||||
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IFeatureInfo
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.testing.util.ParseHelper
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.Test
|
||||
import org.junit.Assert
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(XtextInjectorProvider)
|
||||
class GrammarConstraintProviderFeatureTest {
|
||||
|
||||
@Inject ValidationTestHelper validator
|
||||
@Inject ParseHelper<Grammar> parser
|
||||
@Inject IGrammarConstraintProvider constraintProvider
|
||||
|
||||
@Test def void simple() {
|
||||
val actual = '''
|
||||
Rule: val=ID;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val[1,1]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void optional() {
|
||||
val actual = '''
|
||||
Rule: {Rule} val=ID?;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val[0,1]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void multi() {
|
||||
val actual = '''
|
||||
Rule: val=ID+;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val[1,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void optionalMulti() {
|
||||
val actual = '''
|
||||
Rule: {Rule} val=ID*;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val[0,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void twoToThree() {
|
||||
val actual = '''
|
||||
Rule: val+=ID val+=ID val+=ID?;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val[2,3]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void twoDoubleLoop() {
|
||||
val actual = '''
|
||||
Rule: {Rule} (val1+=ID val2+=ID)*;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val1[0,*]
|
||||
val2[0,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void zeroToThree() {
|
||||
val actual = '''
|
||||
Rule: (val1+=ID | val2+=ID | val3+=ID) (val1+=ID | val2+=ID) val1+=ID;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val1[1,3]
|
||||
val2[0,2]
|
||||
val3[0,1]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void unordered() {
|
||||
val actual = '''
|
||||
Rule: val1+=ID & val2+=ID;
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val1[0,*]
|
||||
val2[0,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void complex1() {
|
||||
val actual = '''
|
||||
Rule: 'a' val1+=ID 'b'
|
||||
(
|
||||
('c' val2+=ID)?
|
||||
& ('d' val3+=ID)?
|
||||
& ('e' val4+=ID)?
|
||||
)
|
||||
('f' val5+=ID*)?
|
||||
('g' val6+=ID*)?
|
||||
'h';
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val1[1,1]
|
||||
val2[0,*]
|
||||
val3[0,*]
|
||||
val4[0,*]
|
||||
val5[0,*]
|
||||
val6[0,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test def void complex2() {
|
||||
val actual = '''
|
||||
Rule: {Rule} (val1+=ID | 'a')
|
||||
(val2+=ID & 'b')
|
||||
('c' | val1+=ID);
|
||||
'''.toFeatureInfo
|
||||
val expected = '''
|
||||
Rule_Rule{
|
||||
val1[0,2]
|
||||
val2[0,*]
|
||||
}
|
||||
'''
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
def assertEquals(String expected, String actual)
|
||||
{
|
||||
val expectedM = expected?.replaceAll(System.lineSeparator, "\n");
|
||||
val actualM = actual?.replaceAll(System.lineSeparator, "\n");
|
||||
Assert.assertEquals(expectedM, actualM)
|
||||
}
|
||||
|
||||
def String toFeatureInfo(CharSequence grammarString) {
|
||||
val grammar = parser.parse('''
|
||||
grammar org.eclipse.xtext.serializer.GrammarConstraintProviderFeatureTestLanguage with org.eclipse.xtext.common.Terminals
|
||||
|
||||
generate GrammarConstraintProviderFeatureTest "http://www.eclipse.org/2010/tmf/xtext/GrammarConstraintProviderFeatureTestLanguage"
|
||||
|
||||
«grammarString»
|
||||
''')
|
||||
validator.assertNoErrors(grammar)
|
||||
val constraints = constraintProvider.getConstraints(grammar).values.map[value]
|
||||
return constraints.map[name + "{\n " + features.map[asString].join("\n ") + "\n}"].join("\n") + "\n"
|
||||
}
|
||||
|
||||
def String asString(IFeatureInfo it) {
|
||||
val upper = if(upperBound == IGrammarConstraintProvider.MAX) "*" else upperBound
|
||||
return feature.name + "[" + lowerBound + "," + upper + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 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.serializer;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.serializer.sequencertest.Model;
|
||||
import org.eclipse.xtext.serializer.sequencertest.MultiKeywordsOrID;
|
||||
import org.eclipse.xtext.serializer.tests.SequencerTestLanguageInjectorProvider;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(SequencerTestLanguageInjectorProvider.class)
|
||||
public class SerializerValidationDiagnosticsTest {
|
||||
@Inject
|
||||
private ParseHelper<Model> parseHelper;
|
||||
|
||||
@Inject
|
||||
private ISerializer serializer;
|
||||
|
||||
@Test
|
||||
public void testSingleValueMandatoryGenerated() throws Exception {
|
||||
Model model = parseHelper.parse("#1 foo bar");
|
||||
model.getX1().setVal1(null);
|
||||
assertSerializationError(model,
|
||||
"A value for feature \'val1\' is missing but required.\n" +
|
||||
"Semantic Object: Model.x1->SimpleGroup\n" +
|
||||
"URI: __synthetic0.sequencertestlanguage\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleValueMandatoryBacktracking() throws Exception {
|
||||
Model model = parseHelper.parse("#3 foo kw1 kw2 bar kw3");
|
||||
model.getX3().setVal1(null);
|
||||
assertSerializationError(model,
|
||||
"Could not serialize SimpleMultiplicities:\n" +
|
||||
"SimpleMultiplicities.val1 is required to have a value, but it does not.\n" +
|
||||
"Semantic Object: Model.x3->SimpleMultiplicities\n" +
|
||||
"URI: __synthetic0.sequencertestlanguage\n" +
|
||||
"Context: SimpleMultiplicities returns SimpleMultiplicities\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValueUpperBoundBacktracking() throws Exception {
|
||||
Model model = parseHelper.parse("#17 foo");
|
||||
MultiKeywordsOrID mt = ((MultiKeywordsOrID) model.getX11());
|
||||
mt.getVal().add("bar");
|
||||
assertSerializationError(model,
|
||||
"Could not serialize MultiKeywordsOrID:\n" +
|
||||
"MultiKeywordsOrID.val violates the upper bound: It holds 2 values, but only 1 are allowed.\n" +
|
||||
"Semantic Object: Model.x11->MultiKeywordsOrID\n" +
|
||||
"URI: __synthetic0.sequencertestlanguage\n" +
|
||||
"Context: MultiKeywordsOrID returns MultiKeywordsOrID\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValueLowerBoundBacktracking() throws Exception {
|
||||
Model model = parseHelper.parse("#17 foo");
|
||||
MultiKeywordsOrID mt = ((MultiKeywordsOrID) model.getX11());
|
||||
mt.getVal().clear();
|
||||
assertSerializationError(model,
|
||||
"Could not serialize MultiKeywordsOrID:\n" +
|
||||
"MultiKeywordsOrID.val violates the lower bound: It holds 0 values, but at least 1 are required.\n" +
|
||||
"Semantic Object: Model.x11->MultiKeywordsOrID\n" +
|
||||
"URI: __synthetic0.sequencertestlanguage\n" +
|
||||
"Context: MultiKeywordsOrID returns MultiKeywordsOrID\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBacktracking() throws Exception {
|
||||
Model model = parseHelper.parse("#8 foo bar");
|
||||
model.getX8().setVal3("baz");
|
||||
assertSerializationError(model,
|
||||
"Could not serialize AltList1 via backtracking.\n" +
|
||||
"Constraint: AltList1_AltList1 returns AltList1: ((val1=ID val2=ID) | (val1=ID val3=ID) | (val1=ID val4=ID?));\n" +
|
||||
"Values: val1(1), val2(1), val3(1)\n" +
|
||||
"Semantic Object: Model.x8->AltList1\n" +
|
||||
"URI: __synthetic0.sequencertestlanguage\n" +
|
||||
"Context: AltList1 returns AltList1\n");
|
||||
}
|
||||
|
||||
private void assertSerializationError(EObject obj, String expected) {
|
||||
try {
|
||||
serializer.serialize(obj);
|
||||
Assert.fail("Serialization should not succeed.");
|
||||
} catch (Throwable t) {
|
||||
String expectedM = expected.toString().trim().replaceAll(System.lineSeparator(), "\n");
|
||||
String messageM = t.getMessage().replaceAll(System.lineSeparator(), "\n");
|
||||
Assert.assertEquals(expectedM, messageM);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2017 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.serializer
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.xtext.serializer.sequencertest.Model
|
||||
import org.eclipse.xtext.serializer.sequencertest.MultiKeywordsOrID
|
||||
import org.eclipse.xtext.serializer.tests.SequencerTestLanguageInjectorProvider
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.testing.util.ParseHelper
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(SequencerTestLanguageInjectorProvider)
|
||||
class SerializerValidationDiagnosticsTest {
|
||||
|
||||
@Inject extension ParseHelper<Model>
|
||||
@Inject extension ISerializer
|
||||
|
||||
@Test def void testSingleValueMandatoryGenerated() {
|
||||
val model = '''
|
||||
#1 foo bar
|
||||
'''.parse
|
||||
model.x1.val1 = null
|
||||
model.assertSerializationError('''
|
||||
A value for feature 'val1' is missing but required.
|
||||
Semantic Object: Model.x1->SimpleGroup
|
||||
URI: __synthetic0.sequencertestlanguage
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def void testSingleValueMandatoryBacktracking() {
|
||||
val model = '''
|
||||
#3 foo kw1 kw2 bar kw3
|
||||
'''.parse
|
||||
model.x3.val1 = null
|
||||
model.assertSerializationError('''
|
||||
Could not serialize SimpleMultiplicities:
|
||||
SimpleMultiplicities.val1 is required to have a value, but it does not.
|
||||
Semantic Object: Model.x3->SimpleMultiplicities
|
||||
URI: __synthetic0.sequencertestlanguage
|
||||
Context: SimpleMultiplicities returns SimpleMultiplicities
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def void testMultiValueUpperBoundBacktracking() {
|
||||
val model = '''
|
||||
#17 foo
|
||||
'''.parse
|
||||
val mt = model.x11 as MultiKeywordsOrID
|
||||
mt.^val += "bar"
|
||||
model.assertSerializationError('''
|
||||
Could not serialize MultiKeywordsOrID:
|
||||
MultiKeywordsOrID.val violates the upper bound: It holds 2 values, but only 1 are allowed.
|
||||
Semantic Object: Model.x11->MultiKeywordsOrID
|
||||
URI: __synthetic0.sequencertestlanguage
|
||||
Context: MultiKeywordsOrID returns MultiKeywordsOrID
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def void testMultiValueLowerBoundBacktracking() {
|
||||
val model = '''
|
||||
#17 foo
|
||||
'''.parse
|
||||
val mt = model.x11 as MultiKeywordsOrID
|
||||
mt.^val.clear
|
||||
model.assertSerializationError('''
|
||||
Could not serialize MultiKeywordsOrID:
|
||||
MultiKeywordsOrID.val violates the lower bound: It holds 0 values, but at least 1 are required.
|
||||
Semantic Object: Model.x11->MultiKeywordsOrID
|
||||
URI: __synthetic0.sequencertestlanguage
|
||||
Context: MultiKeywordsOrID returns MultiKeywordsOrID
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def void testBacktracking() {
|
||||
val model = '''
|
||||
#8 foo bar
|
||||
'''.parse
|
||||
model.x8.val3 = "baz"
|
||||
model.assertSerializationError('''
|
||||
Could not serialize AltList1 via backtracking.
|
||||
Constraint: AltList1_AltList1 returns AltList1: ((val1=ID val2=ID) | (val1=ID val3=ID) | (val1=ID val4=ID?));
|
||||
Values: val1(1), val2(1), val3(1)
|
||||
Semantic Object: Model.x8->AltList1
|
||||
URI: __synthetic0.sequencertestlanguage
|
||||
Context: AltList1 returns AltList1
|
||||
''')
|
||||
}
|
||||
|
||||
def private assertSerializationError(EObject obj, String expected) {
|
||||
try {
|
||||
obj.serialize
|
||||
Assert.fail("Serialization should not succeed.")
|
||||
} catch (Throwable t) {
|
||||
val expectedM = expected.toString.trim.replaceAll(System.lineSeparator, "\n")
|
||||
val messageM = t.message.replaceAll(System.lineSeparator, "\n")
|
||||
|
||||
Assert.assertEquals(expectedM, messageM)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/**
|
||||
* Copyright (c) 2014, 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.tasks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
||||
import org.eclipse.xtext.documentation.impl.AbstractMultiLineCommentProvider;
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageRuntimeModule;
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
public class DefaultTaskFinderTest extends AbstractXtextTests {
|
||||
public static class NoJdtTestLanguageStandaloneSetupCustom extends NoJdtTestLanguageStandaloneSetup {
|
||||
@Override
|
||||
public Injector createInjector() {
|
||||
return Guice.createInjector(new NoJdtTestLanguageRuntimeModule() {
|
||||
@SuppressWarnings("unused")
|
||||
public void configureEndTag(Binder binder) {
|
||||
binder.bind(String.class).annotatedWith(Names.named(AbstractMultiLineCommentProvider.END_TAG))
|
||||
.toInstance("\\*\\*\\*/");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private ITaskFinder finder;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(NoJdtTestLanguageStandaloneSetup.class);
|
||||
finder = get(DefaultTaskFinder.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonXtextResource() {
|
||||
assertContainsTasks(new ResourceImpl(), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
Task task1 = new Task();
|
||||
task1.setTag(new TaskTag("TODO", Priority.NORMAL));
|
||||
task1.setDescription(" foo");
|
||||
task1.setOffset(2);
|
||||
task1.setLineNumber(1);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(new TaskTag("FIXME", Priority.HIGH));
|
||||
task2.setDescription(" bar");
|
||||
task2.setOffset(17);
|
||||
task2.setLineNumber(3);
|
||||
Task task3 = new Task();
|
||||
task3.setTag(new TaskTag("TODO", Priority.NORMAL));
|
||||
task3.setDescription(" Get rid of this ");
|
||||
task3.setOffset(73);
|
||||
task3.setLineNumber(7);
|
||||
assertContainsTasks(getResourceFromString(
|
||||
"//TODO foo\n" +
|
||||
"/*\n" +
|
||||
" * FIXME bar\n" +
|
||||
" * Fixme no match\n" +
|
||||
" * FOO also no match\n" +
|
||||
" */\n" +
|
||||
"/* TODO Get rid of this */\n" +
|
||||
"Hello notATODO!\n"),
|
||||
Lists.newArrayList(task1, task2, task3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialEndTag() throws Exception {
|
||||
with(NoJdtTestLanguageStandaloneSetupCustom.class);
|
||||
finder = get(DefaultTaskFinder.class);
|
||||
Task task = new Task();
|
||||
task.setTag(new TaskTag("TODO", Priority.NORMAL));
|
||||
task.setDescription(" Get rid of this ");
|
||||
task.setOffset(3);
|
||||
task.setLineNumber(1);
|
||||
assertContainsTasks(getResourceFromString(
|
||||
"/* TODO Get rid of this ***/\n" +
|
||||
"Hello notATODO!\n"),
|
||||
Lists.newArrayList(task));
|
||||
}
|
||||
|
||||
private void assertContainsTasks(Resource resource, List<Task> expectedTasks) {
|
||||
List<Task> actualTasks = finder.findTasks(resource);
|
||||
Assert.assertEquals(expectedTasks.size(), actualTasks.size());
|
||||
for (int i = 0; i < expectedTasks.size(); i++) {
|
||||
Assert.assertEquals(expectedTasks.get(i), actualTasks.get(i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 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.tasks
|
||||
|
||||
import com.google.inject.Binder
|
||||
import com.google.inject.Guice
|
||||
import java.util.List
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageRuntimeModule
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests
|
||||
import org.eclipse.xtext.tests.LineDelimiters
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import com.google.inject.name.Names
|
||||
import org.eclipse.xtext.documentation.impl.AbstractMultiLineCommentProvider
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
class DefaultTaskFinderTest extends AbstractXtextTests {
|
||||
|
||||
ITaskFinder finder
|
||||
|
||||
@Before
|
||||
override void setUp() {
|
||||
super.setUp();
|
||||
with(NoJdtTestLanguageStandaloneSetup)
|
||||
finder = get(DefaultTaskFinder)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testNonXtextResource() {
|
||||
new ResourceImpl().assertContainsTasks(#[])
|
||||
}
|
||||
|
||||
@Test
|
||||
def void test() {
|
||||
getResourceFromString(
|
||||
LineDelimiters.toUnix(
|
||||
'''
|
||||
//TODO foo
|
||||
/*
|
||||
* FIXME bar
|
||||
* Fixme no match
|
||||
* FOO also no match
|
||||
*/
|
||||
/* TODO Get rid of this */
|
||||
Hello notATODO!
|
||||
''')
|
||||
)
|
||||
.assertContainsTasks(#[
|
||||
new Task => [
|
||||
tag = new TaskTag => [
|
||||
name = "TODO"
|
||||
priority = Priority.NORMAL
|
||||
]
|
||||
description = " foo"
|
||||
offset = 2
|
||||
lineNumber = 1
|
||||
],
|
||||
new Task => [
|
||||
tag = new TaskTag => [
|
||||
name = "FIXME"
|
||||
priority = Priority.HIGH
|
||||
]
|
||||
description = " bar"
|
||||
offset = 17
|
||||
lineNumber = 3
|
||||
],
|
||||
new Task => [
|
||||
tag = new TaskTag => [
|
||||
name = "TODO"
|
||||
priority = Priority.NORMAL
|
||||
]
|
||||
description = " Get rid of this "
|
||||
offset = 73
|
||||
lineNumber = 7
|
||||
]
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testSpecialEndTag() {
|
||||
with(NoJdtTestLanguageStandaloneSetupCustom)
|
||||
finder = get(DefaultTaskFinder)
|
||||
getResourceFromString(
|
||||
LineDelimiters.toUnix(
|
||||
'''
|
||||
/* TODO Get rid of this ***/
|
||||
Hello notATODO!
|
||||
''')
|
||||
)
|
||||
.assertContainsTasks(#[
|
||||
new Task => [
|
||||
tag = new TaskTag => [
|
||||
name = "TODO"
|
||||
priority = Priority.NORMAL
|
||||
]
|
||||
description = " Get rid of this "
|
||||
offset = 3
|
||||
lineNumber = 1
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
static class NoJdtTestLanguageStandaloneSetupCustom extends NoJdtTestLanguageStandaloneSetup {
|
||||
|
||||
override createInjector() {
|
||||
return Guice.createInjector(new NoJdtTestLanguageRuntimeModule() {
|
||||
def configureEndTag(Binder binder) {
|
||||
binder.bind(String).annotatedWith(
|
||||
Names.named(AbstractMultiLineCommentProvider.END_TAG)
|
||||
).toInstance("\\*\\*\\*/")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private def assertContainsTasks(Resource resource, List<Task> expectedTasks) {
|
||||
val actualTasks = finder.findTasks(resource)
|
||||
assertEquals(expectedTasks.size, actualTasks.size)
|
||||
for (i : 0 ..< expectedTasks.size) {
|
||||
assertEquals(expectedTasks.get(i), actualTasks.get(i))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
/**
|
||||
* Copyright (c) 2014, 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.tasks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
public class DefaultTaskParserTest {
|
||||
private ITaskParser parser;
|
||||
|
||||
private TaskTags definitions;
|
||||
|
||||
private final TaskTag TODO = new TaskTag("TODO", Priority.NORMAL);
|
||||
|
||||
private final TaskTag todo = new TaskTag("todo", Priority.NORMAL);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new DefaultTaskTagProvider().getTaskTags(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCase() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new TaskTags();
|
||||
definitions.setCaseSensitive(true);
|
||||
definitions.getTaskTags().addAll(Lists.newArrayList(TODO, todo));
|
||||
Task task1 = new Task();
|
||||
task1.setTag(TODO);
|
||||
task1.setDescription(" uppercase match");
|
||||
task1.setLineNumber(2);
|
||||
task1.setOffset(6);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(todo);
|
||||
task2.setDescription(" lowercase match");
|
||||
task2.setLineNumber(3);
|
||||
task2.setOffset(30);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * TODO uppercase match\n" +
|
||||
" * todo lowercase match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCaseCaseInsensitive() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new TaskTags();
|
||||
definitions.setCaseSensitive(false);
|
||||
definitions.getTaskTags().addAll(Lists.newArrayList(TODO, todo));
|
||||
Task task1 = new Task();
|
||||
task1.setTag(TODO);
|
||||
task1.setDescription(" uppercase match");
|
||||
task1.setLineNumber(2);
|
||||
task1.setOffset(6);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(TODO);
|
||||
task2.setDescription(" lowercase match");
|
||||
task2.setLineNumber(3);
|
||||
task2.setOffset(30);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * TODO uppercase match\n" +
|
||||
" * todo lowercase match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityMergeIfHigher() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new TaskTags();
|
||||
definitions.setCaseSensitive(false);
|
||||
definitions.getTaskTags().addAll(Lists.newArrayList(TODO, new TaskTag("todo", Priority.HIGH)));
|
||||
Task task1 = new Task();
|
||||
task1.setTag(new TaskTag("todo", Priority.HIGH));
|
||||
task1.setDescription(" uppercase match");
|
||||
task1.setLineNumber(2);
|
||||
task1.setOffset(6);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(new TaskTag("todo", Priority.HIGH));
|
||||
task2.setDescription(" lowercase match");
|
||||
task2.setLineNumber(3);
|
||||
task2.setOffset(30);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * TODO uppercase match\n" +
|
||||
" * todo lowercase match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityNoMergeIfLower() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new TaskTags();
|
||||
definitions.setCaseSensitive(false);
|
||||
definitions.getTaskTags().addAll(Lists.newArrayList(TODO, new TaskTag("todo", Priority.LOW)));
|
||||
Task task1 = new Task();
|
||||
task1.setTag(TODO);
|
||||
task1.setDescription(" uppercase match");
|
||||
task1.setLineNumber(2);
|
||||
task1.setOffset(6);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(TODO);
|
||||
task2.setDescription(" lowercase match");
|
||||
task2.setLineNumber(3);
|
||||
task2.setOffset(30);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * TODO uppercase match\n" +
|
||||
" * todo lowercase match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityNoMergeIfSame() {
|
||||
parser = new DefaultTaskParser();
|
||||
definitions = new TaskTags();
|
||||
definitions.setCaseSensitive(false);
|
||||
definitions.getTaskTags().addAll(Lists.newArrayList(TODO, todo));
|
||||
Task task1 = new Task();
|
||||
task1.setTag(TODO);
|
||||
task1.setDescription(" uppercase match");
|
||||
task1.setLineNumber(2);
|
||||
task1.setOffset(6);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(TODO);
|
||||
task2.setDescription(" lowercase match");
|
||||
task2.setLineNumber(3);
|
||||
task2.setOffset(30);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * TODO uppercase match\n" +
|
||||
" * todo lowercase match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaseInSensitive() {
|
||||
definitions.setCaseSensitive(false);
|
||||
Task task = new Task();
|
||||
task.setTag(new TaskTag("FIXME", Priority.HIGH));
|
||||
task.setDescription(" case insensitive match");
|
||||
task.setLineNumber(2);
|
||||
task.setOffset(6);
|
||||
assertContainsTasks(
|
||||
"/*\n" +
|
||||
" * FixMe case insensitive match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaseSensitive() {
|
||||
Task task1 = new Task();
|
||||
task1.setTag(TODO);
|
||||
task1.setDescription(" this is a task");
|
||||
task1.setLineNumber(1);
|
||||
task1.setOffset(3);
|
||||
Task task2 = new Task();
|
||||
task2.setTag(new TaskTag("FIXME", Priority.HIGH));
|
||||
task2.setDescription(" this cannot work");
|
||||
task2.setLineNumber(2);
|
||||
task2.setOffset(26);
|
||||
Task task3 = new Task();
|
||||
task3.setTag(new TaskTag("XXX", Priority.NORMAL));
|
||||
task3.setDescription(": god, this is bad");
|
||||
task3.setLineNumber(3);
|
||||
task3.setOffset(52);
|
||||
Task task4 = new Task();
|
||||
task4.setTag(TODO);
|
||||
task4.setDescription("");
|
||||
task4.setLineNumber(4);
|
||||
task4.setOffset(77);
|
||||
assertContainsTasks(
|
||||
"/* TODO this is a task\n" +
|
||||
" * FIXME this cannot work\n" +
|
||||
" * XXX: god, this is bad\n" +
|
||||
" * TODO\n" +
|
||||
" * FixMe this should not match\n" +
|
||||
" */\n",
|
||||
Lists.newArrayList(task1, task2, task3, task4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongInputManyTasks() {
|
||||
int expectation = 100000;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("/*\n");
|
||||
for (int i = 1; i <= expectation; i++) {
|
||||
builder.append(" * FIXME this cannot work\n");
|
||||
}
|
||||
builder.append(" */\n");
|
||||
String source = builder.toString();
|
||||
List<Task> parsed = parser.parseTasks(source, definitions);
|
||||
Assert.assertEquals(expectation, parsed.size());
|
||||
for (int i = 0; i < expectation; i++) {
|
||||
Assert.assertEquals(i+ 2, parsed.get(i).getLineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertContainsTasks(String source, List<Task> expectedTasks) {
|
||||
List<Task> actualTasks = parser.parseTasks(source, definitions);
|
||||
Assert.assertEquals(expectedTasks.size(), actualTasks.size());
|
||||
for (int i = 0; i < expectedTasks.size(); i++) {
|
||||
Assert.assertEquals(expectedTasks.get(i), actualTasks.get(i));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,288 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 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.tasks
|
||||
|
||||
import java.util.List
|
||||
import org.eclipse.xtext.tests.LineDelimiters
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
import static org.eclipse.xtext.tasks.Priority.*
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
class DefaultTaskParserTest {
|
||||
ITaskParser parser
|
||||
TaskTags definitions
|
||||
|
||||
val TODO = createTaskTag("TODO", NORMAL)
|
||||
val todo = createTaskTag("todo", NORMAL)
|
||||
|
||||
@Pure
|
||||
private def static TaskTag createTaskTag(String tag, Priority priority) {
|
||||
new TaskTag => [
|
||||
it.name = tag
|
||||
it.priority = priority
|
||||
]
|
||||
}
|
||||
|
||||
@Before
|
||||
def void setup() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new DefaultTaskTagProvider().getTaskTags(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTasksWithDifferentCase() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new TaskTags => [
|
||||
caseSensitive = true
|
||||
taskTags += #[ TODO, todo ]
|
||||
]
|
||||
|
||||
'''
|
||||
/*
|
||||
* TODO uppercase match
|
||||
* todo lowercase match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " uppercase match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
],
|
||||
new Task() => [
|
||||
tag = todo
|
||||
description = " lowercase match"
|
||||
lineNumber = 3
|
||||
offset = 30
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTasksWithDifferentCaseCaseInsensitive() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new TaskTags => [
|
||||
caseSensitive = false
|
||||
taskTags += #[ TODO, todo ]
|
||||
]
|
||||
|
||||
'''
|
||||
/*
|
||||
* TODO uppercase match
|
||||
* todo lowercase match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " uppercase match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
],
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " lowercase match"
|
||||
lineNumber = 3
|
||||
offset = 30
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTasksWithDifferentCasePriorityMergeIfHigher() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new TaskTags => [
|
||||
caseSensitive = false
|
||||
taskTags += #[
|
||||
TODO,
|
||||
createTaskTag("todo", HIGH)
|
||||
]
|
||||
]
|
||||
|
||||
'''
|
||||
/*
|
||||
* TODO uppercase match
|
||||
* todo lowercase match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = createTaskTag("todo", HIGH)
|
||||
description = " uppercase match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
],
|
||||
new Task() => [
|
||||
tag = createTaskTag("todo", HIGH)
|
||||
description = " lowercase match"
|
||||
lineNumber = 3
|
||||
offset = 30
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTasksWithDifferentCasePriorityNoMergeIfLower() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new TaskTags => [
|
||||
caseSensitive = false
|
||||
taskTags += #[
|
||||
TODO,
|
||||
createTaskTag("todo", LOW)
|
||||
]
|
||||
]
|
||||
|
||||
'''
|
||||
/*
|
||||
* TODO uppercase match
|
||||
* todo lowercase match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " uppercase match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
],
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " lowercase match"
|
||||
lineNumber = 3
|
||||
offset = 30
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTasksWithDifferentCasePriorityNoMergeIfSame() {
|
||||
parser = new DefaultTaskParser
|
||||
definitions = new TaskTags => [
|
||||
caseSensitive = false
|
||||
taskTags += #[
|
||||
TODO,
|
||||
todo
|
||||
]
|
||||
]
|
||||
|
||||
'''
|
||||
/*
|
||||
* TODO uppercase match
|
||||
* todo lowercase match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " uppercase match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
],
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " lowercase match"
|
||||
lineNumber = 3
|
||||
offset = 30
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCaseInSensitive() {
|
||||
definitions.caseSensitive = false
|
||||
'''
|
||||
/*
|
||||
* FixMe case insensitive match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = createTaskTag("FIXME", HIGH)
|
||||
description = " case insensitive match"
|
||||
lineNumber = 2
|
||||
offset = 6
|
||||
]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testCaseSensitive() {
|
||||
'''
|
||||
/* TODO this is a task
|
||||
* FIXME this cannot work
|
||||
* XXX: god, this is bad
|
||||
* TODO
|
||||
* FixMe this should not match
|
||||
*/
|
||||
'''.assertContainsTasks(
|
||||
#[
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = " this is a task"
|
||||
lineNumber = 1
|
||||
offset = 3
|
||||
],
|
||||
new Task() => [
|
||||
tag = createTaskTag("FIXME", HIGH)
|
||||
description = " this cannot work"
|
||||
lineNumber = 2
|
||||
offset = 26
|
||||
],
|
||||
new Task() => [
|
||||
tag = createTaskTag("XXX", NORMAL)
|
||||
description = ": god, this is bad"
|
||||
lineNumber = 3
|
||||
offset = 52
|
||||
],
|
||||
new Task() => [
|
||||
tag = TODO
|
||||
description = ""
|
||||
lineNumber = 4
|
||||
offset = 77
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testLongInputManyTasks() {
|
||||
val expectation = 100000
|
||||
val String source = '''
|
||||
/*
|
||||
«FOR i: 1..expectation»
|
||||
* FIXME this cannot work
|
||||
«ENDFOR»
|
||||
*/
|
||||
'''
|
||||
val parsed = parser.parseTasks(LineDelimiters.toUnix(source), definitions)
|
||||
assertEquals(expectation, parsed.size)
|
||||
for(i: 0..<expectation) {
|
||||
assertEquals(i+2, parsed.get(i).lineNumber)
|
||||
}
|
||||
}
|
||||
|
||||
private def assertContainsTasks(CharSequence source, List<Task> expectedTasks) {
|
||||
val actualTasks = parser.parseTasks(LineDelimiters.toUnix(source.toString), definitions)
|
||||
assertEquals(expectedTasks.size, actualTasks.size)
|
||||
for (i : 0 ..< expectedTasks.size) {
|
||||
assertEquals(expectedTasks.get(i), actualTasks.get(i))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* Copyright (c) 2013, 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.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
public class StringsDiffTest {
|
||||
@Test
|
||||
public void testDiff_0() {
|
||||
assertDiff("foo", "foo", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_1() {
|
||||
assertDiff("foo", "bar",
|
||||
"[foo]\n" +
|
||||
"vs\n" +
|
||||
"[bar]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_2() {
|
||||
assertDiff("foo1", "foobar",
|
||||
"foo[1]\n" +
|
||||
"vs\n" +
|
||||
"foo[bar]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_3() {
|
||||
assertDiff("foo", "foofoo",
|
||||
"foo[]\n" +
|
||||
"vs\n" +
|
||||
"foo[foo]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_4() {
|
||||
assertDiff("foo", "barfoo",
|
||||
"[]foo\n" +
|
||||
"vs\n" +
|
||||
"[bar]foo\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_5() {
|
||||
assertDiff("2foo", "barfoo",
|
||||
"[2]foo\n" +
|
||||
"vs\n" +
|
||||
"[bar]foo\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_6() {
|
||||
assertDiff("0123456789foo1", "0123456789foobar",
|
||||
"...3456789foo[1]\n" +
|
||||
"vs\n" +
|
||||
"...3456789foo[bar]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_7() {
|
||||
assertDiff("0123456789foo", "0123456789foofoo",
|
||||
"...3456789foo[]\n" +
|
||||
"vs\n" +
|
||||
"...3456789foo[foo]\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_8() {
|
||||
assertDiff("foo0123456789", "barfoo0123456789",
|
||||
"[]foo0123456...\n" +
|
||||
"vs\n" +
|
||||
"[bar]foo0123456...\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_9() {
|
||||
assertDiff("2foo0123456789", "barfoo0123456789",
|
||||
"[2]foo0123456...\n" +
|
||||
"vs\n" +
|
||||
"[bar]foo0123456...\n");
|
||||
}
|
||||
|
||||
protected void assertDiff(String one, String two, CharSequence expected) {
|
||||
if (expected != null) {
|
||||
expected = expected.toString().trim();
|
||||
}
|
||||
String actual = DiffUtil.diff(one, two);
|
||||
if (actual != null) {
|
||||
actual = actual.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013, 2017 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.util
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
class StringsDiffTest {
|
||||
|
||||
@Test def testDiff_0() {
|
||||
assertDiff('foo', 'foo', null)
|
||||
}
|
||||
|
||||
@Test def testDiff_1() {
|
||||
assertDiff('foo', 'bar', '''
|
||||
[foo]
|
||||
vs
|
||||
[bar]
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_2() {
|
||||
assertDiff('foo1', 'foobar', '''
|
||||
foo[1]
|
||||
vs
|
||||
foo[bar]
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_3() {
|
||||
assertDiff('foo', 'foofoo', '''
|
||||
foo[]
|
||||
vs
|
||||
foo[foo]
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_4() {
|
||||
assertDiff('foo', 'barfoo', '''
|
||||
[]foo
|
||||
vs
|
||||
[bar]foo
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_5() {
|
||||
assertDiff('2foo', 'barfoo', '''
|
||||
[2]foo
|
||||
vs
|
||||
[bar]foo
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_6() {
|
||||
assertDiff('0123456789foo1', '0123456789foobar', '''
|
||||
...3456789foo[1]
|
||||
vs
|
||||
...3456789foo[bar]
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_7() {
|
||||
assertDiff('0123456789foo', '0123456789foofoo', '''
|
||||
...3456789foo[]
|
||||
vs
|
||||
...3456789foo[foo]
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_8() {
|
||||
assertDiff('foo0123456789', 'barfoo0123456789', '''
|
||||
[]foo0123456...
|
||||
vs
|
||||
[bar]foo0123456...
|
||||
''')
|
||||
}
|
||||
|
||||
@Test def testDiff_9() {
|
||||
assertDiff('2foo0123456789', 'barfoo0123456789', '''
|
||||
[2]foo0123456...
|
||||
vs
|
||||
[bar]foo0123456...
|
||||
''')
|
||||
}
|
||||
|
||||
|
||||
protected def assertDiff(String one, String two, CharSequence expected) {
|
||||
val expectedM = expected?.toString()?.trim?.replaceAll(System.lineSeparator, "\n")
|
||||
val actualM = DiffUtil.diff(one, two)?.replaceAll(System.lineSeparator, "\n")
|
||||
assertEquals(expectedM, actualM)
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,353 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2017 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.serializer;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider;
|
||||
import org.eclipse.xtext.serializer.analysis.SerializationContextMap;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(XtextInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class GrammarConstraintProviderFeatureTest {
|
||||
@Inject
|
||||
private ValidationTestHelper validator;
|
||||
|
||||
@Inject
|
||||
private ParseHelper<Grammar> parser;
|
||||
|
||||
@Inject
|
||||
private IGrammarConstraintProvider constraintProvider;
|
||||
|
||||
@Test
|
||||
public void simple() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: val=ID; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val[1,1]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optional() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: {Rule} val=ID?; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val[0,1]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: val=ID+; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val[1,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionalMulti() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: {Rule} val=ID*; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoToThree() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: val+=ID val+=ID val+=ID?; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val[2,3]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoDoubleLoop() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: {Rule} (val1+=ID val2+=ID)*; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val1[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val2[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroToThree() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: (val1+=ID | val2+=ID | val3+=ID) (val1+=ID | val2+=ID) val1+=ID; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val1[1,3]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val2[0,2]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val3[0,1]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unordered() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: val1+=ID & val2+=ID; ");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val1[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val2[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complex1() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: \'a\' val1+=ID \'b\'");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(\'c\' val2+=ID)?");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("& (\'d\' val3+=ID)?");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("& (\'e\' val4+=ID)?");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append(")");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(\'f\' val5+=ID*)?");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(\'g\' val6+=ID*)?");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("\'h\';");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val1[1,1]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val2[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val3[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val4[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val5[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val6[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void complex2() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Rule: {Rule} (val1+=ID | \'a\')");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(val2+=ID & \'b\')");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("(\'c\' | val1+=ID);");
|
||||
_builder.newLine();
|
||||
final String actual = this.toFeatureInfo(_builder);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Rule_Rule{");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val1[0,2]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append(" ");
|
||||
_builder_1.append("val2[0,*]");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("}");
|
||||
_builder_1.newLine();
|
||||
final String expected = _builder_1.toString();
|
||||
this.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public void assertEquals(final String expected, final String actual) {
|
||||
String _replaceAll = null;
|
||||
if (expected!=null) {
|
||||
_replaceAll=expected.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
final String expectedM = _replaceAll;
|
||||
String _replaceAll_1 = null;
|
||||
if (actual!=null) {
|
||||
_replaceAll_1=actual.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
final String actualM = _replaceAll_1;
|
||||
Assert.assertEquals(expectedM, actualM);
|
||||
}
|
||||
|
||||
public String toFeatureInfo(final CharSequence grammarString) {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("grammar org.eclipse.xtext.serializer.GrammarConstraintProviderFeatureTestLanguage with org.eclipse.xtext.common.Terminals");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append("generate GrammarConstraintProviderFeatureTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarConstraintProviderFeatureTestLanguage\"");
|
||||
_builder.newLine();
|
||||
_builder.newLine();
|
||||
_builder.append(grammarString);
|
||||
_builder.newLineIfNotEmpty();
|
||||
final Grammar grammar = this.parser.parse(_builder);
|
||||
this.validator.assertNoErrors(grammar);
|
||||
final Function1<SerializationContextMap.Entry<IGrammarConstraintProvider.IConstraint>, IGrammarConstraintProvider.IConstraint> _function = (SerializationContextMap.Entry<IGrammarConstraintProvider.IConstraint> it) -> {
|
||||
return it.getValue();
|
||||
};
|
||||
final List<IGrammarConstraintProvider.IConstraint> constraints = ListExtensions.<SerializationContextMap.Entry<IGrammarConstraintProvider.IConstraint>, IGrammarConstraintProvider.IConstraint>map(this.constraintProvider.getConstraints(grammar).values(), _function);
|
||||
final Function1<IGrammarConstraintProvider.IConstraint, String> _function_1 = (IGrammarConstraintProvider.IConstraint it) -> {
|
||||
String _name = it.getName();
|
||||
String _plus = (_name + "{\n ");
|
||||
final Function1<IGrammarConstraintProvider.IFeatureInfo, String> _function_2 = (IGrammarConstraintProvider.IFeatureInfo it_1) -> {
|
||||
return this.asString(it_1);
|
||||
};
|
||||
String _join = IterableExtensions.join(ListExtensions.<IGrammarConstraintProvider.IFeatureInfo, String>map(((List<IGrammarConstraintProvider.IFeatureInfo>)Conversions.doWrapArray(it.getFeatures())), _function_2), "\n ");
|
||||
String _plus_1 = (_plus + _join);
|
||||
return (_plus_1 + "\n}");
|
||||
};
|
||||
String _join = IterableExtensions.join(ListExtensions.<IGrammarConstraintProvider.IConstraint, String>map(constraints, _function_1), "\n");
|
||||
return (_join + "\n");
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
public String asString(final IGrammarConstraintProvider.IFeatureInfo it) {
|
||||
Object _xifexpression = null;
|
||||
int _upperBound = it.getUpperBound();
|
||||
boolean _equals = (_upperBound == IGrammarConstraintProvider.MAX);
|
||||
if (_equals) {
|
||||
_xifexpression = "*";
|
||||
} else {
|
||||
_xifexpression = Integer.valueOf(it.getUpperBound());
|
||||
}
|
||||
final Object upper = ((Object)_xifexpression);
|
||||
String _name = it.getFeature().getName();
|
||||
String _plus = (_name + "[");
|
||||
int _lowerBound = it.getLowerBound();
|
||||
String _plus_1 = (_plus + Integer.valueOf(_lowerBound));
|
||||
String _plus_2 = (_plus_1 + ",");
|
||||
String _plus_3 = (_plus_2 + upper);
|
||||
return (_plus_3 + "]");
|
||||
}
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2016, 2017 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.serializer;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.serializer.ISerializer;
|
||||
import org.eclipse.xtext.serializer.sequencertest.AltList1;
|
||||
import org.eclipse.xtext.serializer.sequencertest.Model;
|
||||
import org.eclipse.xtext.serializer.sequencertest.MultiKeywordsOrID;
|
||||
import org.eclipse.xtext.serializer.sequencertest.SimpleGroup;
|
||||
import org.eclipse.xtext.serializer.sequencertest.SimpleMultiplicities;
|
||||
import org.eclipse.xtext.serializer.tests.SequencerTestLanguageInjectorProvider;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(SequencerTestLanguageInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class SerializerValidationDiagnosticsTest {
|
||||
@Inject
|
||||
@Extension
|
||||
private ParseHelper<Model> _parseHelper;
|
||||
|
||||
@Inject
|
||||
@Extension
|
||||
private ISerializer _iSerializer;
|
||||
|
||||
@Test
|
||||
public void testSingleValueMandatoryGenerated() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#1 foo bar");
|
||||
_builder.newLine();
|
||||
final Model model = this._parseHelper.parse(_builder);
|
||||
SimpleGroup _x1 = model.getX1();
|
||||
_x1.setVal1(null);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("A value for feature \'val1\' is missing but required.");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Semantic Object: Model.x1->SimpleGroup");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("URI: __synthetic0.sequencertestlanguage");
|
||||
_builder_1.newLine();
|
||||
this.assertSerializationError(model, _builder_1.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleValueMandatoryBacktracking() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#3 foo kw1 kw2 bar kw3");
|
||||
_builder.newLine();
|
||||
final Model model = this._parseHelper.parse(_builder);
|
||||
SimpleMultiplicities _x3 = model.getX3();
|
||||
_x3.setVal1(null);
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Could not serialize SimpleMultiplicities:");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("SimpleMultiplicities.val1 is required to have a value, but it does not.");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Semantic Object: Model.x3->SimpleMultiplicities");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("URI: __synthetic0.sequencertestlanguage");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Context: SimpleMultiplicities returns SimpleMultiplicities");
|
||||
_builder_1.newLine();
|
||||
this.assertSerializationError(model, _builder_1.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValueUpperBoundBacktracking() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#17 foo");
|
||||
_builder.newLine();
|
||||
final Model model = this._parseHelper.parse(_builder);
|
||||
EObject _x11 = model.getX11();
|
||||
final MultiKeywordsOrID mt = ((MultiKeywordsOrID) _x11);
|
||||
EList<String> _val = mt.getVal();
|
||||
_val.add("bar");
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Could not serialize MultiKeywordsOrID:");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("MultiKeywordsOrID.val violates the upper bound: It holds 2 values, but only 1 are allowed.");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Semantic Object: Model.x11->MultiKeywordsOrID");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("URI: __synthetic0.sequencertestlanguage");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Context: MultiKeywordsOrID returns MultiKeywordsOrID");
|
||||
_builder_1.newLine();
|
||||
this.assertSerializationError(model, _builder_1.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiValueLowerBoundBacktracking() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#17 foo");
|
||||
_builder.newLine();
|
||||
final Model model = this._parseHelper.parse(_builder);
|
||||
EObject _x11 = model.getX11();
|
||||
final MultiKeywordsOrID mt = ((MultiKeywordsOrID) _x11);
|
||||
mt.getVal().clear();
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Could not serialize MultiKeywordsOrID:");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("MultiKeywordsOrID.val violates the lower bound: It holds 0 values, but at least 1 are required.");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Semantic Object: Model.x11->MultiKeywordsOrID");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("URI: __synthetic0.sequencertestlanguage");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Context: MultiKeywordsOrID returns MultiKeywordsOrID");
|
||||
_builder_1.newLine();
|
||||
this.assertSerializationError(model, _builder_1.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBacktracking() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("#8 foo bar");
|
||||
_builder.newLine();
|
||||
final Model model = this._parseHelper.parse(_builder);
|
||||
AltList1 _x8 = model.getX8();
|
||||
_x8.setVal3("baz");
|
||||
StringConcatenation _builder_1 = new StringConcatenation();
|
||||
_builder_1.append("Could not serialize AltList1 via backtracking.");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Constraint: AltList1_AltList1 returns AltList1: ((val1=ID val2=ID) | (val1=ID val3=ID) | (val1=ID val4=ID?));");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Values: val1(1), val2(1), val3(1)");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Semantic Object: Model.x8->AltList1");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("URI: __synthetic0.sequencertestlanguage");
|
||||
_builder_1.newLine();
|
||||
_builder_1.append("Context: AltList1 returns AltList1");
|
||||
_builder_1.newLine();
|
||||
this.assertSerializationError(model, _builder_1.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertSerializationError(final EObject obj, final String expected) {
|
||||
try {
|
||||
this._iSerializer.serialize(obj);
|
||||
Assert.fail("Serialization should not succeed.");
|
||||
} catch (final Throwable _t) {
|
||||
if (_t instanceof Throwable) {
|
||||
final Throwable t = (Throwable)_t;
|
||||
final String expectedM = expected.toString().trim().replaceAll(System.lineSeparator(), "\n");
|
||||
final String messageM = t.getMessage().replaceAll(System.lineSeparator(), "\n");
|
||||
Assert.assertEquals(expectedM, messageM);
|
||||
} else {
|
||||
throw Exceptions.sneakyThrow(_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2014, 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.tasks;
|
||||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.name.Names;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.documentation.impl.AbstractMultiLineCommentProvider;
|
||||
import org.eclipse.xtext.tasks.DefaultTaskFinder;
|
||||
import org.eclipse.xtext.tasks.ITaskFinder;
|
||||
import org.eclipse.xtext.tasks.Priority;
|
||||
import org.eclipse.xtext.tasks.Task;
|
||||
import org.eclipse.xtext.tasks.TaskTag;
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageRuntimeModule;
|
||||
import org.eclipse.xtext.testlanguages.noJdt.NoJdtTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.eclipse.xtext.tests.LineDelimiters;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class DefaultTaskFinderTest extends AbstractXtextTests {
|
||||
public static class NoJdtTestLanguageStandaloneSetupCustom extends NoJdtTestLanguageStandaloneSetup {
|
||||
@Override
|
||||
public Injector createInjector() {
|
||||
abstract class __NoJdtTestLanguageStandaloneSetupCustom_1 extends NoJdtTestLanguageRuntimeModule {
|
||||
public abstract void configureEndTag(final Binder binder);
|
||||
}
|
||||
|
||||
__NoJdtTestLanguageStandaloneSetupCustom_1 ___NoJdtTestLanguageStandaloneSetupCustom_1 = new __NoJdtTestLanguageStandaloneSetupCustom_1() {
|
||||
public void configureEndTag(final Binder binder) {
|
||||
binder.<String>bind(String.class).annotatedWith(
|
||||
Names.named(AbstractMultiLineCommentProvider.END_TAG)).toInstance("\\*\\*\\*/");
|
||||
}
|
||||
};
|
||||
return Guice.createInjector(___NoJdtTestLanguageStandaloneSetupCustom_1);
|
||||
}
|
||||
}
|
||||
|
||||
private ITaskFinder finder;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() {
|
||||
try {
|
||||
super.setUp();
|
||||
this.with(NoJdtTestLanguageStandaloneSetup.class);
|
||||
this.finder = this.<DefaultTaskFinder>get(DefaultTaskFinder.class);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonXtextResource() {
|
||||
this.assertContainsTasks(new ResourceImpl(), Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("//TODO foo");
|
||||
_builder.newLine();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* FIXME bar");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* Fixme no match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* FOO also no match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
_builder.append("/* TODO Get rid of this */");
|
||||
_builder.newLine();
|
||||
_builder.append("Hello notATODO!");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function = (Task it) -> {
|
||||
TaskTag _taskTag = new TaskTag();
|
||||
final Procedure1<TaskTag> _function_1 = (TaskTag it_1) -> {
|
||||
it_1.setName("TODO");
|
||||
it_1.setPriority(Priority.NORMAL);
|
||||
};
|
||||
TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_1);
|
||||
it.setTag(_doubleArrow);
|
||||
it.setDescription(" foo");
|
||||
it.setOffset(2);
|
||||
it.setLineNumber(1);
|
||||
};
|
||||
Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
TaskTag _taskTag = new TaskTag();
|
||||
final Procedure1<TaskTag> _function_2 = (TaskTag it_1) -> {
|
||||
it_1.setName("FIXME");
|
||||
it_1.setPriority(Priority.HIGH);
|
||||
};
|
||||
TaskTag _doubleArrow_1 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_2);
|
||||
it.setTag(_doubleArrow_1);
|
||||
it.setDescription(" bar");
|
||||
it.setOffset(17);
|
||||
it.setLineNumber(3);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_1);
|
||||
Task _task_2 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
TaskTag _taskTag = new TaskTag();
|
||||
final Procedure1<TaskTag> _function_3 = (TaskTag it_1) -> {
|
||||
it_1.setName("TODO");
|
||||
it_1.setPriority(Priority.NORMAL);
|
||||
};
|
||||
TaskTag _doubleArrow_2 = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_3);
|
||||
it.setTag(_doubleArrow_2);
|
||||
it.setDescription(" Get rid of this ");
|
||||
it.setOffset(73);
|
||||
it.setLineNumber(7);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_2, _function_2);
|
||||
this.assertContainsTasks(this.getResourceFromString(
|
||||
LineDelimiters.toUnix(_builder.toString())),
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1, _doubleArrow_2)));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialEndTag() {
|
||||
try {
|
||||
this.with(DefaultTaskFinderTest.NoJdtTestLanguageStandaloneSetupCustom.class);
|
||||
this.finder = this.<DefaultTaskFinder>get(DefaultTaskFinder.class);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/* TODO Get rid of this ***/");
|
||||
_builder.newLine();
|
||||
_builder.append("Hello notATODO!");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function = (Task it) -> {
|
||||
TaskTag _taskTag = new TaskTag();
|
||||
final Procedure1<TaskTag> _function_1 = (TaskTag it_1) -> {
|
||||
it_1.setName("TODO");
|
||||
it_1.setPriority(Priority.NORMAL);
|
||||
};
|
||||
TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function_1);
|
||||
it.setTag(_doubleArrow);
|
||||
it.setDescription(" Get rid of this ");
|
||||
it.setOffset(3);
|
||||
it.setLineNumber(1);
|
||||
};
|
||||
Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
|
||||
this.assertContainsTasks(this.getResourceFromString(
|
||||
LineDelimiters.toUnix(_builder.toString())),
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow)));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertContainsTasks(final Resource resource, final List<Task> expectedTasks) {
|
||||
final List<Task> actualTasks = this.finder.findTasks(resource);
|
||||
Assert.assertEquals(expectedTasks.size(), actualTasks.size());
|
||||
int _size = expectedTasks.size();
|
||||
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
|
||||
for (final Integer i : _doubleDotLessThan) {
|
||||
Assert.assertEquals(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,400 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2014 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.tasks;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.tasks.DefaultTaskParser;
|
||||
import org.eclipse.xtext.tasks.DefaultTaskTagProvider;
|
||||
import org.eclipse.xtext.tasks.ITaskParser;
|
||||
import org.eclipse.xtext.tasks.Priority;
|
||||
import org.eclipse.xtext.tasks.Task;
|
||||
import org.eclipse.xtext.tasks.TaskTag;
|
||||
import org.eclipse.xtext.tasks.TaskTags;
|
||||
import org.eclipse.xtext.tests.LineDelimiters;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
|
||||
import org.eclipse.xtext.xbase.lib.IntegerRange;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Stefan Oehme - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class DefaultTaskParserTest {
|
||||
private ITaskParser parser;
|
||||
|
||||
private TaskTags definitions;
|
||||
|
||||
private final TaskTag TODO = DefaultTaskParserTest.createTaskTag("TODO", Priority.NORMAL);
|
||||
|
||||
private final TaskTag todo = DefaultTaskParserTest.createTaskTag("todo", Priority.NORMAL);
|
||||
|
||||
@Pure
|
||||
private static TaskTag createTaskTag(final String tag, final Priority priority) {
|
||||
TaskTag _taskTag = new TaskTag();
|
||||
final Procedure1<TaskTag> _function = (TaskTag it) -> {
|
||||
it.setName(tag);
|
||||
it.setPriority(priority);
|
||||
};
|
||||
return ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
this.definitions = new DefaultTaskTagProvider().getTaskTags(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCase() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
TaskTags _taskTags = new TaskTags();
|
||||
final Procedure1<TaskTags> _function = (TaskTags it) -> {
|
||||
it.setCaseSensitive(true);
|
||||
List<TaskTag> _taskTags_1 = it.getTaskTags();
|
||||
Iterables.<TaskTag>addAll(_taskTags_1, Collections.<TaskTag>unmodifiableList(CollectionLiterals.<TaskTag>newArrayList(this.TODO, this.todo)));
|
||||
};
|
||||
TaskTags _doubleArrow = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
|
||||
this.definitions = _doubleArrow;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO uppercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* todo lowercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" uppercase match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task, _function_1);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(this.todo);
|
||||
it.setDescription(" lowercase match");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(30);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_2);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow_1, _doubleArrow_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCaseCaseInsensitive() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
TaskTags _taskTags = new TaskTags();
|
||||
final Procedure1<TaskTags> _function = (TaskTags it) -> {
|
||||
it.setCaseSensitive(false);
|
||||
List<TaskTag> _taskTags_1 = it.getTaskTags();
|
||||
Iterables.<TaskTag>addAll(_taskTags_1, Collections.<TaskTag>unmodifiableList(CollectionLiterals.<TaskTag>newArrayList(this.TODO, this.todo)));
|
||||
};
|
||||
TaskTags _doubleArrow = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
|
||||
this.definitions = _doubleArrow;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO uppercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* todo lowercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" uppercase match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task, _function_1);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" lowercase match");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(30);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_2);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow_1, _doubleArrow_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityMergeIfHigher() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
TaskTags _taskTags = new TaskTags();
|
||||
final Procedure1<TaskTags> _function = (TaskTags it) -> {
|
||||
it.setCaseSensitive(false);
|
||||
List<TaskTag> _taskTags_1 = it.getTaskTags();
|
||||
TaskTag _createTaskTag = DefaultTaskParserTest.createTaskTag("todo", Priority.HIGH);
|
||||
Iterables.<TaskTag>addAll(_taskTags_1, Collections.<TaskTag>unmodifiableList(CollectionLiterals.<TaskTag>newArrayList(this.TODO, _createTaskTag)));
|
||||
};
|
||||
TaskTags _doubleArrow = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
|
||||
this.definitions = _doubleArrow;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO uppercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* todo lowercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(DefaultTaskParserTest.createTaskTag("todo", Priority.HIGH));
|
||||
it.setDescription(" uppercase match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task, _function_1);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(DefaultTaskParserTest.createTaskTag("todo", Priority.HIGH));
|
||||
it.setDescription(" lowercase match");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(30);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_2);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow_1, _doubleArrow_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityNoMergeIfLower() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
TaskTags _taskTags = new TaskTags();
|
||||
final Procedure1<TaskTags> _function = (TaskTags it) -> {
|
||||
it.setCaseSensitive(false);
|
||||
List<TaskTag> _taskTags_1 = it.getTaskTags();
|
||||
TaskTag _createTaskTag = DefaultTaskParserTest.createTaskTag("todo", Priority.LOW);
|
||||
Iterables.<TaskTag>addAll(_taskTags_1, Collections.<TaskTag>unmodifiableList(CollectionLiterals.<TaskTag>newArrayList(this.TODO, _createTaskTag)));
|
||||
};
|
||||
TaskTags _doubleArrow = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
|
||||
this.definitions = _doubleArrow;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO uppercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* todo lowercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" uppercase match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task, _function_1);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" lowercase match");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(30);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_2);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow_1, _doubleArrow_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTasksWithDifferentCasePriorityNoMergeIfSame() {
|
||||
DefaultTaskParser _defaultTaskParser = new DefaultTaskParser();
|
||||
this.parser = _defaultTaskParser;
|
||||
TaskTags _taskTags = new TaskTags();
|
||||
final Procedure1<TaskTags> _function = (TaskTags it) -> {
|
||||
it.setCaseSensitive(false);
|
||||
List<TaskTag> _taskTags_1 = it.getTaskTags();
|
||||
Iterables.<TaskTag>addAll(_taskTags_1, Collections.<TaskTag>unmodifiableList(CollectionLiterals.<TaskTag>newArrayList(this.TODO, this.todo)));
|
||||
};
|
||||
TaskTags _doubleArrow = ObjectExtensions.<TaskTags>operator_doubleArrow(_taskTags, _function);
|
||||
this.definitions = _doubleArrow;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO uppercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* todo lowercase match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" uppercase match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task, _function_1);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" lowercase match");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(30);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_2);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow_1, _doubleArrow_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaseInSensitive() {
|
||||
this.definitions.setCaseSensitive(false);
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* FixMe case insensitive match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function = (Task it) -> {
|
||||
it.setTag(DefaultTaskParserTest.createTaskTag("FIXME", Priority.HIGH));
|
||||
it.setDescription(" case insensitive match");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(6);
|
||||
};
|
||||
Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaseSensitive() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/* TODO this is a task");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* FIXME this cannot work");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* XXX: god, this is bad");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* TODO");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("* FixMe this should not match");
|
||||
_builder.newLine();
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
Task _task = new Task();
|
||||
final Procedure1<Task> _function = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription(" this is a task");
|
||||
it.setLineNumber(1);
|
||||
it.setOffset(3);
|
||||
};
|
||||
Task _doubleArrow = ObjectExtensions.<Task>operator_doubleArrow(_task, _function);
|
||||
Task _task_1 = new Task();
|
||||
final Procedure1<Task> _function_1 = (Task it) -> {
|
||||
it.setTag(DefaultTaskParserTest.createTaskTag("FIXME", Priority.HIGH));
|
||||
it.setDescription(" this cannot work");
|
||||
it.setLineNumber(2);
|
||||
it.setOffset(26);
|
||||
};
|
||||
Task _doubleArrow_1 = ObjectExtensions.<Task>operator_doubleArrow(_task_1, _function_1);
|
||||
Task _task_2 = new Task();
|
||||
final Procedure1<Task> _function_2 = (Task it) -> {
|
||||
it.setTag(DefaultTaskParserTest.createTaskTag("XXX", Priority.NORMAL));
|
||||
it.setDescription(": god, this is bad");
|
||||
it.setLineNumber(3);
|
||||
it.setOffset(52);
|
||||
};
|
||||
Task _doubleArrow_2 = ObjectExtensions.<Task>operator_doubleArrow(_task_2, _function_2);
|
||||
Task _task_3 = new Task();
|
||||
final Procedure1<Task> _function_3 = (Task it) -> {
|
||||
it.setTag(this.TODO);
|
||||
it.setDescription("");
|
||||
it.setLineNumber(4);
|
||||
it.setOffset(77);
|
||||
};
|
||||
Task _doubleArrow_3 = ObjectExtensions.<Task>operator_doubleArrow(_task_3, _function_3);
|
||||
this.assertContainsTasks(_builder,
|
||||
Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList(_doubleArrow, _doubleArrow_1, _doubleArrow_2, _doubleArrow_3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongInputManyTasks() {
|
||||
final int expectation = 100000;
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*");
|
||||
_builder.newLine();
|
||||
{
|
||||
IntegerRange _upTo = new IntegerRange(1, expectation);
|
||||
for(final Integer i : _upTo) {
|
||||
_builder.append(" ");
|
||||
_builder.append("* FIXME this cannot work");
|
||||
_builder.newLine();
|
||||
}
|
||||
}
|
||||
_builder.append(" ");
|
||||
_builder.append("*/");
|
||||
_builder.newLine();
|
||||
final String source = _builder.toString();
|
||||
final List<Task> parsed = this.parser.parseTasks(LineDelimiters.toUnix(source), this.definitions);
|
||||
Assert.assertEquals(expectation, parsed.size());
|
||||
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, expectation, true);
|
||||
for (final Integer i_1 : _doubleDotLessThan) {
|
||||
Assert.assertEquals(((i_1).intValue() + 2), parsed.get((i_1).intValue()).getLineNumber());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertContainsTasks(final CharSequence source, final List<Task> expectedTasks) {
|
||||
final List<Task> actualTasks = this.parser.parseTasks(LineDelimiters.toUnix(source.toString()), this.definitions);
|
||||
Assert.assertEquals(expectedTasks.size(), actualTasks.size());
|
||||
int _size = expectedTasks.size();
|
||||
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
|
||||
for (final Integer i : _doubleDotLessThan) {
|
||||
Assert.assertEquals(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2013, 2017 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.util;
|
||||
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.util.DiffUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class StringsDiffTest {
|
||||
@Test
|
||||
public void testDiff_0() {
|
||||
this.assertDiff("foo", "foo", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_1() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("[foo]");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("[bar]");
|
||||
_builder.newLine();
|
||||
this.assertDiff("foo", "bar", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_2() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo[1]");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("foo[bar]");
|
||||
_builder.newLine();
|
||||
this.assertDiff("foo1", "foobar", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_3() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("foo[]");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("foo[foo]");
|
||||
_builder.newLine();
|
||||
this.assertDiff("foo", "foofoo", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_4() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("[]foo");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("[bar]foo");
|
||||
_builder.newLine();
|
||||
this.assertDiff("foo", "barfoo", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_5() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("[2]foo");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("[bar]foo");
|
||||
_builder.newLine();
|
||||
this.assertDiff("2foo", "barfoo", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_6() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("...3456789foo[1]");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("...3456789foo[bar]");
|
||||
_builder.newLine();
|
||||
this.assertDiff("0123456789foo1", "0123456789foobar", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_7() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("...3456789foo[]");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("...3456789foo[foo]");
|
||||
_builder.newLine();
|
||||
this.assertDiff("0123456789foo", "0123456789foofoo", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_8() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("[]foo0123456...");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("[bar]foo0123456...");
|
||||
_builder.newLine();
|
||||
this.assertDiff("foo0123456789", "barfoo0123456789", _builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiff_9() {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("[2]foo0123456...");
|
||||
_builder.newLine();
|
||||
_builder.append("vs");
|
||||
_builder.newLine();
|
||||
_builder.append("[bar]foo0123456...");
|
||||
_builder.newLine();
|
||||
this.assertDiff("2foo0123456789", "barfoo0123456789", _builder);
|
||||
}
|
||||
|
||||
protected void assertDiff(final String one, final String two, final CharSequence expected) {
|
||||
String _string = null;
|
||||
if (expected!=null) {
|
||||
_string=expected.toString();
|
||||
}
|
||||
String _trim = null;
|
||||
if (_string!=null) {
|
||||
_trim=_string.trim();
|
||||
}
|
||||
String _replaceAll = null;
|
||||
if (_trim!=null) {
|
||||
_replaceAll=_trim.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
final String expectedM = _replaceAll;
|
||||
String _diff = DiffUtil.diff(one, two);
|
||||
String _replaceAll_1 = null;
|
||||
if (_diff!=null) {
|
||||
_replaceAll_1=_diff.replaceAll(System.lineSeparator(), "\n");
|
||||
}
|
||||
final String actualM = _replaceAll_1;
|
||||
Assert.assertEquals(expectedM, actualM);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others.
|
||||
* Copyright (c) 2014, 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.
|
||||
|
@ -17,6 +17,21 @@ public class TaskTag {
|
|||
|
||||
private Priority priority;
|
||||
|
||||
/**
|
||||
* @since 2.6
|
||||
*/
|
||||
public TaskTag() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.24
|
||||
*/
|
||||
public TaskTag(String name, Priority priority) {
|
||||
this.name = name;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return name.length();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue