Search in sources :

Example 1 with TypeUsage

use of org.eclipse.xtext.xbase.imports.TypeUsage in project xtext-xtend by eclipse.

the class TypeUsageCollectorTest method hasUnresolvedType.

private void hasUnresolvedType(final Resource resource, final String... typeNames) {
    final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
    final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
        return it.getUsedTypeName();
    };
    final Set<String> usedNames = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
    Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>) Conversions.doWrapArray(typeNames))), usedNames);
}
Also used : TypeUsages(org.eclipse.xtext.xbase.imports.TypeUsages) XtextResource(org.eclipse.xtext.resource.XtextResource) TypeUsage(org.eclipse.xtext.xbase.imports.TypeUsage)

Example 2 with TypeUsage

use of org.eclipse.xtext.xbase.imports.TypeUsage in project xtext-eclipse by eclipse.

the class InteractiveUnresolvedTypeResolver method resolve.

@Override
public void resolve(TypeUsages typeUsages, XtextResource resource) {
    if (typeUsages.getUnresolvedTypeUsages().isEmpty() || resource == null)
        return;
    Multimap<String, TypeUsage> name2usage = LinkedHashMultimap.create();
    for (TypeUsage unresolved : typeUsages.getUnresolvedTypeUsages()) {
        String text = unresolved.getUsedTypeName();
        text = nameValueConverter.toValue(text, null);
        name2usage.put(text, unresolved);
    }
    for (String name : name2usage.keySet()) {
        Iterable<TypeUsage> usages = name2usage.get(name);
        JvmDeclaredType resolvedType = resolve(name, usages, resource);
        if (resolvedType != null) {
            for (TypeUsage usage : usages) typeUsages.addTypeUsage(resolvedType, usage.getSuffix(), usage.getTextRegion(), usage.getContext());
        }
    }
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) TypeUsage(org.eclipse.xtext.xbase.imports.TypeUsage)

Example 3 with TypeUsage

use of org.eclipse.xtext.xbase.imports.TypeUsage in project xtext-xtend by eclipse.

the class TypeUsageCollectorTest method hasUnresolvedTypeSuffix.

private void hasUnresolvedTypeSuffix(final CharSequence xtendFile, final String... suffix) {
    try {
        final Resource resource = this.file(xtendFile.toString()).eResource();
        final TypeUsages typeUsages = this.typeUsageCollector.collectTypeUsages(((XtextResource) resource));
        final Function1<TypeUsage, String> _function = (TypeUsage it) -> {
            return it.getSuffix();
        };
        final Set<String> foundSuffix = IterableExtensions.<String>toSet(ListExtensions.<TypeUsage, String>map(typeUsages.getUnresolvedTypeUsages(), _function));
        Assert.assertEquals(IterableExtensions.<String>toSet(((Iterable<String>) Conversions.doWrapArray(suffix))), foundSuffix);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : TypeUsages(org.eclipse.xtext.xbase.imports.TypeUsages) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) TypeUsage(org.eclipse.xtext.xbase.imports.TypeUsage)

Aggregations

TypeUsage (org.eclipse.xtext.xbase.imports.TypeUsage)3 XtextResource (org.eclipse.xtext.resource.XtextResource)2 TypeUsages (org.eclipse.xtext.xbase.imports.TypeUsages)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1