Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Automatic Validation
Automatic Validation [message #1016019] Mon, 04 March 2013 15:43 Go to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi all,

I do not change value converter default error with own error ."Couldn't convert empty string to an int value" not changed Sad I use import org.eclipse.xtext.common.services.DefaultTerminalConverters and UI package .will be very happy if you could help me.

Best Regars
Re: Automatic Validation [message #1016064 is a reply to message #1016019] Mon, 04 March 2013 19:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmmm i dont get what your actual problem is. Can you please elaborate

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Automatic Validation [message #1016157 is a reply to message #1016064] Tue, 05 March 2013 09:56 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
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
Re: Automatic Validation [message #1016265 is a reply to message #1016157] Tue, 05 March 2013 18:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
toValue("own mesaage", null)

=>

public Integer toValue(String string, AbstractNode node) {
if (Strings.isNullOrEmpty(string))

will never ever come true

so you might actually call return toValue(string, null); instead


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Content assist strangely behaving in relation to scoping
Next Topic:Xtext editor with pages
Goto Forum:
  


Current Time: Thu Apr 25 15:35:27 GMT 2024

Powered by FUDForum. Page generated in 0.03769 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top