use of org.eclipse.xtext.resource.impl.AliasedEObjectDescription in project xtext-core by eclipse.
the class ImportScope method getLocalElementsByName.
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
List<IEObjectDescription> result = newArrayList();
QualifiedName resolvedQualifiedName = null;
ISelectable importFrom = getImportFrom();
for (ImportNormalizer normalizer : normalizers) {
final QualifiedName resolvedName = normalizer.resolve(name);
if (resolvedName != null) {
Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(type, resolvedName, isIgnoreCase());
for (IEObjectDescription resolvedElement : resolvedElements) {
if (resolvedQualifiedName == null)
resolvedQualifiedName = resolvedName;
else if (!resolvedQualifiedName.equals(resolvedName)) {
if (result.get(0).getEObjectOrProxy() != resolvedElement.getEObjectOrProxy()) {
return emptyList();
}
}
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;
}
use of org.eclipse.xtext.resource.impl.AliasedEObjectDescription in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method getImportedTypesScope.
protected IScope getImportedTypesScope(EObject model, final String misspelled, final IScope actualScope, IJavaSearchScope scope) {
if (scope == null) {
return IScope.NULLSCOPE;
}
try {
final Set<String> visiblePackages = importsConfiguration.getImplicitlyImportedPackages((XtextResource) model.eResource());
final Set<String> importedTypes = Sets.newHashSet();
final Set<String> seen = Sets.newHashSet();
XImportSection importSection = importsConfiguration.getImportSection((XtextResource) model.eResource());
if (importSection != null) {
parseImportSection(importSection, new IAcceptor<String>() {
@Override
public void accept(String t) {
visiblePackages.add(t);
}
}, new IAcceptor<String>() {
@Override
public void accept(String t) {
importedTypes.add(t);
}
});
}
SearchEngine searchEngine = new SearchEngine();
final List<IEObjectDescription> validProposals = Lists.newArrayList();
for (String importedType : importedTypes) {
if (validProposals.size() <= 5 && seen.add(importedType)) {
int dot = importedType.lastIndexOf('.');
if (dot != -1) {
importedType = importedType.substring(dot + 1);
}
if (isSimilarTypeName(misspelled, importedType)) {
QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(importedType);
for (IEObjectDescription element : actualScope.getElements(qualifiedName)) {
validProposals.add(new AliasedEObjectDescription(qualifiedName, element));
break;
}
}
}
}
try {
for (String visiblePackage : visiblePackages) {
if (validProposals.size() <= 5) {
searchEngine.searchAllTypeNames(visiblePackage.toCharArray(), SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scope, new TypeNameRequestor() {
@Override
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
StringBuilder typeNameBuilder = new StringBuilder(simpleTypeName.length);
for (char[] enclosingType : enclosingTypeNames) {
typeNameBuilder.append(enclosingType);
typeNameBuilder.append('.');
}
typeNameBuilder.append(simpleTypeName);
String typeName = typeNameBuilder.toString();
if (isSimilarTypeName(misspelled, typeName)) {
String fqNameAsString = getQualifiedTypeName(packageName, enclosingTypeNames, simpleTypeName);
if (seen.add(fqNameAsString)) {
QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(typeName);
for (IEObjectDescription element : actualScope.getElements(qualifiedName)) {
validProposals.add(new AliasedEObjectDescription(qualifiedName, element));
break;
}
}
}
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor() {
@Override
public boolean isCanceled() {
return validProposals.size() > 5;
}
});
}
}
} catch (OperationCanceledException exc) {
// enough proposals
}
return new SimpleScope(validProposals);
} catch (JavaModelException jme) {
return IScope.NULLSCOPE;
}
}
use of org.eclipse.xtext.resource.impl.AliasedEObjectDescription in project xtext-core by eclipse.
the class ImportScopeTest method testAllAliasedElements_05.
@Test
public void testAllAliasedElements_05() throws Exception {
final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com", "foo"), EcorePackage.Literals.EANNOTATION, null);
final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("com", "bar"), EcorePackage.Literals.EANNOTATION, null);
final IEObjectDescription desc3 = new EObjectDescription(QualifiedName.create("de", "foo"), EcorePackage.Literals.EATTRIBUTE, null);
final ArrayList<IEObjectDescription> newArrayList = newArrayList(desc1, desc2, desc3);
ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("COM"), true, true);
ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("DE"), true, true);
TestableImportScope scope = new TestableImportScope(newArrayList(n1, n2), IScope.NULLSCOPE, null, EcorePackage.Literals.EOBJECT, true);
Iterable<IEObjectDescription> elements = scope.getAliasedElements(newArrayList);
assertEquals(1, size(elements));
assertSame(desc2, ((AliasedEObjectDescription) elements.iterator().next()).getAliasedEObjectDescription());
}
use of org.eclipse.xtext.resource.impl.AliasedEObjectDescription in project xtext-core by eclipse.
the class ImportScopeTest method testAllAliasedElements_00.
@Test
public void testAllAliasedElements_00() throws Exception {
final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com", "foo"), EcorePackage.Literals.EANNOTATION, null);
final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("com", "foo"), EcorePackage.Literals.EATTRIBUTE, null);
final ArrayList<IEObjectDescription> newArrayList = newArrayList(desc1, desc2);
ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, true);
ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de"), true, true);
TestableImportScope scope = new TestableImportScope(newArrayList(n1, n2), IScope.NULLSCOPE, null, EcorePackage.Literals.EOBJECT, true);
Iterable<IEObjectDescription> elements = scope.getAliasedElements(newArrayList);
assertEquals(2, size(elements));
Iterator<IEObjectDescription> iterator = elements.iterator();
assertSame(desc1, ((AliasedEObjectDescription) iterator.next()).getAliasedEObjectDescription());
assertSame(desc2, ((AliasedEObjectDescription) iterator.next()).getAliasedEObjectDescription());
}
Aggregations