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

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2020-04-06 11:47:25 +02:00
parent 72b943a021
commit dcd234c02a
13 changed files with 143 additions and 361 deletions

View file

@ -1,31 +1,31 @@
/*******************************************************************************
* Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others.
* 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.enumrules
package org.eclipse.xtext.enumrules;
import org.eclipse.xtext.enumrules.multiRuleenums.MyEnum
import org.junit.Test
import org.eclipse.xtext.enumrules.multiRuleenums.MyEnum;
import org.junit.Test;
import static org.junit.Assert.*
import static org.junit.Assert.*;
/**
* @author Sven Efftinge - Initial contribution and API
*/
class MultiRuleEnumTest {
public class MultiRuleEnumTest {
/**
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=413395
*/
@Test def void testEnumOrder() {
assertEquals(0, MyEnum.A_VALUE)
assertEquals(1, MyEnum.B_VALUE)
assertEquals(2, MyEnum.C_VALUE)
assertEquals(3, MyEnum.D_VALUE)
assertEquals(4, MyEnum.E_VALUE)
@Test public void testEnumOrder() {
assertEquals(0, MyEnum.A_VALUE);
assertEquals(1, MyEnum.B_VALUE);
assertEquals(2, MyEnum.C_VALUE);
assertEquals(3, MyEnum.D_VALUE);
assertEquals(4, MyEnum.E_VALUE);
}
}
}

View file

@ -1,50 +1,50 @@
/*******************************************************************************
* Copyright (c) 2017 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2017, 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.formatting2.debug
package org.eclipse.xtext.formatting2.debug;
import org.junit.Before
import org.junit.Test
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Florian Stolte - Initial contribution and API
*/
class TextRegionsToStringTest {
public class TextRegionsToStringTest {
TextRegionsToString textRegionsToString;
@Before
def void init() {
textRegionsToString = new TextRegionsToString
textRegionsToString.ignoreCarriageReturnInQuotes = true
public void init() {
textRegionsToString = new TextRegionsToString();
textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
}
@Test
def testQuote() {
public void testQuote() {
// insert quotes
assertEquals("\"import some.thing\"", textRegionsToString.quote("import some.thing", 30))
assertEquals("\"import some.thing\"", textRegionsToString.quote("import some.thing", 17))
assertEquals("\"import some.thing\"", textRegionsToString.quote("import some.thing", 30));
assertEquals("\"import some.thing\"", textRegionsToString.quote("import some.thing", 17));
// shorten result
assertEquals("\"import ...\"", textRegionsToString.quote("import some.thing", 10))
assertEquals("\"import some.t...\"", textRegionsToString.quote("import some.thing", 16))
assertEquals("\"import ...\"", textRegionsToString.quote("import some.thing", 10));
assertEquals("\"import some.t...\"", textRegionsToString.quote("import some.thing", 16));
// remove windows line endings
assertEquals("\"\\nimport some.thing\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 30))
assertEquals("\"\\nimport some.thing\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 19))
assertEquals("\"\\nimport some.thing\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 30));
assertEquals("\"\\nimport some.thing\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 19));
// remove windows line endings and shorten
assertEquals("\"\\nimport...\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 10))
assertEquals("\"\\nimport some.th...\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 18))
assertEquals("\"\\nimport...\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 10));
assertEquals("\"\\nimport some.th...\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 18));
// keep windows line endings
textRegionsToString.ignoreCarriageReturnInQuotes = false
assertEquals("\"\\r\\nimport some.thing\\r\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 30))
textRegionsToString.setIgnoreCarriageReturnInQuotes(false);
assertEquals("\"\\r\\nimport some.thing\\r\\n\"", textRegionsToString.quote("\r\nimport some.thing\r\n", 30));
}
}
}

View file

@ -0,0 +1,55 @@
/**
* 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.index;
import org.eclipse.xtext.testing.GlobalRegistries;
import org.eclipse.xtext.testing.IInjectorProvider;
import org.eclipse.xtext.testing.IRegistryConfigurator;
import com.google.inject.Injector;
/**
* @author Sven Efftinge - Initial contribution and API
*/
public class IndexTestLanguageInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
protected GlobalRegistries.GlobalStateMemento stateBeforeInjectorCreation;
protected GlobalRegistries.GlobalStateMemento stateAfterInjectorCreation;
protected Injector injector;
public IndexTestLanguageInjectorProvider() {
GlobalRegistries.initializeDefaults();
}
@Override
public Injector getInjector() {
if (injector == null) {
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
injector = internalCreateInjector();
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
}
return this.injector;
}
protected Injector internalCreateInjector() {
return new IndexTestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
}
@Override
public void restoreRegistry() {
stateBeforeInjectorCreation.restoreGlobalState();
}
@Override
public void setupRegistry() {
getInjector();
stateAfterInjectorCreation.restoreGlobalState();
}
}

View file

@ -1,52 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 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.index
import com.google.inject.Injector
import org.eclipse.xtext.testing.GlobalRegistries
import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento
import org.eclipse.xtext.testing.IInjectorProvider
import org.eclipse.xtext.testing.IRegistryConfigurator
/**
* @author Sven Efftinge - Initial contribution and API
*/
class IndexTestLanguageInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
protected GlobalStateMemento stateBeforeInjectorCreation
protected GlobalStateMemento stateAfterInjectorCreation
protected Injector injector
new() {
GlobalRegistries.initializeDefaults()
}
override Injector getInjector() {
if (injector === null) {
stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState()
this.injector = internalCreateInjector()
stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState()
}
return injector
}
def protected Injector internalCreateInjector() {
new IndexTestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration()
}
override void restoreRegistry() {
stateBeforeInjectorCreation.restoreGlobalState()
}
override void setupRegistry() {
getInjector()
stateAfterInjectorCreation.restoreGlobalState()
}
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
* 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.
@ -8,13 +8,10 @@
*/
package org.eclipse.xtext.parser.indentation;
import org.eclipse.xtext.parser.indentation.IndentationAwareLanguageTest;
import org.eclipse.xtext.parser.indentation.NodeModelTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ IndentationAwareLanguageTest.class, NodeModelTest.class })
@SuppressWarnings("all")
public class IndentationAwareLanguageSuite {
}

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
* 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.
@ -19,6 +19,5 @@ import org.junit.runner.RunWith;
*/
@RunWith(XtextSmokeTestRunner.class)
@ProcessedBy(value = PartialParsingProcessor.class, processInParallel = true)
@SuppressWarnings("all")
public class IndentationAwarePartialParsingTests extends IndentationAwareLanguageSuite {
}

View file

@ -1,29 +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.parser.indentation
import org.eclipse.xtext.testing.smoketest.ProcessedBy
import org.eclipse.xtext.testing.smoketest.XtextSmokeTestRunner
import org.eclipse.xtext.testing.smoketest.processors.PartialParsingProcessor
import org.junit.runner.RunWith
import org.junit.runners.Suite.SuiteClasses
import org.junit.runners.Suite
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
@RunWith(XtextSmokeTestRunner)
@ProcessedBy(value = PartialParsingProcessor, processInParallel = true)
class IndentationAwarePartialParsingTests extends IndentationAwareLanguageSuite {
}
@RunWith(Suite)
@SuiteClasses(IndentationAwareLanguageTest, NodeModelTest)
class IndentationAwareLanguageSuite {
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* 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.util;
import java.io.File;
import org.eclipse.emf.common.util.URI;
import org.junit.Test;
import static org.junit.Assert.*;
public class UriUtilTest {
@Test
public void testPrefix() {
URI prefix = URI.createURI("file:/foo/");
URI uri = URI.createURI("file:/foo/bar");
assertTrue(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresSameScheme() {
URI prefix = URI.createURI("platform:/foo/");
URI uri = URI.createURI("file:/foo/bar");
assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresTrailingSeparator() {
URI prefix = URI.createURI("file:/foo");
URI uri = URI.createURI("file:/foo/bar");
assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresSegmentsToMatch() {
URI prefix = URI.createURI("file:/foo");
URI uri = URI.createURI("file:/buzz/bar");
assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testFolderUriHasTrailingSeparator() {
File folder = new File(".");
URI uri = UriUtil.createFolderURI(folder);
assertTrue(uri.hasTrailingPathSeparator());
assertEquals(".", uri.segment(uri.segmentCount() - 2));
}
}

View file

@ -1,55 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 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 java.io.File
import org.eclipse.emf.common.util.URI
import org.junit.Test
import static org.junit.Assert.*
import static extension org.eclipse.xtext.util.UriUtil.*
class UriUtilTest {
@Test
def void testPrefix() {
val prefix = URI.createURI("file:/foo/")
val uri = URI.createURI("file:/foo/bar")
assertTrue(prefix.isPrefixOf(uri))
}
@Test
def void testPrefixRequiresSameScheme() {
val prefix = URI.createURI("platform:/foo/")
val uri = URI.createURI("file:/foo/bar")
assertFalse(prefix.isPrefixOf(uri))
}
@Test
def void testPrefixRequiresTrailingSeparator() {
val prefix = URI.createURI("file:/foo")
val uri = URI.createURI("file:/foo/bar")
assertFalse(prefix.isPrefixOf(uri))
}
@Test
def void testPrefixRequiresSegmentsToMatch() {
val prefix = URI.createURI("file:/foo")
val uri = URI.createURI("file:/buzz/bar")
assertFalse(prefix.isPrefixOf(uri))
}
@Test
def void testFolderUriHasTrailingSeparator() {
val folder = new File(".")
val uri = folder.createFolderURI
assertTrue(uri.hasTrailingPathSeparator)
assertEquals(".", uri.segment(uri.segmentCount - 2))
}
}

View file

@ -1,31 +0,0 @@
/**
* Copyright (c) 2013 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.enumrules;
import org.eclipse.xtext.enumrules.multiRuleenums.MyEnum;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Sven Efftinge - Initial contribution and API
*/
@SuppressWarnings("all")
public class MultiRuleEnumTest {
/**
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=413395
*/
@Test
public void testEnumOrder() {
Assert.assertEquals(0, MyEnum.A_VALUE);
Assert.assertEquals(1, MyEnum.B_VALUE);
Assert.assertEquals(2, MyEnum.C_VALUE);
Assert.assertEquals(3, MyEnum.D_VALUE);
Assert.assertEquals(4, MyEnum.E_VALUE);
}
}

View file

@ -1,43 +0,0 @@
/**
* Copyright (c) 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.formatting2.debug;
import org.eclipse.xtext.formatting2.debug.TextRegionsToString;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* @author Florian Stolte - Initial contribution and API
*/
@SuppressWarnings("all")
public class TextRegionsToStringTest {
private TextRegionsToString textRegionsToString;
@Before
public void init() {
TextRegionsToString _textRegionsToString = new TextRegionsToString();
this.textRegionsToString = _textRegionsToString;
this.textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
}
@Test
public void testQuote() {
Assert.assertEquals("\"import some.thing\"", this.textRegionsToString.quote("import some.thing", 30));
Assert.assertEquals("\"import some.thing\"", this.textRegionsToString.quote("import some.thing", 17));
Assert.assertEquals("\"import ...\"", this.textRegionsToString.quote("import some.thing", 10));
Assert.assertEquals("\"import some.t...\"", this.textRegionsToString.quote("import some.thing", 16));
Assert.assertEquals("\"\\nimport some.thing\\n\"", this.textRegionsToString.quote("\r\nimport some.thing\r\n", 30));
Assert.assertEquals("\"\\nimport some.thing\\n\"", this.textRegionsToString.quote("\r\nimport some.thing\r\n", 19));
Assert.assertEquals("\"\\nimport...\"", this.textRegionsToString.quote("\r\nimport some.thing\r\n", 10));
Assert.assertEquals("\"\\nimport some.th...\"", this.textRegionsToString.quote("\r\nimport some.thing\r\n", 18));
this.textRegionsToString.setIgnoreCarriageReturnInQuotes(false);
Assert.assertEquals("\"\\r\\nimport some.thing\\r\\n\"", this.textRegionsToString.quote("\r\nimport some.thing\r\n", 30));
}
}

View file

@ -1,56 +0,0 @@
/**
* Copyright (c) 2015 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.index;
import com.google.inject.Injector;
import org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup;
import org.eclipse.xtext.testing.GlobalRegistries;
import org.eclipse.xtext.testing.IInjectorProvider;
import org.eclipse.xtext.testing.IRegistryConfigurator;
/**
* @author Sven Efftinge - Initial contribution and API
*/
@SuppressWarnings("all")
public class IndexTestLanguageInjectorProvider implements IInjectorProvider, IRegistryConfigurator {
protected GlobalRegistries.GlobalStateMemento stateBeforeInjectorCreation;
protected GlobalRegistries.GlobalStateMemento stateAfterInjectorCreation;
protected Injector injector;
public IndexTestLanguageInjectorProvider() {
GlobalRegistries.initializeDefaults();
}
@Override
public Injector getInjector() {
if ((this.injector == null)) {
this.stateBeforeInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
this.injector = this.internalCreateInjector();
this.stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
}
return this.injector;
}
protected Injector internalCreateInjector() {
return new IndexTestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
}
@Override
public void restoreRegistry() {
this.stateBeforeInjectorCreation.restoreGlobalState();
}
@Override
public void setupRegistry() {
this.getInjector();
this.stateAfterInjectorCreation.restoreGlobalState();
}
}

View file

@ -1,56 +0,0 @@
/**
* Copyright (c) 2015 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 java.io.File;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.util.UriUtil;
import org.junit.Assert;
import org.junit.Test;
@SuppressWarnings("all")
public class UriUtilTest {
@Test
public void testPrefix() {
final URI prefix = URI.createURI("file:/foo/");
final URI uri = URI.createURI("file:/foo/bar");
Assert.assertTrue(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresSameScheme() {
final URI prefix = URI.createURI("platform:/foo/");
final URI uri = URI.createURI("file:/foo/bar");
Assert.assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresTrailingSeparator() {
final URI prefix = URI.createURI("file:/foo");
final URI uri = URI.createURI("file:/foo/bar");
Assert.assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testPrefixRequiresSegmentsToMatch() {
final URI prefix = URI.createURI("file:/foo");
final URI uri = URI.createURI("file:/buzz/bar");
Assert.assertFalse(UriUtil.isPrefixOf(prefix, uri));
}
@Test
public void testFolderUriHasTrailingSeparator() {
final File folder = new File(".");
final URI uri = UriUtil.createFolderURI(folder);
Assert.assertTrue(uri.hasTrailingPathSeparator());
int _segmentCount = uri.segmentCount();
int _minus = (_segmentCount - 2);
Assert.assertEquals(".", uri.segment(_minus));
}
}