Search in sources :

Example 1 with OptionReader

use of com.squareup.wire.schema.internal.parser.OptionReader in project schema2proto by entur.

the class ModifyProto method addFieldOption.

public void addFieldOption(FieldOption fieldOption, Schema prunedSchema) throws InvalidProtobufException {
    MessageType type = (MessageType) prunedSchema.getType(fieldOption.targetMessageType);
    if (type == null) {
        throw new InvalidProtobufException("Did not find existing type " + fieldOption.targetMessageType);
    }
    Field field = type.field(fieldOption.field);
    if (field == null) {
        throw new InvalidProtobufException("Did not find existing field " + fieldOption.field);
    }
    if (StringUtils.isEmpty(fieldOption.option)) {
        throw new InvalidProtobufException("Missing option for field " + fieldOption.field);
    }
    OptionReader reader = new OptionReader(new SyntaxReader(fieldOption.option.toCharArray(), null));
    reader.readOptions().forEach(option -> field.options().add(option));
}
Also used : NewField(no.entur.schema2proto.modifyproto.config.NewField) Field(com.squareup.wire.schema.Field) OptionReader(com.squareup.wire.schema.internal.parser.OptionReader) SyntaxReader(com.squareup.wire.schema.internal.parser.SyntaxReader) MessageType(com.squareup.wire.schema.MessageType)

Aggregations

Field (com.squareup.wire.schema.Field)1 MessageType (com.squareup.wire.schema.MessageType)1 OptionReader (com.squareup.wire.schema.internal.parser.OptionReader)1 SyntaxReader (com.squareup.wire.schema.internal.parser.SyntaxReader)1 NewField (no.entur.schema2proto.modifyproto.config.NewField)1