Java Code Examples for org.eclipse.xtext.scoping.impl.ImportNormalizer#resolve()

The following examples show how to use org.eclipse.xtext.scoping.impl.ImportNormalizer#resolve() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeScopeWithWildcardImports.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	for(int i = 0; i < imports.length; i++) {
		ImportNormalizer[] chunk = imports[i];
		IEObjectDescription result = null;
		for(int j = 0; j < chunk.length; j++) {
			ImportNormalizer normalizer = chunk[j];
			QualifiedName resolvedName = normalizer.resolve(name);
			if (resolvedName != null) {
				IEObjectDescription candidate = typeScope.getSingleElement(resolvedName, true);
				if (candidate != null) {
					if (result == null) {
						result = candidate;
					} else {
						return null;
					}
				}
			}
		}
		if (result != null) {
			return result;
		}
	}
	return getSingleElementFromParent(name);
}
 
Example 2
Source File: NonResolvingImportScope.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
	List<IEObjectDescription> result = newArrayList();
	QualifiedName resolvedQualifiedName = null;
	ISelectable importFrom = getImportFrom();
	for (ImportNormalizer normalizer : myNormalizers) {
		final QualifiedName resolvedName = normalizer.resolve(name);
		if (resolvedName != null) {
			Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(myType, resolvedName,
					isIgnoreCase());
			for (IEObjectDescription resolvedElement : resolvedElements) {
				if (resolvedQualifiedName == null)
					resolvedQualifiedName = resolvedName;
				else if (!resolvedQualifiedName.equals(resolvedName)) {
					// change is here
					if (result.get(0).getEObjectURI().equals(resolvedElement.getEObjectURI())) {
						return emptyList();
					}
					// change is above
				}
				QualifiedName alias = normalizer.deresolve(resolvedElement.getName());
				if (alias == null)
					throw new IllegalStateException("Couldn't deresolve " + resolvedElement.getName()
							+ " with import " + normalizer);
				final AliasedEObjectDescription aliasedEObjectDescription = new AliasedEObjectDescription(alias,
						resolvedElement);
				result.add(aliasedEObjectDescription);
			}
		}
	}
	return result;
}