Search in sources :

Example 6 with NamedElement

use of org.eclipse.n4js.n4JS.NamedElement 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 7 with NamedElement

use of org.eclipse.n4js.n4JS.NamedElement in project n4js by eclipse.

the class N4ClassDeclarationImpl method getExportedName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getExportedName() {
    boolean _isExported = this.isExported();
    if (_isExported) {
        EObject _eContainer = this.eContainer();
        final ExportDeclaration exportDecl = ((ExportDeclaration) _eContainer);
        boolean _isDefaultExport = exportDecl.isDefaultExport();
        if (_isDefaultExport) {
            return "default";
        }
        final ExportableElement me = this;
        String _switchResult = null;
        boolean _matched = false;
        if (me instanceof NamedElement) {
            _matched = true;
            _switchResult = ((NamedElement) me).getName();
        }
        if (!_matched) {
            if (me instanceof IdentifiableElement) {
                _matched = true;
                _switchResult = ((IdentifiableElement) me).getName();
            }
        }
        return _switchResult;
    }
    return null;
}
Also used : ExportableElement(org.eclipse.n4js.n4JS.ExportableElement) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) NamedElement(org.eclipse.n4js.n4JS.NamedElement)

Example 8 with NamedElement

use of org.eclipse.n4js.n4JS.NamedElement in project n4js by eclipse.

the class N4TypeDeclarationImpl method getExportedName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getExportedName() {
    boolean _isExported = this.isExported();
    if (_isExported) {
        EObject _eContainer = this.eContainer();
        final ExportDeclaration exportDecl = ((ExportDeclaration) _eContainer);
        boolean _isDefaultExport = exportDecl.isDefaultExport();
        if (_isDefaultExport) {
            return "default";
        }
        final ExportableElement me = this;
        String _switchResult = null;
        boolean _matched = false;
        if (me instanceof NamedElement) {
            _matched = true;
            _switchResult = ((NamedElement) me).getName();
        }
        if (!_matched) {
            if (me instanceof IdentifiableElement) {
                _matched = true;
                _switchResult = ((IdentifiableElement) me).getName();
            }
        }
        return _switchResult;
    }
    return null;
}
Also used : ExportableElement(org.eclipse.n4js.n4JS.ExportableElement) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) NamedElement(org.eclipse.n4js.n4JS.NamedElement)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)8 NamedElement (org.eclipse.n4js.n4JS.NamedElement)8 IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)7 ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)6 ExportableElement (org.eclipse.n4js.n4JS.ExportableElement)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 ArrayDeque (java.util.ArrayDeque)1 URI (org.eclipse.emf.common.util.URI)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ParameterParser (org.eclipse.xpect.parameter.ParameterParser)1 Xpect (org.eclipse.xpect.runner.Xpect)1 ICrossEReferenceAndEObject (org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject)1 TypeResource (org.eclipse.xtext.common.types.access.TypeResource)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1