diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java new file mode 100644 index 000000000..cd1bd25cf --- /dev/null +++ b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.xtext.ide.serializer.hooks.IReferenceUpdaterContext; +import org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference; +import org.eclipse.xtext.ide.serializer.impl.EObjectDescriptionDeltaProvider; +import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater; +import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import; +import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node; +import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.PartialSerializationTestLanguageFactory; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.xbase.lib.IterableExtensions; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; + +/** + * @author Moritz Eysholdt - Initial contribution and API + */ +public class PartialSerializationTestLanguageReferenceUpdater extends ReferenceUpdater { + @Inject + private IQualifiedNameConverter converter; + + @Override + public void update(IReferenceUpdaterContext context) { + super.update(context); + Node node = IterableExtensions.head(Iterables.filter(context.getResource().getContents(), Node.class)); + if (node == null) { + return; + } + Set toDelete = new HashSet<>(); + Set toAdd = new HashSet<>(); + Map toChange = new HashMap<>(); + Map imports = IterableExtensions.toMap(node.getImports(), + (Import it) -> converter.toQualifiedName(it.getImportedNamespace())); + for (IUpdatableReference target : context.getUpdatableReferences()) { + EObjectDescriptionDeltaProvider.Delta delta = this + .findContainingDelta(context.getEObjectDescriptionDeltas(), target.getTargetEObject()); + if (delta != null) { + QualifiedName original = IterableExtensions + .head(delta.getSnapshot().getDescriptions()).getQualifiedName(); + QualifiedName modified = IterableExtensions.head(delta.getDescriptions()) + .getQualifiedName(); + if (!Objects.equal(original, modified)) { + Import imp = imports.get(original); + if (imp != null) { + toChange.put(imp, modified); + } + } + } + } + context.modifyModel(() -> { + for (Import toDel : toDelete) { + EcoreUtil.remove(toDel); + } + for (Map.Entry toCh : toChange.entrySet()) { + Import imp = toCh.getKey(); + QualifiedName name = toCh.getValue(); + imp.setImportedNamespace(converter.toString(name)); + } + for (QualifiedName toA : toAdd) { + Import newImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport(); + newImport.setImportedNamespace(converter.toString(toA)); + node.getImports().add(newImport); + } + }); + } +} diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.xtend b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.xtend deleted file mode 100644 index ce0feda21..000000000 --- a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.xtend +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer - -import com.google.inject.Inject -import org.eclipse.emf.ecore.util.EcoreUtil -import org.eclipse.xtext.ide.serializer.hooks.IReferenceUpdaterContext -import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.PartialSerializationTestLanguageFactory -import org.eclipse.xtext.naming.IQualifiedNameConverter -import org.eclipse.xtext.naming.QualifiedName - -/** - * @author Moritz Eysholdt - Initial contribution and API - */ -class PartialSerializationTestLanguageReferenceUpdater extends ReferenceUpdater { - - @Inject IQualifiedNameConverter converter - - override update(IReferenceUpdaterContext context) { - super.update(context) - val node = context.resource.contents.filter(Node).head - if (node === null) { - return - } - val toDelete = newHashSet - val toAdd = newHashSet - val toChange = newHashMap() - val imports = node.imports.toMap[converter.toQualifiedName(importedNamespace)] - - for (target : context.updatableReferences) { - val delta = context.EObjectDescriptionDeltas.findContainingDelta(target.targetEObject) - if (delta !== null) { - val original = delta.snapshot.descriptions.head.qualifiedName - val modified = delta.descriptions.head.qualifiedName - if (original != modified) { - val imp = imports.get(original) - if (imp !== null) { - toChange.put(imp, modified) - } - } - } - } - context.modifyModel [ - for (toDel : toDelete) { - EcoreUtil.remove(toDel) - } - for (toCh : toChange.entrySet) { - val imp = toCh.key - val name = toCh.value - imp.importedNamespace = converter.toString(name) - } - for (toA : toAdd) { - node.imports += PartialSerializationTestLanguageFactory.eINSTANCE.createImport => [ - importedNamespace = converter.toString(toA) - ] - } - ] - } -} diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java new file mode 100644 index 000000000..390de8ce5 --- /dev/null +++ b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2019, 2020 TypeFox (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer; + +import com.google.inject.Inject; +import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; +import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder; +import org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference; +import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.scoping.IScope; +import org.eclipse.xtext.scoping.IScopeProvider; +import org.eclipse.xtext.serializer.tokens.SerializerScopeProviderBinding; + +/** + * Customized reference updater to handle FQN renaming gracefully. + * + *

+ * When renaming {@code Foo} to {@code Bar}, it follows the default logic, but + * when renaming {@code my.type.Foo} to {@code Bar}, it will result in + * {@code my.type.Bar} instead of {@code Bar}. + */ +public class TestLanguageReferenceUpdater extends ReferenceUpdater { + @Inject + private IQualifiedNameConverter nameConverter; + + @Inject + @SerializerScopeProviderBinding + private IScopeProvider scopeProvider; + + @Override + public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference ref) { + if (rewriter.isModified(ref.getReferenceRegion())) { + return; + } + IScope scope = scopeProvider.getScope(ref.getSourceEObject(), ref.getEReference()); + ISemanticRegion region = ref.getReferenceRegion(); + QualifiedName oldName = nameConverter.toQualifiedName(region.getText()); + IEObjectDescription oldDesc = scope.getSingleElement(oldName); + if (oldDesc != null && oldDesc.getEObjectOrProxy() == ref.getTargetEObject()) { + return; + } + String newName = findValidName(ref, scope); + if (newName != null) { + if (oldName.getSegmentCount() > 1) { + newName = oldName.skipLast(1).append(newName).toString(); + } + rewriter.replace(region, newName); + } + } +} diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.xtend b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.xtend deleted file mode 100644 index 76cb247f9..000000000 --- a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.xtend +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 TypeFox (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer - -import com.google.inject.Inject -import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder -import org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference -import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater -import org.eclipse.xtext.naming.IQualifiedNameConverter -import org.eclipse.xtext.scoping.IScopeProvider -import org.eclipse.xtext.serializer.tokens.SerializerScopeProviderBinding - -/** - * Customized reference updater to handle FQN renaming gracefully. - * - *

- * When renaming {@code Foo} to {@code Bar}, it follows the default logic, - * but when renaming {@code my.type.Foo} to {@code Bar}, it will result - * in {@code my.type.Bar} instead of {@code Bar}. - */ -class TestLanguageReferenceUpdater extends ReferenceUpdater { - - @Inject - IQualifiedNameConverter nameConverter; - - @Inject - @SerializerScopeProviderBinding - IScopeProvider scopeProvider; - - override void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference it) { - if (rewriter.isModified(referenceRegion)) { - return; - } - val scope = scopeProvider.getScope(sourceEObject, EReference); - val region = referenceRegion; - val oldName = nameConverter.toQualifiedName(region.text); - val oldDesc = scope.getSingleElement(oldName); - if (oldDesc !== null && oldDesc.EObjectOrProxy === targetEObject) { - return; - } - var newName = findValidName(it, scope); - if (newName !== null) { - // Check if the original was a FQN. If so, "rename" the last segment only. - if (oldName.segmentCount > 1) { - newName = oldName.skipLast(1).append(newName).toString; - } - rewriter.replace(region, newName); - } - } - -} diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java new file mode 100644 index 000000000..8ca08481c --- /dev/null +++ b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.tests.testlanguage.ide.server; + +import java.util.List; + +import org.eclipse.lsp4j.CodeLens; +import org.eclipse.lsp4j.CodeLensParams; +import org.eclipse.lsp4j.Command; +import org.eclipse.lsp4j.Position; +import org.eclipse.xtext.ide.server.Document; +import org.eclipse.xtext.ide.server.codelens.ICodeLensResolver; +import org.eclipse.xtext.ide.server.codelens.ICodeLensService; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.util.CancelIndicator; + +import com.google.common.collect.Lists; + +/** + * @author Sven Efftinge - Initial contribution and API + */ +public class CodeLensService implements ICodeLensService, ICodeLensResolver { + @Override + public List computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, + CancelIndicator indicator) { + CodeLens codeLens = new CodeLens(); + Command command = new Command(); + command.setCommand("do.this"); + command.setTitle("Do Awesome Stuff"); + command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true))); + codeLens.setCommand(command); + Position _position = new Position(1, 2); + codeLens.setData(_position); + return Lists.newArrayList(codeLens); + } + + @Override + public CodeLens resolveCodeLens(Document document, XtextResource resource, CodeLens codeLens, + CancelIndicator indicator) { + codeLens.getCommand().setTitle(codeLens.getCommand().getTitle() + "(RESOLVED)"); + return codeLens; + } +} diff --git a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.xtend b/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.xtend deleted file mode 100644 index 4238a2bc9..000000000 --- a/org.eclipse.xtext.ide.tests/testlang-src/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.xtend +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.tests.testlanguage.ide.server - -import org.eclipse.xtext.ide.server.codelens.ICodeLensService -import org.eclipse.xtext.ide.server.codelens.ICodeLensResolver -import org.eclipse.xtext.ide.server.Document -import org.eclipse.xtext.resource.XtextResource -import org.eclipse.lsp4j.CodeLensParams -import org.eclipse.xtext.util.CancelIndicator -import org.eclipse.lsp4j.CodeLens -import org.eclipse.lsp4j.Command -import org.eclipse.lsp4j.Position - -/** - * @author Sven Efftinge - Initial contribution and API - */ -class CodeLensService implements ICodeLensService, ICodeLensResolver { - - override computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, CancelIndicator indicator) { - return #[new CodeLens() => [ - command = new Command() => [ - command = "do.this" - title = "Do Awesome Stuff" - arguments = #[ - 'foo', - 1, - true - ] - ] - data = new Position(1,2) - ]] - } - - override resolveCodeLens(Document document, XtextResource resource, CodeLens codeLens, CancelIndicator indicator) { - codeLens.command.title = codeLens.command.title + "(RESOLVED)" - return codeLens - } - -} diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java deleted file mode 100644 index 232e63150..000000000 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/PartialSerializationTestLanguageReferenceUpdater.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.xtext.ide.serializer.hooks.IReferenceUpdaterContext; -import org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference; -import org.eclipse.xtext.ide.serializer.impl.EObjectDescriptionDeltaProvider; -import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater; -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Import; -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node; -import org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.PartialSerializationTestLanguageFactory; -import org.eclipse.xtext.naming.IQualifiedNameConverter; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.IEObjectDescription; -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.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -/** - * @author Moritz Eysholdt - Initial contribution and API - */ -@SuppressWarnings("all") -public class PartialSerializationTestLanguageReferenceUpdater extends ReferenceUpdater { - @Inject - private IQualifiedNameConverter converter; - - @Override - public void update(final IReferenceUpdaterContext context) { - super.update(context); - final Node node = IterableExtensions.head(Iterables.filter(context.getResource().getContents(), Node.class)); - if ((node == null)) { - return; - } - final HashSet toDelete = CollectionLiterals.newHashSet(); - final HashSet toAdd = CollectionLiterals.newHashSet(); - final HashMap toChange = CollectionLiterals.newHashMap(); - final Function1 _function = (Import it) -> { - return this.converter.toQualifiedName(it.getImportedNamespace()); - }; - final Map imports = IterableExtensions.toMap(node.getImports(), _function); - List _updatableReferences = context.getUpdatableReferences(); - for (final IUpdatableReference target : _updatableReferences) { - { - final EObjectDescriptionDeltaProvider.Delta delta = this.findContainingDelta(context.getEObjectDescriptionDeltas(), target.getTargetEObject()); - if ((delta != null)) { - final QualifiedName original = IterableExtensions.head(delta.getSnapshot().getDescriptions()).getQualifiedName(); - final QualifiedName modified = IterableExtensions.head(delta.getDescriptions()).getQualifiedName(); - boolean _notEquals = (!Objects.equal(original, modified)); - if (_notEquals) { - final Import imp = imports.get(original); - if ((imp != null)) { - toChange.put(imp, modified); - } - } - } - } - } - final Runnable _function_1 = () -> { - for (final Import toDel : toDelete) { - EcoreUtil.remove(toDel); - } - Set> _entrySet = toChange.entrySet(); - for (final Map.Entry toCh : _entrySet) { - { - final Import imp = toCh.getKey(); - final QualifiedName name = toCh.getValue(); - imp.setImportedNamespace(this.converter.toString(name)); - } - } - for (final QualifiedName toA : toAdd) { - EList _imports = node.getImports(); - Import _createImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport(); - final Procedure1 _function_2 = (Import it) -> { - it.setImportedNamespace(this.converter.toString(toA)); - }; - Import _doubleArrow = ObjectExtensions.operator_doubleArrow(_createImport, _function_2); - _imports.add(_doubleArrow); - } - }; - context.modifyModel(_function_1); - } -} diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java deleted file mode 100644 index 6357d528c..000000000 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/serializer/TestLanguageReferenceUpdater.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2019 TypeFox (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.tests.testlanguage.ide.serializer; - -import com.google.inject.Inject; -import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; -import org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder; -import org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference; -import org.eclipse.xtext.ide.serializer.impl.ReferenceUpdater; -import org.eclipse.xtext.naming.IQualifiedNameConverter; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.scoping.IScope; -import org.eclipse.xtext.scoping.IScopeProvider; -import org.eclipse.xtext.serializer.tokens.SerializerScopeProviderBinding; - -/** - * Customized reference updater to handle FQN renaming gracefully. - * - *

- * When renaming {@code Foo} to {@code Bar}, it follows the default logic, - * but when renaming {@code my.type.Foo} to {@code Bar}, it will result - * in {@code my.type.Bar} instead of {@code Bar}. - */ -@SuppressWarnings("all") -public class TestLanguageReferenceUpdater extends ReferenceUpdater { - @Inject - private IQualifiedNameConverter nameConverter; - - @Inject - @SerializerScopeProviderBinding - private IScopeProvider scopeProvider; - - @Override - public void updateReference(final ITextRegionDiffBuilder rewriter, final IUpdatableReference it) { - boolean _isModified = rewriter.isModified(it.getReferenceRegion()); - if (_isModified) { - return; - } - final IScope scope = this.scopeProvider.getScope(it.getSourceEObject(), it.getEReference()); - final ISemanticRegion region = it.getReferenceRegion(); - final QualifiedName oldName = this.nameConverter.toQualifiedName(region.getText()); - final IEObjectDescription oldDesc = scope.getSingleElement(oldName); - if (((oldDesc != null) && (oldDesc.getEObjectOrProxy() == it.getTargetEObject()))) { - return; - } - String newName = this.findValidName(it, scope); - if ((newName != null)) { - int _segmentCount = oldName.getSegmentCount(); - boolean _greaterThan = (_segmentCount > 1); - if (_greaterThan) { - newName = oldName.skipLast(1).append(newName).toString(); - } - rewriter.replace(region, newName); - } - } -} diff --git a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java b/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java deleted file mode 100644 index 2c2409d4b..000000000 --- a/org.eclipse.xtext.ide.tests/xtend-gen/org/eclipse/xtext/ide/tests/testlanguage/ide/server/CodeLensService.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.tests.testlanguage.ide.server; - -import java.util.Collections; -import java.util.List; -import org.eclipse.lsp4j.CodeLens; -import org.eclipse.lsp4j.CodeLensParams; -import org.eclipse.lsp4j.Command; -import org.eclipse.lsp4j.Position; -import org.eclipse.xtext.ide.server.Document; -import org.eclipse.xtext.ide.server.codelens.ICodeLensResolver; -import org.eclipse.xtext.ide.server.codelens.ICodeLensService; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -/** - * @author Sven Efftinge - Initial contribution and API - */ -@SuppressWarnings("all") -public class CodeLensService implements ICodeLensService, ICodeLensResolver { - @Override - public List computeCodeLenses(final Document document, final XtextResource resource, final CodeLensParams params, final CancelIndicator indicator) { - CodeLens _codeLens = new CodeLens(); - final Procedure1 _function = (CodeLens it) -> { - Command _command = new Command(); - final Procedure1 _function_1 = (Command it_1) -> { - it_1.setCommand("do.this"); - it_1.setTitle("Do Awesome Stuff"); - it_1.setArguments(Collections.unmodifiableList(CollectionLiterals.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)))); - }; - Command _doubleArrow = ObjectExtensions.operator_doubleArrow(_command, _function_1); - it.setCommand(_doubleArrow); - Position _position = new Position(1, 2); - it.setData(_position); - }; - CodeLens _doubleArrow = ObjectExtensions.operator_doubleArrow(_codeLens, _function); - return Collections.unmodifiableList(CollectionLiterals.newArrayList(_doubleArrow)); - } - - @Override - public CodeLens resolveCodeLens(final Document document, final XtextResource resource, final CodeLens codeLens, final CancelIndicator indicator) { - Command _command = codeLens.getCommand(); - String _title = codeLens.getCommand().getTitle(); - String _plus = (_title + "(RESOLVED)"); - _command.setTitle(_plus); - return codeLens; - } -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java new file mode 100644 index 000000000..62ec790aa --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java @@ -0,0 +1,145 @@ +/** + * Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.editor.hierarchy; + +import javax.inject.Provider; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.findReferences.IReferenceFinder; +import org.eclipse.xtext.findReferences.TargetURICollector; +import org.eclipse.xtext.findReferences.TargetURIs; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.util.concurrent.IUnitOfWork; +import org.eclipse.xtext.xbase.lib.IterableExtensions; + +import com.google.common.base.Objects; +import com.google.inject.Inject; + +/** + * @author kosyakov - Initial contribution and API + * @since 2.10 + */ +public abstract class AbstractHierarchyBuilder implements IHierarchyBuilder { + private IReferenceFinder.IResourceAccess resourceAccess; + + private IResourceDescriptions indexData; + + @Inject + private IReferenceFinder referenceFinder; + + @Inject + private TargetURICollector targetURICollector; + + @Inject + private Provider targetURIProvider; + + @Inject + private IHierarchyNodeLocationProvider hierarchyNodeLocationProvider; + + @Inject + private IResourceServiceProvider.Registry resourceServiceProviderRegistry; + + protected R readOnly(URI objectURI, IUnitOfWork work) { + return getResourceAccess().readOnly(objectURI, (ResourceSet resourceSet) -> { + EObject targetObject = resourceSet.getEObject(objectURI, true); + return work.exec(targetObject); + }); + } + + protected IEObjectDescription getDescription(URI objectURI) { + IResourceDescription resourceDescription = getIndexData().getResourceDescription(objectURI.trimFragment()); + if (resourceDescription == null) { + return null; + } + for (IEObjectDescription o : resourceDescription.getExportedObjects()) { + if (Objects.equal(o.getEObjectURI(), objectURI)) { + return o; + } + } + return null; + } + + protected IEObjectDescription getDescription(EObject object) { + if (object == null) { + return null; + } + return IterableExtensions.head(getIndexData().getExportedObjectsByObject(object)); + } + + protected boolean isAssignable(EClass superType, EClassifier type) { + if (type instanceof EClass) { + return EcoreUtil2.isAssignableFrom(superType, ((EClass) type)); + } + return false; + } + + protected IReferenceFinder.IResourceAccess getResourceAccess() { + return resourceAccess; + } + + public void setResourceAccess(IReferenceFinder.IResourceAccess resourceAccess) { + this.resourceAccess = resourceAccess; + } + + protected IResourceDescriptions getIndexData() { + return indexData; + } + + public void setIndexData(IResourceDescriptions indexData) { + this.indexData = indexData; + } + + protected IReferenceFinder getReferenceFinder() { + return referenceFinder; + } + + public void setReferenceFinder(IReferenceFinder referenceFinder) { + this.referenceFinder = referenceFinder; + } + + protected TargetURICollector getTargetURICollector() { + return targetURICollector; + } + + public void setTargetURICollector(TargetURICollector targetURICollector) { + this.targetURICollector = targetURICollector; + } + + protected Provider getTargetURIProvider() { + return targetURIProvider; + } + + public void setTargetURIProvider(Provider targetURIProvider) { + this.targetURIProvider = targetURIProvider; + } + + protected IHierarchyNodeLocationProvider getHierarchyNodeLocationProvider() { + return hierarchyNodeLocationProvider; + } + + public void setHierarchyNodeLocationProvider(IHierarchyNodeLocationProvider hierarchyNodeLocationProvider) { + this.hierarchyNodeLocationProvider = hierarchyNodeLocationProvider; + } + + protected IResourceServiceProvider.Registry getResourceServiceProviderRegistry() { + return resourceServiceProviderRegistry; + } + + public void setResourceServiceProviderRegistry(IResourceServiceProvider.Registry resourceServiceProviderRegistry) { + this.resourceServiceProviderRegistry = resourceServiceProviderRegistry; + } +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.xtend deleted file mode 100644 index e58194760..000000000 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.xtend +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.editor.hierarchy - -import com.google.inject.Inject -import javax.inject.Provider -import org.eclipse.emf.common.util.URI -import org.eclipse.emf.ecore.EClass -import org.eclipse.emf.ecore.EClassifier -import org.eclipse.emf.ecore.EObject -import org.eclipse.xtend.lib.annotations.Accessors -import org.eclipse.xtext.findReferences.IReferenceFinder -import org.eclipse.xtext.findReferences.IReferenceFinder.IResourceAccess -import org.eclipse.xtext.findReferences.TargetURICollector -import org.eclipse.xtext.findReferences.TargetURIs -import org.eclipse.xtext.resource.IEObjectDescription -import org.eclipse.xtext.resource.IResourceDescriptions -import org.eclipse.xtext.resource.IResourceServiceProvider -import org.eclipse.xtext.util.concurrent.IUnitOfWork - -import static extension org.eclipse.xtext.EcoreUtil2.* - -/** - * @author kosyakov - Initial contribution and API - * @since 2.10 - */ -@Accessors(PUBLIC_SETTER, PROTECTED_GETTER) -abstract class AbstractHierarchyBuilder implements IHierarchyBuilder { - - IResourceAccess resourceAccess - - IResourceDescriptions indexData - - @Inject - IReferenceFinder referenceFinder - - @Inject - TargetURICollector targetURICollector - - @Inject - Provider targetURIProvider - - @Inject - IHierarchyNodeLocationProvider hierarchyNodeLocationProvider - - @Inject - IResourceServiceProvider.Registry resourceServiceProviderRegistry - - protected def R readOnly(URI objectURI, IUnitOfWork work) { - return getResourceAccess.readOnly(objectURI) [ resourceSet | - val targetObject = resourceSet.getEObject(objectURI, true) - return work.exec(targetObject) - ] - } - - protected def IEObjectDescription getDescription(URI objectURI) { - val resourceDescription = getIndexData.getResourceDescription(objectURI.trimFragment) - if(resourceDescription === null) return null - - return resourceDescription.exportedObjects.findFirst[EObjectURI == objectURI] - } - - protected def IEObjectDescription getDescription(EObject object) { - if(object === null) return null - return getIndexData.getExportedObjectsByObject(object).head - } - - protected def isAssignable(EClass superType, EClassifier type) { - if (type instanceof EClass) - return superType.isAssignableFrom(type) - return false - } - -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java new file mode 100644 index 000000000..b6dce20a0 --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.editor.hierarchy; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNodeLocationProvider; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.resource.ILocationInFileProvider; +import org.eclipse.xtext.util.ITextRegion; +import org.eclipse.xtext.util.ITextRegionWithLineInformation; +import org.eclipse.xtext.util.TextRegionWithLineInformation; + +/** + * @author kosyakov - Initial contribution and API + * @since 2.10 + */ +@Singleton +public class DefaultHierarchyNodeLocationProvider implements IHierarchyNodeLocationProvider { + @Inject + protected ILocationInFileProvider locationInFileProvider; + + @Override + public ITextRegionWithLineInformation getTextRegion(EObject obj) { + if (obj == null) { + return ITextRegionWithLineInformation.EMPTY_REGION; + } + ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(obj); + return toTextRegionWithLineInformation(obj, textRegion); + } + + @Override + public ITextRegionWithLineInformation getTextRegion(EObject owner, EStructuralFeature feature, int indexInList) { + if (owner == null) { + return ITextRegionWithLineInformation.EMPTY_REGION; + } + ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList); + return toTextRegionWithLineInformation(owner, textRegion); + } + + protected ITextRegionWithLineInformation toTextRegionWithLineInformation(EObject obj, ITextRegion textRegion) { + if (textRegion == null) { + return ITextRegionWithLineInformation.EMPTY_REGION; + } + if (textRegion instanceof ITextRegionWithLineInformation) { + return (ITextRegionWithLineInformation) textRegion; + } + ICompositeNode node = NodeModelUtils.getNode(obj); + if (node == null) { + return new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), 0, 0); + } + int startLine = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine() - 1; + int endLine = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset() + textRegion.getLength()).getLine() + - 1; + return new TextRegionWithLineInformation(textRegion.getOffset(), textRegion.getLength(), startLine, endLine); + } +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.xtend deleted file mode 100644 index 2ba5bf932..000000000 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.xtend +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.editor.hierarchy - -import com.google.inject.Inject -import com.google.inject.Singleton -import org.eclipse.emf.ecore.EObject -import org.eclipse.emf.ecore.EStructuralFeature -import org.eclipse.xtext.resource.ILocationInFileProvider -import org.eclipse.xtext.util.ITextRegion -import org.eclipse.xtext.util.ITextRegionWithLineInformation -import org.eclipse.xtext.util.TextRegionWithLineInformation - -import static extension org.eclipse.xtext.nodemodel.util.NodeModelUtils.* - -/** - * @author kosyakov - Initial contribution and API - * @since 2.10 - */ -@Singleton -class DefaultHierarchyNodeLocationProvider implements IHierarchyNodeLocationProvider { - - @Inject - protected ILocationInFileProvider locationInFileProvider - - override getTextRegion(EObject obj) { - if(obj === null) return ITextRegionWithLineInformation.EMPTY_REGION - - val textRegion = locationInFileProvider.getSignificantTextRegion(obj) - return obj.toTextRegionWithLineInformation(textRegion) - } - - override getTextRegion(EObject owner, EStructuralFeature feature, int indexInList) { - if(owner === null) return ITextRegionWithLineInformation.EMPTY_REGION - - val textRegion = locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList) - return owner.toTextRegionWithLineInformation(textRegion) - } - - protected def toTextRegionWithLineInformation(EObject obj, ITextRegion textRegion) { - if (textRegion === null) - return ITextRegionWithLineInformation.EMPTY_REGION - - if (textRegion instanceof ITextRegionWithLineInformation) - return textRegion - - val node = obj.node - if (node === null) { - return new TextRegionWithLineInformation(textRegion.offset, textRegion.length, 0, 0) - } - val startLine = node.getLineAndColumn(textRegion.offset).line - 1 - val endLine = node.getLineAndColumn(textRegion.offset + textRegion.length).line - 1 - return new TextRegionWithLineInformation(textRegion.offset, textRegion.length, startLine, endLine) - } - -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java new file mode 100644 index 000000000..bc07f956d --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java @@ -0,0 +1,49 @@ +/** + * 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.ide.editor.syntaxcoloring; + +import com.google.inject.Singleton; +import java.util.regex.Pattern; +import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper; +import org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles; + +/** + * @author Anton Kosyakov + * @since 2.9 + */ +@Singleton +public class DefaultAntlrTokenToAttributeIdMapper extends AbstractAntlrTokenToAttributeIdMapper { + private static final Pattern QUOTED = Pattern.compile("(?:^\'([^\']*)\'$)|(?:^\"([^\"]*)\")$", Pattern.MULTILINE); + + private static final Pattern PUNCTUATION = Pattern.compile("\\p{Punct}*"); + + @Override + protected String calculateId(final String tokenName, final int tokenType) { + if (tokenName == null) { + return HighlightingStyles.DEFAULT_ID; + } + if (DefaultAntlrTokenToAttributeIdMapper.PUNCTUATION.matcher(tokenName).matches()) { + return HighlightingStyles.PUNCTUATION_ID; + } + if (DefaultAntlrTokenToAttributeIdMapper.QUOTED.matcher(tokenName).matches()) { + return HighlightingStyles.KEYWORD_ID; + } + switch (tokenName) { + case "RULE_STRING": + return HighlightingStyles.STRING_ID; + case "RULE_INT": + return HighlightingStyles.NUMBER_ID; + case "RULE_ML_COMMENT": + case "RULE_SL_COMMENT": + return HighlightingStyles.COMMENT_ID; + default: + return HighlightingStyles.DEFAULT_ID; + } + } +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.xtend deleted file mode 100644 index 7d620c435..000000000 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.xtend +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2014, 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.ide.editor.syntaxcoloring - -import com.google.inject.Singleton -import java.util.regex.Pattern - -/** - * @author Anton Kosyakov - * @since 2.9 - */ -@Singleton -class DefaultAntlrTokenToAttributeIdMapper extends AbstractAntlrTokenToAttributeIdMapper { - - static val QUOTED = Pattern.compile("(?:^'([^']*)'$)|(?:^\"([^\"]*)\")$", Pattern.MULTILINE) - - static val PUNCTUATION = Pattern.compile("\\p{Punct}*") - - override protected calculateId(String tokenName, int tokenType) { - switch tokenName { - case PUNCTUATION.matcher(tokenName).matches: - HighlightingStyles.PUNCTUATION_ID - case QUOTED.matcher(tokenName).matches: - HighlightingStyles.KEYWORD_ID - case "RULE_STRING": - HighlightingStyles.STRING_ID - case "RULE_INT": - HighlightingStyles.NUMBER_ID - case "RULE_ML_COMMENT", - case "RULE_SL_COMMENT": - HighlightingStyles.COMMENT_ID - default: - HighlightingStyles.DEFAULT_ID - } - } - -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java new file mode 100644 index 000000000..2ae227f8f --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java @@ -0,0 +1,112 @@ +/** + * Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.refactoring; + +import java.io.IOException; +import java.util.List; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.ide.serializer.IChangeSerializer; +import org.eclipse.xtext.xbase.lib.Exceptions; + +/** + * @author koehnlein - Initial contribution and API + * @since 2.13 + */ +public class ResourceRelocationContext { + public enum ChangeType { + COPY, MOVE, RENAME; + } + + private final ResourceRelocationContext.ChangeType changeType; + + private final List changes; + + private final RefactoringIssueAcceptor issueAcceptor; + + private final IChangeSerializer changeSerializer; + + private final ResourceSet resourceSet; + + /** + * Loads and watches the respective resource, applies the relocation change and calls the given + * modification with the renamed/moved/copied resource. + * + * @param change + * the change to execute + * @param modification + * the side-effect the rename/move/copy operation should have. + */ + public void addModification(ResourceRelocationChange change, + IChangeSerializer.IModification modification) { + changeSerializer.addModification(loadAndWatchResource(change), modification); + } + + /** + * Loads and watches the respective resource and applies the relocation change. Clients may usually rather call + * {@link #addModification} to register their side-effects. + * + * @param change + * the change to execute + */ + protected Resource loadAndWatchResource(ResourceRelocationChange change) { + if (changeType != null) { + switch (changeType) { + case MOVE: + case RENAME: + Resource original = resourceSet.getResource(change.getFromURI(), true); + changeSerializer.addModification(original, (Resource it) -> original.setURI(change.getToURI())); + return original; + case COPY: + Resource copy = resourceSet.createResource(change.getFromURI()); + try { + copy.load(resourceSet.getURIConverter().createInputStream(change.getFromURI()), null); + } catch (IOException e) { + Exceptions.sneakyThrow(e); + } + copy.setURI(change.getToURI()); + return copy; + default: + return null; + } + } + return null; + } + + public ResourceRelocationContext(ResourceRelocationContext.ChangeType changeType, + List changes, RefactoringIssueAcceptor issueAcceptor, + IChangeSerializer changeSerializer, ResourceSet resourceSet) { + this.changeType = changeType; + this.changes = changes; + this.issueAcceptor = issueAcceptor; + this.changeSerializer = changeSerializer; + this.resourceSet = resourceSet; + } + + public ResourceRelocationContext.ChangeType getChangeType() { + return changeType; + } + + public List getChanges() { + return changes; + } + + public RefactoringIssueAcceptor getIssueAcceptor() { + return issueAcceptor; + } + + public IChangeSerializer getChangeSerializer() { + return changeSerializer; + } + + public ResourceSet getResourceSet() { + return resourceSet; + } +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.xtend deleted file mode 100644 index 223b85c4d..000000000 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.xtend +++ /dev/null @@ -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.ide.refactoring - -import java.util.List -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.emf.ecore.resource.ResourceSet -import org.eclipse.xtend.lib.annotations.Accessors -import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor -import org.eclipse.xtext.ide.serializer.IChangeSerializer - -/** - * @author koehnlein - Initial contribution and API - * @since 2.13 - */ -@FinalFieldsConstructor -@Accessors(PUBLIC_GETTER) -class ResourceRelocationContext { - - val ChangeType changeType - val List changes - val RefactoringIssueAcceptor issueAcceptor - - val IChangeSerializer changeSerializer - val ResourceSet resourceSet - - enum ChangeType { - COPY, - MOVE, - RENAME - } - - /** - * Loads and watches the respective resource, applies the relocation change and - * calls the given modification with the renamed/moved/copied resource. - * - * @param change the change to execute - * @param modification the side-effect the rename/move/copy operation should have. - */ - def void addModification(ResourceRelocationChange change, IChangeSerializer.IModification modification) { - changeSerializer.addModification(loadAndWatchResource(change), modification) - } - - /** - * Loads and watches the respective resource and applies the relocation change. - * Clients may usually rather call {@link #addModification} to register their - * side-effects. - * - * @param change the change to execute - */ - protected def Resource loadAndWatchResource(ResourceRelocationChange change) { - val resource = switch changeType { - case MOVE, - case RENAME: { - val original = resourceSet.getResource(change.fromURI, true) - changeSerializer.addModification(original)[original.URI = change.toURI] - original - } - case COPY: { - val copy = resourceSet.createResource(change.fromURI) - copy.load(resourceSet.URIConverter.createInputStream(change.fromURI), null) - copy.URI = change.toURI - copy - } - } - return resource - } -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LaunchArgs.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LaunchArgs.java new file mode 100644 index 000000000..9fe3f6cf9 --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LaunchArgs.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2016, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.server; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; + +public class LaunchArgs { + private InputStream in; + + private OutputStream out; + + private PrintWriter trace; + + private boolean validate; + + public InputStream getIn() { + return in; + } + + public void setIn(InputStream in) { + this.in = in; + } + + public OutputStream getOut() { + return out; + } + + public void setOut(OutputStream out) { + this.out = out; + } + + public PrintWriter getTrace() { + return trace; + } + + public void setTrace(PrintWriter trace) { + this.trace = trace; + } + + public boolean isValidate() { + return validate; + } + + public void setValidate(boolean validate) { + this.validate = validate; + } +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerLauncher.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerLauncher.xtend index 8e83aba95..19d3a9887 100644 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerLauncher.xtend +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerLauncher.xtend @@ -20,7 +20,6 @@ import java.io.PrintStream import java.io.PrintWriter import org.eclipse.lsp4j.jsonrpc.Launcher import org.eclipse.lsp4j.services.LanguageClient -import org.eclipse.xtend.lib.annotations.Accessors /** * @author Sven Efftinge - Initial contribution and API @@ -130,11 +129,3 @@ class ServerLauncher { } } - -@Accessors -class LaunchArgs { - InputStream in - OutputStream out - PrintWriter trace - boolean validate -} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java new file mode 100644 index 000000000..ecc1209d3 --- /dev/null +++ b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java @@ -0,0 +1,122 @@ +/** + * Copyright (c) 2017, 2020 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.ide.server.commands; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.apache.log4j.Logger; +import org.eclipse.lsp4j.ClientCapabilities; +import org.eclipse.lsp4j.ExecuteCommandCapabilities; +import org.eclipse.lsp4j.ExecuteCommandOptions; +import org.eclipse.lsp4j.ExecuteCommandParams; +import org.eclipse.lsp4j.Registration; +import org.eclipse.lsp4j.RegistrationParams; +import org.eclipse.lsp4j.Unregistration; +import org.eclipse.lsp4j.UnregistrationParams; +import org.eclipse.lsp4j.WorkspaceClientCapabilities; +import org.eclipse.lsp4j.services.LanguageClient; +import org.eclipse.xtext.ide.server.ILanguageServerAccess; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.util.CancelIndicator; +import org.eclipse.xtext.util.IDisposable; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; + +/** + * @author Sven Efftinge - Initial contribution and API + */ +public class ExecutableCommandRegistry { + + private static final Logger LOG = Logger.getLogger(ExecutableCommandRegistry.class); + private static final String METHOD = "workspace/executeCommand"; + + private Multimap registeredCommands; + + private LanguageClient client; + + public void initialize(Iterable allLanguages, ClientCapabilities capabilities, + LanguageClient client) { + this.client = client; + this.registeredCommands = HashMultimap.create(); + boolean hasDynamicRegistration = false; + WorkspaceClientCapabilities workspace = capabilities.getWorkspace(); + if (workspace != null) { + ExecuteCommandCapabilities executeCommandCapabilities = workspace.getExecuteCommand(); + if (executeCommandCapabilities != null) { + Boolean dynamicRegistration = executeCommandCapabilities.getDynamicRegistration(); + if (dynamicRegistration != null) { + hasDynamicRegistration = dynamicRegistration.booleanValue(); + } + } + } + for (IResourceServiceProvider lang : allLanguages) { + IExecutableCommandService service = lang.get(IExecutableCommandService.class); + if (service != null) { + List commands = service.initialize(); + for (String c : commands) { + registeredCommands.put(c, service); + } + if (hasDynamicRegistration) { + service.initializeDynamicRegistration((String command) -> { + return register(command, service); + }); + } + } + } + } + + protected IDisposable register(String command, IExecutableCommandService service) { + String requestId = UUID.randomUUID().toString(); + Registration reg = new Registration(); + reg.setId(requestId); + reg.setMethod(ExecutableCommandRegistry.METHOD); + ExecuteCommandOptions executeCommandOptions = new ExecuteCommandOptions(); + executeCommandOptions.setCommands(Collections.unmodifiableList(Lists.newArrayList(command))); + reg.setRegisterOptions(executeCommandOptions); + RegistrationParams registrationParams = new RegistrationParams(); + registrationParams.setRegistrations(Lists.newArrayList(reg)); + client.registerCapability(registrationParams); + registeredCommands.put(command, service); + return () -> { + Unregistration unReg = new Unregistration(); + unReg.setId(requestId); + unReg.setMethod(ExecutableCommandRegistry.METHOD); + UnregistrationParams unregistrationParams = new UnregistrationParams(); + unregistrationParams.setUnregisterations(Lists.newArrayList(unReg)); + this.client.unregisterCapability(unregistrationParams); + this.registeredCommands.remove(command, service); + }; + } + + public Object executeCommand(ExecuteCommandParams params, ILanguageServerAccess access, + CancelIndicator cancelIndicator) { + Object result = null; + for (IExecutableCommandService service : registeredCommands.get(params.getCommand())) { + Object localResult = service.execute(params, access, cancelIndicator); + if (localResult != null) { + if (result != null) { + ExecutableCommandRegistry.LOG.error("Multiple commands '" + params.getCommand() + + "' have been registered. All are executed but only one result will be send back."); + } else { + result = localResult; + } + } + } + return result; + } + + public List getCommands() { + return Lists.newArrayList(registeredCommands.keySet()); + } + +} diff --git a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.xtend b/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.xtend deleted file mode 100644 index 44a326eb2..000000000 --- a/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.xtend +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.ide.server.commands - -import com.google.common.collect.HashMultimap -import com.google.common.collect.Multimap -import java.util.UUID -import org.eclipse.lsp4j.ClientCapabilities -import org.eclipse.lsp4j.ExecuteCommandOptions -import org.eclipse.lsp4j.ExecuteCommandParams -import org.eclipse.lsp4j.Registration -import org.eclipse.lsp4j.RegistrationParams -import org.eclipse.lsp4j.Unregistration -import org.eclipse.lsp4j.UnregistrationParams -import org.eclipse.lsp4j.services.LanguageClient -import org.eclipse.xtext.ide.server.ILanguageServerAccess -import org.eclipse.xtext.resource.IResourceServiceProvider -import org.eclipse.xtext.util.CancelIndicator -import org.eclipse.xtext.util.IDisposable -import org.eclipse.xtext.util.internal.Log - -/** - * @author Sven Efftinge - Initial contribution and API - */ -@Log class ExecutableCommandRegistry { - - static val METHOD = 'workspace/executeCommand' - - Multimap registeredCommands - - LanguageClient client - - def void initialize(Iterable allLanguages, ClientCapabilities capabilities, LanguageClient client) { - this.client = client - registeredCommands = HashMultimap.create - val boolean hasDynamicRegistration = capabilities.workspace?.executeCommand?.dynamicRegistration ?: false - for (lang : allLanguages) { - val service = lang.get(IExecutableCommandService) - if (service !== null) { - val commands = service.initialize() - for (c : commands) { - registeredCommands.put(c, service) - } - if (hasDynamicRegistration) { - service.initializeDynamicRegistration[ command | - this.register(command, service) - ] - } - } - } - } - - protected def IDisposable register(String command, IExecutableCommandService service) { - val requestId = UUID.randomUUID.toString - val reg = new Registration => [ - id = requestId - method = METHOD - registerOptions = new ExecuteCommandOptions => [ - commands = #[command] - ] - ] - client.registerCapability(new RegistrationParams => [ - it.registrations = newArrayList(reg) - ]) - registeredCommands.put(command, service) - return [ - val unReg = new Unregistration => [ - id = requestId - method = METHOD - ] - client.unregisterCapability(new UnregistrationParams => [ - it.unregisterations = newArrayList(unReg) - ]) - registeredCommands.remove(command, service) - ] - } - - def Object executeCommand(ExecuteCommandParams params, ILanguageServerAccess access, CancelIndicator cancelIndicator) { - var Object result = null - for (service : this.registeredCommands.get(params.command)) { - val localResult = service.execute(params, access, cancelIndicator) - if (localResult !== null) { - if (result !== null) { - org.eclipse.xtext.ide.server.commands.ExecutableCommandRegistry.LOG.error('''Multiple commands '«params.command»' have been registered. All are executed but only one result will be send back.''') - } else { - result = localResult - } - } - } - return result - } - - def getCommands() { - return this.registeredCommands.keySet.toList - } - -} \ No newline at end of file diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java deleted file mode 100644 index 70ece2987..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/AbstractHierarchyBuilder.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.editor.hierarchy; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import javax.inject.Provider; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtend.lib.annotations.AccessorType; -import org.eclipse.xtend.lib.annotations.Accessors; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.findReferences.IReferenceFinder; -import org.eclipse.xtext.findReferences.TargetURICollector; -import org.eclipse.xtext.findReferences.TargetURIs; -import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyBuilder; -import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNodeLocationProvider; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.resource.IResourceDescriptions; -import org.eclipse.xtext.resource.IResourceServiceProvider; -import org.eclipse.xtext.util.concurrent.IUnitOfWork; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pure; - -/** - * @author kosyakov - Initial contribution and API - * @since 2.10 - */ -@Accessors({ AccessorType.PUBLIC_SETTER, AccessorType.PROTECTED_GETTER }) -@SuppressWarnings("all") -public abstract class AbstractHierarchyBuilder implements IHierarchyBuilder { - private IReferenceFinder.IResourceAccess resourceAccess; - - private IResourceDescriptions indexData; - - @Inject - private IReferenceFinder referenceFinder; - - @Inject - private TargetURICollector targetURICollector; - - @Inject - private Provider targetURIProvider; - - @Inject - private IHierarchyNodeLocationProvider hierarchyNodeLocationProvider; - - @Inject - private IResourceServiceProvider.Registry resourceServiceProviderRegistry; - - protected R readOnly(final URI objectURI, final IUnitOfWork work) { - final IUnitOfWork _function = (ResourceSet resourceSet) -> { - final EObject targetObject = resourceSet.getEObject(objectURI, true); - return work.exec(targetObject); - }; - return this.getResourceAccess().readOnly(objectURI, _function); - } - - protected IEObjectDescription getDescription(final URI objectURI) { - final IResourceDescription resourceDescription = this.getIndexData().getResourceDescription(objectURI.trimFragment()); - if ((resourceDescription == null)) { - return null; - } - final Function1 _function = (IEObjectDescription it) -> { - URI _eObjectURI = it.getEObjectURI(); - return Boolean.valueOf(Objects.equal(_eObjectURI, objectURI)); - }; - return IterableExtensions.findFirst(resourceDescription.getExportedObjects(), _function); - } - - protected IEObjectDescription getDescription(final EObject object) { - if ((object == null)) { - return null; - } - return IterableExtensions.head(this.getIndexData().getExportedObjectsByObject(object)); - } - - protected boolean isAssignable(final EClass superType, final EClassifier type) { - if ((type instanceof EClass)) { - return EcoreUtil2.isAssignableFrom(superType, ((EClass)type)); - } - return false; - } - - @Pure - protected IReferenceFinder.IResourceAccess getResourceAccess() { - return this.resourceAccess; - } - - public void setResourceAccess(final IReferenceFinder.IResourceAccess resourceAccess) { - this.resourceAccess = resourceAccess; - } - - @Pure - protected IResourceDescriptions getIndexData() { - return this.indexData; - } - - public void setIndexData(final IResourceDescriptions indexData) { - this.indexData = indexData; - } - - @Pure - protected IReferenceFinder getReferenceFinder() { - return this.referenceFinder; - } - - public void setReferenceFinder(final IReferenceFinder referenceFinder) { - this.referenceFinder = referenceFinder; - } - - @Pure - protected TargetURICollector getTargetURICollector() { - return this.targetURICollector; - } - - public void setTargetURICollector(final TargetURICollector targetURICollector) { - this.targetURICollector = targetURICollector; - } - - @Pure - protected Provider getTargetURIProvider() { - return this.targetURIProvider; - } - - public void setTargetURIProvider(final Provider targetURIProvider) { - this.targetURIProvider = targetURIProvider; - } - - @Pure - protected IHierarchyNodeLocationProvider getHierarchyNodeLocationProvider() { - return this.hierarchyNodeLocationProvider; - } - - public void setHierarchyNodeLocationProvider(final IHierarchyNodeLocationProvider hierarchyNodeLocationProvider) { - this.hierarchyNodeLocationProvider = hierarchyNodeLocationProvider; - } - - @Pure - protected IResourceServiceProvider.Registry getResourceServiceProviderRegistry() { - return this.resourceServiceProviderRegistry; - } - - public void setResourceServiceProviderRegistry(final IResourceServiceProvider.Registry resourceServiceProviderRegistry) { - this.resourceServiceProviderRegistry = resourceServiceProviderRegistry; - } -} diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultCallHierarchyBuilder.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultCallHierarchyBuilder.java index f6dba4cb0..3be7df09f 100644 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultCallHierarchyBuilder.java +++ b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultCallHierarchyBuilder.java @@ -18,6 +18,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtend.lib.annotations.Accessors; +import org.eclipse.xtext.findReferences.IReferenceFinder; import org.eclipse.xtext.findReferences.ReferenceAcceptor; import org.eclipse.xtext.findReferences.TargetURIs; import org.eclipse.xtext.ide.editor.hierarchy.AbstractHierarchyBuilder; @@ -30,6 +31,7 @@ import org.eclipse.xtext.nodemodel.ICompositeNode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.resource.IReferenceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.util.IAcceptor; import org.eclipse.xtext.util.ITextRegionWithLineInformation; @@ -103,6 +105,7 @@ public class DefaultCallHierarchyBuilder extends AbstractHierarchyBuilder implem final IUnitOfWork _function = (EObject sourceDeclaration) -> { Object _xblockexpression = null; { + IReferenceFinder _referenceFinder = this.getReferenceFinder(); IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry(); final IAcceptor _function_1 = (IReferenceDescription reference) -> { boolean _filterReference = this.filterReference(reference); @@ -116,7 +119,7 @@ public class DefaultCallHierarchyBuilder extends AbstractHierarchyBuilder implem } }; ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function_1); - this.getReferenceFinder().findAllReferences(sourceDeclaration, _referenceAcceptor, monitor); + _referenceFinder.findAllReferences(sourceDeclaration, _referenceAcceptor, monitor); _xblockexpression = null; } return _xblockexpression; @@ -126,6 +129,9 @@ public class DefaultCallHierarchyBuilder extends AbstractHierarchyBuilder implem protected void findSourceDeclarations(final URI targetDeclarationURI, final IProgressMonitor monitor, final Procedure2 acceptor) { final TargetURIs targetURIs = this.collectTargetURIs(targetDeclarationURI); + IReferenceFinder _referenceFinder = this.getReferenceFinder(); + IReferenceFinder.IResourceAccess _resourceAccess = this.getResourceAccess(); + IResourceDescriptions _indexData = this.getIndexData(); IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry(); final IAcceptor _function = (IReferenceDescription reference) -> { boolean _filterReference = this.filterReference(reference); @@ -139,9 +145,7 @@ public class DefaultCallHierarchyBuilder extends AbstractHierarchyBuilder implem } }; ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function); - this.getReferenceFinder().findAllReferences(targetURIs, - this.getResourceAccess(), - this.getIndexData(), _referenceAcceptor, monitor); + _referenceFinder.findAllReferences(targetURIs, _resourceAccess, _indexData, _referenceAcceptor, monitor); } protected TargetURIs collectTargetURIs(final URI targetURI) { diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java deleted file mode 100644 index 2ac91b010..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/hierarchy/DefaultHierarchyNodeLocationProvider.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.editor.hierarchy; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.xtext.ide.editor.hierarchy.IHierarchyNodeLocationProvider; -import org.eclipse.xtext.nodemodel.ICompositeNode; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.eclipse.xtext.resource.ILocationInFileProvider; -import org.eclipse.xtext.util.ITextRegion; -import org.eclipse.xtext.util.ITextRegionWithLineInformation; -import org.eclipse.xtext.util.TextRegionWithLineInformation; - -/** - * @author kosyakov - Initial contribution and API - * @since 2.10 - */ -@Singleton -@SuppressWarnings("all") -public class DefaultHierarchyNodeLocationProvider implements IHierarchyNodeLocationProvider { - @Inject - protected ILocationInFileProvider locationInFileProvider; - - @Override - public ITextRegionWithLineInformation getTextRegion(final EObject obj) { - if ((obj == null)) { - return ITextRegionWithLineInformation.EMPTY_REGION; - } - final ITextRegion textRegion = this.locationInFileProvider.getSignificantTextRegion(obj); - return this.toTextRegionWithLineInformation(obj, textRegion); - } - - @Override - public ITextRegionWithLineInformation getTextRegion(final EObject owner, final EStructuralFeature feature, final int indexInList) { - if ((owner == null)) { - return ITextRegionWithLineInformation.EMPTY_REGION; - } - final ITextRegion textRegion = this.locationInFileProvider.getSignificantTextRegion(owner, feature, indexInList); - return this.toTextRegionWithLineInformation(owner, textRegion); - } - - protected ITextRegionWithLineInformation toTextRegionWithLineInformation(final EObject obj, final ITextRegion textRegion) { - if ((textRegion == null)) { - return ITextRegionWithLineInformation.EMPTY_REGION; - } - if ((textRegion instanceof ITextRegionWithLineInformation)) { - return ((ITextRegionWithLineInformation)textRegion); - } - final ICompositeNode node = NodeModelUtils.getNode(obj); - if ((node == null)) { - int _offset = textRegion.getOffset(); - int _length = textRegion.getLength(); - return new TextRegionWithLineInformation(_offset, _length, 0, 0); - } - int _line = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine(); - final int startLine = (_line - 1); - int _offset_1 = textRegion.getOffset(); - int _length_1 = textRegion.getLength(); - int _plus = (_offset_1 + _length_1); - int _line_1 = NodeModelUtils.getLineAndColumn(node, _plus).getLine(); - final int endLine = (_line_1 - 1); - int _offset_2 = textRegion.getOffset(); - int _length_2 = textRegion.getLength(); - return new TextRegionWithLineInformation(_offset_2, _length_2, startLine, endLine); - } -} diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java deleted file mode 100644 index eaa374ae7..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/editor/syntaxcoloring/DefaultAntlrTokenToAttributeIdMapper.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2014, 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.ide.editor.syntaxcoloring; - -import com.google.common.base.Objects; -import com.google.inject.Singleton; -import java.util.regex.Pattern; -import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper; -import org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles; - -/** - * @author Anton Kosyakov - * @since 2.9 - */ -@Singleton -@SuppressWarnings("all") -public class DefaultAntlrTokenToAttributeIdMapper extends AbstractAntlrTokenToAttributeIdMapper { - private static final Pattern QUOTED = Pattern.compile("(?:^\'([^\']*)\'$)|(?:^\"([^\"]*)\")$", Pattern.MULTILINE); - - private static final Pattern PUNCTUATION = Pattern.compile("\\p{Punct}*"); - - @Override - protected String calculateId(final String tokenName, final int tokenType) { - String _switchResult = null; - boolean _matched = false; - boolean _matches = DefaultAntlrTokenToAttributeIdMapper.PUNCTUATION.matcher(tokenName).matches(); - if (_matches) { - _matched=true; - _switchResult = HighlightingStyles.PUNCTUATION_ID; - } - if (!_matched) { - boolean _matches_1 = DefaultAntlrTokenToAttributeIdMapper.QUOTED.matcher(tokenName).matches(); - if (_matches_1) { - _matched=true; - _switchResult = HighlightingStyles.KEYWORD_ID; - } - } - if (!_matched) { - if (Objects.equal(tokenName, "RULE_STRING")) { - _matched=true; - _switchResult = HighlightingStyles.STRING_ID; - } - } - if (!_matched) { - if (Objects.equal(tokenName, "RULE_INT")) { - _matched=true; - _switchResult = HighlightingStyles.NUMBER_ID; - } - } - if (!_matched) { - if (Objects.equal(tokenName, "RULE_ML_COMMENT")) { - _matched=true; - } - if (!_matched) { - if (Objects.equal(tokenName, "RULE_SL_COMMENT")) { - _matched=true; - } - } - if (_matched) { - _switchResult = HighlightingStyles.COMMENT_ID; - } - } - if (!_matched) { - _switchResult = HighlightingStyles.DEFAULT_ID; - } - return _switchResult; - } -} diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java deleted file mode 100644 index a5ebed1b8..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/refactoring/ResourceRelocationContext.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.refactoring; - -import java.util.List; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -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.ide.refactoring.RefactoringIssueAcceptor; -import org.eclipse.xtext.ide.refactoring.ResourceRelocationChange; -import org.eclipse.xtext.ide.serializer.IChangeSerializer; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Pure; - -/** - * @author koehnlein - Initial contribution and API - * @since 2.13 - */ -@FinalFieldsConstructor -@Accessors(AccessorType.PUBLIC_GETTER) -@SuppressWarnings("all") -public class ResourceRelocationContext { - public enum ChangeType { - COPY, - - MOVE, - - RENAME; - } - - private final ResourceRelocationContext.ChangeType changeType; - - private final List changes; - - private final RefactoringIssueAcceptor issueAcceptor; - - private final IChangeSerializer changeSerializer; - - private final ResourceSet resourceSet; - - /** - * Loads and watches the respective resource, applies the relocation change and - * calls the given modification with the renamed/moved/copied resource. - * - * @param change the change to execute - * @param modification the side-effect the rename/move/copy operation should have. - */ - public void addModification(final ResourceRelocationChange change, final IChangeSerializer.IModification modification) { - this.changeSerializer.addModification(this.loadAndWatchResource(change), modification); - } - - /** - * Loads and watches the respective resource and applies the relocation change. - * Clients may usually rather call {@link #addModification} to register their - * side-effects. - * - * @param change the change to execute - */ - protected Resource loadAndWatchResource(final ResourceRelocationChange change) { - try { - Resource _switchResult = null; - final ResourceRelocationContext.ChangeType changeType = this.changeType; - if (changeType != null) { - switch (changeType) { - case MOVE: - case RENAME: - Resource _xblockexpression = null; - { - final Resource original = this.resourceSet.getResource(change.getFromURI(), true); - final IChangeSerializer.IModification _function = (Resource it) -> { - original.setURI(change.getToURI()); - }; - this.changeSerializer.addModification(original, _function); - _xblockexpression = original; - } - _switchResult = _xblockexpression; - break; - case COPY: - Resource _xblockexpression_1 = null; - { - final Resource copy = this.resourceSet.createResource(change.getFromURI()); - copy.load(this.resourceSet.getURIConverter().createInputStream(change.getFromURI()), null); - copy.setURI(change.getToURI()); - _xblockexpression_1 = copy; - } - _switchResult = _xblockexpression_1; - break; - default: - break; - } - } - final Resource resource = _switchResult; - return resource; - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public ResourceRelocationContext(final ResourceRelocationContext.ChangeType changeType, final List changes, final RefactoringIssueAcceptor issueAcceptor, final IChangeSerializer changeSerializer, final ResourceSet resourceSet) { - super(); - this.changeType = changeType; - this.changes = changes; - this.issueAcceptor = issueAcceptor; - this.changeSerializer = changeSerializer; - this.resourceSet = resourceSet; - } - - @Pure - public ResourceRelocationContext.ChangeType getChangeType() { - return this.changeType; - } - - @Pure - public List getChanges() { - return this.changes; - } - - @Pure - public RefactoringIssueAcceptor getIssueAcceptor() { - return this.issueAcceptor; - } - - @Pure - public IChangeSerializer getChangeSerializer() { - return this.changeSerializer; - } - - @Pure - public ResourceSet getResourceSet() { - return this.resourceSet; - } -} diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/LaunchArgs.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/LaunchArgs.java deleted file mode 100644 index 5a1288ea2..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/LaunchArgs.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2016, 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.server; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import org.eclipse.xtend.lib.annotations.Accessors; -import org.eclipse.xtext.xbase.lib.Pure; - -@Accessors -@SuppressWarnings("all") -public class LaunchArgs { - private InputStream in; - - private OutputStream out; - - private PrintWriter trace; - - private boolean validate; - - @Pure - public InputStream getIn() { - return this.in; - } - - public void setIn(final InputStream in) { - this.in = in; - } - - @Pure - public OutputStream getOut() { - return this.out; - } - - public void setOut(final OutputStream out) { - this.out = out; - } - - @Pure - public PrintWriter getTrace() { - return this.trace; - } - - public void setTrace(final PrintWriter trace) { - this.trace = trace; - } - - @Pure - public boolean isValidate() { - return this.validate; - } - - public void setValidate(final boolean validate) { - this.validate = validate; - } -} diff --git a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java b/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java deleted file mode 100644 index 97333d6ad..000000000 --- a/org.eclipse.xtext.ide/xtend-gen/org/eclipse/xtext/ide/server/commands/ExecutableCommandRegistry.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.ide.server.commands; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import org.apache.log4j.Logger; -import org.eclipse.lsp4j.ClientCapabilities; -import org.eclipse.lsp4j.ExecuteCommandCapabilities; -import org.eclipse.lsp4j.ExecuteCommandOptions; -import org.eclipse.lsp4j.ExecuteCommandParams; -import org.eclipse.lsp4j.Registration; -import org.eclipse.lsp4j.RegistrationParams; -import org.eclipse.lsp4j.Unregistration; -import org.eclipse.lsp4j.UnregistrationParams; -import org.eclipse.lsp4j.WorkspaceClientCapabilities; -import org.eclipse.lsp4j.services.LanguageClient; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.ide.server.ILanguageServerAccess; -import org.eclipse.xtext.ide.server.commands.IExecutableCommandService; -import org.eclipse.xtext.resource.IResourceServiceProvider; -import org.eclipse.xtext.util.CancelIndicator; -import org.eclipse.xtext.util.IDisposable; -import org.eclipse.xtext.util.internal.Log; -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.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; - -/** - * @author Sven Efftinge - Initial contribution and API - */ -@Log -@SuppressWarnings("all") -public class ExecutableCommandRegistry { - private static final String METHOD = "workspace/executeCommand"; - - private Multimap registeredCommands; - - private LanguageClient client; - - public void initialize(final Iterable allLanguages, final ClientCapabilities capabilities, final LanguageClient client) { - this.client = client; - this.registeredCommands = HashMultimap.create(); - Boolean _elvis = null; - WorkspaceClientCapabilities _workspace = capabilities.getWorkspace(); - ExecuteCommandCapabilities _executeCommand = null; - if (_workspace!=null) { - _executeCommand=_workspace.getExecuteCommand(); - } - Boolean _dynamicRegistration = null; - if (_executeCommand!=null) { - _dynamicRegistration=_executeCommand.getDynamicRegistration(); - } - if (_dynamicRegistration != null) { - _elvis = _dynamicRegistration; - } else { - _elvis = Boolean.valueOf(false); - } - final boolean hasDynamicRegistration = (boolean) _elvis; - for (final IResourceServiceProvider lang : allLanguages) { - { - final IExecutableCommandService service = lang.get(IExecutableCommandService.class); - if ((service != null)) { - final List commands = service.initialize(); - for (final String c : commands) { - this.registeredCommands.put(c, service); - } - if (hasDynamicRegistration) { - final Function1 _function = (String command) -> { - return this.register(command, service); - }; - service.initializeDynamicRegistration(_function); - } - } - } - } - } - - protected IDisposable register(final String command, final IExecutableCommandService service) { - final String requestId = UUID.randomUUID().toString(); - Registration _registration = new Registration(); - final Procedure1 _function = (Registration it) -> { - it.setId(requestId); - it.setMethod(ExecutableCommandRegistry.METHOD); - ExecuteCommandOptions _executeCommandOptions = new ExecuteCommandOptions(); - final Procedure1 _function_1 = (ExecuteCommandOptions it_1) -> { - it_1.setCommands(Collections.unmodifiableList(CollectionLiterals.newArrayList(command))); - }; - ExecuteCommandOptions _doubleArrow = ObjectExtensions.operator_doubleArrow(_executeCommandOptions, _function_1); - it.setRegisterOptions(_doubleArrow); - }; - final Registration reg = ObjectExtensions.operator_doubleArrow(_registration, _function); - RegistrationParams _registrationParams = new RegistrationParams(); - final Procedure1 _function_1 = (RegistrationParams it) -> { - it.setRegistrations(CollectionLiterals.newArrayList(reg)); - }; - RegistrationParams _doubleArrow = ObjectExtensions.operator_doubleArrow(_registrationParams, _function_1); - this.client.registerCapability(_doubleArrow); - this.registeredCommands.put(command, service); - final IDisposable _function_2 = () -> { - Unregistration _unregistration = new Unregistration(); - final Procedure1 _function_3 = (Unregistration it) -> { - it.setId(requestId); - it.setMethod(ExecutableCommandRegistry.METHOD); - }; - final Unregistration unReg = ObjectExtensions.operator_doubleArrow(_unregistration, _function_3); - UnregistrationParams _unregistrationParams = new UnregistrationParams(); - final Procedure1 _function_4 = (UnregistrationParams it) -> { - it.setUnregisterations(CollectionLiterals.newArrayList(unReg)); - }; - UnregistrationParams _doubleArrow_1 = ObjectExtensions.operator_doubleArrow(_unregistrationParams, _function_4); - this.client.unregisterCapability(_doubleArrow_1); - this.registeredCommands.remove(command, service); - }; - return _function_2; - } - - public Object executeCommand(final ExecuteCommandParams params, final ILanguageServerAccess access, final CancelIndicator cancelIndicator) { - Object result = null; - Collection _get = this.registeredCommands.get(params.getCommand()); - for (final IExecutableCommandService service : _get) { - { - final Object localResult = service.execute(params, access, cancelIndicator); - if ((localResult != null)) { - if ((result != null)) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("Multiple commands \'"); - String _command = params.getCommand(); - _builder.append(_command); - _builder.append("\' have been registered. All are executed but only one result will be send back."); - ExecutableCommandRegistry.LOG.error(_builder); - } else { - result = localResult; - } - } - } - } - return result; - } - - public List getCommands() { - return IterableExtensions.toList(this.registeredCommands.keySet()); - } - - private static final Logger LOG = Logger.getLogger(ExecutableCommandRegistry.class); -} diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java new file mode 100644 index 000000000..f68c643bf --- /dev/null +++ b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java @@ -0,0 +1,157 @@ +/** + * 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; + +import com.google.inject.Inject; +import org.eclipse.xtext.Grammar; +import org.eclipse.xtext.GrammarUtil; +import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.eclipse.xtext.xtext.generator.model.TypeReference; +import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig; + +/** + * Configuration of the names of the generated classes. Create a subclass and + * register it with a specialized {@link DefaultGeneratorModule} in order to + * customize some class or package names. + */ +public class XtextGeneratorNaming { + @Inject + private IXtextProjectConfig projectConfig; + + public String getRuntimeBasePackage(Grammar grammar) { + return GrammarUtil.getNamespace(grammar); + } + + public String getRuntimeTestBasePackage(Grammar grammar) { + return getRuntimeBasePackage(grammar) + ".tests"; + } + + public TypeReference getRuntimeModule(Grammar grammar) { + return new TypeReference(getRuntimeBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "RuntimeModule"); + } + + public TypeReference getRuntimeGenModule(Grammar grammar) { + return new TypeReference(getRuntimeBasePackage(grammar), + "Abstract" + GrammarUtil.getSimpleName(grammar) + "RuntimeModule"); + } + + public TypeReference getRuntimeDefaultModule(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.service.DefaultRuntimeModule"); + } + + public TypeReference getRuntimeSetup(Grammar grammar) { + return new TypeReference(getRuntimeBasePackage(grammar), + GrammarUtil.getSimpleName(grammar) + "StandaloneSetup"); + } + + public TypeReference getRuntimeGenSetup(Grammar grammar) { + return new TypeReference(getRuntimeBasePackage(grammar), + GrammarUtil.getSimpleName(grammar) + "StandaloneSetupGenerated"); + } + + public String getGenericIdeBasePackage(Grammar grammar) { + return getRuntimeBasePackage(grammar) + ".ide"; + } + + public String getGenericIdeTestBasePackage(Grammar grammar) { + return getGenericIdeBasePackage(grammar) + ".tests"; + } + + public TypeReference getGenericIdeModule(Grammar grammar) { + return new TypeReference(getGenericIdeBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "IdeModule"); + } + + public TypeReference getGenericIdeGenModule(Grammar grammar) { + return new TypeReference(getGenericIdeBasePackage(grammar), + "Abstract" + GrammarUtil.getSimpleName(grammar) + "IdeModule"); + } + + public TypeReference getGenericIdeDefaultModule(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.ide.DefaultIdeModule"); + } + + public TypeReference getGenericIdeSetup(Grammar grammar) { + return new TypeReference(getGenericIdeBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "IdeSetup"); + } + + public String getEclipsePluginBasePackage(Grammar grammar) { + return GrammarUtil.getNamespace(grammar) + ".ui"; + } + + public String getEclipsePluginTestBasePackage(Grammar grammar) { + return getEclipsePluginBasePackage(grammar) + ".tests"; + } + + public TypeReference getEclipsePluginModule(Grammar grammar) { + return new TypeReference(getEclipsePluginBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "UiModule"); + } + + public TypeReference getEclipsePluginGenModule(Grammar grammar) { + return new TypeReference(getEclipsePluginBasePackage(grammar), + "Abstract" + GrammarUtil.getSimpleName(grammar) + "UiModule"); + } + + public TypeReference getEclipsePluginDefaultModule(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.ui.DefaultUiModule"); + } + + public TypeReference getEclipsePluginExecutableExtensionFactory(Grammar grammar) { + return new TypeReference(getEclipsePluginBasePackage(grammar), + GrammarUtil.getSimpleName(grammar) + "ExecutableExtensionFactory"); + } + + public TypeReference getEclipsePluginEditor(Grammar grammar) { + return new TypeReference(getEclipsePluginBasePackage(grammar) + ".editor", + GrammarUtil.getSimpleName(grammar) + "Editor"); + } + + public TypeReference getEclipsePluginXbaseEditor(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.xbase.ui.editor.XbaseEditor"); + } + + public TypeReference getEclipsePluginDefaultEditor(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.ui.editor.XtextEditor"); + } + + /** + * @return name for the eclipsePlugin Activator or null if + * eclipsePlugin has no name + */ + public TypeReference getEclipsePluginActivator() { + String pluginName = projectConfig.getEclipsePlugin().getName(); + if (pluginName == null) { + return null; + } + String activatorName = pluginName.replaceAll("\\.ui$", ""); + activatorName = StringExtensions.toFirstUpper(activatorName.substring(activatorName.lastIndexOf('.') + 1)) + + "Activator"; + return new TypeReference(pluginName + ".internal", activatorName); + } + + public String getWebBasePackage(Grammar grammar) { + return GrammarUtil.getNamespace(grammar) + ".web"; + } + + public TypeReference getWebModule(Grammar grammar) { + return new TypeReference(getWebBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "WebModule"); + } + + public TypeReference getWebDefaultModule(Grammar grammar) { + return new TypeReference("org.eclipse.xtext.web.server.DefaultWebModule"); + } + + public TypeReference getWebGenModule(Grammar grammar) { + return new TypeReference(getWebBasePackage(grammar), + "Abstract" + GrammarUtil.getSimpleName(grammar) + "WebModule"); + } + + public TypeReference getWebSetup(Grammar grammar) { + return new TypeReference(getWebBasePackage(grammar), GrammarUtil.getSimpleName(grammar) + "WebSetup"); + } +} diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.xtend b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.xtend deleted file mode 100644 index 5851ec7dc..000000000 --- a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.xtend +++ /dev/null @@ -1,155 +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 - -import com.google.inject.Inject -import org.eclipse.xtext.Grammar -import org.eclipse.xtext.xtext.generator.model.TypeReference -import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig - -import static org.eclipse.xtext.GrammarUtil.* - -/** - * Configuration of the names of the generated classes. Create a subclass and register it with a specialized - * {@link DefaultGeneratorModule} in order to customize some class or package names. - */ -class XtextGeneratorNaming { - - @Inject - IXtextProjectConfig projectConfig - - def getRuntimeBasePackage(Grammar grammar) { - return getNamespace(grammar) - } - - def getRuntimeTestBasePackage(Grammar grammar) { - grammar.runtimeBasePackage + ".tests" - } - - def getRuntimeModule(Grammar grammar) { - new TypeReference(grammar.runtimeBasePackage, getSimpleName(grammar) + 'RuntimeModule') - } - - def getRuntimeGenModule(Grammar grammar) { - new TypeReference(grammar.runtimeBasePackage, 'Abstract' + getSimpleName(grammar) + 'RuntimeModule') - } - - def getRuntimeDefaultModule(Grammar grammar) { - new TypeReference('org.eclipse.xtext.service.DefaultRuntimeModule') - } - - def getRuntimeSetup(Grammar grammar) { - new TypeReference(grammar.runtimeBasePackage, getSimpleName(grammar) + 'StandaloneSetup') - } - - def getRuntimeGenSetup(Grammar grammar) { - new TypeReference(grammar.runtimeBasePackage, getSimpleName(grammar) + 'StandaloneSetupGenerated') - } - - def getGenericIdeBasePackage(Grammar grammar) { - return grammar.runtimeBasePackage+".ide" - } - - def getGenericIdeTestBasePackage(Grammar grammar) { - grammar.genericIdeBasePackage + ".tests" - } - - def getGenericIdeModule(Grammar grammar) { - new TypeReference(grammar.genericIdeBasePackage, getSimpleName(grammar) + 'IdeModule') - } - - def getGenericIdeGenModule(Grammar grammar) { - new TypeReference(grammar.genericIdeBasePackage, 'Abstract' + getSimpleName(grammar) + 'IdeModule') - } - - def getGenericIdeDefaultModule(Grammar grammar) { - new TypeReference('org.eclipse.xtext.ide.DefaultIdeModule') - } - - def getGenericIdeSetup(Grammar grammar) { - new TypeReference(grammar.genericIdeBasePackage, getSimpleName(grammar) + 'IdeSetup') - } - - def getEclipsePluginBasePackage(Grammar grammar) { - return getNamespace(grammar) + '.ui' - } - - def getEclipsePluginTestBasePackage(Grammar grammar) { - grammar.eclipsePluginBasePackage + ".tests" - } - - def getEclipsePluginModule(Grammar grammar) { - new TypeReference(grammar.eclipsePluginBasePackage, getSimpleName(grammar) + 'UiModule') - } - - def getEclipsePluginGenModule(Grammar grammar) { - new TypeReference(grammar.eclipsePluginBasePackage, 'Abstract' + getSimpleName(grammar) + 'UiModule') - } - - def getEclipsePluginDefaultModule(Grammar grammar) { - new TypeReference('org.eclipse.xtext.ui.DefaultUiModule') - } - - def getEclipsePluginExecutableExtensionFactory(Grammar grammar) { - new TypeReference(grammar.eclipsePluginBasePackage, getSimpleName(grammar) + 'ExecutableExtensionFactory') - } - - def getEclipsePluginEditor(Grammar grammar) { - new TypeReference(grammar.eclipsePluginBasePackage + '.editor', getSimpleName(grammar) + 'Editor') - } - - def getEclipsePluginXbaseEditor(Grammar grammar) { - new TypeReference('org.eclipse.xtext.xbase.ui.editor.XbaseEditor') - } - - def getEclipsePluginDefaultEditor(Grammar grammar) { - new TypeReference('org.eclipse.xtext.ui.editor.XtextEditor') - } - - /** - * @return name for the eclipsePlugin Activator or null if eclipsePlugin has no name - */ - def getEclipsePluginActivator() { - val pluginName = projectConfig.eclipsePlugin.name - - if(pluginName === null) { - return null - } - - // start determining the activator's name by stripping the common ".ui" suffix - var activatorName = pluginName.replaceAll('\\.ui$', '') - - // build the activator's name based on the last segment of the stripped FQN - // the call of 'new TypeReference(...)' below checks for invalid characters - activatorName = activatorName.substring(activatorName.lastIndexOf('.') + 1).toFirstUpper + 'Activator' - - new TypeReference(pluginName + '.internal', activatorName) - } - - def getWebBasePackage(Grammar grammar) { - return getNamespace(grammar) + ".web" - } - - def getWebModule(Grammar grammar) { - new TypeReference(grammar.webBasePackage, getSimpleName(grammar) + 'WebModule') - } - - def getWebDefaultModule(Grammar grammar) { - new TypeReference('org.eclipse.xtext.web.server.DefaultWebModule') - } - - def getWebGenModule(Grammar grammar) { - new TypeReference(grammar.webBasePackage, 'Abstract' + getSimpleName(grammar) + 'WebModule') - } - - def getWebSetup(Grammar grammar) { - new TypeReference(grammar.webBasePackage, getSimpleName(grammar) + 'WebSetup') - } - -} diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java new file mode 100644 index 000000000..f4cd9cbff --- /dev/null +++ b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java @@ -0,0 +1,67 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.mwe.utils.ProjectMapping; +import org.eclipse.emf.mwe.utils.StandaloneSetup; +import org.eclipse.xtext.xbase.lib.Pair; +import org.eclipse.xtext.xtext.generator.model.project.ISubProjectConfig; +import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig; + +import com.google.inject.Inject; +import com.google.inject.Injector; + +/** + * Standalone setup for resolving EMF URIs in the context of the + * {@link XtextGenerator}. The actual setup is done by {@link StandaloneSetup}. + */ +public class XtextGeneratorStandaloneSetup implements IGuiceAwareGeneratorComponent { + @Inject + private IXtextProjectConfig projectConfig; + + private boolean scanClasspath = true; + + @Override + public void initialize(Injector injector) { + injector.injectMembers(this); + setup(); + } + + private void setup() { + StandaloneSetup delegate = new StandaloneSetup(); + delegate.setScanClassPath(scanClasspath); + for (Pair mapping : getProjectMappings()) { + ProjectMapping projectMapping = new ProjectMapping(); + projectMapping.setProjectName(mapping.getKey()); + projectMapping.setPath(mapping.getValue()); + delegate.addProjectMapping(projectMapping); + } + } + + private Iterable> getProjectMappings() { + List> result = new ArrayList<>(); + for (ISubProjectConfig cfg : projectConfig.getEnabledProjects()) { + if (cfg.getName() != null && cfg.getRoot() != null) { + result.add(Pair.of(cfg.getName(), cfg.getRoot().getPath())); + } + } + return result; + } + + public boolean isScanClasspath() { + return scanClasspath; + } + + public void setScanClasspath(boolean scanClasspath) { + this.scanClasspath = scanClasspath; + } +} diff --git a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.xtend b/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.xtend deleted file mode 100644 index 4c7ab3030..000000000 --- a/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.xtend +++ /dev/null @@ -1,49 +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 - -import com.google.inject.Inject -import com.google.inject.Injector -import org.eclipse.emf.mwe.utils.ProjectMapping -import org.eclipse.emf.mwe.utils.StandaloneSetup -import org.eclipse.xtend.lib.annotations.Accessors -import org.eclipse.xtext.util.internal.Log -import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig - -/** - * Standalone setup for resolving EMF URIs in the context of the {@link XtextGenerator}. The actual - * setup is done by {@link StandaloneSetup}. - */ -@Log -class XtextGeneratorStandaloneSetup implements IGuiceAwareGeneratorComponent { - - @Inject IXtextProjectConfig projectConfig - - @Accessors boolean scanClasspath = true - - override initialize(Injector injector) { - injector.injectMembers(this) - setup() - } - - private def void setup() { - val delegate = new StandaloneSetup - delegate.scanClassPath = scanClasspath - projectMappings.forEach [ mapping | - delegate.addProjectMapping(new ProjectMapping => [ - projectName = mapping.key - path = mapping.value - ]) - ] - } - - private def getProjectMappings() { - projectConfig.enabledProjects.filter[name !== null && root !== null].map[name -> root.path] - } -} diff --git a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java deleted file mode 100644 index 41a18386d..000000000 --- a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorNaming.java +++ /dev/null @@ -1,208 +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; - -import com.google.inject.Inject; -import org.eclipse.xtext.Grammar; -import org.eclipse.xtext.GrammarUtil; -import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.eclipse.xtext.xtext.generator.model.TypeReference; -import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig; - -/** - * Configuration of the names of the generated classes. Create a subclass and register it with a specialized - * {@link DefaultGeneratorModule} in order to customize some class or package names. - */ -@SuppressWarnings("all") -public class XtextGeneratorNaming { - @Inject - private IXtextProjectConfig projectConfig; - - public String getRuntimeBasePackage(final Grammar grammar) { - return GrammarUtil.getNamespace(grammar); - } - - public String getRuntimeTestBasePackage(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - return (_runtimeBasePackage + ".tests"); - } - - public TypeReference getRuntimeModule(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "RuntimeModule"); - return new TypeReference(_runtimeBasePackage, _plus); - } - - public TypeReference getRuntimeGenModule(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = ("Abstract" + _simpleName); - String _plus_1 = (_plus + "RuntimeModule"); - return new TypeReference(_runtimeBasePackage, _plus_1); - } - - public TypeReference getRuntimeDefaultModule(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.service.DefaultRuntimeModule"); - } - - public TypeReference getRuntimeSetup(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "StandaloneSetup"); - return new TypeReference(_runtimeBasePackage, _plus); - } - - public TypeReference getRuntimeGenSetup(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "StandaloneSetupGenerated"); - return new TypeReference(_runtimeBasePackage, _plus); - } - - public String getGenericIdeBasePackage(final Grammar grammar) { - String _runtimeBasePackage = this.getRuntimeBasePackage(grammar); - return (_runtimeBasePackage + ".ide"); - } - - public String getGenericIdeTestBasePackage(final Grammar grammar) { - String _genericIdeBasePackage = this.getGenericIdeBasePackage(grammar); - return (_genericIdeBasePackage + ".tests"); - } - - public TypeReference getGenericIdeModule(final Grammar grammar) { - String _genericIdeBasePackage = this.getGenericIdeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "IdeModule"); - return new TypeReference(_genericIdeBasePackage, _plus); - } - - public TypeReference getGenericIdeGenModule(final Grammar grammar) { - String _genericIdeBasePackage = this.getGenericIdeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = ("Abstract" + _simpleName); - String _plus_1 = (_plus + "IdeModule"); - return new TypeReference(_genericIdeBasePackage, _plus_1); - } - - public TypeReference getGenericIdeDefaultModule(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.ide.DefaultIdeModule"); - } - - public TypeReference getGenericIdeSetup(final Grammar grammar) { - String _genericIdeBasePackage = this.getGenericIdeBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "IdeSetup"); - return new TypeReference(_genericIdeBasePackage, _plus); - } - - public String getEclipsePluginBasePackage(final Grammar grammar) { - String _namespace = GrammarUtil.getNamespace(grammar); - return (_namespace + ".ui"); - } - - public String getEclipsePluginTestBasePackage(final Grammar grammar) { - String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar); - return (_eclipsePluginBasePackage + ".tests"); - } - - public TypeReference getEclipsePluginModule(final Grammar grammar) { - String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "UiModule"); - return new TypeReference(_eclipsePluginBasePackage, _plus); - } - - public TypeReference getEclipsePluginGenModule(final Grammar grammar) { - String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = ("Abstract" + _simpleName); - String _plus_1 = (_plus + "UiModule"); - return new TypeReference(_eclipsePluginBasePackage, _plus_1); - } - - public TypeReference getEclipsePluginDefaultModule(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.ui.DefaultUiModule"); - } - - public TypeReference getEclipsePluginExecutableExtensionFactory(final Grammar grammar) { - String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "ExecutableExtensionFactory"); - return new TypeReference(_eclipsePluginBasePackage, _plus); - } - - public TypeReference getEclipsePluginEditor(final Grammar grammar) { - String _eclipsePluginBasePackage = this.getEclipsePluginBasePackage(grammar); - String _plus = (_eclipsePluginBasePackage + ".editor"); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus_1 = (_simpleName + "Editor"); - return new TypeReference(_plus, _plus_1); - } - - public TypeReference getEclipsePluginXbaseEditor(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.xbase.ui.editor.XbaseEditor"); - } - - public TypeReference getEclipsePluginDefaultEditor(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.ui.editor.XtextEditor"); - } - - /** - * @return name for the eclipsePlugin Activator or null if eclipsePlugin has no name - */ - public TypeReference getEclipsePluginActivator() { - TypeReference _xblockexpression = null; - { - final String pluginName = this.projectConfig.getEclipsePlugin().getName(); - if ((pluginName == null)) { - return null; - } - String activatorName = pluginName.replaceAll("\\.ui$", ""); - int _lastIndexOf = activatorName.lastIndexOf("."); - int _plus = (_lastIndexOf + 1); - String _firstUpper = StringExtensions.toFirstUpper(activatorName.substring(_plus)); - String _plus_1 = (_firstUpper + "Activator"); - activatorName = _plus_1; - _xblockexpression = new TypeReference((pluginName + ".internal"), activatorName); - } - return _xblockexpression; - } - - public String getWebBasePackage(final Grammar grammar) { - String _namespace = GrammarUtil.getNamespace(grammar); - return (_namespace + ".web"); - } - - public TypeReference getWebModule(final Grammar grammar) { - String _webBasePackage = this.getWebBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "WebModule"); - return new TypeReference(_webBasePackage, _plus); - } - - public TypeReference getWebDefaultModule(final Grammar grammar) { - return new TypeReference("org.eclipse.xtext.web.server.DefaultWebModule"); - } - - public TypeReference getWebGenModule(final Grammar grammar) { - String _webBasePackage = this.getWebBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = ("Abstract" + _simpleName); - String _plus_1 = (_plus + "WebModule"); - return new TypeReference(_webBasePackage, _plus_1); - } - - public TypeReference getWebSetup(final Grammar grammar) { - String _webBasePackage = this.getWebBasePackage(grammar); - String _simpleName = GrammarUtil.getSimpleName(grammar); - String _plus = (_simpleName + "WebSetup"); - return new TypeReference(_webBasePackage, _plus); - } -} diff --git a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java b/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java deleted file mode 100644 index 077a07df0..000000000 --- a/org.eclipse.xtext.xtext.generator/xtend-gen/org/eclipse/xtext/xtext/generator/XtextGeneratorStandaloneSetup.java +++ /dev/null @@ -1,85 +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; - -import com.google.inject.Inject; -import com.google.inject.Injector; -import java.util.function.Consumer; -import org.apache.log4j.Logger; -import org.eclipse.emf.mwe.utils.ProjectMapping; -import org.eclipse.emf.mwe.utils.StandaloneSetup; -import org.eclipse.xtend.lib.annotations.Accessors; -import org.eclipse.xtext.util.internal.Log; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xtext.generator.IGuiceAwareGeneratorComponent; -import org.eclipse.xtext.xtext.generator.model.project.ISubProjectConfig; -import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig; - -/** - * Standalone setup for resolving EMF URIs in the context of the {@link XtextGenerator}. The actual - * setup is done by {@link StandaloneSetup}. - */ -@Log -@SuppressWarnings("all") -public class XtextGeneratorStandaloneSetup implements IGuiceAwareGeneratorComponent { - @Inject - private IXtextProjectConfig projectConfig; - - @Accessors - private boolean scanClasspath = true; - - @Override - public void initialize(final Injector injector) { - injector.injectMembers(this); - this.setup(); - } - - private void setup() { - final StandaloneSetup delegate = new StandaloneSetup(); - delegate.setScanClassPath(this.scanClasspath); - final Consumer> _function = (Pair mapping) -> { - ProjectMapping _projectMapping = new ProjectMapping(); - final Procedure1 _function_1 = (ProjectMapping it) -> { - it.setProjectName(mapping.getKey()); - it.setPath(mapping.getValue()); - }; - ProjectMapping _doubleArrow = ObjectExtensions.operator_doubleArrow(_projectMapping, _function_1); - delegate.addProjectMapping(_doubleArrow); - }; - this.getProjectMappings().forEach(_function); - } - - private Iterable> getProjectMappings() { - final Function1 _function = (ISubProjectConfig it) -> { - return Boolean.valueOf(((it.getName() != null) && (it.getRoot() != null))); - }; - final Function1> _function_1 = (ISubProjectConfig it) -> { - String _name = it.getName(); - String _path = it.getRoot().getPath(); - return Pair.of(_name, _path); - }; - return IterableExtensions.map(IterableExtensions.filter(this.projectConfig.getEnabledProjects(), _function), _function_1); - } - - private static final Logger LOG = Logger.getLogger(XtextGeneratorStandaloneSetup.class); - - @Pure - public boolean isScanClasspath() { - return this.scanClasspath; - } - - public void setScanClasspath(final boolean scanClasspath) { - this.scanClasspath = scanClasspath; - } -}