Search in sources :

Example 76 with IScope

use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.

the class ScopeXpectMethod method scopeWithPosition.

/**
 * Compares scope including resource name and line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithPosition(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, true, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, true, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 77 with IScope

use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.

the class ScopeXpectMethod method scopeWithResource.

/**
 * Compares scope including resource name but not line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithResource(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, false, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 78 with IScope

use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.

the class N4JSGlobalScopeProvider method createContainerScopeWithContext.

/**
 * Creates a new container scope containing only resource descriptions of the current project. With this container a
 * {@link UserDataAwareScope} is created.
 * <p>
 * This method is called for every container (that is source folder or archive) the current project depends on
 * according to the settings in the manifest,. This information has been indirectly retrieved via
 * {@link org.eclipse.n4js.projectModel.IN4JSProject#getDependencies()}.
 */
@Override
protected IScope createContainerScopeWithContext(Resource resource, IScope parent, IContainer container, Predicate<IEObjectDescription> filter, EClass type, boolean ignoreCase) {
    if (resource != null) {
        URI uriToFilter = resource.getURI();
        // do filter context-resource from scope except in case of static polyfills.
        if (container.hasResourceDescription(uriToFilter) && !isStaticPolyFiller(resource))
            container = new FilterUriContainer(uriToFilter, container);
        IScope result = UserDataAwareScope.createScope(parent, container, filter, type, ignoreCase, resource.getResourceSet(), canLoadFromDescriptionHelper, container);
        return result;
    }
    return IScope.NULLSCOPE;
}
Also used : FilterUriContainer(org.eclipse.xtext.resource.containers.FilterUriContainer) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI)

Example 79 with IScope

use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.

the class ComposedMemberScope method createComposedMember.

/**
 * Key method of entire scoping for composed types e.g. union/intersection types. This creates a new TMember as a
 * combination of all members of the given name in the type's contained types. If those members cannot be combined
 * into a single valid member, this method creates a dummy placeholder.
 */
private TMember createComposedMember(String memberName) {
    // check all subScopes for a member of the given name and
    // merge the properties of the existing members into 'composedMember'
    final Resource resource = EcoreUtilN4.getResource(request.context, composedTypeRef);
    ComposedMemberInfoBuilder cmiBuilder = new ComposedMemberInfoBuilder();
    cmiBuilder.init(writeAccess, resource, ts);
    for (int idx = 0; idx < subScopes.length; idx++) {
        final IScope subScope = subScopes[idx];
        final TypeRef typeRef = composedTypeRef.getTypeRefs().get(idx);
        final Resource res = EcoreUtilN4.getResource(request.context, composedTypeRef);
        final RuleEnvironment GwithSubstitutions = ts.createRuleEnvironmentForContext(typeRef, res);
        final TMember member = findMemberInSubScope(subScope, memberName);
        cmiBuilder.addMember(member, GwithSubstitutions);
    }
    // produce result
    ComposedMemberInfo cmi = cmiBuilder.get();
    ComposedMemberFactory cmf = getComposedMemberFactory(cmi);
    if (!cmf.isEmpty()) {
        // at least one of the subScopes had an element of that name
        final TMember result;
        if (cmf.isValid()) {
            // success case: The element for that name can be merged into a valid composed member
            result = cmf.create(memberName);
        } else {
            // some of the subScopes do not have an element for that name OR
            // they do not form a valid composed member (e.g. they are of different kind)
            // -> produce a specific error message explaining the incompatibility
            // (this error placeholder will be wrapped with a UncommonMemberDescription
            // in #getSingleLocalElementByName(QualifiedName) above)
            result = createErrorPlaceholder(memberName);
        }
        // add composed member to ComposedTypeRef's cache (without notifications to avoid cache-clear)
        final ComposedMemberCache cache = getOrCreateComposedMemberCache();
        if (cache != null) {
            EcoreUtilN4.doWithDeliver(false, () -> {
                cache.getCachedComposedMembers().add(result);
            }, cache);
        }
        // if cache==null: simply do not cache the composed member (i.e. member won't be contained in a resource!)
        return result;
    } else {
        // -> produce the ordinary "Cannot resolve reference ..." error by returning 'null'
        return null;
    }
}
Also used : TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache) TMember(org.eclipse.n4js.ts.types.TMember)

Example 80 with IScope

use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.

the class N4JSImportedNamespaceAwareLocalScopeProvider method getResourceScope.

@Override
protected IScope getResourceScope(Resource res, EReference reference) {
    EObject context = res.getContents().get(0);
    // ||-- changed super-impl here:
    // IDE-662 filtering ArgumentsType & EnumBaseType from globalScobe, since it is a VirtualBaseType.
    Predicate<IEObjectDescription> filter = p -> {
        String name = p.getName().toString();
        return !("ArgumentsType".equals(name) || "EnumBaseType".equals(name));
    };
    IScope globalScope = getGlobalScope(res, reference, filter);
    // -- done change --||
    List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference));
    // IDE-1735 adding support for static-polyfills:
    TModule module = (TModule) res.getContents().get(1);
    if (module.isStaticPolyfillModule()) {
        // limit to situations of resources, that contain at least
        // one @StaticPolyfill
        normalizers.add(createImportedNamespaceResolver(module.getQualifiedName() + N4JSQualifiedNameConverter.DELIMITER + "*", false));
    }
    if (!normalizers.isEmpty()) {
        globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference));
    }
    IScope resScope = getResourceScope(globalScope, context, reference);
    return resScope;
}
Also used : ImportedNamespaceAwareLocalScopeProvider(org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider) N4JSQualifiedNameConverter(org.eclipse.n4js.naming.N4JSQualifiedNameConverter) IScope(org.eclipse.xtext.scoping.IScope) EObject(org.eclipse.emf.ecore.EObject) ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) N4TSQualifiedNameProvider(org.eclipse.n4js.ts.scoping.N4TSQualifiedNameProvider) TModule(org.eclipse.n4js.ts.types.TModule) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Predicate(com.google.common.base.Predicate) Resource(org.eclipse.emf.ecore.resource.Resource) EReference(org.eclipse.emf.ecore.EReference) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) TModule(org.eclipse.n4js.ts.types.TModule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IScope (org.eclipse.xtext.scoping.IScope)148 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)57 Test (org.junit.Test)53 EObject (org.eclipse.emf.ecore.EObject)43 QualifiedName (org.eclipse.xtext.naming.QualifiedName)26 XtextResource (org.eclipse.xtext.resource.XtextResource)19 EReference (org.eclipse.emf.ecore.EReference)17 EClass (org.eclipse.emf.ecore.EClass)15 StringInputStream (org.eclipse.xtext.util.StringInputStream)15 URI (org.eclipse.emf.common.util.URI)12 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)12 ArrayList (java.util.ArrayList)10 Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 AbstractScopingTest (com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)7 Predicate (com.google.common.base.Predicate)6 EClassifier (org.eclipse.emf.ecore.EClassifier)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6