package edu.iastate.cs.boa.conversion;

import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Strings;

public class LONGValueConverter extends AbstractLexerBasedConverter<Long> {
	@Override
	protected String toEscapedString(Long value) {
		return value.toString();
	}
	
	public Long toValue(String string, INode node) {
		if (Strings.isEmpty(string))
			throw new ValueConverterException("Couldn't convert empty string to a long value.", node, null);

		try {
			// FIXME doesnt handle binary
			long val = Long.decode(string);
			return Long.valueOf(val);
		} catch (NumberFormatException e) {
			throw new ValueConverterException("Couldn't convert '" + string + "' to an long value.", node, e);
		}
	}
}

@@ -33,16 +33,46 @@
 rsion;%0A%0A
+import java.math.BigInteger;%0A%0A
 import o
@@ -640,73 +640,129 @@
 %0A%09%09%09
-// FIXME doesnt handle binary%0A%09%09%09long val = Long.decode(string
+if (string.toLowerCase().startsWith(%220b%22))%0A%09%09%09%09return Long.valueOf(new BigInteger(string.substring(2), 2).longValue()
 );%0A
+%0A
 %09%09%09r
@@ -780,19 +780,35 @@
 valueOf(
-val
+Long.decode(string)
 );%0A%09%09%7D c
@@ -916,17 +916,16 @@
  %22' to a
-n
  long va

support binary ints