Java 类com.google.protobuf.DescriptorProtos.SourceCodeInfo 实例源码

项目:api-compiler    文件:BuilderVisitor.java   
protected void addFieldToMessageAncestor(
    int generationsToSkip,
    FieldDescriptorProto.Builder fieldDesc,
    SourceCodeInfo.Location location) {
  BuilderVisitorNodeInfo ancestorInfo = getAncestorInfo(generationsToSkip);
  if (ancestorInfo instanceof MessageNodeInfo) {
    ((MessageNodeInfo) ancestorInfo).addNewField(fieldDesc, location);
    setModified(true);
  } else {
    throw new RuntimeException(
        String.format(
            "Tried to add a field to a %s, but can only add to %s",
            ancestorInfo.node().getClass(), DescriptorProto.Builder.class));
  }
}
项目:api-compiler    文件:FileNodeInfo.java   
public void processDeletedChildren(Iterable<Message.Builder> elements) {
  if (manageSourceCodeInfo) {
    for (Message.Builder element : elements) {
      ProtoPathWrapper path = pathFromElement(element);
      if (path != null && !path.isEmpty()) {
        ProtoPathTree<SourceCodeInfo.Location> subtree = pathToLocation.getSubtree(path);
        modifiedSourceCodeInfo = true;
        subtree.markForDeletion(true);
      }
    }
  }
}
项目:api-compiler    文件:FileNodeInfo.java   
public void processAddedFields(DescriptorProto.Builder message, Iterable<FieldLocation> fields) {
  if (manageSourceCodeInfo) {
    ProtoPathWrapper messagePath = pathFromElement(message);
    if (messagePath == null) {
      throw new RuntimeException(
          String.format(
              "Internal error - couldn't find path for proto message %s",
              ProtoHelpers.getName(message)));
    }
    ProtoPathWrapper fieldsPath =
        ProtoHelpers.buildPath(messagePath, DescriptorProto.FIELD_FIELD_NUMBER);
    ProtoPathTree<SourceCodeInfo.Location> fieldsPathTree =
        pathToLocation.getSubtree(fieldsPath, true);
    for (FieldLocation field : fields) {
      Integer fieldIndex = fieldsPathTree.size();
      if (fieldIndex > 0
          && (fieldsPathTree.firstKey() != 0 || fieldsPathTree.lastKey() != (fieldIndex - 1))) {
        throw new RuntimeException(
            String.format(
                "BuilderVisitor internal error - non-contiguous field indexes found [%d..%d]\n",
                fieldsPathTree.firstKey(), fieldsPathTree.lastKey()));
      }
      fieldsPathTree.addDataElement(
          new ProtoPathWrapper(fieldIndex), // relative path of field within this message
          field.location());
      elementToOriginalPath.put(
          field.fieldDescriptor(), ProtoHelpers.buildPath(fieldsPath, fieldIndex));
    }
  }
}
项目:api-compiler    文件:FileNodeInfo.java   
private void setupPathsForFile(FileDescriptorProto.Builder file) {
  // Populate location map
  if (file.hasSourceCodeInfo() && manageSourceCodeInfo) {
    for (SourceCodeInfo.Location location : file.getSourceCodeInfo().getLocationList()) {
      pathToLocation.addDataElement(new ProtoPathWrapper(location.getPathList()), location);
    }
  } else {
    // Turn off SourceCodeInfo management if there is none.
    manageSourceCodeInfo = false;
  }
}
项目:api-compiler    文件:FileNodeInfo.java   
private void resetPathsForFile(FileDescriptorProto.Builder file) {
  if (modifiedSourceCodeInfo) {
    SourceCodeInfo.Builder sourceCodeInfo = file.getSourceCodeInfoBuilder();
    sourceCodeInfo.clearLocation();

    new LocationInfoUpdater(sourceCodeInfo).visit(pathToLocation);

    modifiedSourceCodeInfo = false;
  }

  elementToOriginalPath.clear();
  pathToLocation.clear();
}
项目:api-compiler    文件:FileNodeInfo.java   
@VisitsBefore
public boolean before(ProtoPathTree<SourceCodeInfo.Location> node) {
  if (node.isRootNode()) {
    numDeletedChildren.push(0);
    // Since the root node isn't the child of anything and there's no location info there, we're
    // done - so just return here.
    return true;
  } else if (!node.isMarkedForDeletion()) {
    // NOTE: This logic for computing the new path assumes that the only nodes that we delete
    // are described by path lists ending with a 0..n index (e.g. the 2nd method of a service
    // would have a path ending in 1 and the 3rd field of a message would have a path ending in
    // 2, regardless of its defined field number). It also assumes that ProtoPathTree.Visitor is
    // going to return the children in ascending numerical order based on their path indexes.
    ProtoPathWrapper originalPath = node.getPathFromRoot();
    if (!originalPath.isEmpty()) {
      ArrayList<Integer> newPath = new ArrayList<>(originalPath.getDepth());
      for (int i = 0; i < originalPath.getDepth(); i++) {
        newPath.add(originalPath.getPathElement(i) - numDeletedChildren.get(i));
      }
      addUpdatedLocationInfo(sourceCodeInfo, node, new ProtoPathWrapper(newPath));
    }
    numDeletedChildren.push(0);
  } else {
    // Don't descend into a deleted node, but note that we found a deleted node, so we can
    // adjust path indexes for later children.
    numDeletedChildren.push(numDeletedChildren.pop() + 1);
    return false;
  }
  return true;
}
项目:api-compiler    文件:FileNodeInfo.java   
private void addUpdatedLocationInfo(
    SourceCodeInfo.Builder sourceCodeInfo,
    ProtoPathTree<SourceCodeInfo.Location> currentPathTree,
    ProtoPathWrapper newPath) {
  // Add the location data from the current node, updating path numbers as we go.
  for (SourceCodeInfo.Location location : currentPathTree.getDataElements()) {
    sourceCodeInfo.addLocation(
        location.toBuilder().clearPath().addAllPath(newPath.getPathElements()).build());
  }
}
项目:protobuf-el    文件:LocationBuilder.java   
public LocationBuilder(final SourceCodeInfo.Builder sourceBuilder,
    final CommonTokenStreamEx tokens) {
  location = null;
  path = new Path();
  currentScope = new FileScope();
  this.sourceBuilder = sourceBuilder;
  leadingComments = new IdentityHashMap<Token, String>();
  this.tokens = tokens;
}
项目:api-compiler    文件:BuilderVisitor.java   
protected void addFieldToMessageParent(
    FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) {
  addFieldToMessageAncestor(0, fieldDesc, location);
}
项目:api-compiler    文件:FileNodeInfo.java   
public ProtoPathTree<SourceCodeInfo.Location> pathToLocation() {
  return pathToLocation;
}
项目:api-compiler    文件:FileNodeInfo.java   
public ProtoPathTree<SourceCodeInfo.Location> getLocationSubtree(ProtoPathWrapper path) {
  return pathToLocation.getSubtree(path);
}
项目:api-compiler    文件:FileNodeInfo.java   
public LocationInfoUpdater(SourceCodeInfo.Builder sourceCodeInfo) {
  this.sourceCodeInfo = sourceCodeInfo;
}
项目:api-compiler    文件:FileNodeInfo.java   
@VisitsAfter
public void after(ProtoPathTree<SourceCodeInfo.Location> node) {
  if (!node.isRootNode()) {
    numDeletedChildren.pop();
  }
}
项目:api-compiler    文件:MessageNodeInfo.java   
public void addNewField(
    FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) {
  toBeAddedFields.add(FieldLocation.create(fieldDesc, location));
}
项目:api-compiler    文件:FieldLocation.java   
public static FieldLocation create(
    FieldDescriptorProto.Builder fieldDescriptor, SourceCodeInfo.Location location) {
  return new AutoValue_FieldLocation(fieldDescriptor, location);
}
项目:api-compiler    文件:FieldLocation.java   
public abstract SourceCodeInfo.Location location();