Search in sources :

Example 21 with LiteralOrComputedPropertyName

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

the class TypeXpectMethod method getTypeString.

private String getTypeString(IEObjectCoveringRegion offset, boolean expectedType) {
    final String calculatedString;
    EObject eobject = offset.getEObject();
    if (eobject instanceof LiteralOrComputedPropertyName) {
        eobject = eobject.eContainer();
    }
    RuleEnvironment G = newRuleEnvironment(eobject);
    Result<org.eclipse.n4js.ts.typeRefs.TypeRef> result;
    if (expectedType) {
        if (!(eobject instanceof Expression && eobject.eContainer() != null))
            return "Not an Expression at given region (required to obtain expected type); got instead: " + eobject.eClass().getName();
        result = ts.expectedTypeIn(G, eobject.eContainer(), (Expression) eobject);
    } else {
        if (eobject instanceof BindingProperty) {
            /*-
				 * Small tweak to allow testing the inferred type of variable declarations within binding patterns. For
				 * example, without this tweak, the following test would fail with a "Not a TypableElement at given
				 * region" exception:
				 *
				 * // Xpect type of 'len' --> number
				 * var {length:len} = "hello";
				 */
            if (((BindingProperty) eobject).getValue() != null && ((BindingProperty) eobject).getValue().getVarDecl() != null) {
                eobject = ((BindingProperty) eobject).getValue().getVarDecl();
            }
        }
        if (!(eobject instanceof TypableElement))
            return "Not a TypableElement at given region; got instead: " + eobject.eClass().getName();
        result = ts.type(G, (TypableElement) eobject);
    }
    if (result.getRuleFailedException() != null) {
        calculatedString = result.getRuleFailedException().getMessage();
    } else {
        calculatedString = result.getValue().getTypeRefAsString();
    }
    return calculatedString;
}
Also used : Expression(org.eclipse.n4js.n4JS.Expression) ParameterizedCallExpression(org.eclipse.n4js.n4JS.ParameterizedCallExpression) TypableElement(org.eclipse.n4js.ts.types.TypableElement) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) RuleEnvironmentExtensions.newRuleEnvironment(org.eclipse.n4js.typesystem.RuleEnvironmentExtensions.newRuleEnvironment) BindingProperty(org.eclipse.n4js.n4JS.BindingProperty)

Example 22 with LiteralOrComputedPropertyName

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

the class PropertyAssignmentImpl method getName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getName() {
    LiteralOrComputedPropertyName _declaredName = this.getDeclaredName();
    String _name = null;
    if (_declaredName != null) {
        _name = _declaredName.getName();
    }
    return _name;
}
Also used : LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)

Example 23 with LiteralOrComputedPropertyName

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

the class N4MethodDeclarationImpl method getName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getName() {
    LiteralOrComputedPropertyName _declaredName = this.getDeclaredName();
    String _name = null;
    if (_declaredName != null) {
        _name = _declaredName.getName();
    }
    return _name;
}
Also used : LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)

Example 24 with LiteralOrComputedPropertyName

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

the class N4MethodDeclarationImpl method basicSetDeclaredName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetDeclaredName(LiteralOrComputedPropertyName newDeclaredName, NotificationChain msgs) {
    LiteralOrComputedPropertyName oldDeclaredName = declaredName;
    declaredName = newDeclaredName;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, N4JSPackage.N4_METHOD_DECLARATION__DECLARED_NAME, oldDeclaredName, newDeclaredName);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)

Example 25 with LiteralOrComputedPropertyName

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

the class N4MethodDeclarationImpl method isValidName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean isValidName() {
    String _name = this.getName();
    boolean _equals = Objects.equal("prototype", _name);
    if (_equals) {
        return false;
    }
    boolean _and = false;
    if (!(Objects.equal("constructor", this.getName()) && this.isGenerator())) {
        _and = false;
    } else {
        LiteralOrComputedPropertyName _declaredName = this.getDeclaredName();
        PropertyNameKind _kind = null;
        if (_declaredName != null) {
            _kind = _declaredName.getKind();
        }
        boolean _tripleNotEquals = (_kind != PropertyNameKind.COMPUTED);
        _and = _tripleNotEquals;
    }
    if (_and) {
        return false;
    }
    return true;
}
Also used : PropertyNameKind(org.eclipse.n4js.n4JS.PropertyNameKind) LiteralOrComputedPropertyName(org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)

Aggregations

LiteralOrComputedPropertyName (org.eclipse.n4js.n4JS.LiteralOrComputedPropertyName)27 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)8 PropertyNameKind (org.eclipse.n4js.n4JS.PropertyNameKind)7 EObject (org.eclipse.emf.ecore.EObject)3 BindingProperty (org.eclipse.n4js.n4JS.BindingProperty)2 Block (org.eclipse.n4js.n4JS.Block)2 CatchBlock (org.eclipse.n4js.n4JS.CatchBlock)2 ExportDeclaration (org.eclipse.n4js.n4JS.ExportDeclaration)2 ExportSpecifier (org.eclipse.n4js.n4JS.ExportSpecifier)2 Expression (org.eclipse.n4js.n4JS.Expression)2 FormalParameter (org.eclipse.n4js.n4JS.FormalParameter)2 FunctionDeclaration (org.eclipse.n4js.n4JS.FunctionDeclaration)2 N4FieldDeclaration (org.eclipse.n4js.n4JS.N4FieldDeclaration)2 ParameterizedCallExpression (org.eclipse.n4js.n4JS.ParameterizedCallExpression)2 Script (org.eclipse.n4js.n4JS.Script)2 ArrayList (java.util.ArrayList)1 URI (org.eclipse.emf.common.util.URI)1 EPackage (org.eclipse.emf.ecore.EPackage)1 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)1 Annotation (org.eclipse.n4js.n4JS.Annotation)1