use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class TypeLookupImpl method findTypeOnScope.
private Type findTypeOnScope(final String typeName, final Function1<? super IEObjectDescription, ? extends Boolean> filter) {
final QualifiedName qualifiedName = this.compilationUnit.getQualifiedNameConverter().toQualifiedName(typeName);
final IEObjectDescription result = this.compilationUnit.getScopeProvider().getScope(this.compilationUnit.getXtendFile(), XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE).getSingleElement(qualifiedName);
if ((((result != null) && TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(result.getEClass())) && (filter.apply(result)).booleanValue())) {
EObject _eObjectOrProxy = result.getEObjectOrProxy();
return this.compilationUnit.toType(((JvmType) _eObjectOrProxy));
}
return null;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class XtendResourceDescription method getImportedNames.
@Override
public Iterable<QualifiedName> getImportedNames() {
if ((this.importedNames != null)) {
return this.importedNames;
}
final HashSet<QualifiedName> result = CollectionLiterals.<QualifiedName>newHashSet();
final EObject astRoot = IterableExtensions.<EObject>head(this.getResource().getContents());
if ((astRoot != null)) {
final IResolvedTypes types = this.typeResolver.resolveTypes(astRoot);
Iterable<XExpression> _filter = Iterables.<XExpression>filter(IteratorExtensions.<Object>toIterable(EcoreUtil.<Object>getAllContents(astRoot, true)), XExpression.class);
for (final XExpression expression : _filter) {
{
boolean _matched = false;
if (expression instanceof XMemberFeatureCall) {
if ((((((XMemberFeatureCall) expression).getFeature() != null) && ((XMemberFeatureCall) expression).getFeature().eIsProxy()) && (!((XMemberFeatureCall) expression).isExplicitOperationCallOrBuilderSyntax()))) {
_matched = true;
final XExpression receiver = ((XMemberFeatureCall) expression).getActualReceiver();
boolean _matched_1 = false;
if (receiver instanceof XAbstractFeatureCall) {
boolean _isTypeLiteral = ((XAbstractFeatureCall) receiver).isTypeLiteral();
if (_isTypeLiteral) {
_matched_1 = true;
final JvmIdentifiableElement type = ((XAbstractFeatureCall) receiver).getFeature();
String _identifier = type.getIdentifier();
String _plus = (_identifier + "$");
String _concreteSyntaxFeatureName = ((XMemberFeatureCall) expression).getConcreteSyntaxFeatureName();
String _plus_1 = (_plus + _concreteSyntaxFeatureName);
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(_plus_1).toLowerCase();
result.add(_lowerCase);
}
}
}
}
if (!_matched) {
if (expression instanceof XAbstractFeatureCall) {
boolean _isTypeLiteral = ((XAbstractFeatureCall) expression).isTypeLiteral();
if (_isTypeLiteral) {
_matched = true;
final JvmIdentifiableElement type = ((XAbstractFeatureCall) expression).getFeature();
if ((type instanceof JvmDeclaredType)) {
final Function1<String, Boolean> _function = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(((JvmType) type), _function);
}
}
}
}
final LightweightTypeReference typeRef = types.getActualType(expression);
if ((typeRef != null)) {
final Function1<String, Boolean> _function = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(typeRef.getType(), _function);
}
}
}
EList<EObject> _contents = this.getResource().getContents();
for (final EObject eobject : _contents) {
{
final Function1<JvmIdentifiableElement, LightweightTypeReference> _function = (JvmIdentifiableElement it) -> {
LightweightTypeReference _xifexpression = null;
if (((!(it instanceof JvmType)) || (it instanceof JvmDeclaredType))) {
_xifexpression = types.getActualType(it);
}
return _xifexpression;
};
final Iterable<LightweightTypeReference> typesOfIdentifiables = IteratorExtensions.<LightweightTypeReference>toIterable(IteratorExtensions.<JvmIdentifiableElement, LightweightTypeReference>map(Iterators.<JvmIdentifiableElement>filter(EcoreUtil.<Object>getAllContents(eobject, true), JvmIdentifiableElement.class), _function));
for (final LightweightTypeReference typeRef : typesOfIdentifiables) {
if ((typeRef != null)) {
final Function1<String, Boolean> _function_1 = (String it) -> {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
return Boolean.valueOf(result.add(_lowerCase));
};
this.registerAllTypes(typeRef.getType(), _function_1);
}
}
}
}
}
Iterables.<QualifiedName>addAll(result, super.getImportedNames());
final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
boolean _contains = XtendResourceDescription.primitivesFilter.contains(it.getLastSegment());
return Boolean.valueOf((!_contains));
};
this.importedNames = IterableExtensions.<QualifiedName>toSet(IterableExtensions.<QualifiedName>filter(result, _function));
return this.importedNames;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class EcoreResourceDescriptionStrategy method createEObjectDescriptions.
protected boolean createEObjectDescriptions(IQualifiedNameProvider qualifiedNameProvider, boolean isNsURI, EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
try {
QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject);
if (qualifiedName != null) {
Map<String, String> userData = Maps.newHashMapWithExpectedSize(1);
userData.put(NS_URI_INDEX_ENTRY, Boolean.toString(isNsURI));
IEObjectDescription description = EObjectDescription.create(qualifiedName, eObject, userData);
acceptor.accept(description);
return true;
}
} catch (Exception exc) {
LOG.error(exc.getMessage(), exc);
}
return false;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class EObjectDescriptionProvider method getEObjectDescriptions.
@Override
public Iterable<IEObjectDescription> getEObjectDescriptions(Resource resource) {
Multimap<EObject, IEObjectDescription> map = HashMultimap.create();
IResourceDescription description = resourceDescriptionManager.getResourceDescription(resource);
for (IEObjectDescription desc : description.getExportedObjects()) {
EObject object = EcoreUtil.resolve(desc.getEObjectOrProxy(), resource);
map.put(object, desc);
}
if (!resource.getContents().isEmpty()) {
TreeIterator<EObject> it = EcoreUtil2.eAll(resource.getContents().get(0));
while (it.hasNext()) {
EObject next = it.next();
if (map.containsKey(next)) {
continue;
}
QualifiedName name = qualifiedNameProvider.getFullyQualifiedName(next);
if (name != null) {
IEObjectDescription desc = EObjectDescription.create(name, next);
map.put(next, desc);
}
}
}
List<IEObjectDescription> result = Lists.newArrayList();
for (Map.Entry<EObject, IEObjectDescription> entry : map.entries()) {
QualifiedName name = computeSimpleName(map, entry.getValue());
SimpleNameDescription copy = new SimpleNameDescription(name, entry.getKey(), entry.getValue());
result.add(copy);
}
return result;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class FileAwareTestLanguageReferenceUpdater method update.
@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);
}
}
Aggregations