/** * If this is a message or enum type, return its declaration location, otherwise * SimpleLocation.UNKNOWN. */ public Location getLocation() { return messageType != null ? messageType.getLocation() : enumType != null ? enumType.getLocation() : SimpleLocation.UNKNOWN; }
/** * If this is a message or enum type, return its declaration location, otherwise * SimpleLocation.UNKNOWN. */ public Location getLocation() { return messageType != null ? messageType.getLocation() : enumType != null ? enumType.getLocation() : SimpleLocation.UNKNOWN; }
@Test public void testGetLocation_enum() { EnumType outer = getOuterEnum(); EnumType inner = getInnerEnum(); verifyLocation("enum OuterEnum {", outer.getLocation()); verifyLocation("enum InnerEnum {", inner.getLocation()); }
@VisitsBefore void visit(EnumType enumType) { // Add the enum type to the set of known types. addType(enumType.getLocation(), enumType.getFullName(), TypeRef.of(enumType)); // Build the field-by-name map for this enum type. Map<String, EnumValue> valueByName = Maps.newLinkedHashMap(); for (EnumValue value : enumType.getValues()) { EnumValue old = valueByName.put(value.getSimpleName(), value); if (old != null) { model .getDiagReporter() .report( Diag.error( value.getLocation(), "Duplicate declaration of enum value '%s'. Previous location: %s", value.getSimpleName(), old.getLocation().getDisplayString())); } } enumType.setValueByNameMap(ImmutableMap.copyOf(valueByName)); }
@VisitsBefore void visit(EnumType enumType) { // Add the enum type to the set of known types. addType(enumType.getLocation(), enumType.getFullName(), TypeRef.of(enumType)); // Build the field-by-name map for this enum type. Map<String, EnumValue> valueByName = Maps.newLinkedHashMap(); for (EnumValue value : enumType.getValues()) { EnumValue old = valueByName.put(value.getSimpleName(), value); if (old != null) { model .getDiagReporter() .report( Diag.error( value.getLocation(), "Duplicate declaration of enum value '%s'. Previous location: %s", value.getSimpleName(), old.getLocation().getDisplayString())); } } enumType.setValueByNameMap(ImmutableMap.copyOf(valueByName)); }