Simple refactorings
This commit is contained in:
@@ -1,12 +1,49 @@
|
||||
package org.springframework.ide.vscode.commons.java.parser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseException;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
public interface CompilationUnitIndex {
|
||||
|
||||
static final CompilationUnitIndex DEFAULT = new DefaultCompilationUnitIndex();
|
||||
static final CompilationUnitIndex DEFAULT = new CompilationUnitIndex() {
|
||||
|
||||
private LoadingCache<URL, CompilationUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, CompilationUnit>() {
|
||||
|
||||
@Override
|
||||
public CompilationUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return JavaParser.parse(in);
|
||||
} catch (ParseException e) {
|
||||
in.close();
|
||||
Log.log("Failed to parse java source file: " + url, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public CompilationUnit getCompilationUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CompilationUnit getCompilationUnit(URL url);
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.parser;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseException;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
class DefaultCompilationUnitIndex implements CompilationUnitIndex {
|
||||
|
||||
private LoadingCache<URL, CompilationUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, CompilationUnit>() {
|
||||
|
||||
@Override
|
||||
public CompilationUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return JavaParser.parse(in);
|
||||
} catch (ParseException e) {
|
||||
in.close();
|
||||
Log.log("Failed to parse java source file: " + url, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public CompilationUnit getCompilationUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.roaster;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jboss.forge.roaster.Roaster;
|
||||
import org.jboss.forge.roaster.model.JavaUnit;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
class DefaultJavaUnitIndex implements JavaUnitIndex {
|
||||
|
||||
private LoadingCache<URL, JavaUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, JavaUnit>() {
|
||||
|
||||
@Override
|
||||
public JavaUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return Roaster.parseUnit(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public JavaUnit getJavaUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,46 @@
|
||||
package org.springframework.ide.vscode.commons.java.roaster;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jboss.forge.roaster.Roaster;
|
||||
import org.jboss.forge.roaster.model.JavaUnit;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
public interface JavaUnitIndex {
|
||||
|
||||
static final JavaUnitIndex DEFAULT = new DefaultJavaUnitIndex();
|
||||
static final JavaUnitIndex DEFAULT = new JavaUnitIndex() {
|
||||
|
||||
private LoadingCache<URL, JavaUnit> cache = CacheBuilder.newBuilder().build(new CacheLoader<URL, JavaUnit>() {
|
||||
|
||||
@Override
|
||||
public JavaUnit load(URL url) throws Exception {
|
||||
InputStream in = url.openStream();
|
||||
try {
|
||||
return Roaster.parseUnit(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@Override
|
||||
public JavaUnit getJavaUnit(URL url) {
|
||||
try {
|
||||
return cache.get(url);
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
JavaUnit getJavaUnit(URL url);
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public class DefaultHtmlJavadocIndex implements HtmlJavadocIndex {
|
||||
|
||||
private Cache<URL, JavadocContents> cache = CacheBuilder.newBuilder().build();
|
||||
|
||||
private static JavadocContents NO_HTML_CONTENT = new JavadocContents(null);
|
||||
|
||||
@Override
|
||||
public JavadocContents getHtmlJavadoc(URL url) {
|
||||
try {
|
||||
JavadocContents content = cache.get(url, () -> {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = url.openStream();
|
||||
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
|
||||
return new JavadocContents(buffer.lines().collect(Collectors.joining("\n")));
|
||||
} catch (IOException e) {
|
||||
return NO_HTML_CONTENT;
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
return content == NO_HTML_CONTENT ? null : content;
|
||||
} catch (ExecutionException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,54 @@
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
|
||||
public interface HtmlJavadocIndex {
|
||||
|
||||
public static final HtmlJavadocIndex DEFAULT = new DefaultHtmlJavadocIndex();
|
||||
static JavadocContents NO_HTML_CONTENT = new JavadocContents(null);
|
||||
|
||||
public static final HtmlJavadocIndex DEFAULT = new HtmlJavadocIndex() {
|
||||
|
||||
private Cache<URL, JavadocContents> cache = CacheBuilder.newBuilder().build();
|
||||
|
||||
|
||||
@Override
|
||||
public JavadocContents getHtmlJavadoc(URL url) {
|
||||
try {
|
||||
JavadocContents content = cache.get(url, () -> {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = url.openStream();
|
||||
BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
|
||||
return new JavadocContents(buffer.lines().collect(Collectors.joining("\n")));
|
||||
} catch (IOException e) {
|
||||
Log.log(e);
|
||||
return NO_HTML_CONTENT;
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
return content == NO_HTML_CONTENT ? null : content;
|
||||
} catch (ExecutionException e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
JavadocContents getHtmlJavadoc(URL url);
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
try {
|
||||
Artifact artifact = getArtifactFromJarFile(classpathResource).get();
|
||||
URL sourceContainer = maven.getSources(artifact).getFile().toURI().toURL();
|
||||
System.out.println("----> SOURCE " + sourceContainer);
|
||||
return SourceUrlProviderFromSourceContainer.JAR_SOURCE_URL_PROVIDER.sourceUrl(sourceContainer,
|
||||
type);
|
||||
} catch (MavenException e) {
|
||||
@@ -175,7 +174,6 @@ public class MavenProjectClasspath implements IClasspath {
|
||||
try {
|
||||
Artifact artifact = getArtifactFromJarFile(classpathResource).get();
|
||||
URL sourceContainer = maven.getSources(artifact).getFile().toURI().toURL();
|
||||
System.out.println("----> SOURCE " + sourceContainer);
|
||||
return SourceUrlProviderFromSourceContainer.JAR_SOURCE_URL_PROVIDER.sourceUrl(sourceContainer,
|
||||
type);
|
||||
} catch (MavenException e) {
|
||||
|
||||
Reference in New Issue
Block a user