mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
[eclipse/xtext#1679] converted Xtend code to Java
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
f909546248
commit
4a29a0bf5d
61 changed files with 1193 additions and 2308 deletions
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 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.filesystem;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess;
|
||||
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
|
||||
import org.eclipse.xtext.generator.OutputConfiguration;
|
||||
import org.eclipse.xtext.generator.URIBasedFileSystemAccess;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.common.base.StandardSystemProperty;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*
|
||||
* @see https://github.com/eclipse/xtext-core/issues/180
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(XtextInjectorProvider.class)
|
||||
public class URIBasedFileSystemAccessTest {
|
||||
private static final String MISSING_RESOURCE_NAME = "someMissingResource";
|
||||
|
||||
private static final String EXISTING_RESOURCE_NAME = "someExistingResource";
|
||||
|
||||
@Inject
|
||||
private URIBasedFileSystemAccess fsa;
|
||||
|
||||
@Inject
|
||||
private IOutputConfigurationProvider configProvider;
|
||||
|
||||
private final ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl();
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
Path tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value());
|
||||
Path output = Files.createTempDirectory(tmpPath, "tempFolder_" + UUID.randomUUID());
|
||||
Path resource = Files.createFile(output.resolve(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME));
|
||||
resource.toFile().deleteOnExit();
|
||||
output.toFile().deleteOnExit();
|
||||
OutputConfiguration config = configProvider.getOutputConfigurations().iterator().next();
|
||||
config.setOutputDirectory(output.toString());
|
||||
Map<String, OutputConfiguration> cfgMap = new HashMap<>();
|
||||
cfgMap.put(IFileSystemAccess.DEFAULT_OUTPUT, config);
|
||||
fsa.setOutputConfigurations(cfgMap);
|
||||
fsa.setConverter(uriConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalseOnAbsent() {
|
||||
Assert.assertFalse(fsa.isFile(URIBasedFileSystemAccessTest.MISSING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueOnPresent() {
|
||||
Assert.assertTrue(fsa.isFile(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME));
|
||||
}
|
||||
}
|
|
@ -1,74 +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.filesystem
|
||||
|
||||
import com.google.common.base.StandardSystemProperty
|
||||
import com.google.inject.Inject
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.UUID
|
||||
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess
|
||||
import org.eclipse.xtext.generator.IOutputConfigurationProvider
|
||||
import org.eclipse.xtext.generator.URIBasedFileSystemAccess
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*
|
||||
* @see https://github.com/eclipse/xtext-core/issues/180
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(XtextInjectorProvider)
|
||||
class URIBasedFileSystemAccessTest {
|
||||
|
||||
static val MISSING_RESOURCE_NAME = 'someMissingResource';
|
||||
static val EXISTING_RESOURCE_NAME = 'someExistingResource';
|
||||
|
||||
@Inject
|
||||
URIBasedFileSystemAccess fsa;
|
||||
|
||||
@Inject
|
||||
IOutputConfigurationProvider configProvider;
|
||||
|
||||
ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl();
|
||||
|
||||
@Before
|
||||
def void before() {
|
||||
val tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value);
|
||||
val output = Files.createTempDirectory(tmpPath, '''tempFolder_«UUID.randomUUID»''');
|
||||
val resource = Files.createFile(output.resolve(EXISTING_RESOURCE_NAME));
|
||||
|
||||
resource.toFile.deleteOnExit;
|
||||
output.toFile.deleteOnExit;
|
||||
|
||||
val config = configProvider.outputConfigurations.head;
|
||||
config.outputDirectory = output.toString;
|
||||
fsa.outputConfigurations = #{IFileSystemAccess.DEFAULT_OUTPUT -> config};
|
||||
fsa.converter = uriConverter;
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testFalseOnAbsent() {
|
||||
assertFalse(fsa.isFile(MISSING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testTrueOnPresent() {
|
||||
assertTrue(fsa.isFile(EXISTING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
|
@ -16,10 +16,9 @@ import org.eclipse.xtext.testing.formatter.FormatterTestRequest;
|
|||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FormatterTesterWithImpl extends FormatterTestHelper {
|
||||
@Override
|
||||
protected IFormatter2 createFormatter(final FormatterTestRequest req) {
|
||||
return ((GenericFormatterTestRequest) req).getFormatter();
|
||||
}
|
||||
@Override
|
||||
protected IFormatter2 createFormatter(FormatterTestRequest req) {
|
||||
return ((GenericFormatterTestRequest) req).getFormatter();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* 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.formatting2.internal;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
public abstract class GenericFormatter<T extends EObject> extends AbstractFormatter2 {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void _format(EObject obj, IFormattableDocument document) {
|
||||
format((T) obj, getRequest().getTextRegionAccess().getExtensions(), document);
|
||||
}
|
||||
|
||||
protected abstract void format(T model, ITextRegionExtensions regionAccess, IFormattableDocument document);
|
||||
|
||||
@Override
|
||||
public void format(Object obj, IFormattableDocument document) {
|
||||
if (obj instanceof XtextResource) {
|
||||
_format((XtextResource) obj, document);
|
||||
return;
|
||||
} else if (obj instanceof EObject) {
|
||||
_format((EObject) obj, document);
|
||||
return;
|
||||
} else if (obj == null) {
|
||||
_format((Void) null, document);
|
||||
return;
|
||||
} else if (obj != null) {
|
||||
_format(obj, document);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
@ -10,24 +10,20 @@ package org.eclipse.xtext.formatting2.internal;
|
|||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.formatting2.internal.GenericFormatter;
|
||||
import org.eclipse.xtext.testing.formatter.FormatterTestRequest;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class GenericFormatterTestRequest extends FormatterTestRequest {
|
||||
@Accessors
|
||||
private GenericFormatter<? extends EObject> formatter;
|
||||
|
||||
@Pure
|
||||
public GenericFormatter<? extends EObject> getFormatter() {
|
||||
return this.formatter;
|
||||
}
|
||||
|
||||
public void setFormatter(final GenericFormatter<? extends EObject> formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
@Accessors
|
||||
private GenericFormatter<? extends EObject> formatter;
|
||||
|
||||
public GenericFormatter<? extends EObject> getFormatter() {
|
||||
return formatter;
|
||||
}
|
||||
|
||||
public void setFormatter(GenericFormatter<? extends EObject> formatter) {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
}
|
|
@ -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,17 +17,16 @@ import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
|||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class GenericFormatterTester {
|
||||
@Inject
|
||||
private FormatterTesterWithImpl tester;
|
||||
|
||||
@Inject
|
||||
private Provider<GenericFormatterTestRequest> requestProvider;
|
||||
|
||||
public void assertFormatted(final Procedure1<? super GenericFormatterTestRequest> test) {
|
||||
final GenericFormatterTestRequest request = this.requestProvider.get();
|
||||
test.apply(request);
|
||||
this.tester.assertFormatted(request);
|
||||
}
|
||||
@Inject
|
||||
private FormatterTesterWithImpl tester;
|
||||
|
||||
@Inject
|
||||
private Provider<GenericFormatterTestRequest> requestProvider;
|
||||
|
||||
public void assertFormatted(Procedure1<? super GenericFormatterTestRequest> test) {
|
||||
GenericFormatterTestRequest request = requestProvider.get();
|
||||
test.apply(request);
|
||||
tester.assertFormatted(request);
|
||||
}
|
||||
}
|
|
@ -1,61 +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.formatting2.internal
|
||||
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Provider
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions
|
||||
import org.eclipse.xtext.testing.formatter.FormatterTestRequest
|
||||
import org.eclipse.xtext.testing.formatter.FormatterTestHelper
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
class GenericFormatterTester {
|
||||
@Inject FormatterTesterWithImpl tester
|
||||
@Inject Provider<GenericFormatterTestRequest> requestProvider
|
||||
|
||||
def void assertFormatted((GenericFormatterTestRequest)=>void test) {
|
||||
val request = requestProvider.get()
|
||||
test.apply(request)
|
||||
tester.assertFormatted(request)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
class FormatterTesterWithImpl extends FormatterTestHelper {
|
||||
override protected createFormatter(FormatterTestRequest req) {
|
||||
(req as GenericFormatterTestRequest).formatter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
class GenericFormatterTestRequest extends FormatterTestRequest {
|
||||
@Accessors GenericFormatter<? extends EObject> formatter
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@Accessors
|
||||
abstract class GenericFormatter<T extends EObject> extends AbstractFormatter2 {
|
||||
override dispatch format(EObject obj, IFormattableDocument document) {
|
||||
format(obj as T, request.textRegionAccess.extensions, document)
|
||||
}
|
||||
|
||||
def protected abstract void format(T model, ITextRegionExtensions regionAccess, IFormattableDocument document)
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
|
@ -24,7 +24,7 @@ import org.junit.runner.RunWith
|
|||
class RegionAccessCommentsTest {
|
||||
@Inject extension RegionAccessTestHelper
|
||||
|
||||
@Test def void testDeleteFirstRegion1() {
|
||||
@Test def void testDeleteFirstRegion1() throws Exception {
|
||||
val access = '''
|
||||
/*h*/
|
||||
|
||||
|
@ -58,7 +58,7 @@ class RegionAccessCommentsTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteFirstRegion2() {
|
||||
@Test def void testDeleteFirstRegion2() throws Exception {
|
||||
val access = '''
|
||||
/*h*/
|
||||
|
||||
|
@ -95,7 +95,7 @@ class RegionAccessCommentsTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteFirstRegion3() {
|
||||
@Test def void testDeleteFirstRegion3() throws Exception {
|
||||
val access = '''
|
||||
/*h*/
|
||||
/*81*/
|
||||
|
@ -134,7 +134,7 @@ class RegionAccessCommentsTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteFirstRegion4() {
|
||||
@Test def void testDeleteFirstRegion4() throws Exception {
|
||||
val access = '''
|
||||
/*h*/
|
||||
/*81*/
|
||||
|
@ -175,7 +175,7 @@ class RegionAccessCommentsTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteMiddleRegion() {
|
||||
@Test def void testDeleteMiddleRegion() throws Exception {
|
||||
val access = '''
|
||||
8
|
||||
a /*a*/ //a
|
||||
|
@ -212,7 +212,7 @@ class RegionAccessCommentsTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testMove() {
|
||||
@Test def void testMove() throws Exception {
|
||||
val access = '''
|
||||
8//8
|
||||
/*a*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
|
@ -30,7 +30,7 @@ class RegionAccessDiffTest {
|
|||
@Inject extension RegionAccessTestHelper
|
||||
@Inject Serializer serializer
|
||||
|
||||
@Test def void testEmptyModification() {
|
||||
@Test def void testEmptyModification() throws Exception {
|
||||
val access = '''
|
||||
1 foo
|
||||
'''.toTextRegionAccess
|
||||
|
@ -55,7 +55,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testSingleSemanticToken() {
|
||||
@Test def void testSingleSemanticToken() throws Exception {
|
||||
val access = '''
|
||||
1 foo
|
||||
'''.toTextRegionAccess
|
||||
|
@ -77,7 +77,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testSerializeChildObject() {
|
||||
@Test def void testSerializeChildObject() throws Exception {
|
||||
val access = '''
|
||||
2 foo
|
||||
'''.toTextRegionAccess
|
||||
|
@ -104,7 +104,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testSerializeRootObject() {
|
||||
@Test def void testSerializeRootObject() throws Exception {
|
||||
val access = '''
|
||||
3 foo
|
||||
'''.toTextRegionAccess
|
||||
|
@ -131,7 +131,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteOne() {
|
||||
@Test def void testDeleteOne() throws Exception {
|
||||
val access = '''
|
||||
4/*1*/prefix/*2*/foo
|
||||
'''.toTextRegionAccess
|
||||
|
@ -158,7 +158,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testDeleteTwo() {
|
||||
@Test def void testDeleteTwo() throws Exception {
|
||||
val access = '''
|
||||
4/*1*/prefix/*2*/foo/*3*/
|
||||
'''.toTextRegionAccess
|
||||
|
@ -184,7 +184,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testInsertInsertReplace() {
|
||||
@Test def void testInsertInsertReplace() throws Exception {
|
||||
val access = '''
|
||||
8 a
|
||||
'''.toTextRegionAccess
|
||||
|
@ -215,7 +215,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testInsertReplaceReplace() {
|
||||
@Test def void testInsertReplaceReplace() throws Exception {
|
||||
val access = '''
|
||||
8 a
|
||||
'''.toTextRegionAccess
|
||||
|
@ -238,7 +238,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testInsertBeforeComment() {
|
||||
@Test def void testInsertBeforeComment() throws Exception {
|
||||
val access = '''
|
||||
8
|
||||
/**/
|
||||
|
@ -270,7 +270,7 @@ class RegionAccessDiffTest {
|
|||
'''
|
||||
}
|
||||
|
||||
@Test def void testMove() {
|
||||
@Test def void testMove() throws Exception {
|
||||
val access = '''
|
||||
8 a b c
|
||||
'''.toTextRegionAccess
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* 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.formatting2.regionaccess.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.formatting2.debug.TextRegionAccessToString;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextReplacement;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegmentDiff;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.TextRegionAccessBuilder;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
|
||||
import org.eclipse.xtext.util.Strings;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
public class RegionAccessTestHelper {
|
||||
@Inject
|
||||
private ParseHelper<Root> parseHelper;
|
||||
|
||||
@Inject
|
||||
private Provider<TextRegionAccessBuilder> textRegionAccessBuilder;
|
||||
|
||||
@Inject
|
||||
private ValidationTestHelper validationTestHelper;
|
||||
|
||||
public ITextRegionAccess toTextRegionAccess(CharSequence file) throws Exception {
|
||||
Root obj = parseHelper.parse(file.toString().replace("\r\n", "\n").trim());
|
||||
validationTestHelper.assertNoErrors(obj);
|
||||
return textRegionAccessBuilder.get().forNodeModel((XtextResource) obj.eResource()).create();
|
||||
}
|
||||
|
||||
public ITextRegionAccess modify(ITextRegionAccess base, Procedure1<? super ITextRegionDiffBuilder> modify) {
|
||||
StringBasedTextRegionAccessDiffBuilder fac = new StringBasedTextRegionAccessDiffBuilder(base);
|
||||
modify.apply(fac);
|
||||
StringBasedTextRegionAccessDiff modified = fac.create();
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void operator_tripleEquals(ITextRegionAccess access, CharSequence expectation) {
|
||||
if (access instanceof ITextRegionAccessDiff) {
|
||||
assertDiffs((ITextRegionAccessDiff) access);
|
||||
}
|
||||
String tra1 = cfg(new TextRegionAccessToString().withRegionAccess(access)) + "\n";
|
||||
Assert.assertEquals(Strings.toPlatformLineSeparator(expectation), Strings.toPlatformLineSeparator(tra1));
|
||||
}
|
||||
|
||||
public void assertDiffs(ITextRegionAccessDiff regions) {
|
||||
ITextRegionRewriter rewriter = regions.getOriginalTextRegionAccess().getRewriter();
|
||||
List<ITextReplacement> result = new ArrayList<>();
|
||||
for (ITextSegmentDiff r : regions.getRegionDifferences()) {
|
||||
ITextSegment originalRegion = r.getOriginalRegion();
|
||||
ITextSegment modifiedRegion = r.getModifiedRegion();
|
||||
ITextReplacement replacement = originalRegion.replaceWith(modifiedRegion.getText());
|
||||
result.add(replacement);
|
||||
}
|
||||
String actual = rewriter.renderToString(result);
|
||||
String expected = regions.regionForDocument().getText();
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private TextRegionAccessToString cfg(TextRegionAccessToString toStr) {
|
||||
return toStr.hideColumnExplanation().withTextWidth(10);
|
||||
}
|
||||
}
|
|
@ -1,74 +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.formatting2.regionaccess.internal
|
||||
|
||||
import com.google.common.collect.Lists
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Provider
|
||||
import org.eclipse.xtext.formatting2.debug.TextRegionAccessToString
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder
|
||||
import org.eclipse.xtext.formatting2.regionaccess.TextRegionAccessBuilder
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.eclipse.xtext.testing.util.ParseHelper
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper
|
||||
import org.junit.Assert
|
||||
|
||||
import static extension org.eclipse.xtext.util.Strings.*
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
class RegionAccessTestHelper {
|
||||
|
||||
@Inject ParseHelper<Root> parseHelper
|
||||
@Inject Provider<TextRegionAccessBuilder> textRegionAccessBuilder
|
||||
@Inject ValidationTestHelper validationTestHelper
|
||||
|
||||
def ITextRegionAccess toTextRegionAccess(CharSequence file) {
|
||||
val obj = parseHelper.parse(file.toString.replace("\r\n", "\n").trim)
|
||||
validationTestHelper.assertNoErrors(obj)
|
||||
return textRegionAccessBuilder.get.forNodeModel(obj.eResource as XtextResource).create
|
||||
}
|
||||
|
||||
def ITextRegionAccess modify(ITextRegionAccess base, (ITextRegionDiffBuilder)=>void modify) {
|
||||
val fac = new StringBasedTextRegionAccessDiffBuilder(base)
|
||||
modify.apply(fac)
|
||||
val modified = fac.create()
|
||||
return modified
|
||||
}
|
||||
|
||||
def ===(ITextRegionAccess access, CharSequence expectation) {
|
||||
if (access instanceof ITextRegionAccessDiff) {
|
||||
assertDiffs(access)
|
||||
}
|
||||
val tra1 = new TextRegionAccessToString().withRegionAccess(access).cfg() + "\n"
|
||||
Assert.assertEquals(expectation.toPlatformLineSeparator, tra1.toPlatformLineSeparator)
|
||||
}
|
||||
|
||||
def void assertDiffs(ITextRegionAccessDiff regions) {
|
||||
val rewriter = regions.getOriginalTextRegionAccess().getRewriter()
|
||||
val result = Lists.newArrayList()
|
||||
for (r : regions.getRegionDifferences()) {
|
||||
val originalRegion = r.originalRegion
|
||||
val modifiedRegion = r.modifiedRegion
|
||||
val replacement = originalRegion.replaceWith(modifiedRegion.text)
|
||||
result.add(replacement)
|
||||
}
|
||||
val actual = rewriter.renderToString(result)
|
||||
val expected = regions.regionForDocument.text
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
private def TextRegionAccessToString cfg(TextRegionAccessToString toStr) {
|
||||
toStr.hideColumnExplanation().withTextWidth(10)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* 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.generator;
|
||||
|
||||
import org.eclipse.emf.ecore.EcorePackage;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class TypeReferenceTest {
|
||||
/**
|
||||
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=480196
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultPackage() {
|
||||
TypeReference ref = TypeReference.typeRef("EString");
|
||||
Assert.assertEquals("", ref.getPackageName());
|
||||
Assert.assertEquals("EString", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnderscopresAnd$() {
|
||||
TypeReference ref = TypeReference.typeRef("E_$tring");
|
||||
Assert.assertEquals("", ref.getPackageName());
|
||||
Assert.assertEquals("E_$tring", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnderscopresAnd$02() {
|
||||
TypeReference ref = TypeReference.typeRef("$.$._$.E_$tring");
|
||||
Assert.assertEquals("$.$._$", ref.getPackageName());
|
||||
Assert.assertEquals("E_$tring", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageName() {
|
||||
TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("MyType", ref.getSimpleName());
|
||||
Assert.assertEquals("org.example", ref.getPackageName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParametrizedType() {
|
||||
TypeReference ref = TypeReference.typeRef("java.util.List", TypeReference.typeRef("String"));
|
||||
Assert.assertEquals("List", ref.getSimpleName());
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("String", ref.getTypeArguments().get(0).getSimpleName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongNestedTypeUsage() {
|
||||
TypeReference.typeRef("java.util.Map.Entry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedType() {
|
||||
TypeReference ref = new TypeReference("java.util", "Map.Entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("Entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Lists.newArrayList("Map", "Entry"), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerCaseNestedType() {
|
||||
TypeReference ref = new TypeReference("java.util", "Map.entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Lists.newArrayList("Map", "entry"), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void testGuessTypeRef() {
|
||||
TypeReference ref = TypeReference.guessTypeRef("java.util.Map.Entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("Entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Lists.newArrayList("Map", "Entry"), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testIllegalTypeRef() {
|
||||
TypeReference.typeRef("java.util.Map.Entry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaPath() {
|
||||
TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("org/example/MyType.java", ref.getJavaPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXtendPath() {
|
||||
TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("org/example/MyType.xtend", ref.getXtendPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEObject() {
|
||||
ResourceSetImpl rs = new ResourceSetImpl();
|
||||
TypeReference ref = new TypeReference(EcorePackage.Literals.EOBJECT, rs);
|
||||
Assert.assertEquals("org.eclipse.emf.ecore.EObject", ref.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug508810() {
|
||||
ResourceSetImpl rs = new ResourceSetImpl();
|
||||
TypeReference ref = new TypeReference(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY, rs);
|
||||
Assert.assertEquals("java.util.Map.Entry", ref.getName());
|
||||
}
|
||||
}
|
|
@ -1,121 +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.generator
|
||||
|
||||
import org.eclipse.emf.ecore.EcorePackage
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
|
||||
|
||||
class TypeReferenceTest {
|
||||
|
||||
/*
|
||||
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=480196
|
||||
*/
|
||||
@Test
|
||||
def void testDefaultPackage() {
|
||||
val ref = "EString".typeRef
|
||||
assertEquals("", ref.packageName)
|
||||
assertEquals("EString", ref.simpleName)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testUnderscopresAnd$() {
|
||||
val ref = "E_$tring".typeRef
|
||||
assertEquals("", ref.packageName)
|
||||
assertEquals("E_$tring", ref.simpleName)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testUnderscopresAnd$02() {
|
||||
val ref = "$.$._$.E_$tring".typeRef
|
||||
assertEquals("$.$._$", ref.packageName)
|
||||
assertEquals("E_$tring", ref.simpleName)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testPackageName() {
|
||||
val ref = "org.example.MyType".typeRef
|
||||
assertEquals("MyType", ref.simpleName)
|
||||
assertEquals("org.example", ref.packageName)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testParametrizedType() {
|
||||
val ref = "java.util.List".typeRef("String".typeRef)
|
||||
assertEquals("List", ref.simpleName)
|
||||
assertEquals("java.util", ref.packageName)
|
||||
assertEquals("String", ref.typeArguments.head.simpleName)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException)
|
||||
def void testWrongNestedTypeUsage() {
|
||||
"java.util.Map.Entry".typeRef
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testNestedType() {
|
||||
val ref = new TypeReference("java.util", "Map.Entry")
|
||||
assertEquals("java.util", ref.packageName)
|
||||
assertEquals("Entry", ref.simpleName)
|
||||
assertEquals(#["Map", "Entry"], ref.simpleNames)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testLowerCaseNestedType() {
|
||||
val ref = new TypeReference("java.util", "Map.entry")
|
||||
assertEquals("java.util", ref.packageName)
|
||||
assertEquals("entry", ref.simpleName)
|
||||
assertEquals(#["Map", "entry"], ref.simpleNames)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
def void testGuessTypeRef() {
|
||||
val ref = TypeReference.guessTypeRef("java.util.Map.Entry")
|
||||
assertEquals("java.util", ref.packageName)
|
||||
assertEquals("Entry", ref.simpleName)
|
||||
assertEquals(#["Map", "Entry"], ref.simpleNames)
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException)
|
||||
def void testIllegalTypeRef() {
|
||||
TypeReference.typeRef("java.util.Map.Entry")
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testJavaPath() {
|
||||
val ref = "org.example.MyType".typeRef
|
||||
assertEquals("org/example/MyType.java", ref.javaPath)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testXtendPath() {
|
||||
val ref = "org.example.MyType".typeRef
|
||||
assertEquals("org/example/MyType.xtend", ref.xtendPath)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testEObject() {
|
||||
val rs = new ResourceSetImpl
|
||||
val ref = new TypeReference(EcorePackage.Literals.EOBJECT, rs)
|
||||
assertEquals("org.eclipse.emf.ecore.EObject", ref.name)
|
||||
}
|
||||
|
||||
@Test
|
||||
def void testBug508810() {
|
||||
val rs = new ResourceSetImpl
|
||||
val ref = new TypeReference(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY, rs)
|
||||
assertEquals("java.util.Map.Entry", ref.name)
|
||||
}
|
||||
}
|
|
@ -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,15 +8,11 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.generator.trace
|
||||
|
||||
import java.util.List
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.generator.trace.TraceRegionToStringTester.Location
|
||||
import org.eclipse.xtext.generator.trace.TraceRegionToStringTester.Region
|
||||
import org.eclipse.xtext.util.ITextRegion
|
||||
import org.eclipse.xtext.util.TextRegion
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.util.Collection
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
|
@ -184,59 +180,3 @@ class TraceRegionToStringTest {
|
|||
|
||||
}
|
||||
|
||||
@Accessors class TraceRegionToStringTester extends AbstractTraceRegionToString {
|
||||
|
||||
static class Location extends LocationData {
|
||||
|
||||
new(int offset, int length, SourceRelativeURI path) {
|
||||
super(offset, length, 0, 0, path)
|
||||
}
|
||||
|
||||
new(int offset, int length) {
|
||||
this(offset, length, null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Region extends TraceRegion {
|
||||
|
||||
new(int myOffset, int myLength, Collection<ILocationData> allLocationData, AbstractTraceRegion parent) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, parent)
|
||||
}
|
||||
|
||||
new(int myOffset, int myLength, Collection<ILocationData> allLocationData) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, null)
|
||||
}
|
||||
|
||||
def Region addChild(int myOffset, int myLength, List<ILocationData> allLocationData) {
|
||||
val child = new Region(myOffset, myLength, allLocationData, this)
|
||||
return child
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val uri1 = new SourceRelativeURI("remote1")
|
||||
val uri2 = new SourceRelativeURI("remote2")
|
||||
String localText
|
||||
String remote1
|
||||
String remote2
|
||||
ITextRegion localFrame
|
||||
Region trace
|
||||
|
||||
new() {
|
||||
showLegend = false
|
||||
}
|
||||
|
||||
override protected getRemoteText(SourceRelativeURI uri) {
|
||||
switch uri {
|
||||
case uri1: remote1
|
||||
case uri2: remote2
|
||||
}
|
||||
}
|
||||
|
||||
override protected getLocalTitle() {
|
||||
"local1"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
/**
|
||||
* 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.generator.trace;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public class TraceRegionToStringTester extends AbstractTraceRegionToString {
|
||||
public static class Location extends LocationData {
|
||||
public Location(int offset, int length, SourceRelativeURI path) {
|
||||
super(offset, length, 0, 0, path);
|
||||
}
|
||||
|
||||
public Location(int offset, int length) {
|
||||
this(offset, length, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Region extends TraceRegion {
|
||||
public Region(int myOffset, int myLength, Collection<ILocationData> allLocationData,
|
||||
AbstractTraceRegion parent) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, parent);
|
||||
}
|
||||
|
||||
public Region(int myOffset, int myLength, Collection<ILocationData> allLocationData) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, null);
|
||||
}
|
||||
|
||||
public TraceRegionToStringTester.Region addChild(int myOffset, int myLength,
|
||||
List<ILocationData> allLocationData) {
|
||||
return new TraceRegionToStringTester.Region(myOffset, myLength,
|
||||
allLocationData, this);
|
||||
}
|
||||
}
|
||||
|
||||
private final SourceRelativeURI uri1 = new SourceRelativeURI("remote1");
|
||||
|
||||
private final SourceRelativeURI uri2 = new SourceRelativeURI("remote2");
|
||||
|
||||
private String localText;
|
||||
|
||||
private String remote1;
|
||||
|
||||
private String remote2;
|
||||
|
||||
private ITextRegion localFrame;
|
||||
|
||||
private TraceRegionToStringTester.Region trace;
|
||||
|
||||
public TraceRegionToStringTester() {
|
||||
setShowLegend(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRemoteText(SourceRelativeURI uri) {
|
||||
if (Objects.equal(uri, uri1)) {
|
||||
return remote1;
|
||||
}
|
||||
if (Objects.equal(uri, uri2)) {
|
||||
return remote2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocalTitle() {
|
||||
return "local1";
|
||||
}
|
||||
|
||||
public SourceRelativeURI getUri1() {
|
||||
return uri1;
|
||||
}
|
||||
|
||||
public SourceRelativeURI getUri2() {
|
||||
return uri2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalText() {
|
||||
return localText;
|
||||
}
|
||||
|
||||
public void setLocalText(String localText) {
|
||||
this.localText = localText;
|
||||
}
|
||||
|
||||
public String getRemote1() {
|
||||
return remote1;
|
||||
}
|
||||
|
||||
public void setRemote1(String remote1) {
|
||||
this.remote1 = remote1;
|
||||
}
|
||||
|
||||
public String getRemote2() {
|
||||
return remote2;
|
||||
}
|
||||
|
||||
public void setRemote2(String remote2) {
|
||||
this.remote2 = remote2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextRegion getLocalFrame() {
|
||||
return localFrame;
|
||||
}
|
||||
|
||||
public void setLocalFrame(ITextRegion localFrame) {
|
||||
this.localFrame = localFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TraceRegionToStringTester.Region getTrace() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
public void setTrace(TraceRegionToStringTester.Region trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Copyright (c) 2018, 2020 TypeFox (https://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.generator.trace.node;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.xtext.generator.trace.LocationData;
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* @author Dennis Huebner - Initial contribution and API
|
||||
*/
|
||||
public class GeneratorNodePerformanceTest {
|
||||
private GeneratorNodeExtensions exts = new GeneratorNodeExtensions();
|
||||
|
||||
// private static final int numberOfLines = 800_000 // Before x sec - after 4.6 sec
|
||||
// private static final int numberOfLines = 80_000 // Before 89 sec - after 0.43 sec
|
||||
private static final int numberOfLines = 40_000; // Before 20 sec - after 0.32 sec
|
||||
// private static final int numberOfLines = 20_000 // Before 5 sec - after 0.25 sec
|
||||
// private static final int numberOfLines = 10_000 // Before 1.8 sec - after 0.25 sec
|
||||
|
||||
@Rule
|
||||
public final Timeout timeout = new Timeout(1000, TimeUnit.MILLISECONDS);
|
||||
|
||||
@Test
|
||||
public void testBasicCreationAndProcessingPerformance() {
|
||||
LocationData root = loc(0);
|
||||
CompositeGeneratorNode node = exts.appendNewLine(exts.append(exts.trace(root), "notindented"));
|
||||
for (int i = 0; i < GeneratorNodePerformanceTest.numberOfLines; i++) {
|
||||
exts.appendNewLine(exts.append(
|
||||
exts.indent(exts.appendNewLine(exts.append(exts.trace(exts.indent(node), loc(1)), "indented1"))),
|
||||
"indented2"));
|
||||
}
|
||||
exts.append(exts.appendNewLine(node), "dedented");
|
||||
GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
|
||||
GeneratorNodeProcessor.Result result = processor.process(node);
|
||||
String resultAsString = null;
|
||||
if (result != null) {
|
||||
resultAsString = result.toString();
|
||||
}
|
||||
Assert.assertFalse(Strings.isNullOrEmpty(resultAsString));
|
||||
}
|
||||
|
||||
private LocationData loc(int idx) {
|
||||
return new LocationData(idx, 100 - idx, 0, 0, new SourceRelativeURI("foo/mymodel.dsl"));
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 TypeFox (https://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.generator.trace.node
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.eclipse.xtext.generator.trace.LocationData
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.Timeout
|
||||
|
||||
/**
|
||||
* @author Dennis Huebner - Initial contribution and API
|
||||
*/
|
||||
class GeneratorNodePerformanceTest {
|
||||
|
||||
extension GeneratorNodeExtensions exts = new GeneratorNodeExtensions()
|
||||
|
||||
// static val numberOfLines = 800_000 // Before x sec - after 4.6 sec
|
||||
// static val numberOfLines = 80_000 // Before 89 sec - after 0.43 sec
|
||||
static val numberOfLines = 40_000 // Before 20 sec - after 0.32 sec
|
||||
// static val numberOfLines = 20_000 // Before 5 sec - after 0.25 sec
|
||||
// static val numberOfLines = 10_000 // Before 1.8 sec - after 0.25 sec
|
||||
@Rule
|
||||
public val Timeout timeout = new Timeout(1000, TimeUnit.MILLISECONDS)
|
||||
|
||||
@Test def void testBasicCreationAndProcessingPerformance() {
|
||||
val root = loc(0)
|
||||
var node = root.trace.append('notindented').appendNewLine
|
||||
for (i : 0 ..< numberOfLines) {
|
||||
node.indent.trace(loc(1)).append('indented1').appendNewLine.indent.append('indented2').appendNewLine
|
||||
}
|
||||
node.appendNewLine.append('dedented')
|
||||
val processor = new GeneratorNodeProcessor
|
||||
Assert.assertFalse(processor.process(node)?.toString.nullOrEmpty)
|
||||
}
|
||||
|
||||
private def loc(int idx) {
|
||||
new LocationData(idx, 100 - idx, 0, 0, new SourceRelativeURI('foo/mymodel.dsl'))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* 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.parser;
|
||||
|
||||
import org.eclipse.xtext.parsetree.reconstr.SerializationErrorTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Model;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.smoketest.processors.PartialParsingProcessor;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
public class Bug410560Test extends AbstractXtextTests {
|
||||
@Override
|
||||
public boolean shouldTestSerializer(XtextResource resource) {
|
||||
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=361355
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(SerializationErrorTestLanguageStandaloneSetup.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithoutIndent_01() throws Exception {
|
||||
Model model = (Model) getModel("{}");
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNull(model.getTest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithoutIndent_02() throws Exception {
|
||||
Model model = (Model) getModel("({})");
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNull(model.getTest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithIndent_01() throws Exception {
|
||||
Model model = (Model) getModel("{tworequired a b}");
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNotNull(model.getTest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithIndent_02() throws Exception {
|
||||
Model model = (Model) getModel("({tworequired a b})");
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNotNull(model.getTest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingChangeIndent() throws Exception {
|
||||
String modelAsString = "({tworequired a b})";
|
||||
Model model = (Model) getModel(modelAsString);
|
||||
XtextResource res = ((XtextResource) model.eResource());
|
||||
res.update(modelAsString.indexOf("a"), 1, "b");
|
||||
Assert.assertSame(model, res.getContents().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveIndent() throws Exception {
|
||||
String modelAsString = "({ tworequired a b })";
|
||||
Model model = (Model) getModel(modelAsString);
|
||||
XtextResource res = ((XtextResource) model.eResource());
|
||||
res.update(modelAsString.indexOf("t"), "tworequired a b".length(), " ");
|
||||
Assert.assertSame(model, res.getContents().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveNestedIndent() throws Exception {
|
||||
String modelAsString = "({{ tworequired a b }})";
|
||||
Model model = (Model) getModel(modelAsString);
|
||||
XtextResource res = ((XtextResource) model.eResource());
|
||||
res.update(modelAsString.indexOf("t"), "tworequired a b".length(), " ");
|
||||
Assert.assertSame(model, res.getContents().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveNestedIndent_01() throws Exception {
|
||||
String modelAsString = "({{ tworequired a b }})";
|
||||
get(PartialParsingProcessor.class).processFile(modelAsString, modelAsString, modelAsString.indexOf("t"),
|
||||
"tworequired a b".length(), " ");
|
||||
}
|
||||
}
|
|
@ -1,96 +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.parser
|
||||
|
||||
import org.eclipse.xtext.parsetree.reconstr.SerializationErrorTestLanguageStandaloneSetup
|
||||
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Model
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.eclipse.xtext.testing.smoketest.processors.PartialParsingProcessor
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class Bug410560Test extends AbstractXtextTests {
|
||||
|
||||
override boolean shouldTestSerializer(XtextResource resource) {
|
||||
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=361355
|
||||
return false;
|
||||
}
|
||||
|
||||
override void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(SerializationErrorTestLanguageStandaloneSetup);
|
||||
}
|
||||
|
||||
@Test def void testParsingWithoutIndent_01() {
|
||||
val model = getModel('''
|
||||
{}
|
||||
''') as Model
|
||||
assertNotNull(model)
|
||||
assertNull(model.test)
|
||||
}
|
||||
|
||||
@Test def void testParsingWithoutIndent_02() {
|
||||
val model = getModel('''
|
||||
({})
|
||||
''') as Model
|
||||
assertNotNull(model)
|
||||
assertNull(model.test)
|
||||
}
|
||||
|
||||
@Test def void testParsingWithIndent_01() {
|
||||
val model = getModel('''
|
||||
{tworequired a b}
|
||||
''') as Model
|
||||
assertNotNull(model)
|
||||
assertNotNull(model.test)
|
||||
}
|
||||
|
||||
@Test def void testParsingWithIndent_02() {
|
||||
val model = getModel('''
|
||||
({tworequired a b})
|
||||
''') as Model
|
||||
assertNotNull(model)
|
||||
assertNotNull(model.test)
|
||||
}
|
||||
|
||||
@Test def void testPartialParsingChangeIndent() {
|
||||
val modelAsString = '({tworequired a b})'
|
||||
val model = getModel(modelAsString) as Model
|
||||
|
||||
val res = model.eResource as XtextResource
|
||||
res.update(modelAsString.indexOf('a'), 1, "b")
|
||||
assertSame(model, res.contents.head)
|
||||
}
|
||||
|
||||
@Test def void testPartialParsingRemoveIndent() {
|
||||
val modelAsString = '({ tworequired a b })'
|
||||
val model = getModel(modelAsString) as Model
|
||||
|
||||
val res = model.eResource as XtextResource
|
||||
res.update(modelAsString.indexOf('t'), 'tworequired a b'.length, " ")
|
||||
assertSame(model, res.contents.head)
|
||||
}
|
||||
|
||||
@Test def void testPartialParsingRemoveNestedIndent() {
|
||||
val modelAsString = '({{ tworequired a b }})'
|
||||
val model = getModel(modelAsString) as Model
|
||||
|
||||
val res = model.eResource as XtextResource
|
||||
res.update(modelAsString.indexOf('t'), 'tworequired a b'.length, " ")
|
||||
assertSame(model, res.contents.head)
|
||||
}
|
||||
|
||||
@Test def void testPartialParsingRemoveNestedIndent_01() {
|
||||
val modelAsString = '({{ tworequired a b }})'
|
||||
get(PartialParsingProcessor).processFile(modelAsString, modelAsString, modelAsString.indexOf('t'), 'tworequired a b'.length, " ")
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2015 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.
|
||||
|
@ -14,12 +14,10 @@ import org.eclipse.xtext.parser.fragments.FragmentTestLanguageExStandaloneSetup;
|
|||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FragmentExsPlainParsingTest extends AbstractFragmentsPlainParsingTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
FragmentTestLanguageExStandaloneSetup _fragmentTestLanguageExStandaloneSetup = new FragmentTestLanguageExStandaloneSetup();
|
||||
this.with(_fragmentTestLanguageExStandaloneSetup);
|
||||
}
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageExStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2015 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(XtextRunner.class)
|
||||
@InjectWith(FragmentsEagerLinkingInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class FragmentsEagerLinkingTest extends AbstractFragmentsTest {
|
||||
}
|
|
@ -1,21 +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.parser.fragments
|
||||
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(FragmentsEagerLinkingInjectorProvider)
|
||||
class FragmentsEagerLinkingTest extends AbstractFragmentsTest {
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2015 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.
|
||||
|
@ -14,12 +14,10 @@ import org.eclipse.xtext.parser.fragments.FragmentTestLanguageExStandaloneSetup;
|
|||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FragmentsExTest extends AbstractFragmentsTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
FragmentTestLanguageExStandaloneSetup _fragmentTestLanguageExStandaloneSetup = new FragmentTestLanguageExStandaloneSetup();
|
||||
this.with(_fragmentTestLanguageExStandaloneSetup);
|
||||
}
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageExStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,19 +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.parser.fragments
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class FragmentsExTest extends AbstractFragmentsTest {
|
||||
override void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageExStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2015 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.
|
||||
|
@ -14,12 +14,10 @@ import org.eclipse.xtext.parser.fragments.FragmentTestLanguageStandaloneSetup;
|
|||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FragmentsPlainParsingTest extends AbstractFragmentsPlainParsingTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
FragmentTestLanguageStandaloneSetup _fragmentTestLanguageStandaloneSetup = new FragmentTestLanguageStandaloneSetup();
|
||||
this.with(_fragmentTestLanguageStandaloneSetup);
|
||||
}
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2015 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.
|
||||
|
@ -14,12 +14,10 @@ import org.eclipse.xtext.parser.fragments.FragmentTestLanguageStandaloneSetup;
|
|||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class FragmentsTest extends AbstractFragmentsTest {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
FragmentTestLanguageStandaloneSetup _fragmentTestLanguageStandaloneSetup = new FragmentTestLanguageStandaloneSetup();
|
||||
this.with(_fragmentTestLanguageStandaloneSetup);
|
||||
}
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,19 +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.parser.fragments
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class FragmentsTest extends AbstractFragmentsTest {
|
||||
override void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,29 +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.parser.fragments
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class FragmentsPlainParsingTest extends AbstractFragmentsPlainParsingTest {
|
||||
override void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageStandaloneSetup());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
class FragmentExsPlainParsingTest extends AbstractFragmentsPlainParsingTest {
|
||||
override void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(new FragmentTestLanguageExStandaloneSetup());
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* 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.
|
||||
|
@ -10,12 +10,8 @@ package org.eclipse.xtext.resource.containers
|
|||
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Provider
|
||||
import java.io.File
|
||||
import java.util.Set
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.naming.QualifiedName
|
||||
import org.eclipse.xtext.resource.IResourceDescription
|
||||
import org.eclipse.xtext.resource.LiveContainerTestLanguageInjectorProvider
|
||||
|
@ -27,9 +23,6 @@ import org.eclipse.xtext.resource.liveContainerTestLanguage.Model
|
|||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.eclipse.xtext.testing.util.ParseHelper
|
||||
import org.eclipse.xtext.workspace.IProjectConfig
|
||||
import org.eclipse.xtext.workspace.ISourceFolder
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig
|
||||
import org.eclipse.xtext.workspace.ProjectConfigAdapter
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig
|
||||
import org.junit.Before
|
||||
|
@ -39,8 +32,6 @@ import org.junit.runner.RunWith
|
|||
import static org.eclipse.xtext.resource.liveContainerTestLanguage.LiveContainerTestLanguagePackage.Literals.*
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import static extension org.eclipse.xtext.util.UriUtil.*
|
||||
|
||||
/**
|
||||
* @author koehnlein - Initial contribution and API
|
||||
*/
|
||||
|
@ -198,36 +189,3 @@ class LiveShadowedChunkedContainerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
class ProjectConfig implements IProjectConfig {
|
||||
|
||||
URI path
|
||||
Set<SourceFolder> sourceFolders = newHashSet
|
||||
String name
|
||||
IWorkspaceConfig workspaceConfig
|
||||
|
||||
new(String name, WorkspaceConfig workspaceConfig) {
|
||||
this.name = name
|
||||
|
||||
this.path = URI.createURI(new File(name).absoluteFile.toURI.toString).appendSegment('')
|
||||
sourceFolders.add(new SourceFolder(path.trimSegments(1).appendSegment('src').appendSegment('')))
|
||||
this.workspaceConfig = workspaceConfig
|
||||
workspaceConfig.addProject(this)
|
||||
}
|
||||
|
||||
override findSourceFolderContaining(URI member) {
|
||||
sourceFolders.findFirst[path.isPrefixOf(member)]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
class SourceFolder implements ISourceFolder {
|
||||
|
||||
val URI path
|
||||
|
||||
override getName() {
|
||||
'src'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* 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.resource.containers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
|
||||
public class ProjectConfig implements IProjectConfig {
|
||||
private final URI path;
|
||||
|
||||
private final Set<SourceFolder> sourceFolders = new HashSet<>();
|
||||
|
||||
private final String name;
|
||||
|
||||
private final IWorkspaceConfig workspaceConfig;
|
||||
|
||||
public ProjectConfig(String name, WorkspaceConfig workspaceConfig) {
|
||||
this.name = name;
|
||||
this.path = URI.createURI(new File(name).getAbsoluteFile().toURI().toString()).appendSegment("");
|
||||
this.sourceFolders.add(new SourceFolder(this.path.trimSegments(1).appendSegment("src").appendSegment("")));
|
||||
this.workspaceConfig = workspaceConfig;
|
||||
workspaceConfig.addProject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceFolder findSourceFolderContaining(URI member) {
|
||||
for (ISourceFolder f : sourceFolders) {
|
||||
if (UriUtil.isPrefixOf(this.path, member)) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public URI getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public Set<SourceFolder> getSourceFolders() {
|
||||
return sourceFolders;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return workspaceConfig;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* 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.resource.containers;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
|
||||
public class SourceFolder implements ISourceFolder {
|
||||
private final URI path;
|
||||
|
||||
public SourceFolder(URI path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "src";
|
||||
}
|
||||
|
||||
public URI getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* Copyright (c) 2018, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.GlobalRegistries;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.KeywordHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
public class KeywordHelperTest extends AbstractXtextTests {
|
||||
private GlobalRegistries.GlobalStateMemento globalStateMemento;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
globalStateMemento = GlobalRegistries.makeCopyOfGlobalState();
|
||||
super.setUp();
|
||||
EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
|
||||
with(XtextStandaloneSetup.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
globalStateMemento.restoreGlobalState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToAntlrTokenIdentifier() throws Exception {
|
||||
// @formatter:off
|
||||
String model =
|
||||
"grammar org.eclipse.xtext.xbase.Xbase with org.eclipse.xtext.common.Terminals\n" +
|
||||
"import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" +
|
||||
"Model returns ecore::EClass : 'model' '/EOF' 'EOF' 'ÄÖÜäöüß' name=ID;";
|
||||
// @formatter:off
|
||||
XtextResource resource = getResourceFromString(model);
|
||||
Grammar grammar = ((Grammar) resource.getContents().get(0));
|
||||
KeywordHelper keywordHelper = new KeywordHelper(grammar, true, new GrammarAccessExtensions());
|
||||
Assert.assertEquals("[/EOF, EOF, model, ÄÖÜäöüß]",
|
||||
IterableExtensions.sort(keywordHelper.getAllKeywords()).toString());
|
||||
Assert.assertEquals("KW_EOF_1", keywordHelper.getRuleName("/EOF"));
|
||||
Assert.assertEquals("KW_EOF", keywordHelper.getRuleName("EOF"));
|
||||
Assert.assertEquals("Model", keywordHelper.getRuleName("model"));
|
||||
Assert.assertEquals("AeOeUeaeOeUe", keywordHelper.getRuleName("ÄÖÜäöüß"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getAsStream(String model) {
|
||||
return getAsStream(model, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import org.eclipse.emf.ecore.EPackage
|
||||
import org.eclipse.emf.ecore.xml.type.XMLTypePackage
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.XtextStandaloneSetup
|
||||
import org.eclipse.xtext.testing.GlobalRegistries
|
||||
import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.KeywordHelper
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
class KeywordHelperTest extends AbstractXtextTests {
|
||||
|
||||
GlobalStateMemento globalStateMemento;
|
||||
|
||||
@Before
|
||||
override setUp() {
|
||||
globalStateMemento = GlobalRegistries.makeCopyOfGlobalState();
|
||||
super.setUp();
|
||||
EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
|
||||
with(XtextStandaloneSetup)
|
||||
}
|
||||
|
||||
@After
|
||||
override tearDown() {
|
||||
super.tearDown()
|
||||
globalStateMemento.restoreGlobalState();
|
||||
}
|
||||
|
||||
@Test def void testToAntlrTokenIdentifier() {
|
||||
val resource = getResourceFromString('''
|
||||
grammar org.eclipse.xtext.xbase.Xbase with org.eclipse.xtext.common.Terminals
|
||||
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
|
||||
Model returns ecore::EClass : "model" "/EOF" "EOF" "ÄÖÜäöüß" name=ID;
|
||||
''')
|
||||
val grammar = resource.contents.head as Grammar
|
||||
val keywordHelper = new KeywordHelper(grammar, true, new GrammarAccessExtensions)
|
||||
assertEquals("[/EOF, EOF, model, ÄÖÜäöüß]", keywordHelper.allKeywords.sort.toString)
|
||||
assertEquals("KW_EOF_1", keywordHelper.getRuleName("/EOF"))
|
||||
assertEquals("KW_EOF", keywordHelper.getRuleName("EOF"))
|
||||
assertEquals("Model", keywordHelper.getRuleName("model"))
|
||||
assertEquals("AeOeUeaeOeUe", keywordHelper.getRuleName("ÄÖÜäöüß")) //ß is not escaped
|
||||
}
|
||||
|
||||
override protected getAsStream(String model) {
|
||||
getAsStream(model, StandardCharsets.ISO_8859_1)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Copyright (c) 2018, 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.wizard.cli;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.tests.TemporaryFolder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author Karsten Thoms (karsten.thoms@itemis.de) - Initial contribution and API
|
||||
* @since 2.15
|
||||
*/
|
||||
public class CliProjectsCreatorMainTest {
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testCreateGreetingsGradleProject() throws Exception {
|
||||
File targetDir = temp.newFolder();
|
||||
// @formatter:off
|
||||
String[] args = new String[] {
|
||||
"-targetDir=" + targetDir.getAbsolutePath(),
|
||||
"-languageName=org.xtext.example.mydsl.MyDsl",
|
||||
"-baseName=org.xtext.example.mydsl",
|
||||
"-extension=mydsl",
|
||||
"-enabledProjects=GenericIDE,RuntimeTest",
|
||||
"-buildSystem=GRADLE",
|
||||
"-sourceLayout=MAVEN",
|
||||
"-languageServer=FATJAR",
|
||||
"-xtextVersion=undefined",
|
||||
"-projectLayout=FLAT",
|
||||
"-javaVersion=JAVA10"
|
||||
};
|
||||
// @formatter:on
|
||||
CliProjectsCreatorMain.main(args);
|
||||
// @formatter:off
|
||||
List<String> files = Lists.newArrayList(
|
||||
"org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/GenerateMyDsl.mwe2",
|
||||
"org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/MyDsl.xtext",
|
||||
"org.xtext.example.mydsl/build.gradle",
|
||||
"org.xtext.example.mydsl.ide/build.gradle",
|
||||
"org.xtext.example.mydsl.parent/build.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradlew",
|
||||
"org.xtext.example.mydsl.parent/gradlew.bat",
|
||||
"org.xtext.example.mydsl.parent/settings.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradle/source-layout.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.jar",
|
||||
"org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.properties");
|
||||
// @formatter:on
|
||||
for (String file : files) {
|
||||
Assert.assertTrue(new File(targetDir, file).exists());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.wizard.cli
|
||||
|
||||
import java.io.File
|
||||
import org.eclipse.xtext.tests.TemporaryFolder
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* @author Karsten Thoms (karsten.thoms@itemis.de) - Initial contribution and API
|
||||
* @since 2.15
|
||||
*/
|
||||
class CliProjectsCreatorMainTest {
|
||||
@Rule public TemporaryFolder temp = new TemporaryFolder
|
||||
|
||||
@Test
|
||||
def void testCreateGreetingsGradleProject () {
|
||||
val targetDir = temp.newFolder
|
||||
val args = #[
|
||||
"-targetDir="+targetDir.absolutePath,
|
||||
"-languageName=org.xtext.example.mydsl.MyDsl",
|
||||
"-baseName=org.xtext.example.mydsl",
|
||||
"-extension=mydsl",
|
||||
"-enabledProjects=GenericIDE,RuntimeTest",
|
||||
"-buildSystem=GRADLE",
|
||||
"-sourceLayout=MAVEN",
|
||||
"-languageServer=FATJAR",
|
||||
"-xtextVersion=undefined",
|
||||
"-projectLayout=FLAT",
|
||||
"-javaVersion=JAVA10"
|
||||
]
|
||||
|
||||
CliProjectsCreatorMain.main(args)
|
||||
|
||||
val files = #[
|
||||
"org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/GenerateMyDsl.mwe2",
|
||||
"org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/MyDsl.xtext",
|
||||
"org.xtext.example.mydsl/build.gradle",
|
||||
"org.xtext.example.mydsl.ide/build.gradle",
|
||||
"org.xtext.example.mydsl.parent/build.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradlew",
|
||||
"org.xtext.example.mydsl.parent/gradlew.bat",
|
||||
"org.xtext.example.mydsl.parent/settings.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradle/source-layout.gradle",
|
||||
"org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.jar",
|
||||
"org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.properties"
|
||||
]
|
||||
|
||||
for (file: files) {
|
||||
assertTrue(new File(targetDir, file).exists())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +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.filesystem;
|
||||
|
||||
import com.google.common.base.StandardSystemProperty;
|
||||
import com.google.inject.Inject;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess;
|
||||
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
|
||||
import org.eclipse.xtext.generator.OutputConfiguration;
|
||||
import org.eclipse.xtext.generator.URIBasedFileSystemAccess;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.tests.XtextInjectorProvider;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author akos.kitta - Initial contribution and API
|
||||
*
|
||||
* @see https://github.com/eclipse/xtext-core/issues/180
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(XtextInjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class URIBasedFileSystemAccessTest {
|
||||
private static final String MISSING_RESOURCE_NAME = "someMissingResource";
|
||||
|
||||
private static final String EXISTING_RESOURCE_NAME = "someExistingResource";
|
||||
|
||||
@Inject
|
||||
private URIBasedFileSystemAccess fsa;
|
||||
|
||||
@Inject
|
||||
private IOutputConfigurationProvider configProvider;
|
||||
|
||||
private ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
try {
|
||||
final Path tmpPath = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value());
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("tempFolder_");
|
||||
UUID _randomUUID = UUID.randomUUID();
|
||||
_builder.append(_randomUUID);
|
||||
final Path output = Files.createTempDirectory(tmpPath, _builder.toString());
|
||||
final Path resource = Files.createFile(output.resolve(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME));
|
||||
resource.toFile().deleteOnExit();
|
||||
output.toFile().deleteOnExit();
|
||||
final OutputConfiguration config = IterableExtensions.<OutputConfiguration>head(this.configProvider.getOutputConfigurations());
|
||||
config.setOutputDirectory(output.toString());
|
||||
Pair<String, OutputConfiguration> _mappedTo = Pair.<String, OutputConfiguration>of(IFileSystemAccess.DEFAULT_OUTPUT, config);
|
||||
this.fsa.setOutputConfigurations(Collections.<String, OutputConfiguration>unmodifiableMap(CollectionLiterals.<String, OutputConfiguration>newHashMap(_mappedTo)));
|
||||
this.fsa.setConverter(this.uriConverter);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFalseOnAbsent() {
|
||||
Assert.assertFalse(this.fsa.isFile(URIBasedFileSystemAccessTest.MISSING_RESOURCE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrueOnPresent() {
|
||||
Assert.assertTrue(this.fsa.isFile(URIBasedFileSystemAccessTest.EXISTING_RESOURCE_NAME));
|
||||
}
|
||||
}
|
|
@ -1,51 +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.formatting2.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public abstract class GenericFormatter<T extends EObject> extends AbstractFormatter2 {
|
||||
@Override
|
||||
protected void _format(final EObject obj, final IFormattableDocument document) {
|
||||
this.format(((T) obj), this.getRequest().getTextRegionAccess().getExtensions(), document);
|
||||
}
|
||||
|
||||
protected abstract void format(final T model, final ITextRegionExtensions regionAccess, final IFormattableDocument document);
|
||||
|
||||
@Override
|
||||
public void format(final Object obj, final IFormattableDocument document) {
|
||||
if (obj instanceof XtextResource) {
|
||||
_format((XtextResource)obj, document);
|
||||
return;
|
||||
} else if (obj instanceof EObject) {
|
||||
_format((EObject)obj, document);
|
||||
return;
|
||||
} else if (obj == null) {
|
||||
_format((Void)null, document);
|
||||
return;
|
||||
} else if (obj != null) {
|
||||
_format(obj, document);
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " +
|
||||
Arrays.<Object>asList(obj, document).toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
|
@ -37,7 +37,7 @@ public class RegionAccessCommentsTest {
|
|||
private RegionAccessTestHelper _regionAccessTestHelper;
|
||||
|
||||
@Test
|
||||
public void testDeleteFirstRegion1() {
|
||||
public void testDeleteFirstRegion1() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*h*/");
|
||||
_builder.newLine();
|
||||
|
@ -110,7 +110,7 @@ public class RegionAccessCommentsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFirstRegion2() {
|
||||
public void testDeleteFirstRegion2() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*h*/");
|
||||
_builder.newLine();
|
||||
|
@ -191,7 +191,7 @@ public class RegionAccessCommentsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFirstRegion3() {
|
||||
public void testDeleteFirstRegion3() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*h*/");
|
||||
_builder.newLine();
|
||||
|
@ -278,7 +278,7 @@ public class RegionAccessCommentsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFirstRegion4() {
|
||||
public void testDeleteFirstRegion4() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("/*h*/");
|
||||
_builder.newLine();
|
||||
|
@ -371,7 +371,7 @@ public class RegionAccessCommentsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMiddleRegion() {
|
||||
public void testDeleteMiddleRegion() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8");
|
||||
_builder.newLine();
|
||||
|
@ -457,7 +457,7 @@ public class RegionAccessCommentsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMove() {
|
||||
public void testMove() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8//8");
|
||||
_builder.newLine();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
|
@ -47,7 +47,7 @@ public class RegionAccessDiffTest {
|
|||
private Serializer serializer;
|
||||
|
||||
@Test
|
||||
public void testEmptyModification() {
|
||||
public void testEmptyModification() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("1 foo");
|
||||
_builder.newLine();
|
||||
|
@ -94,7 +94,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSingleSemanticToken() {
|
||||
public void testSingleSemanticToken() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("1 foo");
|
||||
_builder.newLine();
|
||||
|
@ -132,7 +132,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeChildObject() {
|
||||
public void testSerializeChildObject() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("2 foo");
|
||||
_builder.newLine();
|
||||
|
@ -181,7 +181,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeRootObject() {
|
||||
public void testSerializeRootObject() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("3 foo");
|
||||
_builder.newLine();
|
||||
|
@ -228,7 +228,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteOne() {
|
||||
public void testDeleteOne() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("4/*1*/prefix/*2*/foo");
|
||||
_builder.newLine();
|
||||
|
@ -285,7 +285,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTwo() {
|
||||
public void testDeleteTwo() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("4/*1*/prefix/*2*/foo/*3*/");
|
||||
_builder.newLine();
|
||||
|
@ -337,7 +337,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertInsertReplace() {
|
||||
public void testInsertInsertReplace() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8 a");
|
||||
_builder.newLine();
|
||||
|
@ -403,7 +403,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertReplaceReplace() {
|
||||
public void testInsertReplaceReplace() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8 a");
|
||||
_builder.newLine();
|
||||
|
@ -443,7 +443,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInsertBeforeComment() {
|
||||
public void testInsertBeforeComment() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8");
|
||||
_builder.newLine();
|
||||
|
@ -512,7 +512,7 @@ public class RegionAccessDiffTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMove() {
|
||||
public void testMove() throws Exception {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("8 a b c");
|
||||
_builder.newLine();
|
||||
|
|
|
@ -1,98 +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.formatting2.regionaccess.internal;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.formatting2.debug.TextRegionAccessToString;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextRegionRewriter;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextReplacement;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.ITextSegmentDiff;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.TextRegionAccessBuilder;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiff;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder;
|
||||
import org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Root;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.util.ParseHelper;
|
||||
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
|
||||
import org.eclipse.xtext.util.Strings;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RegionAccessTestHelper {
|
||||
@Inject
|
||||
private ParseHelper<Root> parseHelper;
|
||||
|
||||
@Inject
|
||||
private Provider<TextRegionAccessBuilder> textRegionAccessBuilder;
|
||||
|
||||
@Inject
|
||||
private ValidationTestHelper validationTestHelper;
|
||||
|
||||
public ITextRegionAccess toTextRegionAccess(final CharSequence file) {
|
||||
try {
|
||||
final Root obj = this.parseHelper.parse(file.toString().replace("\r\n", "\n").trim());
|
||||
this.validationTestHelper.assertNoErrors(obj);
|
||||
Resource _eResource = obj.eResource();
|
||||
return this.textRegionAccessBuilder.get().forNodeModel(((XtextResource) _eResource)).create();
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
public ITextRegionAccess modify(final ITextRegionAccess base, final Procedure1<? super ITextRegionDiffBuilder> modify) {
|
||||
final StringBasedTextRegionAccessDiffBuilder fac = new StringBasedTextRegionAccessDiffBuilder(base);
|
||||
modify.apply(fac);
|
||||
final StringBasedTextRegionAccessDiff modified = fac.create();
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void operator_tripleEquals(final ITextRegionAccess access, final CharSequence expectation) {
|
||||
if ((access instanceof ITextRegionAccessDiff)) {
|
||||
this.assertDiffs(((ITextRegionAccessDiff)access));
|
||||
}
|
||||
TextRegionAccessToString _cfg = this.cfg(new TextRegionAccessToString().withRegionAccess(access));
|
||||
final String tra1 = (_cfg + "\n");
|
||||
Assert.assertEquals(Strings.toPlatformLineSeparator(expectation), Strings.toPlatformLineSeparator(tra1));
|
||||
}
|
||||
|
||||
public void assertDiffs(final ITextRegionAccessDiff regions) {
|
||||
final ITextRegionRewriter rewriter = regions.getOriginalTextRegionAccess().getRewriter();
|
||||
final ArrayList<ITextReplacement> result = Lists.<ITextReplacement>newArrayList();
|
||||
List<ITextSegmentDiff> _regionDifferences = regions.getRegionDifferences();
|
||||
for (final ITextSegmentDiff r : _regionDifferences) {
|
||||
{
|
||||
final ITextSegment originalRegion = r.getOriginalRegion();
|
||||
final ITextSegment modifiedRegion = r.getModifiedRegion();
|
||||
final ITextReplacement replacement = originalRegion.replaceWith(modifiedRegion.getText());
|
||||
result.add(replacement);
|
||||
}
|
||||
}
|
||||
final String actual = rewriter.renderToString(result);
|
||||
final String expected = regions.regionForDocument().getText();
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private TextRegionAccessToString cfg(final TextRegionAccessToString toStr) {
|
||||
return toStr.hideColumnExplanation().withTextWidth(10);
|
||||
}
|
||||
}
|
|
@ -1,121 +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.generator;
|
||||
|
||||
import java.util.Collections;
|
||||
import org.eclipse.emf.ecore.EcorePackage;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class TypeReferenceTest {
|
||||
/**
|
||||
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=480196
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultPackage() {
|
||||
final TypeReference ref = TypeReference.typeRef("EString");
|
||||
Assert.assertEquals("", ref.getPackageName());
|
||||
Assert.assertEquals("EString", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnderscopresAnd$() {
|
||||
final TypeReference ref = TypeReference.typeRef("E_$tring");
|
||||
Assert.assertEquals("", ref.getPackageName());
|
||||
Assert.assertEquals("E_$tring", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnderscopresAnd$02() {
|
||||
final TypeReference ref = TypeReference.typeRef("$.$._$.E_$tring");
|
||||
Assert.assertEquals("$.$._$", ref.getPackageName());
|
||||
Assert.assertEquals("E_$tring", ref.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageName() {
|
||||
final TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("MyType", ref.getSimpleName());
|
||||
Assert.assertEquals("org.example", ref.getPackageName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParametrizedType() {
|
||||
final TypeReference ref = TypeReference.typeRef("java.util.List", TypeReference.typeRef("String"));
|
||||
Assert.assertEquals("List", ref.getSimpleName());
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("String", IterableExtensions.<TypeReference>head(ref.getTypeArguments()).getSimpleName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongNestedTypeUsage() {
|
||||
TypeReference.typeRef("java.util.Map.Entry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedType() {
|
||||
final TypeReference ref = new TypeReference("java.util", "Map.Entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("Entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Map", "Entry")), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerCaseNestedType() {
|
||||
final TypeReference ref = new TypeReference("java.util", "Map.entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Map", "entry")), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void testGuessTypeRef() {
|
||||
final TypeReference ref = TypeReference.guessTypeRef("java.util.Map.Entry");
|
||||
Assert.assertEquals("java.util", ref.getPackageName());
|
||||
Assert.assertEquals("Entry", ref.getSimpleName());
|
||||
Assert.assertEquals(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Map", "Entry")), ref.getSimpleNames());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testIllegalTypeRef() {
|
||||
TypeReference.typeRef("java.util.Map.Entry");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaPath() {
|
||||
final TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("org/example/MyType.java", ref.getJavaPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXtendPath() {
|
||||
final TypeReference ref = TypeReference.typeRef("org.example.MyType");
|
||||
Assert.assertEquals("org/example/MyType.xtend", ref.getXtendPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEObject() {
|
||||
final ResourceSetImpl rs = new ResourceSetImpl();
|
||||
final TypeReference ref = new TypeReference(EcorePackage.Literals.EOBJECT, rs);
|
||||
Assert.assertEquals("org.eclipse.emf.ecore.EObject", ref.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug508810() {
|
||||
final ResourceSetImpl rs = new ResourceSetImpl();
|
||||
final TypeReference ref = new TypeReference(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY, rs);
|
||||
Assert.assertEquals("java.util.Map.Entry", ref.getName());
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -1,146 +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.generator.trace;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.generator.trace.AbstractTraceRegion;
|
||||
import org.eclipse.xtext.generator.trace.AbstractTraceRegionToString;
|
||||
import org.eclipse.xtext.generator.trace.ILocationData;
|
||||
import org.eclipse.xtext.generator.trace.LocationData;
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
|
||||
import org.eclipse.xtext.generator.trace.TraceRegion;
|
||||
import org.eclipse.xtext.util.ITextRegion;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public class TraceRegionToStringTester extends AbstractTraceRegionToString {
|
||||
public static class Location extends LocationData {
|
||||
public Location(final int offset, final int length, final SourceRelativeURI path) {
|
||||
super(offset, length, 0, 0, path);
|
||||
}
|
||||
|
||||
public Location(final int offset, final int length) {
|
||||
this(offset, length, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Region extends TraceRegion {
|
||||
public Region(final int myOffset, final int myLength, final Collection<ILocationData> allLocationData, final AbstractTraceRegion parent) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, parent);
|
||||
}
|
||||
|
||||
public Region(final int myOffset, final int myLength, final Collection<ILocationData> allLocationData) {
|
||||
super(myOffset, myLength, 0, 0, true, allLocationData, null);
|
||||
}
|
||||
|
||||
public TraceRegionToStringTester.Region addChild(final int myOffset, final int myLength, final List<ILocationData> allLocationData) {
|
||||
final TraceRegionToStringTester.Region child = new TraceRegionToStringTester.Region(myOffset, myLength, allLocationData, this);
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
private final SourceRelativeURI uri1 = new SourceRelativeURI("remote1");
|
||||
|
||||
private final SourceRelativeURI uri2 = new SourceRelativeURI("remote2");
|
||||
|
||||
private String localText;
|
||||
|
||||
private String remote1;
|
||||
|
||||
private String remote2;
|
||||
|
||||
private ITextRegion localFrame;
|
||||
|
||||
private TraceRegionToStringTester.Region trace;
|
||||
|
||||
public TraceRegionToStringTester() {
|
||||
this.setShowLegend(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRemoteText(final SourceRelativeURI uri) {
|
||||
String _switchResult = null;
|
||||
boolean _matched = false;
|
||||
if (Objects.equal(uri, this.uri1)) {
|
||||
_matched=true;
|
||||
_switchResult = this.remote1;
|
||||
}
|
||||
if (!_matched) {
|
||||
if (Objects.equal(uri, this.uri2)) {
|
||||
_matched=true;
|
||||
_switchResult = this.remote2;
|
||||
}
|
||||
}
|
||||
return _switchResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocalTitle() {
|
||||
return "local1";
|
||||
}
|
||||
|
||||
@Pure
|
||||
public SourceRelativeURI getUri1() {
|
||||
return this.uri1;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public SourceRelativeURI getUri2() {
|
||||
return this.uri2;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getLocalText() {
|
||||
return this.localText;
|
||||
}
|
||||
|
||||
public void setLocalText(final String localText) {
|
||||
this.localText = localText;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getRemote1() {
|
||||
return this.remote1;
|
||||
}
|
||||
|
||||
public void setRemote1(final String remote1) {
|
||||
this.remote1 = remote1;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getRemote2() {
|
||||
return this.remote2;
|
||||
}
|
||||
|
||||
public void setRemote2(final String remote2) {
|
||||
this.remote2 = remote2;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public ITextRegion getLocalFrame() {
|
||||
return this.localFrame;
|
||||
}
|
||||
|
||||
public void setLocalFrame(final ITextRegion localFrame) {
|
||||
this.localFrame = localFrame;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public TraceRegionToStringTester.Region getTrace() {
|
||||
return this.trace;
|
||||
}
|
||||
|
||||
public void setTrace(final TraceRegionToStringTester.Region trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2018 TypeFox (https://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.generator.trace.node;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.eclipse.xtext.generator.trace.LocationData;
|
||||
import org.eclipse.xtext.generator.trace.SourceRelativeURI;
|
||||
import org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode;
|
||||
import org.eclipse.xtext.generator.trace.node.GeneratorNodeExtensions;
|
||||
import org.eclipse.xtext.generator.trace.node.GeneratorNodeProcessor;
|
||||
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.StringExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.Timeout;
|
||||
|
||||
/**
|
||||
* @author Dennis Huebner - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class GeneratorNodePerformanceTest {
|
||||
@Extension
|
||||
private GeneratorNodeExtensions exts = new GeneratorNodeExtensions();
|
||||
|
||||
private static final int numberOfLines = 40_000;
|
||||
|
||||
@Rule
|
||||
public final Timeout timeout = new Timeout(1000, TimeUnit.MILLISECONDS);
|
||||
|
||||
@Test
|
||||
public void testBasicCreationAndProcessingPerformance() {
|
||||
final LocationData root = this.loc(0);
|
||||
CompositeGeneratorNode node = this.exts.appendNewLine(this.exts.append(this.exts.trace(root), "notindented"));
|
||||
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, GeneratorNodePerformanceTest.numberOfLines, true);
|
||||
for (final Integer i : _doubleDotLessThan) {
|
||||
this.exts.appendNewLine(this.exts.append(this.exts.indent(this.exts.appendNewLine(this.exts.append(this.exts.trace(this.exts.indent(node), this.loc(1)), "indented1"))), "indented2"));
|
||||
}
|
||||
this.exts.append(this.exts.appendNewLine(node), "dedented");
|
||||
final GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
|
||||
GeneratorNodeProcessor.Result _process = processor.process(node);
|
||||
String _string = null;
|
||||
if (_process!=null) {
|
||||
_string=_process.toString();
|
||||
}
|
||||
Assert.assertFalse(StringExtensions.isNullOrEmpty(_string));
|
||||
}
|
||||
|
||||
private LocationData loc(final int idx) {
|
||||
SourceRelativeURI _sourceRelativeURI = new SourceRelativeURI("foo/mymodel.dsl");
|
||||
return new LocationData(idx, (100 - idx), 0, 0, _sourceRelativeURI);
|
||||
}
|
||||
}
|
|
@ -1,154 +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.parser;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.parsetree.reconstr.SerializationErrorTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.parsetree.reconstr.serializationerror.Model;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.smoketest.processors.PartialParsingProcessor;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class Bug410560Test extends AbstractXtextTests {
|
||||
@Override
|
||||
public boolean shouldTestSerializer(final XtextResource resource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.with(SerializationErrorTestLanguageStandaloneSetup.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithoutIndent_01() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("{}");
|
||||
_builder.newLine();
|
||||
EObject _model = this.getModel(_builder.toString());
|
||||
final Model model = ((Model) _model);
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNull(model.getTest());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithoutIndent_02() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("({})");
|
||||
_builder.newLine();
|
||||
EObject _model = this.getModel(_builder.toString());
|
||||
final Model model = ((Model) _model);
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNull(model.getTest());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithIndent_01() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("{tworequired a b}");
|
||||
_builder.newLine();
|
||||
EObject _model = this.getModel(_builder.toString());
|
||||
final Model model = ((Model) _model);
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNotNull(model.getTest());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingWithIndent_02() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("({tworequired a b})");
|
||||
_builder.newLine();
|
||||
EObject _model = this.getModel(_builder.toString());
|
||||
final Model model = ((Model) _model);
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertNotNull(model.getTest());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingChangeIndent() {
|
||||
try {
|
||||
final String modelAsString = "({tworequired a b})";
|
||||
EObject _model = this.getModel(modelAsString);
|
||||
final Model model = ((Model) _model);
|
||||
Resource _eResource = model.eResource();
|
||||
final XtextResource res = ((XtextResource) _eResource);
|
||||
res.update(modelAsString.indexOf("a"), 1, "b");
|
||||
Assert.assertSame(model, IterableExtensions.<EObject>head(res.getContents()));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveIndent() {
|
||||
try {
|
||||
final String modelAsString = "({ tworequired a b })";
|
||||
EObject _model = this.getModel(modelAsString);
|
||||
final Model model = ((Model) _model);
|
||||
Resource _eResource = model.eResource();
|
||||
final XtextResource res = ((XtextResource) _eResource);
|
||||
res.update(modelAsString.indexOf("t"), "tworequired a b".length(), " ");
|
||||
Assert.assertSame(model, IterableExtensions.<EObject>head(res.getContents()));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveNestedIndent() {
|
||||
try {
|
||||
final String modelAsString = "({{ tworequired a b }})";
|
||||
EObject _model = this.getModel(modelAsString);
|
||||
final Model model = ((Model) _model);
|
||||
Resource _eResource = model.eResource();
|
||||
final XtextResource res = ((XtextResource) _eResource);
|
||||
res.update(modelAsString.indexOf("t"), "tworequired a b".length(), " ");
|
||||
Assert.assertSame(model, IterableExtensions.<EObject>head(res.getContents()));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialParsingRemoveNestedIndent_01() {
|
||||
try {
|
||||
final String modelAsString = "({{ tworequired a b }})";
|
||||
this.<PartialParsingProcessor>get(PartialParsingProcessor.class).processFile(modelAsString, modelAsString, modelAsString.indexOf("t"), "tworequired a b".length(), " ");
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* 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.
|
||||
|
|
|
@ -1,75 +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.resource.containers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.resource.containers.SourceFolder;
|
||||
import org.eclipse.xtext.util.UriUtil;
|
||||
import org.eclipse.xtext.workspace.IProjectConfig;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.workspace.IWorkspaceConfig;
|
||||
import org.eclipse.xtext.workspace.WorkspaceConfig;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
@Accessors(AccessorType.PUBLIC_GETTER)
|
||||
@SuppressWarnings("all")
|
||||
public class ProjectConfig implements IProjectConfig {
|
||||
private URI path;
|
||||
|
||||
private Set<SourceFolder> sourceFolders = CollectionLiterals.<SourceFolder>newHashSet();
|
||||
|
||||
private String name;
|
||||
|
||||
private IWorkspaceConfig workspaceConfig;
|
||||
|
||||
public ProjectConfig(final String name, final WorkspaceConfig workspaceConfig) {
|
||||
this.name = name;
|
||||
this.path = URI.createURI(new File(name).getAbsoluteFile().toURI().toString()).appendSegment("");
|
||||
URI _appendSegment = this.path.trimSegments(1).appendSegment("src").appendSegment("");
|
||||
SourceFolder _sourceFolder = new SourceFolder(_appendSegment);
|
||||
this.sourceFolders.add(_sourceFolder);
|
||||
this.workspaceConfig = workspaceConfig;
|
||||
workspaceConfig.addProject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceFolder findSourceFolderContaining(final URI member) {
|
||||
final Function1<SourceFolder, Boolean> _function = (SourceFolder it) -> {
|
||||
return Boolean.valueOf(UriUtil.isPrefixOf(this.path, member));
|
||||
};
|
||||
return IterableExtensions.<SourceFolder>findFirst(this.sourceFolders, _function);
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Set<SourceFolder> getSourceFolders() {
|
||||
return this.sourceFolders;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public IWorkspaceConfig getWorkspaceConfig() {
|
||||
return this.workspaceConfig;
|
||||
}
|
||||
}
|
|
@ -1,38 +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.resource.containers;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.workspace.ISourceFolder;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@Accessors(AccessorType.PUBLIC_GETTER)
|
||||
@SuppressWarnings("all")
|
||||
public class SourceFolder implements ISourceFolder {
|
||||
private final URI path;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "src";
|
||||
}
|
||||
|
||||
public SourceFolder(final URI path) {
|
||||
super();
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.GlobalRegistries;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.KeywordHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class KeywordHelperTest extends AbstractXtextTests {
|
||||
private GlobalRegistries.GlobalStateMemento globalStateMemento;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() {
|
||||
try {
|
||||
this.globalStateMemento = GlobalRegistries.makeCopyOfGlobalState();
|
||||
super.setUp();
|
||||
EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
|
||||
this.with(XtextStandaloneSetup.class);
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@Override
|
||||
public void tearDown() {
|
||||
try {
|
||||
super.tearDown();
|
||||
this.globalStateMemento.restoreGlobalState();
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToAntlrTokenIdentifier() {
|
||||
try {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("grammar org.eclipse.xtext.xbase.Xbase with org.eclipse.xtext.common.Terminals");
|
||||
_builder.newLine();
|
||||
_builder.append("import \"http://www.eclipse.org/emf/2002/Ecore\" as ecore");
|
||||
_builder.newLine();
|
||||
_builder.append("Model returns ecore::EClass : \"model\" \"/EOF\" \"EOF\" \"ÄÖÜäöüß\" name=ID;");
|
||||
_builder.newLine();
|
||||
final XtextResource resource = this.getResourceFromString(_builder.toString());
|
||||
EObject _head = IterableExtensions.<EObject>head(resource.getContents());
|
||||
final Grammar grammar = ((Grammar) _head);
|
||||
GrammarAccessExtensions _grammarAccessExtensions = new GrammarAccessExtensions();
|
||||
final KeywordHelper keywordHelper = new KeywordHelper(grammar, true, _grammarAccessExtensions);
|
||||
Assert.assertEquals("[/EOF, EOF, model, ÄÖÜäöüß]", IterableExtensions.<String>sort(keywordHelper.getAllKeywords()).toString());
|
||||
Assert.assertEquals("KW_EOF_1", keywordHelper.getRuleName("/EOF"));
|
||||
Assert.assertEquals("KW_EOF", keywordHelper.getRuleName("EOF"));
|
||||
Assert.assertEquals("Model", keywordHelper.getRuleName("model"));
|
||||
Assert.assertEquals("AeOeUeaeOeUe", keywordHelper.getRuleName("ÄÖÜäöüß"));
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getAsStream(final String model) {
|
||||
return this.getAsStream(model, StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2018 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.wizard.cli;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.eclipse.xtext.tests.TemporaryFolder;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Conversions;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xtext.wizard.cli.CliProjectsCreatorMain;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Karsten Thoms (karsten.thoms@itemis.de) - Initial contribution and API
|
||||
* @since 2.15
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class CliProjectsCreatorMainTest {
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void testCreateGreetingsGradleProject() {
|
||||
try {
|
||||
final File targetDir = this.temp.newFolder();
|
||||
String _absolutePath = targetDir.getAbsolutePath();
|
||||
String _plus = ("-targetDir=" + _absolutePath);
|
||||
final List<String> args = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_plus, "-languageName=org.xtext.example.mydsl.MyDsl", "-baseName=org.xtext.example.mydsl", "-extension=mydsl", "-enabledProjects=GenericIDE,RuntimeTest", "-buildSystem=GRADLE", "-sourceLayout=MAVEN", "-languageServer=FATJAR", "-xtextVersion=undefined", "-projectLayout=FLAT", "-javaVersion=JAVA10"));
|
||||
CliProjectsCreatorMain.main(((String[])Conversions.unwrapArray(args, String.class)));
|
||||
final List<String> files = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/GenerateMyDsl.mwe2", "org.xtext.example.mydsl/src/main/java/org/xtext/example/mydsl/MyDsl.xtext", "org.xtext.example.mydsl/build.gradle", "org.xtext.example.mydsl.ide/build.gradle", "org.xtext.example.mydsl.parent/build.gradle", "org.xtext.example.mydsl.parent/gradlew", "org.xtext.example.mydsl.parent/gradlew.bat", "org.xtext.example.mydsl.parent/settings.gradle", "org.xtext.example.mydsl.parent/gradle/source-layout.gradle", "org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.jar", "org.xtext.example.mydsl.parent/gradle/wrapper/gradle-wrapper.properties"));
|
||||
for (final String file : files) {
|
||||
Assert.assertTrue(new File(targetDir, file).exists());
|
||||
}
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
* 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.xtext.wizard;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
public class EPackageInfo {
|
||||
private final EPackage ePackage;
|
||||
|
||||
private final URI ePackageImportURI;
|
||||
|
||||
private final URI genmodelURI;
|
||||
|
||||
private final String ePackageJavaFQN;
|
||||
|
||||
private final String bundleID;
|
||||
|
||||
public EPackageInfo(EPackage ePackage, URI ePackageImportURI, URI genmodelURI, String ePackageJavaFQN,
|
||||
String bundleID) {
|
||||
this.ePackage = ePackage;
|
||||
this.ePackageImportURI = ePackageImportURI;
|
||||
this.genmodelURI = genmodelURI;
|
||||
this.ePackageJavaFQN = ePackageJavaFQN;
|
||||
this.bundleID = bundleID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((bundleID == null) ? 0 : bundleID.hashCode());
|
||||
result = prime * result + ((ePackage == null) ? 0 : ePackage.hashCode());
|
||||
result = prime * result + ((ePackageImportURI == null) ? 0 : ePackageImportURI.hashCode());
|
||||
result = prime * result + ((ePackageJavaFQN == null) ? 0 : ePackageJavaFQN.hashCode());
|
||||
result = prime * result + ((genmodelURI == null) ? 0 : genmodelURI.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
EPackageInfo other = (EPackageInfo) obj;
|
||||
if (bundleID == null) {
|
||||
if (other.bundleID != null)
|
||||
return false;
|
||||
} else if (!bundleID.equals(other.bundleID))
|
||||
return false;
|
||||
if (ePackage == null) {
|
||||
if (other.ePackage != null)
|
||||
return false;
|
||||
} else if (!ePackage.equals(other.ePackage))
|
||||
return false;
|
||||
if (ePackageImportURI == null) {
|
||||
if (other.ePackageImportURI != null)
|
||||
return false;
|
||||
} else if (!ePackageImportURI.equals(other.ePackageImportURI))
|
||||
return false;
|
||||
if (ePackageJavaFQN == null) {
|
||||
if (other.ePackageJavaFQN != null)
|
||||
return false;
|
||||
} else if (!ePackageJavaFQN.equals(other.ePackageJavaFQN))
|
||||
return false;
|
||||
if (genmodelURI == null) {
|
||||
if (other.genmodelURI != null)
|
||||
return false;
|
||||
} else if (!genmodelURI.equals(other.genmodelURI))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.add("ePackage", ePackage);
|
||||
b.add("ePackageImportURI", ePackageImportURI);
|
||||
b.add("genmodelURI", genmodelURI);
|
||||
b.add("ePackageJavaFQN", ePackageJavaFQN);
|
||||
b.add("bundleID", bundleID);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public EPackage getEPackage() {
|
||||
return ePackage;
|
||||
}
|
||||
|
||||
public URI getEPackageImportURI() {
|
||||
return ePackageImportURI;
|
||||
}
|
||||
|
||||
public URI getGenmodelURI() {
|
||||
return genmodelURI;
|
||||
}
|
||||
|
||||
public String getEPackageJavaFQN() {
|
||||
return ePackageJavaFQN;
|
||||
}
|
||||
|
||||
public String getBundleID() {
|
||||
return bundleID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* 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.xtext.wizard;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
|
||||
public class Ecore2XtextConfiguration {
|
||||
private final Set<EPackageInfo> ePackageInfos = new HashSet<>();
|
||||
|
||||
private EPackageInfo defaultEPackageInfo;
|
||||
|
||||
private EClass rootElementClass;
|
||||
|
||||
public Set<EPackageInfo> getEPackageInfos() {
|
||||
return ePackageInfos;
|
||||
}
|
||||
|
||||
public EPackageInfo getDefaultEPackageInfo() {
|
||||
return defaultEPackageInfo;
|
||||
}
|
||||
|
||||
public void setDefaultEPackageInfo(EPackageInfo defaultEPackageInfo) {
|
||||
this.defaultEPackageInfo = defaultEPackageInfo;
|
||||
}
|
||||
|
||||
public EClass getRootElementClass() {
|
||||
return rootElementClass;
|
||||
}
|
||||
|
||||
public void setRootElementClass(EClass rootElementClass) {
|
||||
this.rootElementClass = rootElementClass;
|
||||
}
|
||||
}
|
|
@ -1,32 +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.xtext.wizard
|
||||
|
||||
import java.util.Set
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.emf.ecore.EClass
|
||||
import org.eclipse.emf.ecore.EPackage
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
|
||||
@Accessors
|
||||
class Ecore2XtextConfiguration {
|
||||
val Set<EPackageInfo> ePackageInfos = newHashSet
|
||||
EPackageInfo defaultEPackageInfo
|
||||
EClass rootElementClass
|
||||
}
|
||||
|
||||
@Data
|
||||
class EPackageInfo {
|
||||
EPackage ePackage
|
||||
URI ePackageImportURI
|
||||
URI genmodelURI
|
||||
String ePackageJavaFQN
|
||||
String bundleID
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* 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.xtext.wizard;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RuntimeTestProjectDescriptor extends TestProjectDescriptor {
|
||||
|
||||
public RuntimeTestProjectDescriptor(TestedProjectDescriptor testedProject) {
|
||||
super(testedProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ExternalDependency> getExternalDependencies() {
|
||||
Set<ExternalDependency> deps = new LinkedHashSet<>();
|
||||
deps.addAll(super.getExternalDependencies());
|
||||
ExternalDependency xtextTesting = ExternalDependency.createXtextDependency("org.eclipse.xtext.testing");
|
||||
xtextTesting.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xtextTesting);
|
||||
ExternalDependency xbaseTesting = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.testing");
|
||||
xbaseTesting.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xbaseTesting);
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfGradleBuild() {
|
||||
return getConfig().getPreferredBuildSystem() == BuildSystem.GRADLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfMavenBuild() {
|
||||
return getConfig().getPreferredBuildSystem() == BuildSystem.MAVEN;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 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.xtext.wizard
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import static org.eclipse.xtext.xtext.wizard.ExternalDependency.*
|
||||
|
||||
@FinalFieldsConstructor
|
||||
class RuntimeTestProjectDescriptor extends TestProjectDescriptor {
|
||||
|
||||
override getExternalDependencies() {
|
||||
val deps = newLinkedHashSet
|
||||
deps += super.externalDependencies
|
||||
deps += createXtextDependency("org.eclipse.xtext.testing") => [maven.scope = Scope.TESTCOMPILE]
|
||||
deps += createXtextDependency("org.eclipse.xtext.xbase.testing") => [maven.scope = Scope.TESTCOMPILE]
|
||||
deps
|
||||
}
|
||||
|
||||
override isPartOfGradleBuild() {
|
||||
config.preferredBuildSystem == BuildSystem.GRADLE
|
||||
}
|
||||
|
||||
override isPartOfMavenBuild() {
|
||||
config.preferredBuildSystem == BuildSystem.MAVEN
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* 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.xtext.wizard;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.xtext.util.JUnitVersion;
|
||||
|
||||
public class UiTestProjectDescriptor extends TestProjectDescriptor {
|
||||
|
||||
public UiTestProjectDescriptor(TestedProjectDescriptor testedProject) {
|
||||
super(testedProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ExternalDependency> getExternalDependencies() {
|
||||
Set<ExternalDependency> deps = new LinkedHashSet<>();
|
||||
deps.addAll(super.getExternalDependencies());
|
||||
ExternalDependency xtextTesting = ExternalDependency.createXtextDependency("org.eclipse.xtext.testing");
|
||||
xtextTesting.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xtextTesting);
|
||||
ExternalDependency xbaseTesting = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.testing");
|
||||
xbaseTesting.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xbaseTesting);
|
||||
if (JUnitVersion.JUNIT_4 == getConfig().getJunitVersion()) {
|
||||
ExternalDependency xtextJunit4 = ExternalDependency.createXtextDependency("org.eclipse.xtext.junit4");
|
||||
xtextJunit4.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xtextJunit4);
|
||||
}
|
||||
ExternalDependency xbaseJunit = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.junit");
|
||||
xbaseJunit.getMaven().setScope(Scope.TESTCOMPILE);
|
||||
deps.add(xbaseJunit);
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfGradleBuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfMavenBuild() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsUiHarness() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,43 +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.xtext.wizard
|
||||
|
||||
import org.eclipse.xtext.xtext.wizard.TestProjectDescriptor
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import static org.eclipse.xtext.xtext.wizard.ExternalDependency.*
|
||||
import org.eclipse.xtext.util.JUnitVersion
|
||||
|
||||
@FinalFieldsConstructor
|
||||
class UiTestProjectDescriptor extends TestProjectDescriptor {
|
||||
|
||||
override getExternalDependencies() {
|
||||
val deps = newLinkedHashSet
|
||||
deps += super.externalDependencies
|
||||
deps += createXtextDependency("org.eclipse.xtext.testing") => [maven.scope = Scope.TESTCOMPILE]
|
||||
deps += createXtextDependency("org.eclipse.xtext.xbase.testing") => [maven.scope = Scope.TESTCOMPILE]
|
||||
if (config.junitVersion == JUnitVersion.JUNIT_4) {
|
||||
deps += createXtextDependency("org.eclipse.xtext.junit4") => [maven.scope = Scope.TESTCOMPILE]
|
||||
}
|
||||
deps += createXtextDependency("org.eclipse.xtext.xbase.junit") => [maven.scope = Scope.TESTCOMPILE]
|
||||
deps
|
||||
}
|
||||
|
||||
override isPartOfGradleBuild() {
|
||||
false
|
||||
}
|
||||
|
||||
override isPartOfMavenBuild() {
|
||||
true
|
||||
}
|
||||
|
||||
override needsUiHarness() {
|
||||
true
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +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.xtext.wizard;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.xtend.lib.annotations.Data;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
@Data
|
||||
@SuppressWarnings("all")
|
||||
public class EPackageInfo {
|
||||
private final EPackage ePackage;
|
||||
|
||||
private final URI ePackageImportURI;
|
||||
|
||||
private final URI genmodelURI;
|
||||
|
||||
private final String ePackageJavaFQN;
|
||||
|
||||
private final String bundleID;
|
||||
|
||||
public EPackageInfo(final EPackage ePackage, final URI ePackageImportURI, final URI genmodelURI, final String ePackageJavaFQN, final String bundleID) {
|
||||
super();
|
||||
this.ePackage = ePackage;
|
||||
this.ePackageImportURI = ePackageImportURI;
|
||||
this.genmodelURI = genmodelURI;
|
||||
this.ePackageJavaFQN = ePackageJavaFQN;
|
||||
this.bundleID = bundleID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.ePackage== null) ? 0 : this.ePackage.hashCode());
|
||||
result = prime * result + ((this.ePackageImportURI== null) ? 0 : this.ePackageImportURI.hashCode());
|
||||
result = prime * result + ((this.genmodelURI== null) ? 0 : this.genmodelURI.hashCode());
|
||||
result = prime * result + ((this.ePackageJavaFQN== null) ? 0 : this.ePackageJavaFQN.hashCode());
|
||||
return prime * result + ((this.bundleID== null) ? 0 : this.bundleID.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
EPackageInfo other = (EPackageInfo) obj;
|
||||
if (this.ePackage == null) {
|
||||
if (other.ePackage != null)
|
||||
return false;
|
||||
} else if (!this.ePackage.equals(other.ePackage))
|
||||
return false;
|
||||
if (this.ePackageImportURI == null) {
|
||||
if (other.ePackageImportURI != null)
|
||||
return false;
|
||||
} else if (!this.ePackageImportURI.equals(other.ePackageImportURI))
|
||||
return false;
|
||||
if (this.genmodelURI == null) {
|
||||
if (other.genmodelURI != null)
|
||||
return false;
|
||||
} else if (!this.genmodelURI.equals(other.genmodelURI))
|
||||
return false;
|
||||
if (this.ePackageJavaFQN == null) {
|
||||
if (other.ePackageJavaFQN != null)
|
||||
return false;
|
||||
} else if (!this.ePackageJavaFQN.equals(other.ePackageJavaFQN))
|
||||
return false;
|
||||
if (this.bundleID == null) {
|
||||
if (other.bundleID != null)
|
||||
return false;
|
||||
} else if (!this.bundleID.equals(other.bundleID))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Pure
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this);
|
||||
b.add("ePackage", this.ePackage);
|
||||
b.add("ePackageImportURI", this.ePackageImportURI);
|
||||
b.add("genmodelURI", this.genmodelURI);
|
||||
b.add("ePackageJavaFQN", this.ePackageJavaFQN);
|
||||
b.add("bundleID", this.bundleID);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
@Pure
|
||||
public EPackage getEPackage() {
|
||||
return this.ePackage;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getEPackageImportURI() {
|
||||
return this.ePackageImportURI;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public URI getGenmodelURI() {
|
||||
return this.genmodelURI;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getEPackageJavaFQN() {
|
||||
return this.ePackageJavaFQN;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getBundleID() {
|
||||
return this.bundleID;
|
||||
}
|
||||
}
|
|
@ -1,49 +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.xtext.wizard;
|
||||
|
||||
import java.util.Set;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xtext.wizard.EPackageInfo;
|
||||
|
||||
@Accessors
|
||||
@SuppressWarnings("all")
|
||||
public class Ecore2XtextConfiguration {
|
||||
private final Set<EPackageInfo> ePackageInfos = CollectionLiterals.<EPackageInfo>newHashSet();
|
||||
|
||||
private EPackageInfo defaultEPackageInfo;
|
||||
|
||||
private EClass rootElementClass;
|
||||
|
||||
@Pure
|
||||
public Set<EPackageInfo> getEPackageInfos() {
|
||||
return this.ePackageInfos;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public EPackageInfo getDefaultEPackageInfo() {
|
||||
return this.defaultEPackageInfo;
|
||||
}
|
||||
|
||||
public void setDefaultEPackageInfo(final EPackageInfo defaultEPackageInfo) {
|
||||
this.defaultEPackageInfo = defaultEPackageInfo;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public EClass getRootElementClass() {
|
||||
return this.rootElementClass;
|
||||
}
|
||||
|
||||
public void setRootElementClass(final EClass rootElementClass) {
|
||||
this.rootElementClass = rootElementClass;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 2016 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.xtext.wizard;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xtext.wizard.BuildSystem;
|
||||
import org.eclipse.xtext.xtext.wizard.ExternalDependency;
|
||||
import org.eclipse.xtext.xtext.wizard.Scope;
|
||||
import org.eclipse.xtext.xtext.wizard.TestProjectDescriptor;
|
||||
import org.eclipse.xtext.xtext.wizard.TestedProjectDescriptor;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class RuntimeTestProjectDescriptor extends TestProjectDescriptor {
|
||||
@Override
|
||||
public Set<ExternalDependency> getExternalDependencies() {
|
||||
LinkedHashSet<ExternalDependency> _xblockexpression = null;
|
||||
{
|
||||
final LinkedHashSet<ExternalDependency> deps = CollectionLiterals.<ExternalDependency>newLinkedHashSet();
|
||||
Set<ExternalDependency> _externalDependencies = super.getExternalDependencies();
|
||||
Iterables.<ExternalDependency>addAll(deps, _externalDependencies);
|
||||
ExternalDependency _createXtextDependency = ExternalDependency.createXtextDependency("org.eclipse.xtext.testing");
|
||||
final Procedure1<ExternalDependency> _function = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency, _function);
|
||||
deps.add(_doubleArrow);
|
||||
ExternalDependency _createXtextDependency_1 = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.testing");
|
||||
final Procedure1<ExternalDependency> _function_1 = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow_1 = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency_1, _function_1);
|
||||
deps.add(_doubleArrow_1);
|
||||
_xblockexpression = deps;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfGradleBuild() {
|
||||
BuildSystem _preferredBuildSystem = this.getConfig().getPreferredBuildSystem();
|
||||
return Objects.equal(_preferredBuildSystem, BuildSystem.GRADLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfMavenBuild() {
|
||||
BuildSystem _preferredBuildSystem = this.getConfig().getPreferredBuildSystem();
|
||||
return Objects.equal(_preferredBuildSystem, BuildSystem.MAVEN);
|
||||
}
|
||||
|
||||
public RuntimeTestProjectDescriptor(final TestedProjectDescriptor testedProject) {
|
||||
super(testedProject);
|
||||
}
|
||||
}
|
|
@ -1,90 +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.xtext.wizard;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
|
||||
import org.eclipse.xtext.util.JUnitVersion;
|
||||
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.eclipse.xtext.xtext.wizard.ExternalDependency;
|
||||
import org.eclipse.xtext.xtext.wizard.Scope;
|
||||
import org.eclipse.xtext.xtext.wizard.TestProjectDescriptor;
|
||||
import org.eclipse.xtext.xtext.wizard.TestedProjectDescriptor;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public class UiTestProjectDescriptor extends TestProjectDescriptor {
|
||||
@Override
|
||||
public Set<ExternalDependency> getExternalDependencies() {
|
||||
LinkedHashSet<ExternalDependency> _xblockexpression = null;
|
||||
{
|
||||
final LinkedHashSet<ExternalDependency> deps = CollectionLiterals.<ExternalDependency>newLinkedHashSet();
|
||||
Set<ExternalDependency> _externalDependencies = super.getExternalDependencies();
|
||||
Iterables.<ExternalDependency>addAll(deps, _externalDependencies);
|
||||
ExternalDependency _createXtextDependency = ExternalDependency.createXtextDependency("org.eclipse.xtext.testing");
|
||||
final Procedure1<ExternalDependency> _function = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency, _function);
|
||||
deps.add(_doubleArrow);
|
||||
ExternalDependency _createXtextDependency_1 = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.testing");
|
||||
final Procedure1<ExternalDependency> _function_1 = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow_1 = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency_1, _function_1);
|
||||
deps.add(_doubleArrow_1);
|
||||
JUnitVersion _junitVersion = this.getConfig().getJunitVersion();
|
||||
boolean _equals = Objects.equal(_junitVersion, JUnitVersion.JUNIT_4);
|
||||
if (_equals) {
|
||||
ExternalDependency _createXtextDependency_2 = ExternalDependency.createXtextDependency("org.eclipse.xtext.junit4");
|
||||
final Procedure1<ExternalDependency> _function_2 = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow_2 = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency_2, _function_2);
|
||||
deps.add(_doubleArrow_2);
|
||||
}
|
||||
ExternalDependency _createXtextDependency_3 = ExternalDependency.createXtextDependency("org.eclipse.xtext.xbase.junit");
|
||||
final Procedure1<ExternalDependency> _function_3 = (ExternalDependency it) -> {
|
||||
ExternalDependency.MavenCoordinates _maven = it.getMaven();
|
||||
_maven.setScope(Scope.TESTCOMPILE);
|
||||
};
|
||||
ExternalDependency _doubleArrow_3 = ObjectExtensions.<ExternalDependency>operator_doubleArrow(_createXtextDependency_3, _function_3);
|
||||
deps.add(_doubleArrow_3);
|
||||
_xblockexpression = deps;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfGradleBuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPartOfMavenBuild() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsUiHarness() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public UiTestProjectDescriptor(final TestedProjectDescriptor testedProject) {
|
||||
super(testedProject);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue