Search in sources :

Example 51 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.

the class FilterWithErrorMarkerScope method getSingleElement.

/**
 * Returns the first not filtered element found in the parent scope; if no such element is found, an
 * {@link IEObjectDescriptionWithError} is created for the element originally found in the parent scope by that
 * name.
 * <p>
 * Note that the extended behavior of looking for possibly shadowed elements makes only sense if the parent's
 * {@link IScope#getElements(QualifiedName)} returns more than one element and if
 * {@link IScope#getSingleElement(EObject)} is only an optimization in case only one element is present.
 */
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
    IEObjectDescription result = parent.getSingleElement(name);
    if (result == null || isAccepted(result)) {
        return result;
    }
    Iterable<IEObjectDescription> allElements = parent.getElements(name);
    for (IEObjectDescription description : allElements) {
        if (isAccepted(description)) {
            return description;
        }
    }
    return wrapFilteredDescription(result);
}
Also used : IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 52 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription 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)

Example 53 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.

the class IntersectionMemberScope method getCheckedDescription.

@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);
    QualifiedName qn = QualifiedName.create(name);
    boolean allDescrWithError = true;
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        allDescrWithError &= descrWithError;
    }
    if (allDescrWithError) {
        return createComposedMemberDescriptionWithErrors(description);
    }
    return description;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 54 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.

the class UnionMemberScope method getCheckedDescription.

@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
    IEObjectDescription description = EObjectDescription.create(member.getName(), member);
    QualifiedName qn = QualifiedName.create(name);
    for (IScope currSubScope : subScopes) {
        IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
        boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
        if (descrWithError) {
            return createComposedMemberDescriptionWithErrors(description);
        }
    }
    return description;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 55 with IEObjectDescription

use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.

the class ImportProvidedElementLabelprovider method getText.

@Override
public String getText(Object element) {
    if (element instanceof ImportableObject) {
        ImportableObject io = (ImportableObject) element;
        return getText(io.getTe());
    }
    if (element instanceof ImportProvidedElement) {
        ImportProvidedElement ele = ((ImportProvidedElement) element);
        TModule tm = ((ImportDeclaration) ele.getImportSpecifier().eContainer()).getModule();
        return ele.getLocalName() + " from " + findLocation(tm);
    }
    if (element instanceof IEObjectDescription) {
        IEObjectDescription ieod = (IEObjectDescription) element;
        EObject eo = ieod.getEObjectOrProxy();
        if (eo instanceof TExportableElement && !eo.eIsProxy()) {
            return getText(eo);
        }
        return ieod.getName().getLastSegment() + " from " + qualifiedNameConverter.toString(ieod.getName().skipLast(1));
    }
    if (element instanceof TExportableElement) {
        TExportableElement te = (TExportableElement) element;
        return te.getName() + " (exported as " + te.getExportedName() + ") from " + findLocation(te.getContainingModule());
    }
    return n4Labelprovider.getText(element);
}
Also used : ImportProvidedElement(org.eclipse.n4js.organize.imports.ImportProvidedElement) TExportableElement(org.eclipse.n4js.ts.types.TExportableElement) EObject(org.eclipse.emf.ecore.EObject) ImportDeclaration(org.eclipse.n4js.n4JS.ImportDeclaration) TModule(org.eclipse.n4js.ts.types.TModule) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)324 Test (org.junit.Test)95 EObject (org.eclipse.emf.ecore.EObject)82 QualifiedName (org.eclipse.xtext.naming.QualifiedName)79 IScope (org.eclipse.xtext.scoping.IScope)56 URI (org.eclipse.emf.common.util.URI)41 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)33 EClass (org.eclipse.emf.ecore.EClass)30 Resource (org.eclipse.emf.ecore.resource.Resource)28 EObjectDescription (org.eclipse.xtext.resource.EObjectDescription)22 AliasedEObjectDescription (org.eclipse.xtext.resource.impl.AliasedEObjectDescription)22 ArrayList (java.util.ArrayList)19 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)14 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)12 StyledString (org.eclipse.jface.viewers.StyledString)12 XtextResource (org.eclipse.xtext.resource.XtextResource)11 StringInputStream (org.eclipse.xtext.util.StringInputStream)11 EReference (org.eclipse.emf.ecore.EReference)10 List (java.util.List)9