Search in sources :

Example 11 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class HyperlinkXpectMethod method getTargetDescription.

private String getTargetDescription(XtextResource resource, IHyperlink hyperlink) {
    final StringBuffer sb = new StringBuffer();
    // append hyperlink text. Only consider the element name and ignore the qualified part.
    String hyperlinkText = hyperlink.getHyperlinkText();
    hyperlinkText = hyperlinkText.substring(hyperlinkText.lastIndexOf('.') + 1);
    if (hyperlinkText != null)
        sb.append(hyperlinkText);
    else
        sb.append("<no hyperlink text>");
    // append description of target element (path from the element to the root of the AST)
    final EObject target = getTarget(resource, hyperlink);
    if (target != null) {
        // build chain of ancestor AST elements
        sb.append(": ");
        final int startLen = sb.length();
        EObject currTarget = target;
        while (currTarget != null) {
            if (currTarget instanceof NamedElement || currTarget instanceof IdentifiableElement) {
                if (sb.length() > startLen)
                    sb.append(" in ");
                String name = currTarget instanceof NamedElement ? ((NamedElement) currTarget).getName() : ((IdentifiableElement) currTarget).getName();
                if (name == null || name.trim().length() == 0)
                    name = "<unnamed>";
                else
                    name = "\"" + name + "\"";
                sb.append(name + "(" + currTarget.eClass().getName() + ")");
            }
            currTarget = currTarget.eContainer();
        }
        // add URI of resource
        final URI targetResURI = target.eResource() != null ? target.eResource().getURI() : null;
        final String fname = targetResURI != null ? targetResURI.lastSegment() : null;
        if (fname != null && fname.trim().length() > 0) {
            sb.append(" in file ");
            sb.append(fname);
        }
    }
    return sb.toString();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement) NamedElement(org.eclipse.n4js.n4JS.NamedElement) URI(org.eclipse.emf.common.util.URI)

Example 12 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement 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 13 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class ParameterizedPropertyAccessExpressionImpl method setProperty.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setProperty(IdentifiableElement newProperty) {
    IdentifiableElement oldProperty = property;
    property = newProperty;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.PARAMETERIZED_PROPERTY_ACCESS_EXPRESSION__PROPERTY, oldProperty, property));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement)

Example 14 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement in project n4js by eclipse.

the class JSXPropertyAttributeImpl method setProperty.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setProperty(IdentifiableElement newProperty) {
    IdentifiableElement oldProperty = property;
    property = newProperty;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.JSX_PROPERTY_ATTRIBUTE__PROPERTY, oldProperty, property));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) IdentifiableElement(org.eclipse.n4js.ts.types.IdentifiableElement)

Example 15 with IdentifiableElement

use of org.eclipse.n4js.ts.types.IdentifiableElement 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)

Aggregations

IdentifiableElement (org.eclipse.n4js.ts.types.IdentifiableElement)27 EObject (org.eclipse.emf.ecore.EObject)12 ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)7 ExportableElement (org.eclipse.n4js.n4JS.ExportableElement)6 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)6 NamedElement (org.eclipse.n4js.n4JS.NamedElement)5 ParameterizedPropertyAccessExpression (org.eclipse.n4js.n4JS.ParameterizedPropertyAccessExpression)5 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)5 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)5 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)5 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)5 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)5 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)5 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)5 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)5 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)5 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)5 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)5 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)5 Result (org.eclipse.xsemantics.runtime.Result)5