Navigatable (@NotNull Project project, @NotNull VirtualFile file, @NotNull String groupId, @NotNull String artifactId) { return Optional.of(file).filter(VirtualFile::isValid) .map(f -> MavenDomUtil.getMavenDomProjectModel(project, f)) .map(projectModel -> findDependency(projectModel, groupId, artifactId)) .map(dependency -> dependency.getArtifactId().getXmlTag()) .map(artifactIdTag -> Pair.create(artifactIdTag.getContainingFile().getVirtualFile(), artifactIdTag.getTextOffset() + artifactIdTag.getName().length() + 2)) .<Navigatable>map(pair -> new NavigatableAdapter() { @Override public void navigate(boolean requestFocus) { navigate(project, pair.getFirst(), pair.getSecond(), requestFocus); } } ).orElse(EmptyNavigatable.INSTANCE); }