use of org.eclipse.xtext.scoping.impl.ImportNormalizer in project xtext-xtend by eclipse.
the class TypeScopeWithWildcardImports method doGetElements.
@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
if (!(type instanceof JvmDeclaredType)) {
return;
}
JvmDeclaredType declaredType = (JvmDeclaredType) type;
String packageName = declaredType.getPackageName();
if (!Strings.isEmpty(packageName)) {
QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
QualifiedName withDot = null;
String withDollar = null;
for (int i = 0; i < imports.length; i++) {
ImportNormalizer[] chunk = imports[i];
for (int j = 0; j < chunk.length; j++) {
ImportNormalizer normalizer = chunk[j];
QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
if (namespacePrefix.equals(qualifiedPackageName)) {
if (withDot == null) {
withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
}
result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
if (withDollar != null) {
result.add(EObjectDescription.create(withDollar, type));
}
}
}
}
}
if (parent != null) {
parent.doGetElements(type, result);
} else {
Iterables.addAll(result, typeScope.getElements(type));
}
}
use of org.eclipse.xtext.scoping.impl.ImportNormalizer in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getImportScope.
private AbstractScope getImportScope(XImportSection importSection, AbstractScope parent, RecordingTypeScope typeScope) {
if (importSection == null)
return parent;
List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
if (importDeclarations.isEmpty()) {
return parent;
}
List<ImportNormalizer> wildcardImports = null;
List<JvmType> concreteImports = null;
List<QualifiedName> importedNames = null;
boolean hasLegacyImport = false;
for (XImportDeclaration importDeclaration : importDeclarations) {
if (!importDeclaration.isStatic()) {
if (importDeclaration.isWildcard()) {
if (wildcardImports == null) {
wildcardImports = Lists.newArrayListWithCapacity(4);
}
String importedNamespace = importDeclaration.getImportedNamespace();
importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2);
QualifiedName qualifiedImportedNamespace = qualifiedNameConverter.toQualifiedName(importedNamespace);
wildcardImports.add(AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(qualifiedImportedNamespace, true, false));
} else {
JvmDeclaredType importedType = importDeclaration.getImportedType();
if (importedType != null && !importedType.eIsProxy()) {
if (concreteImports == null || importedNames == null) /* to make JDT happy */
{
concreteImports = Lists.newArrayListWithCapacity(10);
importedNames = Lists.newArrayListWithCapacity(10);
}
concreteImports.add(importedType);
if (importedType.eContainer() instanceof JvmDeclaredType) {
String importSyntax = getImportsConfiguration().getLegacyImportSyntax(importDeclaration);
if (importSyntax != null) {
hasLegacyImport = true;
importedNames.add(getQualifiedNameConverter().toQualifiedName(importSyntax));
} else
importedNames.add(null);
} else {
importedNames.add(null);
}
}
}
}
}
return getImportScope(wildcardImports, concreteImports, hasLegacyImport ? importedNames : null, parent, typeScope);
}
use of org.eclipse.xtext.scoping.impl.ImportNormalizer in project xtext-core by eclipse.
the class FileAwareTestLanguageImportScopeProvider method internalGetImportedNamespaceResolvers.
@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;
}
use of org.eclipse.xtext.scoping.impl.ImportNormalizer in project xtext-xtend by eclipse.
the class TypeScopeWithWildcardImports method getSingleElement.
@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);
}
use of org.eclipse.xtext.scoping.impl.ImportNormalizer in project xtext-core by eclipse.
the class QualifiedNameTest method testBug354473.
@Test
public void testBug354473() {
DefaultImpl impl = new IQualifiedNameConverter.DefaultImpl();
QualifiedName name = impl.toQualifiedName(".");
ImportNormalizer normalizer = new ImportNormalizer(QualifiedName.create("Test"), true, false);
assertNull(normalizer.resolve(name));
}
Aggregations