Search in sources :

Example 66 with IEObjectDescription

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

the class VirtualBaseTypeScope method buildMap.

@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
    TypeDefs typeDefinitions = (TypeDefs) resource.getContents().get(0);
    for (Type type : typeDefinitions.getTypes()) {
        if (type instanceof VirtualBaseType) {
            // only virtualBase children.
            IEObjectDescription description = EObjectDescription.create(type.getName(), type);
            elements.put(description.getName(), description);
        }
    }
}
Also used : Type(org.eclipse.n4js.ts.types.Type) VirtualBaseType(org.eclipse.n4js.ts.types.VirtualBaseType) VirtualBaseType(org.eclipse.n4js.ts.types.VirtualBaseType) TypeDefs(org.eclipse.n4js.ts.types.TypeDefs) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 67 with IEObjectDescription

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

the class OriginAwareScope method getSingleElement.

/**
 * Enhanced query-Method marking the originating import as used.
 *
 * @see org.eclipse.xtext.scoping.IScope#getSingleElement(org.eclipse.xtext.naming.QualifiedName)
 */
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
    IEObjectDescription ret = delegatee.getSingleElement(name);
    if (ret == null)
        return null;
    ImportSpecifier origin = origins.get(ret);
    if (origin != null) {
        EObject script = EcoreUtil.getRootContainer(origin);
        if ((script instanceof Script) && ((Script) script).isFlaggedUsageMarkingFinished()) {
        // do nothing as linking phase is over
        } else {
            // return usage aware description
            return getUsageAwareDescription(ret);
        }
    }
    return ret;
}
Also used : ImportSpecifier(org.eclipse.n4js.n4JS.ImportSpecifier) Script(org.eclipse.n4js.n4JS.Script) EObject(org.eclipse.emf.ecore.EObject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 68 with IEObjectDescription

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

the class ComposedMemberDescriptionWithError method initialize.

private boolean initialize() {
    if (message == null) {
        IEObjectDescription[] descriptions = new IEObjectDescription[subScopes.length];
        // use string here, since EnumLiteral is
        MapOfIndexes<String> indexesPerMemberType = new MapOfIndexes<>();
        // not a TMember!
        MapOfIndexes<String> indexesPerCode = new MapOfIndexes<>();
        List<String> missingFrom = new ArrayList<>();
        final QualifiedName name = getName();
        boolean readOnlyField = false;
        for (int i = 0; i < max; i++) {
            IEObjectDescription description = subScopes[i].getSingleElement(name);
            if (description != null) {
                descriptions[i] = description;
                EObject eobj = description.getEObjectOrProxy();
                String type = getMemberTypeName(eobj);
                indexesPerMemberType.add(type, i);
                if (description instanceof IEObjectDescriptionWithError) {
                    String subCode = ((IEObjectDescriptionWithError) description).getIssueCode();
                    indexesPerCode.add(subCode, i);
                }
                if ("field".equals(type)) {
                    readOnlyField |= !((TField) eobj).isWriteable();
                }
            } else {
                missingFrom.add(getNameForSubScope(i));
            }
        }
        return initMessageAndCode(missingFrom, indexesPerMemberType, name, readOnlyField, descriptions, indexesPerCode);
    }
    return false;
}
Also used : TField(org.eclipse.n4js.ts.types.TField) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EObject(org.eclipse.emf.ecore.EObject)

Example 69 with IEObjectDescription

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

the class ComposedMemberScope method getAllLocalElements.

/**
 * Returns all elements of union. No erroneous descriptions (instances of IEObjectDescriptionWithError) will be
 * considered here, as we assume this method to be called from content assist and we do not want to show wrong
 * elements. These descriptions will be returned by {@link #getSingleElement(QualifiedName)} though to show errors
 * in case of explicit references to these members.
 */
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
    // collect all names from subScopes
    final Set<String> names = new HashSet<>();
    for (IScope currSubScope : subScopes) {
        try {
            for (IEObjectDescription currDesc : currSubScope.getAllElements()) {
                // omit erroneous bindings (they will be provided in getSingleLocalElement... though)
                if (!(currDesc instanceof IEObjectDescriptionWithError)) {
                    String name = currDesc.getName().getLastSegment();
                    names.add(name);
                }
            }
        } catch (UnsupportedOperationException e) {
        // according to API doc of IScope#getAllElements(), scopes are free to throw an
        // UnsupportedOperationException --> therefore we catch and ignore this here
        }
    }
    List<IEObjectDescription> descriptions = new ArrayList<>(names.size());
    for (String name : names) {
        IEObjectDescription description = getSingleLocalElementByName(QualifiedName.create(name));
        if (description != null && !(description instanceof IEObjectDescriptionWithError)) {
            descriptions.add(description);
        }
    }
    return descriptions;
}
Also used : ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) HashSet(java.util.HashSet) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 70 with IEObjectDescription

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

the class ComposedMemberScope method getSingleLocalElementByName.

/**
 * Returns description for given element, name is assumed to consist of a single segment containing the simple name
 * of the member. If no subScope contains a member with given name, null is returned. In other error cases (no or
 * wrong access, mixed types etc.), {@link IEObjectDescriptionWithError}, and in particular
 * {@link UnionMemberDescriptionWithError}, will be returned.
 */
@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName qualifiedName) {
    String name = qualifiedName.getLastSegment();
    TMember member = getOrCreateComposedMember(name);
    if (member == null) {
        // no such member, no need for "merging" descriptions, there won't be any
        return null;
    }
    if (isErrorPlaceholder(member)) {
        return createComposedMemberDescriptionWithErrors(EObjectDescription.create(member.getName(), member));
    }
    IEObjectDescription description = getCheckedDescription(name, member);
    return description;
}
Also used : TMember(org.eclipse.n4js.ts.types.TMember) 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