| 1 | /** |
| 2 | * <copyright> |
| 3 | * </copyright> |
| 4 | * |
| 5 | * $Id$ |
| 6 | */ |
| 7 | package de.uka.ipd.sdq.pcm.cost.impl; |
| 8 | |
| 9 | import de.uka.ipd.sdq.pcm.cost.ScalarFunction; |
| 10 | import de.uka.ipd.sdq.pcm.cost.costPackage; |
| 11 | import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.MyPCMStoExLexer; |
| 12 | import de.uka.ipd.sdq.pcm.stochasticexpressions.parser.MyPCMStoExParser; |
| 13 | |
| 14 | import de.uka.ipd.sdq.stoex.Expression; |
| 15 | import de.uka.ipd.sdq.stoex.Term; |
| 16 | |
| 17 | import org.antlr.runtime.ANTLRStringStream; |
| 18 | import org.antlr.runtime.CommonTokenStream; |
| 19 | import org.antlr.runtime.RecognitionException; |
| 20 | import org.eclipse.emf.common.notify.Notification; |
| 21 | |
| 22 | import org.eclipse.emf.ecore.EClass; |
| 23 | import org.eclipse.emf.ecore.InternalEObject; |
| 24 | |
| 25 | import org.eclipse.emf.ecore.impl.ENotificationImpl; |
| 26 | import org.eclipse.emf.ecore.impl.EObjectImpl; |
| 27 | |
| 28 | /** |
| 29 | * <!-- begin-user-doc --> |
| 30 | * An implementation of the model object '<em><b>Scalar Function</b></em>'. |
| 31 | * <!-- end-user-doc --> |
| 32 | * <p> |
| 33 | * The following features are implemented: |
| 34 | * <ul> |
| 35 | * <li>{@link de.uka.ipd.sdq.pcm.cost.impl.ScalarFunctionImpl#getSpecification <em>Specification</em>}</li> |
| 36 | * <li>{@link de.uka.ipd.sdq.pcm.cost.impl.ScalarFunctionImpl#getTerm <em>Term</em>}</li> |
| 37 | * </ul> |
| 38 | * </p> |
| 39 | * |
| 40 | * @generated |
| 41 | */ |
| 42 | public class ScalarFunctionImpl extends EObjectImpl implements ScalarFunction { |
| 43 | /** |
| 44 | * The default value of the '{@link #getSpecification() <em>Specification</em>}' attribute. |
| 45 | * <!-- begin-user-doc --> |
| 46 | * <!-- end-user-doc --> |
| 47 | * @see #getSpecification() |
| 48 | * @generated |
| 49 | * @ordered |
| 50 | */ |
| 51 | protected static final String SPECIFICATION_EDEFAULT = null; |
| 52 | |
| 53 | /** |
| 54 | * The cached value of the '{@link #getSpecification() <em>Specification</em>}' attribute. |
| 55 | * <!-- begin-user-doc --> |
| 56 | * <!-- end-user-doc --> |
| 57 | * @see #getSpecification() |
| 58 | * @generated |
| 59 | * @ordered |
| 60 | */ |
| 61 | protected String specification = SPECIFICATION_EDEFAULT; |
| 62 | |
| 63 | /** |
| 64 | * <!-- begin-user-doc --> |
| 65 | * <!-- end-user-doc --> |
| 66 | * @generated |
| 67 | */ |
| 68 | protected ScalarFunctionImpl() { |
| 69 | super(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * <!-- begin-user-doc --> |
| 74 | * <!-- end-user-doc --> |
| 75 | * @generated |
| 76 | */ |
| 77 | @Override |
| 78 | protected EClass eStaticClass() { |
| 79 | return costPackage.Literals.SCALAR_FUNCTION; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * <!-- begin-user-doc --> |
| 84 | * <!-- end-user-doc --> |
| 85 | * @generated |
| 86 | */ |
| 87 | public String getSpecification() { |
| 88 | return specification; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * <!-- begin-user-doc --> |
| 93 | * <!-- end-user-doc --> |
| 94 | * @generated |
| 95 | */ |
| 96 | public void setSpecification(String newSpecification) { |
| 97 | String oldSpecification = specification; |
| 98 | specification = newSpecification; |
| 99 | if (eNotificationRequired()) |
| 100 | eNotify(new ENotificationImpl(this, Notification.SET, costPackage.SCALAR_FUNCTION__SPECIFICATION, oldSpecification, specification)); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * <!-- begin-user-doc --> |
| 105 | * <!-- end-user-doc --> |
| 106 | * @generated |
| 107 | */ |
| 108 | public Term getTerm() { |
| 109 | Term term = basicGetTerm(); |
| 110 | return term != null && term.eIsProxy() ? (Term)eResolveProxy((InternalEObject)term) : term; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * <!-- begin-user-doc --> |
| 115 | * <!-- end-user-doc --> |
| 116 | * @generated not |
| 117 | */ |
| 118 | public Term basicGetTerm() { |
| 119 | if (specification == null) |
| 120 | return null; |
| 121 | MyPCMStoExLexer lexer = new MyPCMStoExLexer(new ANTLRStringStream(this.getSpecification())); |
| 122 | MyPCMStoExParser parser = new MyPCMStoExParser(new CommonTokenStream(lexer)); |
| 123 | Expression e; |
| 124 | try { |
| 125 | e = parser.expression(); |
| 126 | } catch (RecognitionException e1) { |
| 127 | return null; |
| 128 | } |
| 129 | if (parser.hasErrors()) |
| 130 | return null; |
| 131 | |
| 132 | if (e instanceof Term) |
| 133 | return (Term)e; |
| 134 | |
| 135 | return null; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * <!-- begin-user-doc --> |
| 140 | * <!-- end-user-doc --> |
| 141 | * @generated not |
| 142 | */ |
| 143 | public boolean isSetTerm() { |
| 144 | return basicGetTerm() != null; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * <!-- begin-user-doc --> |
| 149 | * <!-- end-user-doc --> |
| 150 | * @generated |
| 151 | */ |
| 152 | @Override |
| 153 | public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| 154 | switch (featureID) { |
| 155 | case costPackage.SCALAR_FUNCTION__SPECIFICATION: |
| 156 | return getSpecification(); |
| 157 | case costPackage.SCALAR_FUNCTION__TERM: |
| 158 | if (resolve) return getTerm(); |
| 159 | return basicGetTerm(); |
| 160 | } |
| 161 | return super.eGet(featureID, resolve, coreType); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * <!-- begin-user-doc --> |
| 166 | * <!-- end-user-doc --> |
| 167 | * @generated |
| 168 | */ |
| 169 | @Override |
| 170 | public void eSet(int featureID, Object newValue) { |
| 171 | switch (featureID) { |
| 172 | case costPackage.SCALAR_FUNCTION__SPECIFICATION: |
| 173 | setSpecification((String)newValue); |
| 174 | return; |
| 175 | } |
| 176 | super.eSet(featureID, newValue); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * <!-- begin-user-doc --> |
| 181 | * <!-- end-user-doc --> |
| 182 | * @generated |
| 183 | */ |
| 184 | @Override |
| 185 | public void eUnset(int featureID) { |
| 186 | switch (featureID) { |
| 187 | case costPackage.SCALAR_FUNCTION__SPECIFICATION: |
| 188 | setSpecification(SPECIFICATION_EDEFAULT); |
| 189 | return; |
| 190 | } |
| 191 | super.eUnset(featureID); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * <!-- begin-user-doc --> |
| 196 | * <!-- end-user-doc --> |
| 197 | * @generated |
| 198 | */ |
| 199 | @Override |
| 200 | public boolean eIsSet(int featureID) { |
| 201 | switch (featureID) { |
| 202 | case costPackage.SCALAR_FUNCTION__SPECIFICATION: |
| 203 | return SPECIFICATION_EDEFAULT == null ? specification != null : !SPECIFICATION_EDEFAULT.equals(specification); |
| 204 | case costPackage.SCALAR_FUNCTION__TERM: |
| 205 | return isSetTerm(); |
| 206 | } |
| 207 | return super.eIsSet(featureID); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * <!-- begin-user-doc --> |
| 212 | * <!-- end-user-doc --> |
| 213 | * @generated |
| 214 | */ |
| 215 | @Override |
| 216 | public String toString() { |
| 217 | if (eIsProxy()) return super.toString(); |
| 218 | |
| 219 | StringBuffer result = new StringBuffer(super.toString()); |
| 220 | result.append(" (specification: "); |
| 221 | result.append(specification); |
| 222 | result.append(')'); |
| 223 | return result.toString(); |
| 224 | } |
| 225 | |
| 226 | } //ScalarFunctionImpl |