mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
[eclipse/xtext#1777] ported xtend code to java
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
ab13977486
commit
b4c4be04fa
9 changed files with 250 additions and 491 deletions
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* 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.formatting2.internal;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument;
|
||||
import org.eclipse.xtext.formatting2.IFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.FormattertestlanguageFactory;
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList;
|
||||
import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider;
|
||||
import org.eclipse.xtext.resource.IResourceFactory;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(FormatterSerializerIntegrationTest.InjectorProvider.class)
|
||||
public class FormatterSerializerIntegrationTest {
|
||||
public static class InjectorProvider extends FormatterTestLanguageInjectorProvider {
|
||||
@Override
|
||||
protected Injector internalCreateInjector() {
|
||||
return new Setup().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Setup extends FormatterTestLanguageStandaloneSetup {
|
||||
@Override
|
||||
public Injector createInjector() {
|
||||
return Guice.createInjector(new Module());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Module extends FormatterTestLanguageRuntimeModule {
|
||||
public Class<? extends IFormatter2> bindIFormatter2() {
|
||||
return Formatter.class;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Formatter extends AbstractFormatter2 {
|
||||
protected void _format(IDList model, @Extension IFormattableDocument document) {
|
||||
document.append(this.textRegionExtensions.regionFor(model).keyword("idlist"),
|
||||
(IHiddenRegionFormatter it) -> {
|
||||
it.setSpace(" ");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void format(Object model, IFormattableDocument document) {
|
||||
if (model instanceof XtextResource) {
|
||||
_format((XtextResource) model, document);
|
||||
return;
|
||||
} else if (model instanceof IDList) {
|
||||
_format((IDList) model, document);
|
||||
return;
|
||||
} else if (model instanceof EObject) {
|
||||
_format((EObject) model, document);
|
||||
return;
|
||||
} else if (model == null) {
|
||||
_format((Void) null, document);
|
||||
return;
|
||||
} else {
|
||||
_format(model, document);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private IResourceFactory factory;
|
||||
|
||||
@Test
|
||||
public void testFormatterIntegrationWithSerializer() throws IOException {
|
||||
Resource resource = factory.createResource(URI.createURI("dummy.ext"));
|
||||
new ResourceSetImpl().getResources().add(resource);
|
||||
IDList model = FormattertestlanguageFactory.eINSTANCE.createIDList();
|
||||
model.getIds().add("foo");
|
||||
resource.getContents().add(model);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
resource.save(new BufferedOutputStream(out), Collections.emptyMap());
|
||||
Assert.assertEquals("idlist foo", out.toString());
|
||||
}
|
||||
}
|
|
@ -1,74 +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.formatting2.internal
|
||||
|
||||
import com.google.inject.Guice
|
||||
import com.google.inject.Inject
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.Collections
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument
|
||||
import org.eclipse.xtext.formatting2.IFormatter2
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.FormattertestlanguageFactory
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList
|
||||
import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider
|
||||
import org.eclipse.xtext.resource.IResourceFactory
|
||||
import org.eclipse.xtext.testing.InjectWith
|
||||
import org.eclipse.xtext.testing.XtextRunner
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner)
|
||||
@InjectWith(InjectorProvider)
|
||||
class FormatterSerializerIntegrationTest {
|
||||
static class InjectorProvider extends FormatterTestLanguageInjectorProvider {
|
||||
override protected internalCreateInjector() {
|
||||
new Setup().createInjectorAndDoEMFRegistration()
|
||||
}
|
||||
}
|
||||
|
||||
static class Setup extends FormatterTestLanguageStandaloneSetup {
|
||||
override createInjector() {
|
||||
return Guice.createInjector(new Module());
|
||||
}
|
||||
}
|
||||
|
||||
static class Module extends FormatterTestLanguageRuntimeModule {
|
||||
def Class<? extends IFormatter2> bindIFormatter2() {
|
||||
return Formatter;
|
||||
}
|
||||
}
|
||||
|
||||
static class Formatter extends AbstractFormatter2 {
|
||||
def dispatch format(IDList model, extension IFormattableDocument document) {
|
||||
model.regionFor.keyword("idlist").append[space = " "]
|
||||
}
|
||||
}
|
||||
|
||||
@Inject IResourceFactory factory;
|
||||
|
||||
@Test def void testFormatterIntegrationWithSerializer() {
|
||||
val resource = factory.createResource(URI.createURI("dummy.ext"))
|
||||
new ResourceSetImpl().resources.add(resource)
|
||||
val model = FormattertestlanguageFactory.eINSTANCE.createIDList
|
||||
model.ids += "foo"
|
||||
resource.contents += model
|
||||
val out = new ByteArrayOutputStream
|
||||
resource.save(new BufferedOutputStream(out), Collections.emptyMap)
|
||||
Assert.assertEquals('idlist foo', out.toString)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,123 +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.formatting2.internal;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.xtext.formatting2.AbstractFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IFormattableDocument;
|
||||
import org.eclipse.xtext.formatting2.IFormatter2;
|
||||
import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
|
||||
import org.eclipse.xtext.formatting2.internal.FormatterTestLanguageRuntimeModule;
|
||||
import org.eclipse.xtext.formatting2.internal.FormatterTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.FormattertestlanguageFactory;
|
||||
import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList;
|
||||
import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider;
|
||||
import org.eclipse.xtext.resource.IResourceFactory;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.testing.InjectWith;
|
||||
import org.eclipse.xtext.testing.XtextRunner;
|
||||
import org.eclipse.xtext.xbase.lib.Exceptions;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* @author Moritz Eysholdt - Initial contribution and API
|
||||
*/
|
||||
@RunWith(XtextRunner.class)
|
||||
@InjectWith(FormatterSerializerIntegrationTest.InjectorProvider.class)
|
||||
@SuppressWarnings("all")
|
||||
public class FormatterSerializerIntegrationTest {
|
||||
public static class InjectorProvider extends FormatterTestLanguageInjectorProvider {
|
||||
@Override
|
||||
protected Injector internalCreateInjector() {
|
||||
return new FormatterSerializerIntegrationTest.Setup().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Setup extends FormatterTestLanguageStandaloneSetup {
|
||||
@Override
|
||||
public Injector createInjector() {
|
||||
FormatterSerializerIntegrationTest.Module _module = new FormatterSerializerIntegrationTest.Module();
|
||||
return Guice.createInjector(_module);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Module extends FormatterTestLanguageRuntimeModule {
|
||||
public Class<? extends IFormatter2> bindIFormatter2() {
|
||||
return FormatterSerializerIntegrationTest.Formatter.class;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Formatter extends AbstractFormatter2 {
|
||||
protected void _format(final IDList model, @Extension final IFormattableDocument document) {
|
||||
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
|
||||
it.setSpace(" ");
|
||||
};
|
||||
document.append(this.textRegionExtensions.regionFor(model).keyword("idlist"), _function);
|
||||
}
|
||||
|
||||
public void format(final Object model, final IFormattableDocument document) {
|
||||
if (model instanceof XtextResource) {
|
||||
_format((XtextResource)model, document);
|
||||
return;
|
||||
} else if (model instanceof IDList) {
|
||||
_format((IDList)model, document);
|
||||
return;
|
||||
} else if (model instanceof EObject) {
|
||||
_format((EObject)model, document);
|
||||
return;
|
||||
} else if (model == null) {
|
||||
_format((Void)null, document);
|
||||
return;
|
||||
} else if (model != null) {
|
||||
_format(model, document);
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unhandled parameter types: " +
|
||||
Arrays.<Object>asList(model, document).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private IResourceFactory factory;
|
||||
|
||||
@Test
|
||||
public void testFormatterIntegrationWithSerializer() {
|
||||
try {
|
||||
final Resource resource = this.factory.createResource(URI.createURI("dummy.ext"));
|
||||
new ResourceSetImpl().getResources().add(resource);
|
||||
final IDList model = FormattertestlanguageFactory.eINSTANCE.createIDList();
|
||||
EList<String> _ids = model.getIds();
|
||||
_ids.add("foo");
|
||||
EList<EObject> _contents = resource.getContents();
|
||||
_contents.add(model);
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
BufferedOutputStream _bufferedOutputStream = new BufferedOutputStream(out);
|
||||
resource.save(_bufferedOutputStream, Collections.<Object, Object>emptyMap());
|
||||
Assert.assertEquals("idlist foo", out.toString());
|
||||
} catch (Throwable _e) {
|
||||
throw Exceptions.sneakyThrow(_e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* 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.generator.model.project;
|
||||
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Configuration of the runtime project, i.e. the main subproject containing the
|
||||
* language definition.
|
||||
*
|
||||
* @noextend This class should not be extended by clients.
|
||||
*/
|
||||
public class RuntimeProjectConfig extends BundleProjectConfig implements IRuntimeProjectConfig {
|
||||
private String ecoreModelPath;
|
||||
|
||||
private IXtextGeneratorFileSystemAccess ecoreModel;
|
||||
|
||||
public void setEcoreModel(String path) {
|
||||
this.ecoreModelPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root-relative path of the folder where the generated .ecore
|
||||
* and .genmodel can be found. The path is delimited by '/', but does not
|
||||
* begin or end with a separator.
|
||||
*/
|
||||
@Override
|
||||
public String getEcoreModelFolder() {
|
||||
String rootPath = getRoot().getPath();
|
||||
String ecoreModelPath = ecoreModel.getPath();
|
||||
if (ecoreModelPath.startsWith(rootPath)) {
|
||||
String relativePath = ecoreModelPath.substring(rootPath.length())
|
||||
.replace("\\", "/");
|
||||
return CharMatcher.is('/').trimFrom(relativePath);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Could not derive the Ecore model folder from the project configuration.\n");
|
||||
builder.append("Please make sure that 'root' is a prefix of 'ecoreModel'.\n");
|
||||
builder.append("was (root='").append(rootPath).append("', ecoreModel='").append(ecoreModelPath).append("')");
|
||||
throw new RuntimeException(builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final Injector injector) {
|
||||
super.initialize(injector);
|
||||
if (ecoreModelPath != null) {
|
||||
ecoreModel = getOwner().newFileSystemAccess(ecoreModelPath, true);
|
||||
ecoreModel.initialize(injector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXbaseLibVersionLowerBound() {
|
||||
return "2.14.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXtendLibVersionLowerBound() {
|
||||
return getXbaseLibVersionLowerBound();
|
||||
}
|
||||
|
||||
public String getEcoreModelPath() {
|
||||
return ecoreModelPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IXtextGeneratorFileSystemAccess getEcoreModel() {
|
||||
return ecoreModel;
|
||||
}
|
||||
}
|
|
@ -1,64 +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.generator.model.project
|
||||
|
||||
import com.google.common.base.CharMatcher
|
||||
import com.google.inject.Injector
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess
|
||||
|
||||
/**
|
||||
* Configuration of the runtime project, i.e. the main subproject containing the language definition.
|
||||
*
|
||||
* @noextend This class should not be extended by clients.
|
||||
*/
|
||||
class RuntimeProjectConfig extends BundleProjectConfig implements IRuntimeProjectConfig {
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
String ecoreModelPath
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
IXtextGeneratorFileSystemAccess ecoreModel
|
||||
|
||||
def void setEcoreModel(String path) {
|
||||
ecoreModelPath = path
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root-relative path of the folder where the generated .ecore and .genmodel can be found.
|
||||
* The path is delimited by '/', but does not begin or end with a separator.
|
||||
*/
|
||||
override String getEcoreModelFolder() {
|
||||
if (ecoreModel.path.startsWith(root.path)) {
|
||||
val relativePath = ecoreModel.path.substring(root.path.length).replace('\\', '/')
|
||||
return CharMatcher.is('/').trimFrom(relativePath)
|
||||
}
|
||||
throw new RuntimeException('''
|
||||
Could not derive the Ecore model folder from the project configuration.
|
||||
Please make sure that 'root' is a prefix of 'ecoreModel'.
|
||||
was (root='«root.path»', ecoreModel='«ecoreModel.path»')
|
||||
|
||||
''')
|
||||
}
|
||||
|
||||
override initialize(Injector injector) {
|
||||
super.initialize(injector)
|
||||
if (ecoreModelPath !== null) {
|
||||
ecoreModel = owner.newFileSystemAccess(ecoreModelPath, true)
|
||||
ecoreModel.initialize(injector)
|
||||
}
|
||||
}
|
||||
|
||||
override getXbaseLibVersionLowerBound() {
|
||||
"2.14.0"
|
||||
}
|
||||
|
||||
override getXtendLibVersionLowerBound() {
|
||||
return getXbaseLibVersionLowerBound()
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +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.generator.model.project;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.inject.Injector;
|
||||
import org.eclipse.xtend.lib.annotations.AccessorType;
|
||||
import org.eclipse.xtend.lib.annotations.Accessors;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.xbase.lib.Pure;
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.project.BundleProjectConfig;
|
||||
import org.eclipse.xtext.xtext.generator.model.project.IRuntimeProjectConfig;
|
||||
|
||||
/**
|
||||
* Configuration of the runtime project, i.e. the main subproject containing the language definition.
|
||||
*
|
||||
* @noextend This class should not be extended by clients.
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class RuntimeProjectConfig extends BundleProjectConfig implements IRuntimeProjectConfig {
|
||||
@Accessors(AccessorType.PUBLIC_GETTER)
|
||||
private String ecoreModelPath;
|
||||
|
||||
@Accessors(AccessorType.PUBLIC_GETTER)
|
||||
private IXtextGeneratorFileSystemAccess ecoreModel;
|
||||
|
||||
public void setEcoreModel(final String path) {
|
||||
this.ecoreModelPath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root-relative path of the folder where the generated .ecore and .genmodel can be found.
|
||||
* The path is delimited by '/', but does not begin or end with a separator.
|
||||
*/
|
||||
@Override
|
||||
public String getEcoreModelFolder() {
|
||||
boolean _startsWith = this.ecoreModel.getPath().startsWith(this.getRoot().getPath());
|
||||
if (_startsWith) {
|
||||
final String relativePath = this.ecoreModel.getPath().substring(this.getRoot().getPath().length()).replace("\\", "/");
|
||||
return CharMatcher.is('/').trimFrom(relativePath);
|
||||
}
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
_builder.append("Could not derive the Ecore model folder from the project configuration. ");
|
||||
_builder.newLine();
|
||||
_builder.append("Please make sure that \'root\' is a prefix of \'ecoreModel\'.");
|
||||
_builder.newLine();
|
||||
_builder.append("was (root=\'");
|
||||
String _path = this.getRoot().getPath();
|
||||
_builder.append(_path);
|
||||
_builder.append("\', ecoreModel=\'");
|
||||
String _path_1 = this.ecoreModel.getPath();
|
||||
_builder.append(_path_1);
|
||||
_builder.append("\')");
|
||||
_builder.newLineIfNotEmpty();
|
||||
_builder.newLine();
|
||||
throw new RuntimeException(_builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final Injector injector) {
|
||||
super.initialize(injector);
|
||||
if ((this.ecoreModelPath != null)) {
|
||||
this.ecoreModel = this.getOwner().newFileSystemAccess(this.ecoreModelPath, true);
|
||||
this.ecoreModel.initialize(injector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXbaseLibVersionLowerBound() {
|
||||
return "2.14.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getXtendLibVersionLowerBound() {
|
||||
return this.getXbaseLibVersionLowerBound();
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getEcoreModelPath() {
|
||||
return this.ecoreModelPath;
|
||||
}
|
||||
|
||||
@Pure
|
||||
@Override
|
||||
public IXtextGeneratorFileSystemAccess getEcoreModel() {
|
||||
return this.ecoreModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public abstract class TestedProjectDescriptor extends ProjectDescriptor {
|
||||
public abstract TestProjectDescriptor getTestProject();
|
||||
|
||||
public TestedProjectDescriptor(final WizardConfiguration config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ExternalDependency> getExternalDependencies() {
|
||||
Set<ExternalDependency> deps = new LinkedHashSet<>();
|
||||
Iterables.addAll(deps, super.getExternalDependencies());
|
||||
if (getTestProject().isInlined()) {
|
||||
Iterables.addAll(deps, getTestProject().getExternalDependencies());
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SourceFolderDescriptor> getSourceFolders() {
|
||||
Set<SourceFolderDescriptor> sourceFolders = new LinkedHashSet<>();
|
||||
Iterables.addAll(sourceFolders, super.getSourceFolders());
|
||||
if (getTestProject().isInlined()) {
|
||||
Iterables.addAll(sourceFolders, getTestProject().getSourceFolders());
|
||||
}
|
||||
return sourceFolders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends AbstractFile> getFiles() {
|
||||
List<AbstractFile> files = new ArrayList<>();
|
||||
Iterables.addAll(files, super.getFiles());
|
||||
if (getTestProject().isInlined()) {
|
||||
Iterable<? extends AbstractFile> filtered = IterableExtensions.filter(getTestProject().getFiles(),
|
||||
(AbstractFile fileFromTestProject) -> files.stream()
|
||||
.noneMatch(f -> Objects.equal(f.getRelativePath(), fileFromTestProject.getRelativePath())));
|
||||
Iterables.addAll(files, filtered);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 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
|
||||
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
|
||||
@FinalFieldsConstructor
|
||||
abstract class TestedProjectDescriptor extends ProjectDescriptor {
|
||||
def TestProjectDescriptor getTestProject()
|
||||
|
||||
override getExternalDependencies() {
|
||||
val deps = newLinkedHashSet
|
||||
deps += super.externalDependencies
|
||||
if (testProject.isInlined)
|
||||
deps += testProject.externalDependencies
|
||||
deps
|
||||
}
|
||||
|
||||
override getSourceFolders() {
|
||||
val sourceFolders = newLinkedHashSet
|
||||
sourceFolders += super.sourceFolders
|
||||
if (testProject.isInlined)
|
||||
sourceFolders += testProject.sourceFolders
|
||||
sourceFolders
|
||||
}
|
||||
|
||||
override getFiles() {
|
||||
val files = newArrayList
|
||||
files += super.files
|
||||
if (testProject.isInlined)
|
||||
files += testProject.files.filter[fileFromTestProject| !files.exists[relativePath == fileFromTestProject.relativePath]]
|
||||
files
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015, 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;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.ArrayList;
|
||||
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.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.wizard.AbstractFile;
|
||||
import org.eclipse.xtext.xtext.wizard.ExternalDependency;
|
||||
import org.eclipse.xtext.xtext.wizard.ProjectDescriptor;
|
||||
import org.eclipse.xtext.xtext.wizard.SourceFolderDescriptor;
|
||||
import org.eclipse.xtext.xtext.wizard.TestProjectDescriptor;
|
||||
import org.eclipse.xtext.xtext.wizard.WizardConfiguration;
|
||||
|
||||
@FinalFieldsConstructor
|
||||
@SuppressWarnings("all")
|
||||
public abstract class TestedProjectDescriptor extends ProjectDescriptor {
|
||||
public abstract TestProjectDescriptor getTestProject();
|
||||
|
||||
@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);
|
||||
boolean _isInlined = this.getTestProject().isInlined();
|
||||
if (_isInlined) {
|
||||
Set<ExternalDependency> _externalDependencies_1 = this.getTestProject().getExternalDependencies();
|
||||
Iterables.<ExternalDependency>addAll(deps, _externalDependencies_1);
|
||||
}
|
||||
_xblockexpression = deps;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SourceFolderDescriptor> getSourceFolders() {
|
||||
LinkedHashSet<SourceFolderDescriptor> _xblockexpression = null;
|
||||
{
|
||||
final LinkedHashSet<SourceFolderDescriptor> sourceFolders = CollectionLiterals.<SourceFolderDescriptor>newLinkedHashSet();
|
||||
Set<SourceFolderDescriptor> _sourceFolders = super.getSourceFolders();
|
||||
Iterables.<SourceFolderDescriptor>addAll(sourceFolders, _sourceFolders);
|
||||
boolean _isInlined = this.getTestProject().isInlined();
|
||||
if (_isInlined) {
|
||||
Set<SourceFolderDescriptor> _sourceFolders_1 = this.getTestProject().getSourceFolders();
|
||||
Iterables.<SourceFolderDescriptor>addAll(sourceFolders, _sourceFolders_1);
|
||||
}
|
||||
_xblockexpression = sourceFolders;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends AbstractFile> getFiles() {
|
||||
ArrayList<AbstractFile> _xblockexpression = null;
|
||||
{
|
||||
final ArrayList<AbstractFile> files = CollectionLiterals.<AbstractFile>newArrayList();
|
||||
Iterable<? extends AbstractFile> _files = super.getFiles();
|
||||
Iterables.<AbstractFile>addAll(files, _files);
|
||||
boolean _isInlined = this.getTestProject().isInlined();
|
||||
if (_isInlined) {
|
||||
final Function1<AbstractFile, Boolean> _function = (AbstractFile fileFromTestProject) -> {
|
||||
final Function1<AbstractFile, Boolean> _function_1 = (AbstractFile it) -> {
|
||||
String _relativePath = it.getRelativePath();
|
||||
String _relativePath_1 = fileFromTestProject.getRelativePath();
|
||||
return Boolean.valueOf(Objects.equal(_relativePath, _relativePath_1));
|
||||
};
|
||||
boolean _exists = IterableExtensions.<AbstractFile>exists(files, _function_1);
|
||||
return Boolean.valueOf((!_exists));
|
||||
};
|
||||
Iterable<? extends AbstractFile> _filter = IterableExtensions.filter(this.getTestProject().getFiles(), _function);
|
||||
Iterables.<AbstractFile>addAll(files, _filter);
|
||||
}
|
||||
_xblockexpression = files;
|
||||
}
|
||||
return _xblockexpression;
|
||||
}
|
||||
|
||||
public TestedProjectDescriptor(final WizardConfiguration config) {
|
||||
super(config);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue