mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
migrated more code to java
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
parent
b0cb8a8397
commit
bbcaac9a86
13 changed files with 144 additions and 300 deletions
|
@ -6,12 +6,6 @@
|
|||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry including="**/*.java|**/*.xtend" kind="src" output="bin/main" path="xtend-gen">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src-gen">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
source.. = src-gen/,\
|
||||
src/,\
|
||||
xtend-gen/
|
||||
src/
|
||||
output.. = bin/main/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring;
|
||||
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.head;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.map;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.toMap;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.toSet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
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.impl.ReferenceUpdater;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameProvider;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwareFactory;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Import;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
import org.eclipse.xtext.xbase.lib.MapExtensions;
|
||||
|
||||
public class FileAwareTestLanguageReferenceUpdater extends ReferenceUpdater {
|
||||
@Inject
|
||||
private IQualifiedNameProvider names;
|
||||
|
||||
private FileAwareFactory fileAwareFactory = FileAwareFactory.eINSTANCE;
|
||||
|
||||
@Override
|
||||
public void update(IReferenceUpdaterContext context) {
|
||||
super.update(context);
|
||||
PackageDeclaration pkg = ((PackageDeclaration) head(context.getResource().getContents()));
|
||||
QualifiedName pkgName = names.getFullyQualifiedName(pkg);
|
||||
Map<Element, Import> actual = toMap(pkg.getImports(), imp -> imp.getElement());
|
||||
Iterable<Element> targets = filter(
|
||||
map(context.getUpdatableReferences(), ur -> ur.getTargetEObject()),
|
||||
Element.class);
|
||||
Set<Element> expected = toSet(filter(targets, e -> !names.getFullyQualifiedName(e).startsWith(pkgName)));
|
||||
Set<Element> toAdd = toSet(filter(expected, it -> !actual.containsKey(it)));
|
||||
Map<Element, Import> toDelete = MapExtensions.filter(actual, (Element e, Import i) -> !expected.contains(e));
|
||||
if (!toAdd.isEmpty() || !toDelete.isEmpty()) {
|
||||
context.modifyModel(() -> {
|
||||
toDelete.values().forEach(it -> EcoreUtil.remove(it));
|
||||
toAdd.forEach(e -> {
|
||||
EList<Import> imports = pkg.getImports();
|
||||
Import newImport = fileAwareFactory.createImport();
|
||||
newImport.setElement(e);
|
||||
imports.add(newImport);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring
|
||||
|
||||
import javax.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.naming.IQualifiedNameProvider
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwareFactory
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element
|
||||
|
||||
class FileAwareTestLanguageReferenceUpdater extends ReferenceUpdater {
|
||||
|
||||
@Inject IQualifiedNameProvider names
|
||||
extension FileAwareFactory = FileAwareFactory.eINSTANCE
|
||||
|
||||
override update(IReferenceUpdaterContext context) {
|
||||
super.update(context)
|
||||
val pkg = context.resource.contents.head as PackageDeclaration
|
||||
val pkgName = names.getFullyQualifiedName(pkg)
|
||||
val actual = pkg.imports.toMap[element]
|
||||
val targets = context.updatableReferences.map[targetEObject].filter(Element)
|
||||
val expected = targets.filter[!names.getFullyQualifiedName(it).startsWith(pkgName)].toSet
|
||||
val toAdd = expected.filter[!actual.containsKey(it)].toSet
|
||||
val toDelete = actual.filter[!expected.contains($0)]
|
||||
if (!toAdd.isEmpty || !toDelete.isEmpty) {
|
||||
context.modifyModel [
|
||||
toDelete.values.forEach[EcoreUtil.remove(it)]
|
||||
toAdd.forEach[e|pkg.imports += createImport => [element = e]]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring;
|
||||
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.drop;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter;
|
||||
import static org.eclipse.xtext.xbase.lib.IterableExtensions.head;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.ide.refactoring.IResourceRelocationStrategy;
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationChange;
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationContext;
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class FileAwareTestLanguageResourceRelocationStrategy implements IResourceRelocationStrategy {
|
||||
|
||||
@Inject
|
||||
private IResourceServiceProvider resourceServiceProvider;
|
||||
|
||||
public boolean canHandle(ResourceRelocationChange change) {
|
||||
return resourceServiceProvider.canHandle(change.getFromURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyChange(ResourceRelocationContext context) {
|
||||
filter(context.getChanges(), c -> canHandle(c)).forEach(change -> {
|
||||
context.addModification(change, resource -> {
|
||||
|
||||
EObject rootElement = head(resource.getContents());
|
||||
if (rootElement instanceof PackageDeclaration) {
|
||||
List<String> segments = change.getToURI().trimSegments(1).segmentsList();
|
||||
String newPackage = Joiner.on(".").join(drop(segments, 2));
|
||||
((PackageDeclaration) rootElement).setName(newPackage);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.ide.refactoring.IResourceRelocationStrategy
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationChange
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationContext
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration
|
||||
|
||||
class FileAwareTestLanguageResourceRelocationStrategy implements IResourceRelocationStrategy {
|
||||
|
||||
@Inject IResourceServiceProvider resourceServiceProvider
|
||||
|
||||
def boolean canHandle(ResourceRelocationChange change) {
|
||||
resourceServiceProvider.canHandle(change.fromURI)
|
||||
}
|
||||
|
||||
override applyChange(ResourceRelocationContext context) {
|
||||
context.changes.filter[ canHandle ].forEach [ change |
|
||||
context.addModification(change) [ resource |
|
||||
val rootElement = resource.contents.head
|
||||
if (rootElement instanceof PackageDeclaration) {
|
||||
val newPackage = change.toURI.trimSegments(1).segmentsList.drop(2).join('.')
|
||||
rootElement.name = newPackage
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
|
@ -4,10 +4,9 @@ import com.google.inject.Injector;
|
|||
import org.eclipse.xtext.testlanguages.fileAware.ide.FileAwareTestLanguageIdeSetup;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.tests.FileAwareTestLanguageInjectorProvider;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class FileAwareTestLanguageIdeInjectorProvider extends FileAwareTestLanguageInjectorProvider {
|
||||
@Override
|
||||
public Injector internalCreateInjector() {
|
||||
return new FileAwareTestLanguageIdeSetup().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
}
|
||||
|
||||
public Injector internalCreateInjector() {
|
||||
return new FileAwareTestLanguageIdeSetup().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.tests
|
||||
|
||||
import com.google.inject.Injector
|
||||
import org.eclipse.xtext.testlanguages.fileAware.ide.FileAwareTestLanguageIdeSetup
|
||||
import org.eclipse.xtext.testlanguages.fileAware.tests.FileAwareTestLanguageInjectorProvider
|
||||
|
||||
class FileAwareTestLanguageIdeInjectorProvider extends FileAwareTestLanguageInjectorProvider {
|
||||
|
||||
override Injector internalCreateInjector() {
|
||||
return new FileAwareTestLanguageIdeSetup().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import javax.inject.Inject;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
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.ReferenceUpdater;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameProvider;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwareFactory;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Import;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function2;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ListExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.MapExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
|
||||
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class FileAwareTestLanguageReferenceUpdater extends ReferenceUpdater {
|
||||
@Inject
|
||||
private IQualifiedNameProvider names;
|
||||
|
||||
@Extension
|
||||
private FileAwareFactory _fileAwareFactory = FileAwareFactory.eINSTANCE;
|
||||
|
||||
@Override
|
||||
public void update(final IReferenceUpdaterContext context) {
|
||||
super.update(context);
|
||||
EObject _head = IterableExtensions.<EObject>head(context.getResource().getContents());
|
||||
final PackageDeclaration pkg = ((PackageDeclaration) _head);
|
||||
final QualifiedName pkgName = this.names.getFullyQualifiedName(pkg);
|
||||
final Function1<Import, Element> _function = (Import it) -> {
|
||||
return it.getElement();
|
||||
};
|
||||
final Map<Element, Import> actual = IterableExtensions.<Element, Import>toMap(pkg.getImports(), _function);
|
||||
final Function1<IUpdatableReference, EObject> _function_1 = (IUpdatableReference it) -> {
|
||||
return it.getTargetEObject();
|
||||
};
|
||||
final Iterable<Element> targets = Iterables.<Element>filter(ListExtensions.<IUpdatableReference, EObject>map(context.getUpdatableReferences(), _function_1), Element.class);
|
||||
final Function1<Element, Boolean> _function_2 = (Element it) -> {
|
||||
boolean _startsWith = this.names.getFullyQualifiedName(it).startsWith(pkgName);
|
||||
return Boolean.valueOf((!_startsWith));
|
||||
};
|
||||
final Set<Element> expected = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(targets, _function_2));
|
||||
final Function1<Element, Boolean> _function_3 = (Element it) -> {
|
||||
boolean _containsKey = actual.containsKey(it);
|
||||
return Boolean.valueOf((!_containsKey));
|
||||
};
|
||||
final Set<Element> toAdd = IterableExtensions.<Element>toSet(IterableExtensions.<Element>filter(expected, _function_3));
|
||||
final Function2<Element, Import, Boolean> _function_4 = (Element $0, Import $1) -> {
|
||||
boolean _contains = expected.contains($0);
|
||||
return Boolean.valueOf((!_contains));
|
||||
};
|
||||
final Map<Element, Import> toDelete = MapExtensions.<Element, Import>filter(actual, _function_4);
|
||||
if (((!toAdd.isEmpty()) || (!toDelete.isEmpty()))) {
|
||||
final Runnable _function_5 = () -> {
|
||||
final Consumer<Import> _function_6 = (Import it) -> {
|
||||
EcoreUtil.remove(it);
|
||||
};
|
||||
toDelete.values().forEach(_function_6);
|
||||
final Consumer<Element> _function_7 = (Element e) -> {
|
||||
EList<Import> _imports = pkg.getImports();
|
||||
Import _createImport = this._fileAwareFactory.createImport();
|
||||
final Procedure1<Import> _function_8 = (Import it) -> {
|
||||
it.setElement(e);
|
||||
};
|
||||
Import _doubleArrow = ObjectExtensions.<Import>operator_doubleArrow(_createImport, _function_8);
|
||||
_imports.add(_doubleArrow);
|
||||
};
|
||||
toAdd.forEach(_function_7);
|
||||
};
|
||||
context.modifyModel(_function_5);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.ide.refactoring;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.function.Consumer;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.ide.refactoring.IResourceRelocationStrategy;
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationChange;
|
||||
import org.eclipse.xtext.ide.refactoring.ResourceRelocationContext;
|
||||
import org.eclipse.xtext.ide.serializer.IChangeSerializer;
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class FileAwareTestLanguageResourceRelocationStrategy implements IResourceRelocationStrategy {
|
||||
@Inject
|
||||
private IResourceServiceProvider resourceServiceProvider;
|
||||
|
||||
public boolean canHandle(final ResourceRelocationChange change) {
|
||||
return this.resourceServiceProvider.canHandle(change.getFromURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyChange(final ResourceRelocationContext context) {
|
||||
final Function1<ResourceRelocationChange, Boolean> _function = (ResourceRelocationChange it) -> {
|
||||
return Boolean.valueOf(this.canHandle(it));
|
||||
};
|
||||
final Consumer<ResourceRelocationChange> _function_1 = (ResourceRelocationChange change) -> {
|
||||
final IChangeSerializer.IModification<Resource> _function_2 = (Resource resource) -> {
|
||||
final EObject rootElement = IterableExtensions.<EObject>head(resource.getContents());
|
||||
if ((rootElement instanceof PackageDeclaration)) {
|
||||
final String newPackage = IterableExtensions.join(IterableExtensions.<String>drop(change.getToURI().trimSegments(1).segmentsList(), 2), ".");
|
||||
((PackageDeclaration)rootElement).setName(newPackage);
|
||||
}
|
||||
};
|
||||
context.addModification(change, _function_2);
|
||||
};
|
||||
IterableExtensions.<ResourceRelocationChange>filter(context.getChanges(), _function).forEach(_function_1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.scoping;
|
||||
|
||||
import static org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwarePackage.Literals.IMPORT__ELEMENT;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.scoping.impl.ImportNormalizer;
|
||||
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Import;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
|
||||
public class FileAwareTestLanguageImportScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
|
||||
|
||||
@Override
|
||||
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
|
||||
List<ImportNormalizer> resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
|
||||
if (context instanceof PackageDeclaration) {
|
||||
resolvers.add(new ImportNormalizer(getQualifiedNameConverter().toQualifiedName(((PackageDeclaration) context).getName()), true, false));
|
||||
for (Import imp : ((PackageDeclaration) context).getImports()) {
|
||||
QualifiedName name = getImportedNamespace(imp);
|
||||
resolvers.add(new ImportNormalizer(name, false, false));
|
||||
}
|
||||
}
|
||||
return resolvers;
|
||||
}
|
||||
|
||||
private QualifiedName getImportedNamespace(Import imp) {
|
||||
Element ele = imp.getElement();
|
||||
if (ele.eIsProxy()) {
|
||||
String name = NodeModelUtils.findNodesForFeature(imp, IMPORT__ELEMENT).get(0).getText().trim();
|
||||
return getQualifiedNameConverter().toQualifiedName(name);
|
||||
} else {
|
||||
return getQualifiedNameProvider().getFullyQualifiedName(ele);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.scoping
|
||||
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.xtext.naming.QualifiedName
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
|
||||
import org.eclipse.xtext.scoping.impl.ImportNormalizer
|
||||
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Import
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration
|
||||
import static org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwarePackage.Literals.*
|
||||
|
||||
class FileAwareTestLanguageImportScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
|
||||
|
||||
override protected internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
|
||||
val resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase)
|
||||
if (context instanceof PackageDeclaration) {
|
||||
resolvers += new ImportNormalizer(qualifiedNameConverter.toQualifiedName(context.name), true, false)
|
||||
for (imp : context.imports) {
|
||||
val name = imp.importedNamespace
|
||||
resolvers += new ImportNormalizer(name, false, false)
|
||||
}
|
||||
}
|
||||
return resolvers
|
||||
}
|
||||
|
||||
private def QualifiedName getImportedNamespace(Import imp) {
|
||||
val ele = imp.element
|
||||
if (ele.eIsProxy) {
|
||||
val name = NodeModelUtils.findNodesForFeature(imp, IMPORT__ELEMENT).head.text.trim
|
||||
return qualifiedNameConverter.toQualifiedName(name)
|
||||
} else {
|
||||
return qualifiedNameProvider.getFullyQualifiedName(ele)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package org.eclipse.xtext.testlanguages.fileAware.scoping;
|
||||
|
||||
import java.util.List;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.naming.QualifiedName;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.scoping.impl.ImportNormalizer;
|
||||
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwarePackage;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Import;
|
||||
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class FileAwareTestLanguageImportScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
|
||||
@Override
|
||||
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, final boolean ignoreCase) {
|
||||
final List<ImportNormalizer> resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
|
||||
if ((context instanceof PackageDeclaration)) {
|
||||
QualifiedName _qualifiedName = this.getQualifiedNameConverter().toQualifiedName(((PackageDeclaration)context).getName());
|
||||
ImportNormalizer _importNormalizer = new ImportNormalizer(_qualifiedName, true, false);
|
||||
resolvers.add(_importNormalizer);
|
||||
EList<Import> _imports = ((PackageDeclaration)context).getImports();
|
||||
for (final Import imp : _imports) {
|
||||
{
|
||||
final QualifiedName name = this.getImportedNamespace(imp);
|
||||
ImportNormalizer _importNormalizer_1 = new ImportNormalizer(name, false, false);
|
||||
resolvers.add(_importNormalizer_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resolvers;
|
||||
}
|
||||
|
||||
private QualifiedName getImportedNamespace(final Import imp) {
|
||||
final Element ele = imp.getElement();
|
||||
boolean _eIsProxy = ele.eIsProxy();
|
||||
if (_eIsProxy) {
|
||||
final String name = IterableExtensions.<INode>head(NodeModelUtils.findNodesForFeature(imp, FileAwarePackage.Literals.IMPORT__ELEMENT)).getText().trim();
|
||||
return this.getQualifiedNameConverter().toQualifiedName(name);
|
||||
} else {
|
||||
return this.getQualifiedNameProvider().getFullyQualifiedName(ele);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue