Search in sources :

Example 1 with IField

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

the class HtmlJavadocTest method html_testFieldAndMethodJavadocForJar.

@Test
public void html_testFieldAndMethodJavadocForJar() throws Exception {
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("org.springframework.boot.SpringApplication");
    assertNotNull(type);
    IField field = type.getField("BANNER_LOCATION_PROPERTY_VALUE");
    assertNotNull(field);
    String expected = String.join("\n", "<h4>BANNER_LOCATION_PROPERTY_VALUE</h4>", "<pre>public static final&nbsp;<a href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true\" title=\"class or interface in java.lang\">String</a> BANNER_LOCATION_PROPERTY_VALUE</pre>", "<div class=\"block\">Default banner location.</div>", "<dl>", "<dt><span class=\"seeLabel\">See Also:</span></dt>", "<dd><a href=\"../../../constant-values.html#org.springframework.boot.SpringApplication.BANNER_LOCATION_PROPERTY_VALUE\">Constant Field Values</a></dd>", "</dl>");
    IJavadoc javaDoc = field.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
    IMethod method = type.getMethod("getListeners", Stream.empty());
    assertNotNull(method);
    expected = String.join("\n", "<h4>getListeners</h4>", "<pre>public&nbsp;<a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/Set.html?is-external=true\" title=\"class or interface in java.util\">Set</a>&lt;org.springframework.context.ApplicationListener&lt;?&gt;&gt;&nbsp;getListeners()</pre>", "<div class=\"block\">Returns read-only ordered Set of the <code>ApplicationListener</code>s that will be", " applied to the SpringApplication and registered with the <code>ApplicationContext</code>", " .</div>", "<dl>", "<dt><span class=\"returnLabel\">Returns:</span></dt>", "<dd>the listeners</dd>", "</dl>");
    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 2 with IField

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

the class HtmlJavadocTest method html_testJavadocOutputFolder.

@Test
public void html_testJavadocOutputFolder() throws Exception {
    MavenJavaProject project = projectSupplier.get();
    IType type = project.getClasspath().findType("hello.Greeting");
    assertNotNull(type);
    String expected = "<div class=\"block\">Comment for Greeting class</div>";
    IJavadoc javaDoc = type.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
    IField field = type.getField("id");
    assertNotNull(field);
    expected = String.join("\n", "<h4>id</h4>", "<pre>protected final&nbsp;long id</pre>", "<div class=\"block\">Comment for id field</div>");
    javaDoc = field.getJavaDoc();
    assertNotNull(javaDoc);
    assertEquals(expected, javaDoc.getRenderable().toHtml());
    IMethod method = type.getMethod("getId", Stream.empty());
    assertNotNull(method);
    expected = String.join("\n", "<h4>getId</h4>", "<pre>public&nbsp;long&nbsp;getId()</pre>", "<div class=\"block\">Comment for getId()</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 3 with IField

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

the class TypeUtil method getEnumConstant.

public IField getEnumConstant(Type enumType, String propName) {
    IType type = findType(enumType);
    // 1: if propname is already spelled exactly...
    IField f = getExactField(type, propName);
    if (f != null)
        return f;
    // 2: most likely enum constant is upper-case form of propname
    String fieldName = StringUtil.hyphensToUpperCase(propName);
    return getExactField(type, fieldName);
}
Also used : IField(org.springframework.ide.vscode.commons.java.IField) IType(org.springframework.ide.vscode.commons.java.IType)

Example 4 with IField

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

the class ApplicationYamlAssistContext method getAllJavaElements.

private static List<IJavaElement> getAllJavaElements(TypeUtil typeUtil, Type parentType, String propName) {
    if (propName != null) {
        Type beanType = parentType;
        if (TypeUtil.isMap(beanType)) {
            Type keyType = typeUtil.getKeyType(beanType);
            if (keyType != null && typeUtil.isEnum(keyType)) {
                IField field = typeUtil.getEnumConstant(keyType, propName);
                if (field != null) {
                    return ImmutableList.of(field);
                }
            }
        } else {
            ArrayList<IJavaElement> elements = new ArrayList<IJavaElement>(3);
            maybeAdd(elements, typeUtil.getField(beanType, propName));
            maybeAdd(elements, typeUtil.getSetter(beanType, propName).get());
            maybeAdd(elements, typeUtil.getGetter(beanType, propName));
            if (!elements.isEmpty()) {
                return elements;
            }
        }
    }
    return ImmutableList.of();
}
Also used : IJavaElement(org.springframework.ide.vscode.commons.java.IJavaElement) Type(org.springframework.ide.vscode.boot.metadata.types.Type) YamlPathSegmentType(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.YamlPathSegmentType) ArrayList(java.util.ArrayList) IField(org.springframework.ide.vscode.commons.java.IField)

Example 5 with IField

use of org.springframework.ide.vscode.commons.java.IField 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)

Aggregations

IField (org.springframework.ide.vscode.commons.java.IField)7 IType (org.springframework.ide.vscode.commons.java.IType)6 Test (org.junit.Test)5 IJavadoc (org.springframework.ide.vscode.commons.javadoc.IJavadoc)5 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)5 IMethod (org.springframework.ide.vscode.commons.java.IMethod)4 ArrayList (java.util.ArrayList)1 Type (org.springframework.ide.vscode.boot.metadata.types.Type)1 IJavaElement (org.springframework.ide.vscode.commons.java.IJavaElement)1 YamlPathSegmentType (org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.YamlPathSegmentType)1