@Test public void testGetLocation_field() { Field field1 = getOuterMessage().getFields().get(0); Field field3 = getInnerMessage().getFields().get(0); verifyLocation("optional string field1 = 1; // Field.", field1.getLocation()); verifyLocation("optional string field3 = 3;", field3.getLocation()); }
@VisitsBefore void visit(MessageType message) { // Add the message to the set of known types. addType(message.getLocation(), message.getFullName(), TypeRef.of(message)); // Add the message's package to the set of known packages addPackage(message.getFile().getFullName()); // Build the field-by-name map for this message, and record field simple names. Map<String, Field> fieldByName = Maps.newLinkedHashMap(); for (Field field : message.getFields()) { fieldNames.add(field.getSimpleName()); Field old = fieldByName.put(field.getSimpleName(), field); if (old != null) { model .getDiagReporter() .report( Diag.error( field.getLocation(), "Duplicate declaration of field '%s'. Previous location: %s", field.getSimpleName(), old.getLocation().getDisplayString())); } } message.setFieldByNameMap(ImmutableMap.copyOf(fieldByName)); }
@VisitsBefore void visit(MessageType message) { // Add the message to the set of known types. addType(message.getLocation(), message.getFullName(), TypeRef.of(message)); // Add the message's package to the set of known packages addPackage(message.getFile().getFullName()); // Build the field-by-name map for this message, and record field simple names. Map<String, Field> fieldByName = Maps.newLinkedHashMap(); for (Field field : message.getFields()) { fieldNames.add(field.getSimpleName()); Field old = fieldByName.put(field.getSimpleName(), field); if (old != null) { model .getDiagReporter() .report( Diag.error( field.getLocation(), "Duplicate declaration of field '%s'. Previous location: %s", field.getSimpleName(), old.getLocation().getDisplayString())); } } message.setFieldByNameMap(ImmutableMap.copyOf(fieldByName)); }
@VisitsBefore void visit(Field field) { // Resolve type of this field. TypeRef type = resolveType(field.getLocation(), field.getProto().getType(), field.getProto().getTypeName()); if (type != null) { if (field.isRepeated()) { type = type.makeRepeated(); } else if (!field.isOptional()) { type = type.makeRequired(); } field.setType(type); } // Check for resolution of oneof. if (field.getProto().hasOneofIndex() && field.getOneof() == null) { // Indicates the oneof index could not be resolved. model .getDiagReporter() .report( Diag.error( field.getLocation(), "Unresolved oneof reference (indicates internal inconsistency of input; oneof " + "index: %s)", field.getProto().getOneofIndex())); } findOptionTypes(field.getOptionFields()); }
@VisitsBefore void visit(Field field) { // Resolve type of this field. TypeRef type = resolveType(field.getLocation(), field.getProto().getType(), field.getProto().getTypeName()); if (type != null) { if (field.isRepeated()) { type = type.makeRepeated(); } else if (!field.isOptional()) { type = type.makeRequired(); } field.setType(type); } // Check for resolution of oneof. if (field.getProto().hasOneofIndex() && field.getOneof() == null) { // Indicates the oneof index could not be resolved. model .getDiagReporter() .report( Diag.error( field.getLocation(), "Unresolved oneof reference (indicates internal inconsistency of input; oneof " + "index: %s)", field.getProto().getOneofIndex())); } findOptionTypes(field.getOptionFields()); }