From eb169e6d60c9167ee9884c172654ff5c3f1c21af Mon Sep 17 00:00:00 2001 From: Cody Schroeder Date: Thu, 20 Apr 2023 20:47:58 -0600 Subject: [PATCH] feat: add KytheURI#toCorpusPath() (#5592) --- .../com/google/devtools/kythe/util/KytheURI.java | 9 +++++++++ .../com/google/devtools/kythe/util/KytheURITest.java | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/kythe/java/com/google/devtools/kythe/util/KytheURI.java b/kythe/java/com/google/devtools/kythe/util/KytheURI.java index 143b7ccad8..54d8b74086 100644 --- a/kythe/java/com/google/devtools/kythe/util/KytheURI.java +++ b/kythe/java/com/google/devtools/kythe/util/KytheURI.java @@ -118,6 +118,15 @@ public VName toVName() { return vName; } + /** Returns the {@link CorpusPath} components of the uri. */ + public CorpusPath toCorpusPath() { + return CorpusPath.newBuilder() + .setCorpus(vName.getCorpus()) + .setRoot(vName.getRoot()) + .setPath(vName.getPath()) + .build(); + } + @Override public String toString() { StringBuilder b = diff --git a/kythe/javatests/com/google/devtools/kythe/util/KytheURITest.java b/kythe/javatests/com/google/devtools/kythe/util/KytheURITest.java index 29ce3f0b17..d3840a589f 100644 --- a/kythe/javatests/com/google/devtools/kythe/util/KytheURITest.java +++ b/kythe/javatests/com/google/devtools/kythe/util/KytheURITest.java @@ -170,6 +170,18 @@ public void testToVName() throws URISyntaxException { assertThat(vname.getLanguage()).isEqualTo(lang); } + public void testToCorpusPath() throws URISyntaxException { + String signature = "magic school truck"; + String corpus = "crazyTown"; + String path = "usa/2.0"; + String root = null; + String lang = "c++"; + CorpusPath cp = new KytheURI(signature, corpus, root, path, lang).toCorpusPath(); + assertThat(cp.getCorpus()).isEqualTo(corpus); + assertThat(cp.getRoot()).isEmpty(); // Proto fields are never null + assertThat(cp.getPath()).isEqualTo(path); + } + public void testParseErrors() { String[] tests = new String[] {