blob: e28bcca8e6e0d617f8650feaf9caa49c4c3a1090 [file] [log] [blame]
/**
* Copyright (c) 2011 NumberFour AG
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* NumberFour AG - initial API and Implementation (Alex Panchenko)
*/
package org.eclipse.dltk.javascript.typeinfo.model.impl;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.ITypeSystem;
import org.eclipse.dltk.javascript.typeinfo.RTypeVariable;
import org.eclipse.dltk.javascript.typeinfo.RTypes;
import org.eclipse.dltk.javascript.typeinfo.model.JSType;
import org.eclipse.dltk.javascript.typeinfo.model.TypeInfoModelPackage;
import org.eclipse.dltk.javascript.typeinfo.model.TypeVariable;
import org.eclipse.dltk.javascript.typeinfo.model.TypeVariableReference;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Type Variable Reference</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.dltk.javascript.typeinfo.model.impl.TypeVariableReferenceImpl#getVariable <em>Variable</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class TypeVariableReferenceImpl extends MinimalEObjectImpl implements TypeVariableReference {
/**
* The cached value of the '{@link #getVariable() <em>Variable</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getVariable()
* @generated
* @ordered
*/
protected TypeVariable variable;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected TypeVariableReferenceImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return TypeInfoModelPackage.Literals.TYPE_VARIABLE_REFERENCE;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TypeVariable getVariable() {
if (variable != null && variable.eIsProxy()) {
InternalEObject oldVariable = (InternalEObject)variable;
variable = (TypeVariable)eResolveProxy(oldVariable);
if (variable != oldVariable) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE, oldVariable, variable));
}
}
return variable;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TypeVariable basicGetVariable() {
return variable;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setVariable(TypeVariable newVariable) {
TypeVariable oldVariable = variable;
variable = newVariable;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE, oldVariable, variable));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public String getName() {
return variable != null ? variable.getName() : "";
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
public IRType toRType(ITypeSystem typeSystem) {
if (variable != null) {
if (typeSystem != null) {
final IRType value = typeSystem.getTypeVariable(variable);
if (value != null) {
return value;
}
}
final JSType bound = variable.getBound();
return bound != null ? RTypes.create(typeSystem, bound)
: new RTypeVariable(variable);
}
return RTypes.none();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE:
if (resolve) return getVariable();
return basicGetVariable();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE:
setVariable((TypeVariable)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE:
setVariable((TypeVariable)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case TypeInfoModelPackage.TYPE_VARIABLE_REFERENCE__VARIABLE:
return variable != null;
}
return super.eIsSet(featureID);
}
} //TypeVariableReferenceImpl