blob: 66642095f97a8e0223c803171f128719ebe92bb7 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013, 2019 CEA LIST and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.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.utilities.ValueUtil;
/**
* n RealObjectDescriptor describes the unboxed representations of an OCL Real.
*/
public class RealObjectDescriptor extends UnboxedValueDescriptor implements UnboxedDescriptor
{
public RealObjectDescriptor(@NonNull ElementId elementId) {
super(elementId, Number.class);
}
@Override
public @NonNull Boolean appendBox(@NonNull JavaStream js, @NonNull JavaLocalContext<@NonNull ?> localContext, @NonNull CGBoxExp cgBoxExp, @NonNull CGValuedElement unboxedValue) {
js.appendDeclaration(cgBoxExp);
js.append(" = ");
if (!unboxedValue.isNonNull()) {
js.appendReferenceTo(unboxedValue);
js.append(" == null ? null : ");
}
js.appendClassReference(null, ValueUtil.class);
js.append(".realValueOf(");
js.appendReferenceTo(unboxedValue);
js.append(")");
js.append(";\n");
return true;
}
@Override
public @NonNull Boolean appendEcore(@NonNull JavaStream js, @NonNull JavaLocalContext<@NonNull ?> localContext, @NonNull CGEcoreExp cgEcoreExp, @NonNull CGValuedElement unboxedValue) {
js.appendDeclaration(cgEcoreExp);
js.append(" = ");
if (!unboxedValue.isNonNull()) {
js.appendReferenceTo(unboxedValue);
js.append(" == null ? null : ");
}
js.appendClassReference(null, ValueUtil.class);
js.append(".realValueOf(");
js.appendReferenceTo(unboxedValue);
js.append(")");
js.append(";\n");
return true;
}
}