Search in sources :

Example 21 with IType

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

the class ClassReferenceProvider method getValuesAsync.

@Override
protected Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) {
    IType targetType = target == null || target.isEmpty() ? javaProject.getClasspath().findType("java.lang.Object") : javaProject.getClasspath().findType(target);
    if (targetType == null) {
        return Flux.empty();
    }
    Set<IType> allSubclasses = javaProject.getClasspath().allSubtypesOf(targetType).filter(t -> Flags.isPublic(t.getFlags()) && !concrete || !isAbstract(t)).collect(Collectors.toSet()).block();
    if (allSubclasses.isEmpty()) {
        return Flux.empty();
    } else {
        return javaProject.getClasspath().fuzzySearchTypes(query, type -> allSubclasses.contains(type)).collectSortedList((o1, o2) -> o2.getT2().compareTo(o1.getT2())).flatMapIterable(l -> l).map(t -> StsValueHint.create(t.getT1()));
    }
}
Also used : StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) Log(org.springframework.ide.vscode.commons.util.Log) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Flux(reactor.core.publisher.Flux) Flags(org.springframework.ide.vscode.commons.java.Flags) Map(java.util.Map) ValueProviderStrategy(org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy) IType(org.springframework.ide.vscode.commons.java.IType) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) IType(org.springframework.ide.vscode.commons.java.IType)

Example 22 with IType

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

the class HtmlJavadocTest method html_testInnerClassLevel2_JavadocForOutputFolder.

@Test
public void html_testInnerClassLevel2_JavadocForOutputFolder() throws Exception {
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("hello.Greeting$TestInnerClass$TestInnerClassLevel2");
    assertNotNull(type);
    IJavadoc javaDoc = type.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals("<div class=\"block\">Comment for level 2 nested class</div>", javaDoc.getRenderable().toHtml());
    IField field = type.getField("innerLevel2Field");
    assertNotNull(field);
    String expected = String.join("\n", "<h4>innerLevel2Field</h4>", "<pre>protected&nbsp;int innerLevel2Field</pre>", "<div class=\"block\">Comment for level 2 inner field</div>");
    javaDoc = field.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
    IMethod method = type.getMethod("getInnerLevel2Field", Stream.empty());
    assertNotNull(method);
    expected = String.join("\n", "<h4>getInnerLevel2Field</h4>", "<pre>public&nbsp;int&nbsp;getInnerLevel2Field()</pre>", "<div class=\"block\">Comment for method inside level 2 nested class</div>");
    javaDoc = method.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IJavadoc(org.springframework.ide.vscode.commons.javadoc.IJavadoc) IMethod(org.springframework.ide.vscode.commons.java.IMethod) IField(org.springframework.ide.vscode.commons.java.IField) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 23 with IType

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

the class HtmlJavadocTest method html_testMethodJavadoc.

@Test
public void html_testMethodJavadoc() throws Exception {
    Assume.assumeTrue(javaVersionHigherThan(6));
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("java.util.ArrayList");
    assertNotNull(type);
    IMethod method = type.getMethod("size", Stream.empty());
    assertNotNull(method);
    String expected = String.join("\n", "<h4>size</h4>", "<pre>public&nbsp;int&nbsp;size()</pre>", "<div class=\"block\">Returns the number of elements in this list.</div>");
    IJavadoc javaDoc = method.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml().substring(0, expected.length()));
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IJavadoc(org.springframework.ide.vscode.commons.javadoc.IJavadoc) IMethod(org.springframework.ide.vscode.commons.java.IMethod) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 24 with IType

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

the class HtmlJavadocTest method html_testNoJavadocField.

@Test
public void html_testNoJavadocField() throws Exception {
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("hello.GreetingController");
    assertNotNull(type);
    IField field = type.getField("template");
    assertNotNull(field);
    String expected = String.join("\n", "<h4>template</h4>", "<pre>public static final&nbsp;<a href=\"http://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true\" title=\"class or interface in java.lang\">String</a> template</pre>", "<dl>", "<dt><span class=\"seeLabel\">See Also:</span></dt>", "<dd><a href=\"../constant-values.html#hello.GreetingController.template\">Constant Field Values</a></dd>", "</dl>");
    IJavadoc javaDoc = field.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IJavadoc(org.springframework.ide.vscode.commons.javadoc.IJavadoc) IField(org.springframework.ide.vscode.commons.java.IField) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 25 with IType

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

the class HtmlJavadocTest method html_testEmptyJavadocClass.

@Test
public void html_testEmptyJavadocClass() throws Exception {
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("hello.Application");
    assertNotNull(type);
    assertNull(type.getJavaDoc());
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Aggregations

IType (org.springframework.ide.vscode.commons.java.IType)30 Test (org.junit.Test)19 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)18 IMethod (org.springframework.ide.vscode.commons.java.IMethod)14 IJavadoc (org.springframework.ide.vscode.commons.javadoc.IJavadoc)11 IField (org.springframework.ide.vscode.commons.java.IField)9 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Stream (java.util.stream.Stream)3 Deprecation (org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)3 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)3 Cache (com.google.common.cache.Cache)2