Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2007 Anyware Technologies 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: Anyware Technologies - initial API and implementation $Id: EcoreAbstractExpression.java,v 1.4 2009/02/02 08:39:08 jlescot Exp $ /
 
 
 package org.eclipse.emf.ecoretools.diagram.expressions;
 
 import java.util.Map;
 
 import  org.eclipse.core.runtime.IStatus;
 import  org.eclipse.core.runtime.Status;

Generated:
 
 public abstract class EcoreAbstractExpression {

Generated:
 
 	private IStatus status = Status.OK_STATUS;

Generated:
 
 	protected void setStatus(int severityString messageThrowable throwable) {
 		this. = new Status(severitypluginID, -1, (message != null) ? message : ""throwable); //$NON-NLS-1$
 		if (!this..isOK()) {
 			EcoreDiagramEditorPlugin.getInstance().logError("Expression problem:" + message + "body:" + body(), throwable); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 	}

Generated:
 
 	public IStatus getStatus() {
 		return ;
 	}

Generated:
 
 	private final String myBody;

Generated:
 
 	public String body() {
 		return ;
 	}

Generated:
 
 	private final EClassifier myContext;

Generated:
 
 	public EClassifier context() {
 		return ;
 	}

Generated:
 
 	protected EcoreAbstractExpression(String bodyEClassifier context) {
 		 = body;
 		 = context;
 	}

Generated:
 
 	protected abstract Object doEvaluate(Object contextMap env);

Generated:
 
 	public Object evaluate(Object context) {
		return evaluate(context.);
	}

Generated:
	public Object evaluate(Object contextMap env) {
		if (context().isInstance(context)) {
			try {
				return doEvaluate(contextenv);
catch (Exception e) {
				EcoreDiagramEditorPlugin.getInstance().logError("Expression evaluation failure: " + body(), e); //$NON-NLS-1$
			}
		}
		return null;
	}

Expression may return number value which is not directly compatible with feature type (e.g. Double when Integer is expected), or EEnumLiteral meta-object when literal instance is expected

Generated:
	public static Object performCast(Object valueEDataType targetType) {
		if (targetType instanceof EEnum) {
			if (value instanceof EEnumLiteral) {
				EEnumLiteral literal = (EEnumLiteralvalue;
				return (literal.getInstance() != null) ? literal.getInstance() : literal;
			}
		}
		if (false == value instanceof Number || targetType == null || targetType.getInstanceClass() == null) {
			return value;
		}
		Class targetClass = targetType.getInstanceClass();
		Number num = (Numbervalue;
		Class valClass = value.getClass();
		Class targetWrapperClass = targetClass;
		if (targetClass.isPrimitive()) {
			targetWrapperClass = EcoreUtil.wrapperClassFor(targetClass);
		}
		if (valClass.equals(targetWrapperClass)) {
			return value;
		}
		if (Number.class.isAssignableFrom(targetWrapperClass)) {
			if (targetWrapperClass.equals(Byte.class))
				return new Byte(num.byteValue());
			if (targetWrapperClass.equals(Integer.class))
				return new Integer(num.intValue());
			if (targetWrapperClass.equals(Short.class))
				return new Short(num.shortValue());
			if (targetWrapperClass.equals(Long.class))
				return new Long(num.longValue());
			if (targetWrapperClass.equals(BigInteger.class))
				return BigInteger.valueOf(num.longValue());
			if (targetWrapperClass.equals(Float.class))
				return new Float(num.floatValue());
			if (targetWrapperClass.equals(Double.class))
				return new Double(num.doubleValue());
			if (targetWrapperClass.equals(BigDecimal.class))
				return new BigDecimal(num.doubleValue());
		}
		return value;
	}
New to GrepCode? Check out our FAQ X