String text = optionValueContext.BOOLEAN_VALUE().getText(); boolean value = Boolean.parseBoolean(text); optionValue = DynamicMessage.Value.createBoolean(sourceCodeLocation, value); } else if (optionValueContext.INTEGER_VALUE() != null) { String text = optionValueContext.INTEGER_VALUE().getText();
String text = optionValueContext.BOOLEAN_VALUE().getText(); boolean value = Boolean.parseBoolean(text); optionValue = DynamicMessage.Value.createBoolean(sourceCodeLocation, value); } else if (optionValueContext.INTEGER_VALUE() != null) { String text = optionValueContext.INTEGER_VALUE().getText();
private DynamicMessage.Value getTextFormatOptionValue(ProtoParser.TextFormatEntryContext ctx) { DynamicMessage.Value optionValue; SourceCodeLocation sourceCodeLocation = getSourceCodeLocation(ctx); if (ctx.textFormat() != null) { optionValue = DynamicMessage.Value.createMessage(sourceCodeLocation, lastTextFormat); } else if (ctx.textFormatOptionValue().BOOLEAN_VALUE() != null) { String text = ctx.textFormatOptionValue().BOOLEAN_VALUE().getText(); boolean value = Boolean.parseBoolean(text); optionValue = DynamicMessage.Value.createBoolean(sourceCodeLocation, value); } else if (ctx.textFormatOptionValue().INTEGER_VALUE() != null) { String text = ctx.textFormatOptionValue().INTEGER_VALUE().getText(); optionValue = parseInteger(sourceCodeLocation, text); } else if (ctx.textFormatOptionValue().STRING_VALUE() != null) { String text = ctx.textFormatOptionValue().STRING_VALUE().getText(); // TODO: unescape optionValue = DynamicMessage.Value.createString(sourceCodeLocation, Util.removeFirstAndLastChar(text)); } else if (ctx.textFormatOptionValue().IDENT() != null) { String text = ctx.textFormatOptionValue().IDENT().getText(); optionValue = DynamicMessage.Value.createEnum(sourceCodeLocation, text); } else if (ctx.textFormatOptionValue().FLOAT_VALUE() != null) { String text = ctx.textFormatOptionValue().FLOAT_VALUE().getText(); double value = Double.parseDouble(text); optionValue = DynamicMessage.Value.createFloat(sourceCodeLocation, value); } else { throw new IllegalStateException(); } return optionValue; }
@Override public void exitMap(ProtoParser.MapContext ctx) { final Field field = context.pop(Field.class); final Message message = context.peek(Message.class); String name = ctx.fieldName().getText(); SourceCodeLocation codeLocation = getSourceCodeLocation(ctx); Message map = new Message(message); String mapEntryTypeName = name + "_entry"; map.setName(mapEntryTypeName); map.setSourceCodeLocation(codeLocation); map.getOptions().set(codeLocation, OPTION_MAP_ENTRY, Value.createBoolean(true)); String keyTypeName = ctx.mapKey().getText(); Field keyField = createMapKeyField(map, keyTypeName, codeLocation); map.addField(keyField); String valueTypeName = ctx.mapValue().getText(); Field valueField = createMapValueField(map, valueTypeName, codeLocation); map.addField(valueField); Integer tag = Integer.decode(ctx.tag().getText()); field.setName(name); field.setTag(tag); field.setIndex(message.getFieldCount() + 1); field.setModifier(REPEATED); field.setTypeName(mapEntryTypeName); field.setType(map); field.setSourceCodeLocation(codeLocation); message.addField(field); message.addMessage(map); attachComments(ctx, field, true); }
private DynamicMessage.Value getTextFormatOptionValue(ProtoParser.TextFormatEntryContext ctx) { DynamicMessage.Value optionValue; SourceCodeLocation sourceCodeLocation = getSourceCodeLocation(ctx); if (ctx.textFormat() != null) { optionValue = DynamicMessage.Value.createMessage(sourceCodeLocation, lastTextFormat); } else if (ctx.textFormatOptionValue().BOOLEAN_VALUE() != null) { String text = ctx.textFormatOptionValue().BOOLEAN_VALUE().getText(); boolean value = Boolean.parseBoolean(text); optionValue = DynamicMessage.Value.createBoolean(sourceCodeLocation, value); } else if (ctx.textFormatOptionValue().INTEGER_VALUE() != null) { String text = ctx.textFormatOptionValue().INTEGER_VALUE().getText(); optionValue = parseInteger(sourceCodeLocation, text); } else if (ctx.textFormatOptionValue().STRING_VALUE() != null) { String text = ctx.textFormatOptionValue().STRING_VALUE().getText(); // TODO: unescape optionValue = DynamicMessage.Value.createString(sourceCodeLocation, Util.removeFirstAndLastChar(text)); } else if (ctx.textFormatOptionValue().IDENT() != null) { String text = ctx.textFormatOptionValue().IDENT().getText(); optionValue = DynamicMessage.Value.createEnum(sourceCodeLocation, text); } else if (ctx.textFormatOptionValue().FLOAT_VALUE() != null) { String text = ctx.textFormatOptionValue().FLOAT_VALUE().getText(); double value = Double.parseDouble(text); optionValue = DynamicMessage.Value.createFloat(sourceCodeLocation, value); } else { throw new IllegalStateException(); } return optionValue; }
@Override public void exitMap(ProtoParser.MapContext ctx) { final Field field = context.pop(Field.class); final Message message = context.peek(Message.class); String name = ctx.fieldName().getText(); SourceCodeLocation codeLocation = getSourceCodeLocation(ctx); Message map = new Message(message); String mapEntryTypeName = name + "_entry"; map.setName(mapEntryTypeName); map.setSourceCodeLocation(codeLocation); map.getOptions().set(codeLocation, OPTION_MAP_ENTRY, Value.createBoolean(true)); String keyTypeName = ctx.mapKey().getText(); Field keyField = createMapKeyField(map, keyTypeName, codeLocation); map.addField(keyField); String valueTypeName = ctx.mapValue().getText(); Field valueField = createMapValueField(map, valueTypeName, codeLocation); map.addField(valueField); Integer tag = Integer.decode(ctx.tag().getText()); field.setName(name); field.setTag(tag); field.setIndex(message.getFieldCount() + 1); field.setModifier(REPEATED); field.setTypeName(mapEntryTypeName); field.setType(map); field.setSourceCodeLocation(codeLocation); message.addField(field); message.addMessage(map); attachComments(ctx, field, true); }