Search in sources :

Example 1 with ICrossEReferenceAndEObject

use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.

the class LinkingXpectMethod method linkedPathname.

/**
 * Similar to {@link #linkedName(IStringExpectation, ICrossEReferenceAndEObject)} but concatenating the fully
 * qualified name again instead of using the qualified name provider, as the latter may not create a valid name for
 * non-globally available elements.
 * <p>
 * The qualified name created by retrieving all "name" properties of the target and its containers, using '/' as
 * separator.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void linkedPathname(@StringExpectation IStringExpectation expectation, ICrossEReferenceAndEObject arg1) {
    EObject targetObject = (EObject) arg1.getEObject().eGet(arg1.getCrossEReference());
    if (targetObject == null) {
        Assert.fail("Reference is null");
        // to avoid warnings in the following
        return;
    }
    if (targetObject.eIsProxy())
        Assert.fail("Reference is a Proxy: " + ((InternalEObject) targetObject).eProxyURI());
    Resource targetResource = targetObject.eResource();
    if (targetResource instanceof TypeResource)
        targetResource = arg1.getEObject().eResource();
    if (!(targetResource instanceof XtextResource))
        Assert.fail("Referenced EObject is not in an XtextResource.");
    Deque<String> segments = new ArrayDeque<>();
    do {
        EStructuralFeature nameFeature = targetObject.eClass().getEStructuralFeature("name");
        if (nameFeature != null) {
            Object obj = targetObject.eGet(nameFeature);
            if (obj instanceof String) {
                segments.push((String) obj);
            }
        } else {
            if (targetObject instanceof NamedElement) {
                segments.push(((NamedElement) targetObject).getName());
            }
        }
        targetObject = targetObject.eContainer();
    } while (targetObject != null);
    String pathname = Joiner.on('/').join(segments);
    expectation.assertEquals(pathname);
}
Also used : TypeResource(org.eclipse.xtext.common.types.access.TypeResource) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtextResource(org.eclipse.xtext.resource.XtextResource) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) NamedElement(org.eclipse.n4js.n4JS.NamedElement) ArrayDeque(java.util.ArrayDeque) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 2 with ICrossEReferenceAndEObject

use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.

the class ScopeXpectMethod method binding.

/**
 * Checks that a given element is bound to something identified by (simple) qualified name. The check is designed as
 * simple as possible. That is, simply the next following expression is tested, and within that we expect a property
 * access or a direct identifiable element. The compared name is the simple qualified name, that is container (type)
 * followed by elements name, without URIs of modules etc.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void binding(// 
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    ParameterizedPropertyAccessExpression ppae = EcoreUtil2.getContainerOfType(eobj, ParameterizedPropertyAccessExpression.class);
    IdentifiableElement element;
    if (ppae != null) {
        element = ppae.getProperty();
    } else if (eobj instanceof IdentifiableElement) {
        element = (IdentifiableElement) eobj;
    } else {
        throw new IllegalArgumentException("Cannot check binding for " + (eobj == null ? "null" : eobj.eClass().getName()));
    }
    String container = "";
    if (element instanceof TMember) {
        container = ((TMember) element).getContainingType().getName() + ".";
    }
    final String qn = container + element.getName();
    // URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(Collections.singleton(qn));
}
Also used : ParameterizedPropertyAccessExpression(org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression) EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) TMember(org.eclipse.n4js.ts.types.TMember) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 3 with ICrossEReferenceAndEObject

use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.

the class ScopeXpectMethod method scope.

@Override
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scope(// 
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAllElements(scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 4 with ICrossEReferenceAndEObject

use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.

the class ScopeXpectMethod method scopeWithPosition.

/**
 * Compares scope including resource name and line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithPosition(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, true, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, true, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Example 5 with ICrossEReferenceAndEObject

use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.

the class ScopeXpectMethod method scopeWithResource.

/**
 * Compares scope including resource name but not line number.
 */
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public // 
void scopeWithResource(// 
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, // 
ICrossEReferenceAndEObject arg1) {
    EObject eobj = arg1.getEObject();
    IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
    for (IEObjectDescription eo : scope.getAllElements()) {
        eo.getEObjectURI();
    }
    URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
    expectation.assertEquals(new ScopeAwareIterable(uri, false, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ICrossEReferenceAndEObject(org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Xpect(org.eclipse.xpect.runner.Xpect) ParameterParser(org.eclipse.xpect.parameter.ParameterParser)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)5 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)5 Xpect (org.eclipse.xpect.runner.Xpect)5 ICrossEReferenceAndEObject (org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject)5 URI (org.eclipse.emf.common.util.URI)3 IScope (org.eclipse.xtext.scoping.IScope)3 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 ArrayDeque (java.util.ArrayDeque)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 NamedElement (org.eclipse.n4js.n4JS.NamedElement)1 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)1 IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)1 TMember (org.eclipse.n4js.ts.types.TMember)1 TypeResource (org.eclipse.xtext.common.types.access.TypeResource)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1