@Override public String getContainerName() { return element.getFile().getLocation().getDisplayString(); }
@Override public String getContainerName() { return element.getFile().getLocation().getDisplayString(); }
@Override public String toString() { return String.format("%s: %s: %s", getKind().toString(), getLocation().getDisplayString(), getMessage()); } }
private void verifyLocation(String exp, Location location) { String[] locations = location.getDisplayString().split(":"); int line = Integer.valueOf(locations[1]) - 1; int column = Integer.valueOf(locations[2]) - 1; String res = protoLines.get(line).substring(column); assertEquals(exp, res); }
@Override public String toString() { return String.format("%s: %s: %s", getKind().toString(), getLocation().getDisplayString(), getMessage()); } }
private static String getLocationWithoutFullPath(final Diag diag) { // /tmp/temp_dir/testFile.json becomes testFile.json String location = diag.getLocation().getDisplayString(); int lastSlashIndex = location.lastIndexOf("/"); if (lastSlashIndex != -1) { return location.substring(lastSlashIndex + 1); } return location; }
private String getLocationWithoutFullPath(final Diag diag) { String location = diag.getLocation().getDisplayString(); int firstSlashIndex = location.indexOf("/"); int lastSlashIndex = location.lastIndexOf("/"); if (firstSlashIndex != -1) { String toReplace = location.substring(firstSlashIndex, lastSlashIndex + 1); location = location.replace(toReplace, ""); } return location; }
public ProtoLocation( DescriptorProtos.SourceCodeInfo.Location location, final ProtoElement element) { // Spit out "?:?" for line:column if there's no "span" set in the location. This can happen // when (for example) a proto transform tool synthesizes a field that doesn't appear in the // source *.proto files. if (location.getSpanCount() > 0) { this.displayString = String.format( "%s:%d:%d", element.getFile().getLocation().getDisplayString(), location.getSpan(0) + 1, location.getSpan(1) + 1); } else { this.displayString = String.format("%s:?:?", element.getFile().getLocation().getDisplayString()); } this.element = element; }
public ProtoLocation( DescriptorProtos.SourceCodeInfo.Location location, final ProtoElement element) { // Spit out "?:?" for line:column if there's no "span" set in the location. This can happen // when (for example) a proto transform tool synthesizes a field that doesn't appear in the // source *.proto files. if (location.getSpanCount() > 0) { this.displayString = String.format( "%s:%d:%d", element.getFile().getLocation().getDisplayString(), location.getSpan(0) + 1, location.getSpan(1) + 1); } else { this.displayString = String.format("%s:?:?", element.getFile().getLocation().getDisplayString()); } this.element = element; }
private void addType(Location location, String fullName, TypeRef type) { String typeName = SymbolTable.getTypeNameInSymbolTable(fullName); TypeRef old = types.put(typeName , type); if (old != null) { model .getDiagReporter() .report( Diag.error( location, "Duplicate declaration of type '%s'. Previous location: %s", fullName, old.getLocation().getDisplayString())); } } }
private void addType(Location location, String fullName, TypeRef type) { String typeName = SymbolTable.getTypeNameInSymbolTable(fullName); TypeRef old = types.put(typeName , type); if (old != null) { model .getDiagReporter() .report( Diag.error( location, "Duplicate declaration of type '%s'. Previous location: %s", fullName, old.getLocation().getDisplayString())); } } }
@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)); }
public static String getDiagToPrint(final Diag diag, boolean trimLocationFullPath) { String message = DiagUtils.getDiagMessage(diag); return String.format( "%s: %s: %s", diag.getKind().toString(), trimLocationFullPath ? getLocationWithoutFullPath(diag) : diag.getLocation().getDisplayString(), message); }
@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 normalize(EnumType enumType) { Enum.Builder coreEnumBuilder = Enum.newBuilder().setName(enumType.getFullName()); coreEnumBuilder.setSourceContext( SourceContext.newBuilder() .setFileName(enumType.getFile().getLocation().getDisplayString())); coreEnumBuilder.setSyntax(enumType.getSyntax()); for (EnumValue value : enumType.getReachableValues()) { com.google.protobuf.EnumValue.Builder coreEnumValueBuilder = com.google.protobuf.EnumValue.newBuilder(); // Use simple name for enum value, as otherwise client has to use // fully qualified name in the request. coreEnumValueBuilder.setName(value.getSimpleName()).setNumber(value.getNumber()); coreEnumValueBuilder.addAllOptions( DescriptorNormalization.getOptions(value.getProto(), includeDefaults)); coreEnumBuilder.addEnumvalue(coreEnumValueBuilder.build()); } coreEnumBuilder.addAllOptions( DescriptorNormalization.getOptions(enumType.getProto(), includeDefaults)); enums.add(coreEnumBuilder.build()); }
@VisitsBefore void normalize(EnumType enumType) { Enum.Builder coreEnumBuilder = Enum.newBuilder().setName(enumType.getFullName()); coreEnumBuilder.setSourceContext( SourceContext.newBuilder() .setFileName(enumType.getFile().getLocation().getDisplayString())); coreEnumBuilder.setSyntax(enumType.getSyntax()); for (EnumValue value : enumType.getReachableValues()) { com.google.protobuf.EnumValue.Builder coreEnumValueBuilder = com.google.protobuf.EnumValue.newBuilder(); // Use simple name for enum value, as otherwise client has to use // fully qualified name in the request. coreEnumValueBuilder.setName(value.getSimpleName()).setNumber(value.getNumber()); coreEnumValueBuilder.addAllOptions( DescriptorNormalization.getOptions(value.getProto(), includeDefaults)); coreEnumBuilder.addEnumvalue(coreEnumValueBuilder.build()); } coreEnumBuilder.addAllOptions( DescriptorNormalization.getOptions(enumType.getProto(), includeDefaults)); enums.add(coreEnumBuilder.build()); }
@VisitsBefore void normalize(Interface iface) { Api.Builder coreApiBuilder = Api.newBuilder().setName(iface.getFullName()); coreApiBuilder.setSourceContext( SourceContext.newBuilder().setFileName(iface.getFile().getLocation().getDisplayString())); coreApiBuilder.setSyntax(iface.getSyntax()); for (Method method : iface.getReachableMethods()) { com.google.protobuf.Method.Builder coreMethodBuilder = com.google.protobuf.Method.newBuilder() .setName(method.getSimpleName()) .setRequestTypeUrl(generateTypeUrl(method.getInputType())) .setResponseTypeUrl(generateTypeUrl(method.getOutputType())); coreMethodBuilder.setRequestStreaming(method.getRequestStreaming()); coreMethodBuilder.setResponseStreaming(method.getResponseStreaming()); coreMethodBuilder.addAllOptions( DescriptorNormalization.getMethodOptions( method.getOptionFields(), false, includeDefaults)); coreApiBuilder.addMethods(coreMethodBuilder); } coreApiBuilder.addAllOptions( DescriptorNormalization.getOptions(iface.getProto(), includeDefaults)); coreApiBuilder.setVersion(iface.getAttribute(VersionAttribute.KEY).majorVersion()); apis.add(coreApiBuilder.build()); }
@VisitsBefore void normalize(Interface iface) { Api.Builder coreApiBuilder = Api.newBuilder().setName(iface.getFullName()); coreApiBuilder.setSourceContext( SourceContext.newBuilder().setFileName(iface.getFile().getLocation().getDisplayString())); coreApiBuilder.setSyntax(iface.getSyntax()); for (Method method : iface.getReachableMethods()) { com.google.protobuf.Method.Builder coreMethodBuilder = com.google.protobuf.Method.newBuilder() .setName(method.getSimpleName()) .setRequestTypeUrl(generateTypeUrl(method.getInputType())) .setResponseTypeUrl(generateTypeUrl(method.getOutputType())); coreMethodBuilder.setRequestStreaming(method.getRequestStreaming()); coreMethodBuilder.setResponseStreaming(method.getResponseStreaming()); coreMethodBuilder.addAllOptions( DescriptorNormalization.getMethodOptions( method.getOptionFields(), false, includeDefaults)); coreApiBuilder.addMethods(coreMethodBuilder); } coreApiBuilder.addAllOptions( DescriptorNormalization.getOptions(iface.getProto(), includeDefaults)); coreApiBuilder.setVersion(iface.getAttribute(VersionAttribute.KEY).majorVersion()); apis.add(coreApiBuilder.build()); }