Search in sources :

Example 1 with IClasspath

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

the class SpringIndexer method getClasspathEntries.

private String[] getClasspathEntries(IJavaProject project) throws Exception {
    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) Arrays(java.util.Arrays) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) SymbolProvider(org.springframework.ide.vscode.boot.java.handlers.SymbolProvider) LoggerFactory(org.slf4j.LoggerFactory) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) FileASTRequestor(org.eclipse.jdt.core.dom.FileASTRequestor) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Location(org.eclipse.lsp4j.Location) AnnotationHierarchyAwareLookup(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup) URI(java.net.URI) Path(java.nio.file.Path) ExceptionUtil(org.springframework.ide.vscode.commons.util.ExceptionUtil) Predicate(java.util.function.Predicate) SymbolAddOnInformation(org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) List(java.util.List) Stream(java.util.stream.Stream) ASTParser(org.eclipse.jdt.core.dom.ASTParser) WorkspaceFolder(org.eclipse.lsp4j.WorkspaceFolder) AST(org.eclipse.jdt.core.dom.AST) Optional(java.util.Optional) SimpleWorkspaceService(org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) MarkerAnnotation(org.eclipse.jdt.core.dom.MarkerAnnotation) JavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder) SymbolKind(org.eclipse.lsp4j.SymbolKind) BootLanguageServerParams(org.springframework.ide.vscode.boot.BootLanguageServerParams) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) ProjectObserver(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) ImmutableList(com.google.common.collect.ImmutableList) Annotation(org.eclipse.jdt.core.dom.Annotation) AnnotationHierarchies(org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies) UriUtil(org.springframework.ide.vscode.commons.util.UriUtil) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) LanguageId(org.springframework.ide.vscode.commons.util.text.LanguageId) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) Logger(org.slf4j.Logger) Files(java.nio.file.Files) JavaCore(org.eclipse.jdt.core.JavaCore) Futures(org.springframework.ide.vscode.commons.util.Futures) FileUtils(org.apache.commons.io.FileUtils) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) File(java.io.File) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Listener(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener) Paths(java.nio.file.Paths) Collections(java.util.Collections) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath)

Example 2 with IClasspath

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

the class SpringResource method projectRelativePath.

private String projectRelativePath(String pathStr) {
    Path path = Paths.get(pathStr);
    IClasspath classpath = project.getClasspath();
    Path outputFolder = classpath.getOutputFolder();
    if (path.startsWith(outputFolder)) {
        return outputFolder.relativize(path).toString();
    }
    return pathStr;
}
Also used : Path(java.nio.file.Path) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath)

Example 3 with IClasspath

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

the class CompilationUnitCache method getClasspathEntries.

private static String[] getClasspathEntries(TextDocument document, IJavaProject project) throws Exception {
    if (project == null) {
        return new String[0];
    } else {
        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) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock) JavaProjectFinder(org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder) Log(org.springframework.ide.vscode.commons.util.Log) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) JavaCore(org.eclipse.jdt.core.JavaCore) ProjectObserver(org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver) Set(java.util.Set) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadLock(java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock) Function(java.util.function.Function) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) HashSet(java.util.HashSet) Stream(java.util.stream.Stream) ASTParser(org.eclipse.jdt.core.dom.ASTParser) Map(java.util.Map) AST(org.eclipse.jdt.core.dom.AST) URI(java.net.URI) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) Path(java.nio.file.Path) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath) IClasspath(org.springframework.ide.vscode.commons.java.IClasspath)

Example 4 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_close.

@Test
public void cu_cache_invalidated_by_doc_close() 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.closeDocument(doc.getId());
    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 5 with IClasspath

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

the class CompilationUnitCacheTest method cu_cached.

@Test
public void cu_cached() 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");
    CompilationUnit cu = getCompilationUnit(doc);
    assertNotNull(cu);
    CompilationUnit cuAnother = getCompilationUnit(doc);
    assertTrue(cu == cuAnother);
}
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)

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