Search in sources :

Example 6 with IClasspath

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

the class CompilationUnitCacheTest method cu_cache_invalidated_by_doc_change.

@Test
public void cu_cache_invalidated_by_doc_change() throws Exception {
    harness = BootJavaLanguageServerHarness.builder().mockDefaults().build();
    harness.useProject(new IJavaProject() {

        @Override
        public IClasspath getClasspath() {
            return new DelegatingCachedClasspath<>(() -> null, null);
        }
    });
    harness.intialize(null);
    TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" + "\n" + "public class SomeClass {\n" + "\n" + "}\n");
    harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
    CompilationUnit cu = getCompilationUnit(doc);
    assertNotNull(cu);
    harness.changeDocument(doc.getUri(), 0, 0, "     ");
    CompilationUnit cuAnother = getCompilationUnit(doc);
    assertNotNull(cuAnother);
    assertFalse(cu == cuAnother);
    CompilationUnit cuYetAnother = getCompilationUnit(doc);
    assertTrue(cuAnother == cuYetAnother);
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) Test(org.junit.Test)

Example 7 with IClasspath

use of org.springframework.ide.vscode.commons.java.IClasspath 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)

Aggregations

IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)6 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)6 Path (java.nio.file.Path)4 Map (java.util.Map)3 Stream (java.util.stream.Stream)3 JavaCore (org.eclipse.jdt.core.JavaCore)3 AST (org.eclipse.jdt.core.dom.AST)3 ASTParser (org.eclipse.jdt.core.dom.ASTParser)3 JavaProjectFinder (org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder)3 URI (java.net.URI)2 List (java.util.List)2 Test (org.junit.Test)2 ProjectObserver (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Files (java.nio.file.Files)1