1 package nl.tudelft.goal.unreal.translators; 2 3 import nl.tudelft.goal.unreal.messages.BotParametersKey; 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 BotParametersKeyTranslator implements Parameter2Java<BotParametersKey> { 11 12 @Override 13 public BotParametersKey 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 (BotParametersKey k : BotParametersKey.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(BotParametersKey.class)); 30 31 throw new TranslationException(message); 32 33 } 34 35 @Override 36 public Class<BotParametersKey> translatesTo() { 37 return BotParametersKey.class; 38 } 39 40 }