blob: e72f11e580d373f5ef8987ab2223f708c1c486a9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013, 2016 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.java.types;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.codegen.cgmodel.CGBoxExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGEcoreExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement;
import org.eclipse.ocl.examples.codegen.java.JavaLocalContext;
import org.eclipse.ocl.examples.codegen.java.JavaStream;
import org.eclipse.ocl.pivot.ids.ElementId;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
/**
* An EnumerationObjectDescriptor the unboxed representation of an Enumeration.
*/
public class EnumerationObjectDescriptor extends UnboxedValueDescriptor
{
public EnumerationObjectDescriptor(@NonNull ElementId elementId, @NonNull Class<?> javaClass) {
super(elementId, javaClass);
}
@Override
public @NonNull Boolean appendBox(@NonNull JavaStream js, @NonNull JavaLocalContext<@NonNull ?> localContext, @NonNull CGBoxExp cgBoxExp, @NonNull CGValuedElement unboxedValue) {
TypeId typeId = unboxedValue.getASTypeId();
js.appendDeclaration(cgBoxExp);
js.append(" = ");
if (!unboxedValue.isNonNull()) {
js.appendReferenceTo(unboxedValue);
js.append(" == null ? null : ");
}
js.appendIdReference(typeId);
js.append(".getEnumerationLiteralId(");
js.appendClassReference(ClassUtil.class);
js.append(".nonNullState(");
js.appendReferenceTo(unboxedValue);
js.append(".getName()))");
js.append(";\n");
return true;
}
@Override
public @NonNull Boolean appendEcore(@NonNull JavaStream js, @NonNull JavaLocalContext<@NonNull ?> localContext, @NonNull CGEcoreExp cgEcoreExp, @NonNull CGValuedElement unboxedValue) {
TypeId typeId = unboxedValue.getASTypeId();
js.appendDeclaration(cgEcoreExp);
js.append(" = ");
if (!unboxedValue.isNonNull()) {
js.appendReferenceTo(unboxedValue);
js.append(" == null ? null : ");
}
js.appendIdReference(typeId);
js.append(".getEnumerationLiteralId(");
js.appendClassReference(ClassUtil.class);
js.append(".nonNullState(");
js.appendReferenceTo(unboxedValue);
js.append(".getName()))");
js.append(";\n");
return true;
}
}