Java Code Examples for io.protostuff.compiler.model.Field#setTag()

The following examples show how to use io.protostuff.compiler.model.Field#setTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageParseListener.java    From protostuff-compiler with Apache License 2.0 6 votes vote down vote up
@Override
public void exitField(ProtoParser.FieldContext ctx) {
    Field field = context.pop(Field.class);
    final FieldContainer fieldContainer = context.peek(FieldContainer.class);
    updateModifier(ctx.fieldModifier(), field);
    String name = ctx.fieldName().getText();
    field.setName(name);
    Integer tag = Integer.decode(ctx.tag().getText());
    field.setTag(tag);
    field.setIndex(fieldContainer.getFieldCount() + 1);
    String type = ctx.typeReference().getText();
    field.setTypeName(type);
    field.setSourceCodeLocation(getSourceCodeLocation(ctx));
    fieldContainer.addField(field);
    attachComments(ctx, field, true);
}
 
Example 2
Source File: MessageParseListener.java    From protostuff-compiler with Apache License 2.0 6 votes vote down vote up
@Override
public void exitGroupBlock(ProtoParser.GroupBlockContext ctx) {
    Group group = context.pop(Group.class);
    group.setName(ctx.groupName().getText());
    group.setSourceCodeLocation(getSourceCodeLocation(ctx));
    final GroupContainer groupContainer = context.peek(GroupContainer.class);
    final FieldContainer fieldContainer = context.peek(FieldContainer.class);
    Field field = new Field(fieldContainer);
    field.setName(group.getName().toLowerCase()); // same behavior as in protoc
    int tag = Integer.decode(ctx.tag().getText());
    field.setTag(tag);
    field.setIndex(fieldContainer.getFieldCount() + 1);
    field.setTypeName(group.getName());
    field.setType(group);
    field.setSourceCodeLocation(getSourceCodeLocation(ctx));
    groupContainer.addGroup(group);
    fieldContainer.addField(field);
    attachComments(ctx, field, true);
}
 
Example 3
Source File: MessageParseListener.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: MessageParseListener.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private Field createMapValueField(Message map, String valueTypeName, SourceCodeLocation codeLocation) {
    Field valueField = new Field(map);
    valueField.setName(MAP_ENTRY_VALUE);
    valueField.setTag(2);
    valueField.setIndex(2);
    valueField.setModifier(OPTIONAL);
    valueField.setTypeName(valueTypeName);
    valueField.setSourceCodeLocation(codeLocation);
    return valueField;
}
 
Example 5
Source File: MessageParseListener.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private Field createMapKeyField(Message map, String keyTypeName, SourceCodeLocation codeLocation) {
    Field keyField = new Field(map);
    keyField.setName(MAP_ENTRY_KEY);
    keyField.setTag(1);
    keyField.setIndex(1);
    keyField.setTypeName(keyTypeName);
    keyField.setModifier(OPTIONAL);
    keyField.setSourceCodeLocation(codeLocation);
    return keyField;
}