blob: e698b6d9c98a75be40a93f3229dfb470dd21712b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013, 2015 CEA LIST and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink(CEA LIST) - Initial API and implementation
*******************************************************************************/
package org.eclipse.ocl.examples.codegen.cgmodel.impl;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.cgmodel.CGModelPackage;
import org.eclipse.ocl.examples.codegen.cgmodel.CGText;
import org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement;
import org.eclipse.ocl.examples.codegen.cgmodel.util.CGModelVisitor;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>CG Text</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.ocl.examples.codegen.cgmodel.impl.CGTextImpl#getTextValue <em>Text Value</em>}</li>
* </ul>
*
* @generated
*/
public class CGTextImpl extends CGConstantImpl implements CGText {
/**
* The default value of the '{@link #getTextValue() <em>Text Value</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTextValue()
* @generated
* @ordered
*/
protected static final String TEXT_VALUE_EDEFAULT = null;
/**
* The cached value of the '{@link #getTextValue() <em>Text Value</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTextValue()
* @generated
* @ordered
*/
protected String textValue = TEXT_VALUE_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected CGTextImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return CGModelPackage.Literals.CG_TEXT;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String getTextValue() {
return textValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setTextValue(String newTextValue) {
String oldTextValue = textValue;
textValue = newTextValue;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, CGModelPackage.CG_TEXT__TEXT_VALUE, oldTextValue, textValue));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
return super.toString();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case CGModelPackage.CG_TEXT__TEXT_VALUE:
return getTextValue();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case CGModelPackage.CG_TEXT__TEXT_VALUE:
setTextValue((String)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case CGModelPackage.CG_TEXT__TEXT_VALUE:
setTextValue(TEXT_VALUE_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case CGModelPackage.CG_TEXT__TEXT_VALUE:
return TEXT_VALUE_EDEFAULT == null ? textValue != null : !TEXT_VALUE_EDEFAULT.equals(textValue);
}
return super.eIsSet(featureID);
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public @Nullable <R> R accept(@NonNull CGModelVisitor<R> visitor) {
return visitor.visitCGText(this);
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public @Nullable TypeId getASTypeId() {
return (TypeId) getTypeId().getElementId(); // FIXME Why irregular?
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public @NonNull Object getConstantValue() {
return ClassUtil.nonNullState(textValue);
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public boolean isCommonable() {
return true;
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public @Nullable Boolean isEquivalentToInternal(@NonNull CGValuedElement thatValue) {
if (!thatValue.isNonInvalid()) {
return null;
}
CGValuedElement value = thatValue.getNamedValue();
if (this == value) {
return Boolean.TRUE;
}
if (!value.isConstant()) {
return null;
}
else if (value instanceof CGText) {
return textValue.equals(((CGText)thatValue).getTextValue());
}
else {
return Boolean.FALSE;
}
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public boolean isGlobal() {
return false;
}
/**
* {@inheritDoc}
* @generated
*/
@Override
public boolean isUncommonable() {
return false;
}
} //CGTextImpl