All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.core.parser.ReflectionParser Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.core.parser;

import java.util.function.Function;

import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.events.MappingEndEvent;
import org.yaml.snakeyaml.events.MappingStartEvent;
import org.yaml.snakeyaml.events.ScalarEvent;

class ReflectionParser extends BaseReflectionParser implements Parser {
   private final Function selector;

   ReflectionParser(Function selector) {
      this.selector = selector;
   }

   @Override
   public void parse(Context ctx, T target) throws ParserException {
      S builder = selector.apply(target);
      ctx.expectEvent(MappingStartEvent.class);
      while (ctx.hasNext()) {
         Event next = ctx.next();
         if (next instanceof MappingEndEvent) {
            return;
         } else if (next instanceof ScalarEvent) {
            invokeWithParameters(ctx, builder, (ScalarEvent) next);
         } else {
            throw ctx.unexpectedEvent(next);
         }
      }
      throw ctx.noMoreEvents(MappingEndEvent.class);
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy