Search in sources :

Example 56 with IEObjectDescription

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

the class FQNImporter method getActualReplacementString.

/**
 * Return the to-be-inserted string if an existing import is present.
 */
@Override
public String getActualReplacementString(ConfigurableCompletionProposal proposal) {
    String syntacticReplacementString = proposal.getReplacementString();
    if (scope != null) {
        final QualifiedName qualifiedName = applyValueConverter(syntacticReplacementString);
        if (qualifiedName.getSegmentCount() == 1) {
            return syntacticReplacementString;
        }
        final IEObjectDescription element = scope.getSingleElement(qualifiedName);
        if (element != null) {
            EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context);
            if (!resolved.eIsProxy()) {
                IEObjectDescription description = findApplicableDescription(resolved, qualifiedName, true);
                if (description != null) {
                    String multisegmentProposal = applyValueConverter(description.getName());
                    return multisegmentProposal;
                }
            }
        }
    }
    return syntacticReplacementString;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 57 with IEObjectDescription

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

the class IsInScopeWithOptionalPositionPredicate method apply.

@Override
public boolean apply(String nameWithPosition) {
    String name = getNameFromNameWithPosition(nameWithPosition);
    String position = getPositionFromNameWithPosition(nameWithPosition);
    QualifiedName qualifiedName = converter.toQualifiedName(name);
    IEObjectDescription desc = scope.getSingleElement(qualifiedName);
    if (desc != null && !(desc instanceof IEObjectDescriptionWithError) && !(desc instanceof UnresolvableObjectDescription)) {
        if (!Strings.isNullOrEmpty(position)) {
            String nameWithPositionOfScopeELement = descriptionToNameWithPosition(currentURI, withLineNumber, desc);
            String positionOfScopeElement = getPositionFromNameWithPosition(nameWithPositionOfScopeELement);
            if (position.equals(positionOfScopeElement)) {
                return true;
            }
        } else {
            return true;
        }
    }
    return false;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) UnresolvableObjectDescription(org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)

Example 58 with IEObjectDescription

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

the class BuiltInTypeScope 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)) {
            IEObjectDescription description = EObjectDescription.create(type.getName(), type);
            elements.put(description.getName(), description);
        }
    }
}
Also used : VirtualBaseType(org.eclipse.n4js.ts.types.VirtualBaseType) AnyType(org.eclipse.n4js.ts.types.AnyType) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) VirtualBaseType(org.eclipse.n4js.ts.types.VirtualBaseType) TypeDefs(org.eclipse.n4js.ts.types.TypeDefs) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 59 with IEObjectDescription

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

the class EnumerableScope method getEObjectOrProxy.

/**
 * Returns a reference to the instance with the given qualified name.
 *
 * @return an optional reference.
 */
protected <T extends EObject> T getEObjectOrProxy(QualifiedName qn) {
    IEObjectDescription description = getSingleElement(qn);
    if (description == null)
        throw new IllegalStateException(qn + " is not contained in this scope");
    @SuppressWarnings("unchecked") T result = (T) description.getEObjectOrProxy();
    return result;
}
Also used : IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 60 with IEObjectDescription

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

the class BuiltInTypeScopeTest method testLoadingBuiltInTypes.

@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
    BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
    IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
    Assert.assertNotNull(anyType);
    String s = "";
    for (Resource resource : resourceSet.getResources()) {
        if (resource.getErrors().size() > 0) {
            for (Diagnostic d : resource.getErrors()) {
                s += "\n  " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
            }
        }
    }
    Assert.assertEquals("Resources definine built-in types must have no error.", "", s);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) BuiltInTypeScope(org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

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