Refactor javadoc service injection
This commit is contained in:
@@ -20,12 +20,8 @@ import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -43,30 +39,6 @@ public class JandexIndex extends BasicJandexIndex {
|
||||
IJavadocProvider createJavadocProvider(File jarContainer);
|
||||
}
|
||||
|
||||
private static final IJavadocProvider ABSENT_JAVADOC_PROVIDER = new IJavadocProvider() {
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IAnnotation method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private JavadocProviderFactory javadocProviderFactory;
|
||||
|
||||
private Cache<File, IJavadocProvider> javadocProvidersCache = CacheBuilder.newBuilder().build();
|
||||
@@ -101,7 +73,7 @@ public class JandexIndex extends BasicJandexIndex {
|
||||
if (javadocProviderFactory != null) {
|
||||
provider = javadocProviderFactory.createJavadocProvider(classpathResource);
|
||||
}
|
||||
return provider == null ? ABSENT_JAVADOC_PROVIDER : provider;
|
||||
return provider == null ? IJavadocProvider.NULL : provider;
|
||||
});
|
||||
} catch (ExecutionException e) {
|
||||
log.error("Failed to retrieve javadoc provider for resource " + classpathResource, e);
|
||||
|
||||
@@ -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
|
||||
@@ -13,12 +13,37 @@ package org.springframework.ide.vscode.commons.java;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavadocProvider {
|
||||
|
||||
|
||||
IJavadoc getJavadoc(IType type);
|
||||
|
||||
|
||||
IJavadoc getJavadoc(IField field);
|
||||
|
||||
|
||||
IJavadoc getJavadoc(IMethod method);
|
||||
|
||||
IJavadoc getJavadoc(IAnnotation annotation);
|
||||
|
||||
final static IJavadocProvider NULL = new IJavadocProvider() {
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IField field) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IMethod method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJavadoc getJavadoc(IAnnotation method) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.net.URI;
|
||||
|
||||
import org.springframework.ide.vscode.commons.jandex.JandexClasspath;
|
||||
import org.springframework.ide.vscode.commons.jandex.JandexIndex.JavadocProviderFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
@@ -27,12 +29,15 @@ public class JavaProject implements IJavaProject, Disposable {
|
||||
private final FileObserver fileObserver;
|
||||
private final JavadocProviderFactory javadocProviderFactory;
|
||||
|
||||
public JavaProject(FileObserver fileObserver, URI uri, IClasspath classpath, JavadocProviderFactory javadocProviderFactory) {
|
||||
public JavaProject(FileObserver fileObserver, URI uri, IClasspath classpath, JavadocService javadocService) {
|
||||
super();
|
||||
this.classpath = classpath;
|
||||
this.fileObserver = fileObserver;
|
||||
this.uri = uri;
|
||||
this.javadocProviderFactory = javadocProviderFactory;
|
||||
this.javadocProviderFactory = (classpathResource) -> {
|
||||
CPE cpe = IClasspathUtil.findEntryForBinaryRoot(classpath, classpathResource);
|
||||
return javadocService.javadocProvider(uri.toString(), cpe);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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
|
||||
@@ -13,8 +13,7 @@ package org.springframework.ide.vscode.commons.java;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.JavaDocProviders;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
/**
|
||||
@@ -30,11 +29,8 @@ public class LegacyJavaProject extends JavaProject {
|
||||
|
||||
final protected Path projectDataCache;
|
||||
|
||||
public LegacyJavaProject(FileObserver fileObserver, URI loactionUri, Path projectDataCache, IClasspath classpath) {
|
||||
super(fileObserver, loactionUri, classpath, classpathResource -> {
|
||||
CPE cpe = IClasspathUtil.findEntryForBinaryRoot(classpath, classpathResource);
|
||||
return JavaDocProviders.createFor(cpe);
|
||||
});
|
||||
public LegacyJavaProject(FileObserver fileObserver, URI loactionUri, Path projectDataCache, IClasspath classpath, JavadocService javadocService) {
|
||||
super(fileObserver, loactionUri, classpath, javadocService);
|
||||
this.projectDataCache = projectDataCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -15,18 +15,13 @@ import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
|
||||
public class HtmlJavadoc implements IJavadoc {
|
||||
|
||||
|
||||
private String html;
|
||||
|
||||
|
||||
public HtmlJavadoc(String html) {
|
||||
this.html = html;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
return Renderables.htmlBlob(html);
|
||||
|
||||
@@ -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
|
||||
@@ -14,9 +14,7 @@ package org.springframework.ide.vscode.commons.javadoc;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
public interface IJavadoc {
|
||||
|
||||
String raw();
|
||||
|
||||
|
||||
Renderable getRenderable();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -47,11 +47,6 @@ public class JdtLsJavadocProvider implements IJavadocProvider {
|
||||
final Renderable renderableDoc = Renderables.mdBlob(md);
|
||||
return new IJavadoc() {
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
throw new UnsupportedOperationException("Raw content unavailable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
return renderableDoc;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 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.javadoc;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
public class RawJavadoc implements IJavadoc {
|
||||
|
||||
private String rawContent;
|
||||
|
||||
public RawJavadoc(String rawContent) {
|
||||
this.rawContent = rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderable getRenderable() {
|
||||
throw new UnsupportedOperationException("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 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.languageserver.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
|
||||
|
||||
public interface JavadocService {
|
||||
|
||||
IJavadocProvider javadocProvider(String projectUri, CPE classpathEntry);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user