final List<OtpErlangObject> result = new ArrayList<OtpErlangObject>();
for (final CompilerOption option : CompilerOption.ALL_OPTIONS) {
final Object optionValue = options.get(option);
if (optionValue != null) {
if (option instanceof BooleanOption) {
final OtpErlangObject val = ((BooleanOption) option)
.toTerm(((Boolean) optionValue).booleanValue());
if (val != null) {
result.add(val);
}
} else if (option instanceof PathsOption) {
final Iterable<String> value = (Iterable<String>) optionValue;
final OtpErlangList val = (OtpErlangList) ((PathsOption) option)
.toTerm(value);
for (final OtpErlangObject inc : val.elements()) {
result.add(inc);
}
} else if (option instanceof ModuleOption) {
final String value = (String) optionValue;
final OtpErlangObject val = ((ModuleOption) option).toTerm(value);
result.add(val);
} else if (option instanceof RawOption) {
final String value = (String) optionValue;
final OtpErlangList val = (OtpErlangList) ((RawOption) option)
.toTerm(value);
for (final OtpErlangObject item : val.elements()) {
result.add(item);
}
} else {
try {
final OtpErlangList val = ((DefineOption) option)
.toTerm((List<Pair<String, String>>) optionValue);
if (val != null) {
result.addAll(Lists.newArrayList(val.elements()));
}
} catch (final TermParserException e) {
ErlLogger.warn(e);
}
}