com.squareup.wire.schema.Location.path()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中com.squareup.wire.schema.Location.path()方法的一些代码示例,展示了Location.path()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Location.path()方法的具体详情如下:
包路径:com.squareup.wire.schema.Location
类名称:Location
方法名:path

Location.path介绍

[英]Returns the path to this location relative to #base.
[中]返回此位置相对于#base的路径。

代码示例

代码示例来源:origin: square/wire

/** Returns the proto file at {@code path}, or null if this schema has no such file. */
public ProtoFile protoFile(String path) {
 for (ProtoFile protoFile : protoFiles) {
  if (protoFile.location().path().equals(path)) {
   return protoFile;
  }
 }
 return null;
}

代码示例来源:origin: square/wire

/** Returns a copy of this location including only its path. */
public Location withPathOnly() {
 return new AutoValue_Location("", path(), -1, -1);
}

代码示例来源:origin: square/wire

@Override public int compare(ProtoFile left, ProtoFile right) {
  return left.location().path().compareTo(right.location().path());
 }
};

代码示例来源:origin: square/wire

/**
 * Computes all possible {@code .wire} profile files for the {@code .proto} at {@code location}
 * and adds them to {@code result}.
 */
void pathsToAttempt(Multimap<Path, String> sink, Location location) {
 Path base = fileSystem.getPath(location.base());
 String path = location.path();
 while (!path.isEmpty()) {
  String parent = path.substring(0, path.lastIndexOf('/', path.length() - 2) + 1);
  String profilePath = parent + name + ".wire";
  sink.put(base, profilePath);
  path = parent;
 }
}

代码示例来源:origin: square/wire

@Override public String toString() {
 return location().path();
}

代码示例来源:origin: square/wire

/**
 * Returns the name of this proto file, like {@code simple_message} for {@code
 * squareup/protos/person/simple_message.proto}.
 */
public String name() {
 String result = location().path();
 int slashIndex = result.lastIndexOf('/');
 if (slashIndex != -1) {
  result = result.substring(slashIndex + 1);
 }
 if (result.endsWith(".proto")) {
  result = result.substring(0, result.length() - ".proto".length());
 }
 return result;
}

代码示例来源:origin: square/wire

private void writeJavaFile(ClassName javaTypeName, TypeSpec typeSpec, Location location,
  Stopwatch stopwatch) throws IOException {
 JavaFile.Builder builder = JavaFile.builder(javaTypeName.packageName(), typeSpec)
   .addFileComment("Code generated by $L, do not edit.", CodegenSample.class.getName());
 if (location != null) {
  builder.addFileComment("\nSource file: $L", location.path());
 }
 JavaFile javaFile = builder.build();
 try {
  javaFile.writeTo(new File(generatedSourceDirectory));
 } catch (IOException e) {
  throw new IOException("Failed to write " + javaFile.packageName + "."
    + javaFile.typeSpec.name + " to " + generatedSourceDirectory, e);
 }
 log.info("Generated %s in %s", javaTypeName, stopwatch);
}

代码示例来源:origin: square/wire

@Override public String toString() {
  StringBuilder result = new StringBuilder();
  if (!base().isEmpty()) {
   result.append(base()).append(File.separator);
  }
  result.append(path());
  if (line() != -1) {
   result.append(" at ").append(line());
   if (column() != -1) {
    result.append(':').append(column());
   }
  }
  return result.toString();
 }
}

代码示例来源:origin: square/wire

public Location at(int line, int column) {
 return new AutoValue_Location(base(), path(), line, column);
}

代码示例来源:origin: square/wire

void validateImport(Location location, ProtoType type) {
 // Map key type is always scalar. No need to validate it.
 if (type.isMap()) type = type.valueType();
 if (type.isScalar()) return;
 String path = location.path();
 String requiredImport = get(type).location().path();
 if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) {
  addError("%s needs to import %s", path, requiredImport);
 }
}

代码示例来源:origin: square/wire

/** Returns a copy of this location with an empty base. */
public Location withoutBase() {
 return new AutoValue_Location("", path(), line(), column());
}

代码示例来源:origin: square/wire

/** Confirms that {@code protoFiles} link correctly against {@code schema}. */
void validate(Schema schema, ImmutableList<ProfileFileElement> profileFiles) {
 List<String> errors = new ArrayList<>();
 for (ProfileFileElement profileFile : profileFiles) {
  for (TypeConfigElement typeConfig : profileFile.typeConfigs()) {
   ProtoType type = importedType(ProtoType.get(typeConfig.type()));
   if (type == null) continue;
   Type resolvedType = schema.getType(type);
   if (resolvedType == null) {
    errors.add(String.format("unable to resolve %s (%s)",
      type, typeConfig.location()));
    continue;
   }
   String requiredImport = resolvedType.location().path();
   if (!profileFile.imports().contains(requiredImport)) {
    errors.add(String.format("%s needs to import %s (%s)",
      typeConfig.location().path(), requiredImport, typeConfig.location()));
   }
  }
 }
 if (!errors.isEmpty()) {
  throw new SchemaException(errors);
 }
}

代码示例来源:origin: square/wire

@Test public void locateInZipFile() throws IOException {
 Files.createDirectories(fileSystem.getPath("/source"));
 Path zip = fileSystem.getPath("/source/protos.zip");
 ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip));
 zipOutputStream.putNextEntry(new ZipEntry("a/b/message.proto"));
 zipOutputStream.write("message Message {}".getBytes(UTF_8));
 zipOutputStream.close();
 Schema schema = new SchemaLoader()
   .addSource(zip)
   .addProto("a/b/message.proto")
   .load();
 Type message = schema.getType("Message");
 assertThat(message).isNotNull();
 assertThat(message.location().base()).isEqualTo("/source/protos.zip");
 assertThat(message.location().path()).isEqualTo("a/b/message.proto");
}

代码示例来源:origin: square/wire

@Test public void loadAllFilesWhenNoneSpecified() throws IOException {
 Files.createDirectories(fileSystem.getPath("/source"));
 writeFile("/source/message1.proto", "message Message1 {}");
 writeFile("/source/message2.proto", "message Message2 {}");
 writeFile("/source/readme.txt", "Here be protos!");
 Schema schema = new SchemaLoader()
   .addSource(fileSystem.getPath("/source"))
   .load();
 Type message1 = schema.getType("Message1");
 assertThat(message1).isNotNull();
 assertThat(message1.location().base()).isEqualTo("/source");
 assertThat(message1.location().path()).isEqualTo("message1.proto");
 Type message2 = schema.getType("Message2");
 assertThat(message2).isNotNull();
 assertThat(message2.location().base()).isEqualTo("/source");
 assertThat(message2.location().path()).isEqualTo("message2.proto");
}

代码示例来源:origin: square/wire

if (!protoFilesList.isEmpty() && !protoFilesList.contains(protoFile.location().path())) {
 continue; // Don't emit anything for files not explicitly compiled.

代码示例来源:origin: square/wire

publicImports.putAll(protoFile.location().path(), protoFile.publicImports());
Collection<String> sink = imports.get(protoFile.location().path());
addImports(sink, protoFile.imports(), publicImports);
addImports(sink, protoFile.publicImports(), publicImports);

代码示例来源:origin: ppdai-incubator/raptor

/** Returns the proto file at {@code path}, or null if this schema has no such file. */
public ProtoFile protoFile(String path) {
 for (ProtoFile protoFile : protoFiles) {
  if (protoFile.location().path().equals(path)) {
   return protoFile;
  }
 }
 return null;
}

代码示例来源:origin: ppdai-incubator/raptor

void validateImport(Location location, ProtoType type) {
 // Map key type is always scalar. No need to validate it.
 if (type.isMap()) type = type.valueType();
 if (type.isScalar()) return;
 String path = location.path();
 String requiredImport = get(type).location().path();
 if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) {
  addError("%s needs to import %s", path, requiredImport);
 }
}

代码示例来源:origin: com.squareup.wire/wire-schema

/** Returns a copy of this location with an empty base. */
public Location withoutBase() {
 return new AutoValue_Location("", path(), line(), column());
}

代码示例来源:origin: com.squareup.wire/wire-schema

void validateImport(Location location, ProtoType type) {
 // Map key type is always scalar. No need to validate it.
 if (type.isMap()) type = type.valueType();
 if (type.isScalar()) return;
 String path = location.path();
 String requiredImport = get(type).location().path();
 if (!path.equals(requiredImport) && !imports.containsEntry(path, requiredImport)) {
  addError("%s needs to import %s", path, requiredImport);
 }
}

相关文章