PT #151978919 VSCode navigation to resource from hovers (POC)
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.jandex;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -17,6 +28,12 @@ import com.google.common.base.Suppliers;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
/**
|
||||
* Classpath with Jandex Java index for searching types
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
*/
|
||||
public abstract class JandexClasspath implements IClasspath {
|
||||
|
||||
public static JavadocProviderTypes providerType = JavadocProviderTypes.HTML;
|
||||
@@ -81,6 +98,11 @@ public abstract class JandexClasspath implements IClasspath {
|
||||
return JandexIndex.getIndexFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<File> findClasspathResourceContainer(String fqName) {
|
||||
return javaIndex.get().findClasspathResourceForType(fqName);
|
||||
}
|
||||
|
||||
abstract protected IJavadocProvider createParserJavadocProvider(File classpathResource);
|
||||
|
||||
abstract protected IJavadocProvider createHtmlJavdocProvider(File classpathResource);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -227,6 +227,27 @@ public class JandexIndex {
|
||||
.orElse(null));
|
||||
|
||||
}
|
||||
|
||||
private Optional<Tuple2<File, ClassInfo>> findMatch(DotName fqName) {
|
||||
return (baseIndex == null ? Stream.<Optional<Tuple2<File, ClassInfo>>>empty()
|
||||
: Arrays.stream(
|
||||
baseIndex)
|
||||
.filter(
|
||||
jandexIndex -> jandexIndex != null)
|
||||
.map(jandexIndex -> jandexIndex.findMatch(fqName))).filter(o -> o.isPresent())
|
||||
.findFirst()
|
||||
// If not found look at indices owned by this
|
||||
// JandexIndex instance
|
||||
.orElseGet(() -> streamOfIndices()
|
||||
.map(e -> Tuples.of(e.getT1(), Optional.ofNullable(e.getT2().getClassByName(fqName))))
|
||||
.filter(t -> t.getT2().isPresent())
|
||||
.map(e -> Tuples.of(e.getT1(), e.getT2().get())).findFirst());
|
||||
}
|
||||
|
||||
public Optional<File> findClasspathResourceForType(String fqName) {
|
||||
Optional<Tuple2<File, ClassInfo>> match = findMatch(DotName.createSimple(fqName));
|
||||
return Optional.ofNullable(match.isPresent() ? match.get().getT1() : null);
|
||||
}
|
||||
|
||||
private IType createType(Tuple2<File, ClassInfo> match) {
|
||||
File classpathResource = match.getT1();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -18,6 +18,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -255,5 +256,17 @@ public class DelegatingCachedClasspath<T extends IClasspath> implements IClasspa
|
||||
new LinkedHashSet<>(newDelegate.getClasspathResources()), newDelegate.getOutputFolder());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<String> getSourceFolders() {
|
||||
T t = cachedDelegate.get();
|
||||
return t == null ? ImmutableList.of() : t.getSourceFolders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<File> findClasspathResourceContainer(String fqName) {
|
||||
T t = cachedDelegate.get();
|
||||
return t == null ? Optional.empty() : t.findClasspathResourceContainer(fqName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -10,7 +10,9 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -54,5 +56,9 @@ public interface IClasspath {
|
||||
* @return classpath resource relative paths
|
||||
*/
|
||||
ImmutableList<String> getClasspathResources();
|
||||
|
||||
ImmutableList<String> getSourceFolders();
|
||||
|
||||
Optional<File> findClasspathResourceContainer(String fqName);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user