Factor staff out in javadoc package
This commit is contained in:
@@ -21,10 +21,10 @@ import org.jboss.jandex.Indexer;
|
||||
import org.jboss.jandex.JarIndexer;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
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 org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
@@ -20,13 +20,13 @@ import org.springframework.ide.vscode.commons.java.Flags;
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaType;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadocProvider;
|
||||
import org.springframework.ide.vscode.commons.java.IMemberValuePair;
|
||||
import org.springframework.ide.vscode.commons.java.IMethod;
|
||||
import org.springframework.ide.vscode.commons.java.IPrimitiveType;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.java.IVoidType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public class Wrappers {
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavaElement {
|
||||
String getElementName();
|
||||
IJavadoc getJavaDoc();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
public interface IJavadocProvider {
|
||||
|
||||
IJavadoc getJavadoc(IType type);
|
||||
|
||||
@@ -6,10 +6,11 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IAnnotation;
|
||||
import org.springframework.ide.vscode.commons.java.IField;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
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 org.springframework.ide.vscode.commons.javadoc.RawJavadoc;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
@@ -25,10 +26,10 @@ public abstract class AbstractJavadocProvider implements IJavadocProvider {
|
||||
public IJavadoc getJavadoc(IType type) {
|
||||
if (type.isEnum()) {
|
||||
EnumDeclaration declaration = getEnumDeclaration(type);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
ClassOrInterfaceDeclaration declaration = getClassOrInterfaceDeclaration(type);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +37,10 @@ public abstract class AbstractJavadocProvider implements IJavadocProvider {
|
||||
IType declaringType = field.getDeclaringType();
|
||||
if (declaringType.isEnum()) {
|
||||
FieldDeclaration declaration = createVisitorToFindField(field).visit(getEnumDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
FieldDeclaration declaration = createVisitorToFindField(field).visit(getClassOrInterfaceDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +51,10 @@ public abstract class AbstractJavadocProvider implements IJavadocProvider {
|
||||
IType declaringType = method.getDeclaringType();
|
||||
if (declaringType.isEnum()) {
|
||||
MethodDeclaration declaration = createVisitorToFindMethod(method).visit(getEnumDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
} else {
|
||||
MethodDeclaration declaration = createVisitorToFindMethod(method).visit(getClassOrInterfaceDeclaration(declaringType), null);
|
||||
return declaration.getJavaDoc() == null ? null : new Javadoc(declaration.getJavaDoc());
|
||||
return declaration.getJavaDoc() == null ? null : new RawJavadoc(declaration.getJavaDoc().toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.springframework.ide.vscode.commons.java.parser;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
|
||||
import com.github.javaparser.ast.comments.JavadocComment;
|
||||
|
||||
final class Javadoc implements IJavadoc {
|
||||
|
||||
private JavadocComment javadocComment;
|
||||
|
||||
Javadoc(JavadocComment javadocComment) {
|
||||
this.javadocComment = javadocComment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return javadocComment.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String plainText() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String html() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String markdown() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
public interface IJavadoc {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.springframework.ide.vscode.commons.javadoc;
|
||||
|
||||
public class RawJavadoc implements IJavadoc {
|
||||
|
||||
private String rawContent;
|
||||
|
||||
public RawJavadoc(String rawContent) {
|
||||
this.rawContent = rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String raw() {
|
||||
return rawContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String plainText() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String html() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String markdown() {
|
||||
throw new UnsupportedOperationException("Not yet implemnted");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,8 @@ import java.nio.file.Paths;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.nio.file.Paths;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavadoc;
|
||||
import org.springframework.ide.vscode.commons.java.IType;
|
||||
import org.springframework.ide.vscode.commons.javadoc.IJavadoc;
|
||||
|
||||
/**
|
||||
* Java project that contains classpath text file
|
||||
|
||||
@@ -94,16 +94,31 @@ public class JavaIndexTest {
|
||||
MavenJavaProject project = projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
|
||||
IType type = project.findType("hello.Greeting");
|
||||
|
||||
assertNotNull(type);
|
||||
assertEquals("* Comment for Greeting class", type.getJavaDoc().raw().trim());
|
||||
assertNotNull(type);
|
||||
String expected = String.join("\n",
|
||||
"/**",
|
||||
" * Comment for Greeting class ",
|
||||
" */"
|
||||
);
|
||||
assertEquals(expected, type.getJavaDoc().raw().trim());
|
||||
|
||||
IField field = type.getField("id");
|
||||
assertNotNull(field);
|
||||
assertEquals("* Comment for id field", field.getJavaDoc().raw().trim());
|
||||
expected = String.join("\n",
|
||||
"/**",
|
||||
" * Comment for id field",
|
||||
" */"
|
||||
);
|
||||
assertEquals(expected, field.getJavaDoc().raw().trim());
|
||||
|
||||
IMethod method = type.getMethod("getId", Stream.empty());
|
||||
assertNotNull(method);
|
||||
assertEquals("* Comment for getId()", method.getJavaDoc().raw().trim());
|
||||
expected = String.join("\n",
|
||||
"/**",
|
||||
" * Comment for getId()",
|
||||
" */"
|
||||
);
|
||||
assertEquals(expected, method.getJavaDoc().raw().trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,15 +126,15 @@ public class JavaIndexTest {
|
||||
MavenJavaProject project = projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
|
||||
IType type = project.findType("hello.Greeting$TestInnerClass");
|
||||
assertNotNull(type);
|
||||
assertEquals("* Comment for inner class", type.getJavaDoc().raw().trim());
|
||||
assertEquals("/**\n * Comment for inner class\n */", type.getJavaDoc().raw().trim());
|
||||
|
||||
IField field = type.getField("innerField");
|
||||
assertNotNull(field);
|
||||
assertEquals("* Comment for inner field", field.getJavaDoc().raw().trim());
|
||||
assertEquals("/**\n \t * Comment for inner field\n \t */", field.getJavaDoc().raw().trim());
|
||||
|
||||
IMethod method = type.getMethod("getInnerField", Stream.empty());
|
||||
assertNotNull(method);
|
||||
assertEquals("* Comment for method inside nested class", method.getJavaDoc().raw().trim());
|
||||
assertEquals("/**\n \t * Comment for method inside nested class\n \t */", method.getJavaDoc().raw().trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,13 +142,21 @@ public class JavaIndexTest {
|
||||
MavenJavaProject project = projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
|
||||
|
||||
IType type = project.findType("org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener");
|
||||
assertNotNull(type);
|
||||
String expectedPrefix = "* {@link ApplicationListener} that replaces the liquibase {@link ServiceLocator} with a";
|
||||
assertEquals(expectedPrefix, type.getJavaDoc().raw().trim().substring(0, expectedPrefix.length()));
|
||||
assertNotNull(type);
|
||||
String expected = String.join("\n",
|
||||
"/**",
|
||||
" * {@link ApplicationListener} that replaces the liquibase {@link ServiceLocator} with a"
|
||||
);
|
||||
assertEquals(expected, type.getJavaDoc().raw().trim().substring(0, expected.length()));
|
||||
|
||||
type = project.findType("org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener$LiquibasePresent");
|
||||
assertNotNull(type);
|
||||
assertEquals("* Inner class to prevent class not found issues.", type.getJavaDoc().raw().trim());
|
||||
assertNotNull(type);
|
||||
expected = String.join("\n",
|
||||
"/**",
|
||||
" * Inner class to prevent class not found issues.",
|
||||
" */"
|
||||
);
|
||||
assertEquals(expected, type.getJavaDoc().raw().trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,12 +168,20 @@ public class JavaIndexTest {
|
||||
|
||||
IField field = type.getField("BANNER_LOCATION_PROPERTY_VALUE");
|
||||
assertNotNull(field);
|
||||
assertEquals("* Default banner location.", field.getJavaDoc().raw().trim());
|
||||
String expected = String.join("\n",
|
||||
"/**",
|
||||
" * Default banner location.",
|
||||
" */"
|
||||
);
|
||||
assertEquals(expected, field.getJavaDoc().raw().trim());
|
||||
|
||||
IMethod method = type.getMethod("getListeners", Stream.empty());
|
||||
assertNotNull(method);
|
||||
String expectedPrefix = "* Returns read-only ordered Set of the {@link ApplicationListener}s that will be";
|
||||
assertEquals(expectedPrefix, method.getJavaDoc().raw().trim().substring(0, expectedPrefix.length()));
|
||||
expected = String.join("\n",
|
||||
"/**",
|
||||
" * Returns read-only ordered Set of the {@link ApplicationListener}s that will be"
|
||||
);
|
||||
assertEquals(expected, method.getJavaDoc().raw().trim().substring(0, expected.length()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user