Search in sources :

Example 41 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class ComposedMemberScope method getOrCreateComposedMemberCache.

/**
 * Returns the composed member cache for the given ComposedTypeRef, creating it if it does not exist yet. Returns
 * <code>null</code> if a cache could not be created, because the given type reference is not contained in an
 * N4JSResource or this resource does not have a TModule.
 */
private ComposedMemberCache getOrCreateComposedMemberCache() {
    if (request.provideContainedMembers) {
        final // 
        MemberAccess contextCasted = // cast is valid, see MemberScopeRequest#provideContainedMembers
        (MemberAccess) request.context;
        final ComposedMemberCache cache = contextCasted.getComposedMemberCache();
        if (cache != null && TypeCompareUtils.isEqual(cache.getComposedTypeRef(), this.composedTypeRef)) {
            return cache;
        }
        // does not exist yet -> create new composed member cache in TModule:
        final Resource res = contextCasted.eResource();
        final TModule module = res instanceof N4JSResource ? ((N4JSResource) res).getModule() : null;
        if (module != null) {
            // Search in the module for composed member cache containing equivalent composed type ref
            for (ComposedMemberCache existingCache : module.getComposedMemberCaches()) {
                if (TypeCompareUtils.isEqual(existingCache.getComposedTypeRef(), composedTypeRef)) {
                    return existingCache;
                }
            }
            final ComposedMemberCache cacheNew = TypesFactory.eINSTANCE.createComposedMemberCache();
            EcoreUtilN4.doWithDeliver(false, () -> {
                // Order important due to notification!
                cacheNew.setComposedTypeRef(TypeUtils.copyIfContained(composedTypeRef));
                module.getComposedMemberCaches().add(cacheNew);
                contextCasted.setComposedMemberCache(cacheNew);
            }, module, contextCasted);
            return cacheNew;
        }
    }
    return null;
}
Also used : MemberAccess(org.eclipse.n4js.n4JS.MemberAccess) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache) TModule(org.eclipse.n4js.ts.types.TModule)

Example 42 with TModule

use of org.eclipse.n4js.ts.types.TModule 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)

Example 43 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method checkAccessibilityAndOverrideCompatibility.

/**
 * @param m
 *            the overriding member
 * @param s
 *            the overridden or implemented member
 * @param consumptionConflict
 *            check override or implementation override, the latter usually stems from a consumption conflict (so
 *            that s did not get consumed in the first place)
 * @param mm
 *            member matrix, only to improve error message
 */
private OverrideCompatibilityResult checkAccessibilityAndOverrideCompatibility(RedefinitionType redefinitionType, TMember m, TMember s, boolean consumptionConflict, MemberMatrix mm) {
    // getter/setter combination not checked here
    if (TypeUtils.isAccessorPair(m, s)) {
        return OverrideCompatibilityResult.ACCESSOR_PAIR;
    }
    // of @CovariantConstructor classes or implementing @CovariantConstructor interfaces
    if (m.isConstructor() && s.isConstructor() && !(isPolyfill(m) || isCovarianceForConstructorsRequired(m, s))) {
        return OverrideCompatibilityResult.COMPATIBLE;
    }
    // Nr.1 of Constraints 67 (Overriding Members) and Constraints 69 (Implementation of Interface Members)
    // --> s must be accessible
    final TModule contextModule = m.getContainingModule();
    final ContainerType<?> contextType = m.getContainingType();
    if (contextModule != null && contextType != null && !memberVisibilityChecker.isVisibleWhenOverriding(contextModule, contextType, contextType, s)) {
        if (!consumptionConflict) {
            // avoid consequential errors
            messageOverrideNonAccessible(redefinitionType, m, s);
        }
        return OverrideCompatibilityResult.ERROR;
    }
    // continue checking Constraints 65
    return constraints_65_overrideCompatible(redefinitionType, m, s, consumptionConflict, mm);
}
Also used : TModule(org.eclipse.n4js.ts.types.TModule)

Example 44 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class N4JSMemberRedefinitionValidator method constraints_42_45_46_AbstractMember.

/**
 * Constraints 42, 3 (Abstract Member)<br>
 * Constraints 45, 4 (Extending Interfaces)<br>
 * Constraints 46, 5 (Implementing Interfaces)
 *
 * This method doesn't add issues for missing override annotations but adds the missing-annotation-members to the
 * given collection.
 */
private void constraints_42_45_46_AbstractMember(MemberMatrix mm, Map<ParameterizedTypeRef, MemberList<TMember>> nonAccessibleAbstractMembersBySuperTypeRef) {
    N4ClassifierDefinition classifierDefinition = getCurrentClassifierDefinition();
    TClassifier classifier = getCurrentClassifier();
    TModule contextModule = EcoreUtil2.getContainerOfType(classifier, TModule.class);
    for (SourceAwareIterator iter = mm.allMembers(); iter.hasNext(); ) {
        TMember m = iter.next();
        if (!iter.isOwnedMember() && m.isAbstract()) {
            if (!memberVisibilityChecker.isVisibleWhenOverriding(contextModule, classifier, classifier, m)) {
                Iterable<ParameterizedTypeRef> superTypeRefs = FindClassifierInHierarchyUtils.findSuperTypesWithMember(classifierDefinition, m);
                for (ParameterizedTypeRef superTypeRef : superTypeRefs) {
                    MemberList<TMember> nonAccessible = nonAccessibleAbstractMembersBySuperTypeRef.get(superTypeRef);
                    if (nonAccessible == null) {
                        nonAccessible = new MemberList<>();
                        nonAccessibleAbstractMembersBySuperTypeRef.put(superTypeRef, nonAccessible);
                    }
                    nonAccessible.add(m);
                }
            }
        }
    }
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) N4ClassifierDefinition(org.eclipse.n4js.n4JS.N4ClassifierDefinition) SourceAwareIterator(org.eclipse.n4js.validation.validators.utils.MemberMatrix.SourceAwareIterator) TModule(org.eclipse.n4js.ts.types.TModule) TMember(org.eclipse.n4js.ts.types.TMember)

Example 45 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class KeyUtils method getSpecKeyWithoutProjectFolder.

/**
 * @return a unique key for the given element. The source folder is not part of the key. Instead, only the module
 *         name is used.
 */
public static String getSpecKeyWithoutProjectFolder(RepoRelativePathHolder rrph, IdentifiableElement element) {
    if (element instanceof TMember) {
        ContainerType<?> containingType = ((TMember) element).getContainingType();
        String specKeyOfType = getSpecKeyWithoutProjectFolder(rrph, containingType);
        String specKey = specKeyOfType + "." + element.getName();
        return specKey;
    }
    TModule module = element.getContainingModule();
    if (module == null) {
        return "GLOBAL.";
    } else {
        RepoRelativePath rrp = rrph.get(element);
        String elementName = nameFromElement(rrph, element);
        String key = getSpecKeyWithoutProjectFolder(rrp, elementName);
        return key;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) TModule(org.eclipse.n4js.ts.types.TModule)

Aggregations

TModule (org.eclipse.n4js.ts.types.TModule)48 EObject (org.eclipse.emf.ecore.EObject)12 Resource (org.eclipse.emf.ecore.resource.Resource)8 URI (org.eclipse.emf.common.util.URI)7 Type (org.eclipse.n4js.ts.types.Type)7 TMember (org.eclipse.n4js.ts.types.TMember)6 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 Script (org.eclipse.n4js.n4JS.Script)4 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 N4JSResource (org.eclipse.n4js.resource.N4JSResource)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)2 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)2 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)2 ContainerType (org.eclipse.n4js.ts.types.ContainerType)2