Search in sources :

Example 61 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ClassReferenceProvider method getValuesAsync.

@Override
protected Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) {
    IType targetType = target == null || target.isEmpty() ? javaProject.getClasspath().findType("java.lang.Object") : javaProject.getClasspath().findType(target);
    if (targetType == null) {
        return Flux.empty();
    }
    Set<IType> allSubclasses = javaProject.getClasspath().allSubtypesOf(targetType).filter(t -> Flags.isPublic(t.getFlags()) && !concrete || !isAbstract(t)).collect(Collectors.toSet()).block();
    if (allSubclasses.isEmpty()) {
        return Flux.empty();
    } else {
        return javaProject.getClasspath().fuzzySearchTypes(query, type -> allSubclasses.contains(type)).collectSortedList((o1, o2) -> o2.getT2().compareTo(o1.getT2())).flatMapIterable(l -> l).map(t -> StsValueHint.create(t.getT1()));
    }
}
Also used : StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) Log(org.springframework.ide.vscode.commons.util.Log) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Flux(reactor.core.publisher.Flux) Flags(org.springframework.ide.vscode.commons.java.Flags) Map(java.util.Map) ValueProviderStrategy(org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy) IType(org.springframework.ide.vscode.commons.java.IType) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) IType(org.springframework.ide.vscode.commons.java.IType)

Example 62 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class BootJavaReferencesHandler method getClasspathEntries.

private String[] getClasspathEntries(IDocument doc) throws Exception {
    IJavaProject project = this.projectFinder.find(new TextDocumentIdentifier(doc.getUri())).get();
    IClasspath classpath = project.getClasspath();
    Stream<Path> classpathEntries = classpath.getClasspathEntries().stream();
    return classpathEntries.filter(path -> path.toFile().exists()).map(path -> path.toAbsolutePath().toString()).toArray(String[]::new);
}
Also used : Path(java.nio.file.Path) ASTNode(org.eclipse.jdt.core.dom.ASTNode) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) JavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) JavaCore(org.eclipse.jdt.core.JavaCore) NodeFinder(org.eclipse.jdt.core.dom.NodeFinder) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) Stream(java.util.stream.Stream) ASTParser(org.eclipse.jdt.core.dom.ASTParser) Annotation(org.eclipse.jdt.core.dom.Annotation) ReferencesHandler(org.springframework.ide.vscode.commons.languageserver.util.ReferencesHandler) Map(java.util.Map) AST(org.eclipse.jdt.core.dom.AST) Location(org.eclipse.lsp4j.Location) Path(java.nio.file.Path) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath)

Example 63 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class GradleProjectTest method findGradleProjectWithNonStandardBuildFile.

@Test
public void findGradleProjectWithNonStandardBuildFile() throws Exception {
    GradleProjectFinder finder = new GradleProjectFinder(new GradleProjectCache(server, GradleCore.getDefault(), false, null));
    File sourceFile = new File(GradleProjectTest.class.getResource("/test-app-2/src/main/java/Library.java").toURI());
    Optional<IJavaProject> project = finder.find(sourceFile);
    assertTrue(project.isPresent());
    assertTrue(project.get() instanceof GradleJavaProject);
    GradleJavaProject gradleProject = (GradleJavaProject) project.get();
    assertEquals(new File(GradleProjectTest.class.getResource("/test-app-2").toURI()), gradleProject.getLocation());
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) File(java.io.File) Test(org.junit.Test)

Aggregations

IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)63 Test (org.junit.Test)52 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)35 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)24 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)8 Ignore (org.junit.Ignore)8 IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)7 File (java.io.File)6 Path (java.nio.file.Path)6 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)6 URI (java.net.URI)5 Map (java.util.Map)5 Listener (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener)5 Stream (java.util.stream.Stream)4 JavaCore (org.eclipse.jdt.core.JavaCore)4 AST (org.eclipse.jdt.core.dom.AST)4 ASTParser (org.eclipse.jdt.core.dom.ASTParser)4 JavaProjectFinder (org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder)4 List (java.util.List)3