示例#1
0
  private static AbstractConfigValue findKey(
      AbstractConfigObject self, String key, ConfigValueType expected, Path originalPath) {
    AbstractConfigValue v = self.peekAssumingResolved(key, originalPath);
    if (v == null) throw new ConfigException.Missing(originalPath.render());

    if (expected != null) v = DefaultTransformer.transform(v, expected);

    if (v.valueType() == ConfigValueType.NULL)
      throw new ConfigException.Null(
          v.origin(), originalPath.render(), expected != null ? expected.name() : null);
    else if (expected != null && v.valueType() != expected)
      throw new ConfigException.WrongType(
          v.origin(), originalPath.render(), expected.name(), v.valueType().name());
    else return v;
  }
示例#2
0
 @SuppressWarnings("unchecked")
 private <T> List<T> getHomogeneousUnwrappedList(String path, ConfigValueType expected) {
   List<T> l = new ArrayList<T>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue cv : list) {
     // variance would be nice, but stupid cast will do
     AbstractConfigValue v = (AbstractConfigValue) cv;
     if (expected != null) {
       v = DefaultTransformer.transform(v, expected);
     }
     if (v.valueType() != expected)
       throw new ConfigException.WrongType(
           v.origin(), path, "list of " + expected.name(), "list of " + v.valueType().name());
     l.add((T) v.unwrapped());
   }
   return l;
 }