Search in sources :

Example 1 with TModule

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

the class KeyUtils method nameFromElement.

private static String nameFromElement(RepoRelativePathHolder rrph, IdentifiableElement element) {
    if (element instanceof TMember) {
        TMember tMember = (TMember) element;
        String name = nameFromElement(rrph, tMember.getContainingType());
        return name + "#" + element.getName();
    }
    TModule module = element.getContainingModule();
    if (module == null) {
        String name = "##global##." + element.getName();
        return name;
    } else {
        String name = module.getModuleSpecifier() + "." + element.getName();
        return name;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) TModule(org.eclipse.n4js.ts.types.TModule)

Example 2 with TModule

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

the class KeyUtils method getSpecKeyPrefix.

/**
 * @return a complete spec key comprised of the whole {@link RepoRelativePath}
 */
public static String getSpecKeyPrefix(RepoRelativePathHolder rrph, IdentifiableElement element) {
    if (element instanceof TMember) {
        ContainerType<?> containingType = ((TMember) element).getContainingType();
        return getSpecKeyPrefix(rrph, containingType);
    }
    TModule module = element.getContainingModule();
    if (module == null) {
        return "GLOBAL.";
    } else {
        RepoRelativePath rrp = rrph.get(element);
        String key = rrp.getFullPath();
        return key;
    }
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) TModule(org.eclipse.n4js.ts.types.TModule)

Example 3 with TModule

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

the class PolyfillValidatorFragment method holdsSameJavascriptVariant.

/**
 * Constraint 155 (static polyfill layout), no. 4
 */
private boolean holdsSameJavascriptVariant(PolyfillValidationState state) {
    final TModule fillerModule = state.polyType.getContainingModule();
    final TModule filledModule = state.filledType.getContainingModule();
    if (fillerModule != null && filledModule != null && fillerModule.isN4jsdModule() != filledModule.isN4jsdModule()) {
        final String fileExt = fillerModule.isN4jsdModule() ? N4JSGlobals.N4JSD_FILE_EXTENSION : N4JSGlobals.N4JS_FILE_EXTENSION;
        final String msg = getMessageForCLF_POLYFILL_STATIC_DIFFERENT_VARIANT(state.name, "." + fileExt);
        addIssue(state, msg, CLF_POLYFILL_STATIC_DIFFERENT_VARIANT);
        return false;
    }
    return true;
}
Also used : TModule(org.eclipse.n4js.ts.types.TModule)

Example 4 with TModule

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

the class PolyfillValidatorFragment method holdPolyfillName.

/**
 * Constraints (Polyfill Class) 156.2 polyfill name and module
 */
private boolean holdPolyfillName(PolyfillValidationState state) {
    if (!state.name.equals(state.filledType.getName())) {
        // (Polyfill Class) 156.2
        final String msg = getMessageForCLF_POLYFILL_DIFFERENT_NAME(state.name, state.filledType.getName());
        addIssue(state, msg, CLF_POLYFILL_DIFFERENT_NAME);
        return false;
    }
    final boolean isGlobalFilled = GLOBAL.hasAnnotation(state.filledType);
    final boolean isGlobalPoly = GLOBAL.hasAnnotation(state.polyType);
    if (isGlobalFilled != isGlobalPoly) {
        // (Polyfill Class) 156.2
        final String msg = getMessageForCLF_POLYFILL_DIFFERENT_GLOBALS(state.name, isGlobalPoly ? "global" : "not global", isGlobalFilled ? "global" : "not global");
        addIssue(state, msg, CLF_POLYFILL_DIFFERENT_GLOBALS);
        return false;
    }
    if (!isGlobalFilled) {
        final TModule polyModule = state.polyType.getContainingModule();
        final TModule filledModule = state.filledType.getContainingModule();
        if (polyModule != null && filledModule != null) {
            // avoid consequential errors
            if (!polyModule.getModuleSpecifier().equals(filledModule.getModuleSpecifier())) {
                // (Polyfill Class)
                // 156.2
                final String msg = getMessageForCLF_POLYFILL_DIFFERENT_MODULE_SPECIFIER(state.name, polyModule.getModuleSpecifier(), filledModule.getModuleSpecifier());
                addIssue(state, msg, CLF_POLYFILL_DIFFERENT_MODULE_SPECIFIER);
                return false;
            }
        }
    }
    return true;
}
Also used : TModule(org.eclipse.n4js.ts.types.TModule)

Example 5 with TModule

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

the class PolyfillValidatorFragment method holdsSinglePolyfillSource.

/**
 * Constraints 129 (Applying Polyfills) No member must be filled by more than one polyfill.
 */
private boolean holdsSinglePolyfillSource(PolyfillValidationState state) {
    EList<TMember> myPolyMember = state.polyType.getOwnedMembers();
    // a) find references to the filled type
    // b) check, that they are in the same Project
    // c) search for clashing contributions.
    XtextResource res = (XtextResource) state.polyType.eResource();
    IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(res);
    // a+b) all polyfills to same calssifier in same project:
    IContainer container = containerManager.getContainer(res.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(res), index);
    // Iterable over all exported Polyfills
    Iterable<IEObjectDescription> iterEObj = container.getExportedObjects(TypesPackage.Literals.TCLASSIFIER, N4TSQualifiedNameProvider.getPolyfillFQN(state.filledType, qualifiedNameProvider), false);
    // collection of involved TModules for each Member.
    ListMultimap<TMember, TModule> clashProviders = LinkedListMultimap.create();
    for (IEObjectDescription pivotObjectDescription : iterEObj) {
        EObject eob = pivotObjectDescription.getEObjectOrProxy();
        // Resolve
        if (eob.eIsProxy()) {
            eob = EcoreUtil.resolve(eob, res);
        }
        if (eob == state.polyType) {
            // saw myself .-.
            continue;
        }
        EList<TMember> pivotPolyMember = ((TClassifier) eob).getOwnedMembers();
        ListMultimap<TMember, TMember> clashing = findClashingMembersByName(myPolyMember, pivotPolyMember);
        for (TMember myMember : clashing.keySet()) {
            // only interested in the module, so first is sufficient
            clashProviders.put(myMember, clashing.get(myMember).get(0).getContainingModule());
        }
    }
    List<TMember> sortedMembers = clashProviders.keySet().stream().sorted().collect(Collectors.toList());
    for (TMember myMember : sortedMembers) {
        // Combine list of Modules involved in the polyfill clash.
        String uris = Stream.concat(Stream.of(myMember.getContainingModule()), clashProviders.get(myMember).stream()).map(u -> u.getQualifiedName().toString()).sorted().reduce("", (a, b) -> a + PREFIX_LIST + b);
        if (uris.startsWith(PREFIX_LIST))
            uris = uris.substring(PREFIX_LIST.length());
        int lastPrefix_idx = uris.lastIndexOf(PREFIX_LIST);
        if (lastPrefix_idx >= 0) {
            StringBuffer sb = new StringBuffer(uris);
            uris = sb.replace(lastPrefix_idx, lastPrefix_idx + PREFIX_LIST.length(), " and ").toString();
        }
        // give Qualified name filled in Property.
        String memberAxis = myMember.getContainingType().getName() + "." + myMember.getName();
        // Issue on filled Member-name declaration:
        String msg = IssueCodes.getMessageForCLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT(uris, memberAxis);
        state.host.addIssue(msg, myMember.getAstElement(), N4JSPackage.Literals.PROPERTY_NAME_OWNER__DECLARED_NAME, IssueCodes.CLF_POLYFILL_MULTIPOLYFILLS_MEMBER_CONFLICT);
    }
    return true;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) XtextResource(org.eclipse.xtext.resource.XtextResource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) EObject(org.eclipse.emf.ecore.EObject) TMember(org.eclipse.n4js.ts.types.TMember) IContainer(org.eclipse.xtext.resource.IContainer) 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