View Javadoc

1   package nl.tudelft.goal.unreal.translators;
2   
3   import nl.tudelft.goal.unreal.messages.ConfigurationKey;
4   import nl.tudelft.goal.unreal.util.EnvironmentUtil;
5   import eis.eis2java.exception.TranslationException;
6   import eis.eis2java.translation.Parameter2Java;
7   import eis.iilang.Identifier;
8   import eis.iilang.Parameter;
9   
10  public class ConfigurationKeyTranslator implements Parameter2Java<ConfigurationKey> {
11  
12  	@Override
13  	public ConfigurationKey translate(Parameter p) throws TranslationException {
14  
15  		if (!(p instanceof Identifier)) {
16  			String message = String.format("%s is not a identifier.", p);
17  			throw new TranslationException(message);
18  		}
19  
20  		String id = ((Identifier) p).getValue();
21  
22  		for (ConfigurationKey k : ConfigurationKey.values()) {
23  			if (k.getKey().equals(id)) {
24  				return k;
25  			}
26  		}
27  		
28  		String message = "%s is not a valid key. Valid keys are: %s.";
29  		message = String.format(message, id, EnvironmentUtil.listValid(ConfigurationKey.class));
30  		
31  		throw new TranslationException(message);
32  
33  	}
34  
35  
36  	@Override
37  	public Class<ConfigurationKey> translatesTo() {
38  		return ConfigurationKey.class;
39  	}
40  
41  }