mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
[eclipse/xtext#1679] converted Xtend code to Java
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
2933c1f7d7
commit
e3c5d32f1b
34 changed files with 972 additions and 1932 deletions
|
@ -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<Import> toDelete = new HashSet<>();
|
||||
Set<QualifiedName> toAdd = new HashSet<>();
|
||||
Map<Import, QualifiedName> toChange = new HashMap<>();
|
||||
Map<QualifiedName, Import> 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<Import, QualifiedName> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 = <Import>newHashSet
|
||||
val toAdd = <QualifiedName>newHashSet
|
||||
val toChange = <Import, QualifiedName>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)
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<? extends CodeLens> 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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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.<Node>head(Iterables.<Node>filter(context.getResource().getContents(), Node.class));
|
||||
if ((node == null)) {
|
||||
return;
|
||||
}
|
||||
final HashSet<Import> toDelete = CollectionLiterals.<Import>newHashSet();
|
||||
final HashSet<QualifiedName> toAdd = CollectionLiterals.<QualifiedName>newHashSet();
|
||||
final HashMap<Import, QualifiedName> toChange = CollectionLiterals.<Import, QualifiedName>newHashMap();
|
||||
final Function1<Import, QualifiedName> _function = (Import it) -> {
|
||||
return this.converter.toQualifiedName(it.getImportedNamespace());
|
||||
};
|
||||
final Map<QualifiedName, Import> imports = IterableExtensions.<QualifiedName, Import>toMap(node.getImports(), _function);
|
||||
List<IUpdatableReference> _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.<IEObjectDescription>head(delta.getSnapshot().getDescriptions()).getQualifiedName();
|
||||
final QualifiedName modified = IterableExtensions.<IEObjectDescription>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<Map.Entry<Import, QualifiedName>> _entrySet = toChange.entrySet();
|
||||
for (final Map.Entry<Import, QualifiedName> toCh : _entrySet) {
|
||||
{
|
||||
final Import imp = toCh.getKey();
|
||||
final QualifiedName name = toCh.getValue();
|
||||
imp.setImportedNamespace(this.converter.toString(name));
|
||||
}
|
||||
}
|
||||
for (final QualifiedName toA : toAdd) {
|
||||
EList<Import> _imports = node.getImports();
|
||||
Import _createImport = PartialSerializationTestLanguageFactory.eINSTANCE.createImport();
|
||||
final Procedure1<Import> _function_2 = (Import it) -> {
|
||||
it.setImportedNamespace(this.converter.toString(toA));
|
||||
};
|
||||
Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_2);
|
||||
_imports.add(_doubleArrow);
|
||||
}
|
||||
};
|
||||
context.modifyModel(_function_1);
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<? extends CodeLens> computeCodeLenses(final Document document, final XtextResource resource, final CodeLensParams params, final CancelIndicator indicator) {
|
||||
CodeLens _codeLens = new CodeLens();
|
||||
final Procedure1<CodeLens> _function = (CodeLens it) -> {
|
||||
Command _command = new Command();
|
||||
final Procedure1<Command> _function_1 = (Command it_1) -> {
|
||||
it_1.setCommand("do.this");
|
||||
it_1.setTitle("Do Awesome Stuff");
|
||||
it_1.setArguments(Collections.<Object>unmodifiableList(CollectionLiterals.<Object>newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true))));
|
||||
};
|
||||
Command _doubleArrow = ObjectExtensions.<Command>operator_doubleArrow(_command, _function_1);
|
||||
it.setCommand(_doubleArrow);
|
||||
Position _position = new Position(1, 2);
|
||||
it.setData(_position);
|
||||
};
|
||||
CodeLens _doubleArrow = ObjectExtensions.<CodeLens>operator_doubleArrow(_codeLens, _function);
|
||||
return Collections.<CodeLens>unmodifiableList(CollectionLiterals.<CodeLens>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;
|
||||
}
|
||||
}
|
|
@ -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<TargetURIs> targetURIProvider;
|
||||
|
||||
@Inject
|
||||
private IHierarchyNodeLocationProvider hierarchyNodeLocationProvider;
|
||||
|
||||
@Inject
|
||||
private IResourceServiceProvider.Registry resourceServiceProviderRegistry;
|
||||
|
||||
protected <R extends Object> R readOnly(URI objectURI, IUnitOfWork<R, EObject> 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<TargetURIs> getTargetURIProvider() {
|
||||
return targetURIProvider;
|
||||
}
|
||||
|
||||
public void setTargetURIProvider(Provider<TargetURIs> 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;
|
||||
}
|
||||
}
|
|
@ -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<TargetURIs> targetURIProvider
|
||||
|
||||
@Inject
|
||||
IHierarchyNodeLocationProvider hierarchyNodeLocationProvider
|
||||
|
||||
@Inject
|
||||
IResourceServiceProvider.Registry resourceServiceProviderRegistry
|
||||
|
||||
protected def <R> R readOnly(URI objectURI, IUnitOfWork<R, EObject> 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
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ResourceRelocationChange> 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
|
||||
* <code>modification</code> 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<Resource> 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<ResourceRelocationChange> 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<ResourceRelocationChange> getChanges() {
|
||||
return changes;
|
||||
}
|
||||
|
||||
public RefactoringIssueAcceptor getIssueAcceptor() {
|
||||
return issueAcceptor;
|
||||
}
|
||||
|
||||
public IChangeSerializer getChangeSerializer() {
|
||||
return changeSerializer;
|
||||
}
|
||||
|
||||
public ResourceSet getResourceSet() {
|
||||
return resourceSet;
|
||||
}
|
||||
}
|
|
@ -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<ResourceRelocationChange> 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 <code>modification</code> 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<Resource> 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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<String, IExecutableCommandService> registeredCommands;
|
||||
|
||||
private LanguageClient client;
|
||||
|
||||
public void initialize(Iterable<? extends IResourceServiceProvider> 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<String> 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<String> getCommands() {
|
||||
return Lists.newArrayList(registeredCommands.keySet());
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, IExecutableCommandService> registeredCommands
|
||||
|
||||
LanguageClient client
|
||||
|
||||
def void initialize(Iterable<? extends IResourceServiceProvider> 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
|
||||
}
|
||||
|
||||
}
|
|
@ -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<TargetURIs> targetURIProvider;
|
||||
|
||||
@Inject
|
||||
private IHierarchyNodeLocationProvider hierarchyNodeLocationProvider;
|
||||
|
||||
@Inject
|
||||
private IResourceServiceProvider.Registry resourceServiceProviderRegistry;
|
||||
|
||||
protected <R extends Object> R readOnly(final URI objectURI, final IUnitOfWork<R, EObject> work) {
|
||||
final IUnitOfWork<R, ResourceSet> _function = (ResourceSet resourceSet) -> {
|
||||
final EObject targetObject = resourceSet.getEObject(objectURI, true);
|
||||
return work.exec(targetObject);
|
||||
};
|
||||
return this.getResourceAccess().<R>readOnly(objectURI, _function);
|
||||
}
|
||||
|
||||
protected IEObjectDescription getDescription(final URI objectURI) {
|
||||
final IResourceDescription resourceDescription = this.getIndexData().getResourceDescription(objectURI.trimFragment());
|
||||
if ((resourceDescription == null)) {
|
||||
return null;
|
||||
}
|
||||
final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
|
||||
URI _eObjectURI = it.getEObjectURI();
|
||||
return Boolean.valueOf(Objects.equal(_eObjectURI, objectURI));
|
||||
};
|
||||
return IterableExtensions.<IEObjectDescription>findFirst(resourceDescription.getExportedObjects(), _function);
|
||||
}
|
||||
|
||||
protected IEObjectDescription getDescription(final EObject object) {
|
||||
if ((object == null)) {
|
||||
return null;
|
||||
}
|
||||
return IterableExtensions.<IEObjectDescription>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<TargetURIs> getTargetURIProvider() {
|
||||
return this.targetURIProvider;
|
||||
}
|
||||
|
||||
public void setTargetURIProvider(final Provider<TargetURIs> 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;
|
||||
}
|
||||
}
|
|
@ -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<Object, EObject> _function = (EObject sourceDeclaration) -> {
|
||||
Object _xblockexpression = null;
|
||||
{
|
||||
IReferenceFinder _referenceFinder = this.getReferenceFinder();
|
||||
IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry();
|
||||
final IAcceptor<IReferenceDescription> _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<? super IEObjectDescription, ? super IReferenceDescription> 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<IReferenceDescription> _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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<ResourceRelocationChange> 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 <code>modification</code> 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<Resource> modification) {
|
||||
this.changeSerializer.<Resource>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<Resource> _function = (Resource it) -> {
|
||||
original.setURI(change.getToURI());
|
||||
};
|
||||
this.changeSerializer.<Resource>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<ResourceRelocationChange> 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<ResourceRelocationChange> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<String, IExecutableCommandService> registeredCommands;
|
||||
|
||||
private LanguageClient client;
|
||||
|
||||
public void initialize(final Iterable<? extends IResourceServiceProvider> allLanguages, final ClientCapabilities capabilities, final LanguageClient client) {
|
||||
this.client = client;
|
||||
this.registeredCommands = HashMultimap.<String, IExecutableCommandService>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.<IExecutableCommandService>get(IExecutableCommandService.class);
|
||||
if ((service != null)) {
|
||||
final List<String> commands = service.initialize();
|
||||
for (final String c : commands) {
|
||||
this.registeredCommands.put(c, service);
|
||||
}
|
||||
if (hasDynamicRegistration) {
|
||||
final Function1<String, IDisposable> _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<Registration> _function = (Registration it) -> {
|
||||
it.setId(requestId);
|
||||
it.setMethod(ExecutableCommandRegistry.METHOD);
|
||||
ExecuteCommandOptions _executeCommandOptions = new ExecuteCommandOptions();
|
||||
final Procedure1<ExecuteCommandOptions> _function_1 = (ExecuteCommandOptions it_1) -> {
|
||||
it_1.setCommands(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(command)));
|
||||
};
|
||||
ExecuteCommandOptions _doubleArrow = ObjectExtensions.<ExecuteCommandOptions>operator_doubleArrow(_executeCommandOptions, _function_1);
|
||||
it.setRegisterOptions(_doubleArrow);
|
||||
};
|
||||
final Registration reg = ObjectExtensions.<Registration>operator_doubleArrow(_registration, _function);
|
||||
RegistrationParams _registrationParams = new RegistrationParams();
|
||||
final Procedure1<RegistrationParams> _function_1 = (RegistrationParams it) -> {
|
||||
it.setRegistrations(CollectionLiterals.<Registration>newArrayList(reg));
|
||||
};
|
||||
RegistrationParams _doubleArrow = ObjectExtensions.<RegistrationParams>operator_doubleArrow(_registrationParams, _function_1);
|
||||
this.client.registerCapability(_doubleArrow);
|
||||
this.registeredCommands.put(command, service);
|
||||
final IDisposable _function_2 = () -> {
|
||||
Unregistration _unregistration = new Unregistration();
|
||||
final Procedure1<Unregistration> _function_3 = (Unregistration it) -> {
|
||||
it.setId(requestId);
|
||||
it.setMethod(ExecutableCommandRegistry.METHOD);
|
||||
};
|
||||
final Unregistration unReg = ObjectExtensions.<Unregistration>operator_doubleArrow(_unregistration, _function_3);
|
||||
UnregistrationParams _unregistrationParams = new UnregistrationParams();
|
||||
final Procedure1<UnregistrationParams> _function_4 = (UnregistrationParams it) -> {
|
||||
it.setUnregisterations(CollectionLiterals.<Unregistration>newArrayList(unReg));
|
||||
};
|
||||
UnregistrationParams _doubleArrow_1 = ObjectExtensions.<UnregistrationParams>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<IExecutableCommandService> _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<String> getCommands() {
|
||||
return IterableExtensions.<String>toList(this.registeredCommands.keySet());
|
||||
}
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ExecutableCommandRegistry.class);
|
||||
}
|
|
@ -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 <code>null</code> 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");
|
||||
}
|
||||
}
|
|
@ -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 <code>null</code> 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')
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, String> mapping : getProjectMappings()) {
|
||||
ProjectMapping projectMapping = new ProjectMapping();
|
||||
projectMapping.setProjectName(mapping.getKey());
|
||||
projectMapping.setPath(mapping.getValue());
|
||||
delegate.addProjectMapping(projectMapping);
|
||||
}
|
||||
}
|
||||
|
||||
private Iterable<Pair<String, String>> getProjectMappings() {
|
||||
List<Pair<String, String>> 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;
|
||||
}
|
||||
}
|
|
@ -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]
|
||||
}
|
||||
}
|
|
@ -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 <code>null</code> 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);
|
||||
}
|
||||
}
|
|
@ -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<Pair<String, String>> _function = (Pair<String, String> mapping) -> {
|
||||
ProjectMapping _projectMapping = new ProjectMapping();
|
||||
final Procedure1<ProjectMapping> _function_1 = (ProjectMapping it) -> {
|
||||
it.setProjectName(mapping.getKey());
|
||||
it.setPath(mapping.getValue());
|
||||
};
|
||||
ProjectMapping _doubleArrow = ObjectExtensions.<ProjectMapping>operator_doubleArrow(_projectMapping, _function_1);
|
||||
delegate.addProjectMapping(_doubleArrow);
|
||||
};
|
||||
this.getProjectMappings().forEach(_function);
|
||||
}
|
||||
|
||||
private Iterable<Pair<String, String>> getProjectMappings() {
|
||||
final Function1<ISubProjectConfig, Boolean> _function = (ISubProjectConfig it) -> {
|
||||
return Boolean.valueOf(((it.getName() != null) && (it.getRoot() != null)));
|
||||
};
|
||||
final Function1<ISubProjectConfig, Pair<String, String>> _function_1 = (ISubProjectConfig it) -> {
|
||||
String _name = it.getName();
|
||||
String _path = it.getRoot().getPath();
|
||||
return Pair.<String, String>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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue