@Test public void resolve_existing_file_multiple_go_path_entries() throws IOException { String goPath = tmpDirWithFile[0] + File.pathSeparator + tmpDirWithFile[1]; GoPathContext context = new GoPathContext(File.separatorChar, File.pathSeparator, goPath); assertThat(context.resolve("file.go")).isEqualTo(existingFileAbsolutePath[0]); assertThat(context.resolvedPaths.keySet()).containsExactly("file.go"); assertThat(context.resolvedPaths.values()).containsExactly(existingFileAbsolutePath[0]); }
public String resolve(String filePath) { return resolvedPaths.computeIfAbsent(filePath, path -> { if (path.startsWith(LINUX_ABSOLUTE_PREFIX)) { return path.substring(1); } else if (path.startsWith(WINDOWS_ABSOLUTE_PREFIX)) { Matcher matcher = WINDOWS_ABSOLUTE_REGEX.matcher(path); if (matcher.find()) { matcher.reset(); return matcher.replaceFirst("$1:\\\\"); } } return prefixByFirstValidGoPath(path) .orElseGet(() -> prefixByFirstGoPath(path)); }); }
GoPathContext { public String resolve(String filePath) { return resolvedPaths.computeIfAbsent(filePath, path -> { if (path.startsWith(LINUX_ABSOLUTE_PREFIX)) { return path.substring(1); } else if (path.startsWith(WINDOWS_ABSOLUTE_PREFIX)) { Matcher matcher = WINDOWS_ABSOLUTE_REGEX.matcher(path); if (matcher.find()) { matcher.reset(); return matcher.replaceFirst("$1:\\\\"); } } return prefixByFirstValidGoPath(path) .orElseGet(() -> prefixByFirstGoPath(path)); }); } }
GoPathContext { public String resolve(String filePath) { return resolvedPaths.computeIfAbsent(filePath, path -> { if (path.startsWith(LINUX_ABSOLUTE_PREFIX)) { return path.substring(1); } else if (path.startsWith(WINDOWS_ABSOLUTE_PREFIX)) { Matcher matcher = WINDOWS_ABSOLUTE_REGEX.matcher(path); if (matcher.find()) { matcher.reset(); return matcher.replaceFirst("$1:\\\\"); } } return prefixByFirstValidGoPath(path) .orElseGet(() -> prefixByFirstGoPath(path)); }); } GoPathContext(char fileSeparator, String pathSeparator, @Nullable String goPath); }
GoPathContext { public String resolve(String filePath) { return resolvedPaths.computeIfAbsent(filePath, path -> { if (path.startsWith(LINUX_ABSOLUTE_PREFIX)) { return path.substring(1); } else if (path.startsWith(WINDOWS_ABSOLUTE_PREFIX)) { Matcher matcher = WINDOWS_ABSOLUTE_REGEX.matcher(path); if (matcher.find()) { matcher.reset(); return matcher.replaceFirst("$1:\\\\"); } } return prefixByFirstValidGoPath(path) .orElseGet(() -> prefixByFirstGoPath(path)); }); } GoPathContext(char fileSeparator, String pathSeparator, @Nullable String goPath); String resolve(String filePath); }
GoPathContext { public String resolve(String filePath) { return resolvedPaths.computeIfAbsent(filePath, path -> { if (path.startsWith(LINUX_ABSOLUTE_PREFIX)) { return path.substring(1); } else if (path.startsWith(WINDOWS_ABSOLUTE_PREFIX)) { Matcher matcher = WINDOWS_ABSOLUTE_REGEX.matcher(path); if (matcher.find()) { matcher.reset(); return matcher.replaceFirst("$1:\\\\"); } } return prefixByFirstValidGoPath(path) .orElseGet(() -> prefixByFirstGoPath(path)); }); } GoPathContext(char fileSeparator, String pathSeparator, @Nullable String goPath); String resolve(String filePath); static final GoPathContext DEFAULT; }