|
|
Re: Automatic Validation [message #1016157 is a reply to message #1016064] |
Tue, 05 March 2013 09:56 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
I want to change "Couldn't convert empty string to an int value" default error message.I change it ,my problem For input string: "own mesaage" shows every time.when I write correct INT ID rule (not empty ) in the language ,I still receive error
Grammar :
Function:
"function" name=ID pages=INT '!'
;
Output Examples:
function sss1 4!//I receive error :For input string: "own mesaage"
Function sss ! //I receive same error :For input string: "own mesaage"
My code is below:
package org.xtext.example.mydsl1.convert;
import org.eclipse.xtext.common.services.DefaultTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.ValueConverterWithValueException;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.impl.AbstractNode;
import com.google.common.base.Strings;
public class MyDsl1TerminalConverters extends DefaultTerminalConverters {
@ValueConverter(rule = "INT")
public IValueConverter<Integer> INT() {
return new IValueConverter<Integer>() {
public Integer toValue(String string, AbstractNode node) {
if ( Strings.isNullOrEmpty(string))
throw new ValueConverterException("Couldn't convert empty string to int sssss", node, null);
try {
return Integer.parseInt(string);
} catch (ValueConverterWithValueException e) {
throw new ValueConverterException("Couldn't convert '"+string+"' to int", node, e);
}
}
@Override
public Integer toValue(String string, INode node)
throws ValueConverterException {
// TODO Auto-generated method stub
return toValue("own mesaage",null );//I receive For input string: "own mesaage" message instead of "Couldn't convert empty string to int" default error message.
}
@Override
public String toString(Integer value)
throws ValueConverterException {
// TODO Auto-generated method stub
return toString();
}
};
Best Regards
|
|
|
|
Powered by
FUDForum. Page generated in 0.02775 seconds