Search in sources :

Example 6 with IMethod

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

the class JavaIndexTest method constructorMethodWithParams.

@Test
public void constructorMethodWithParams() throws Exception {
    MavenJavaProject project = mavenProjectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file");
    IType type = project.getClasspath().findType("java.util.ArrayList");
    assertNotNull(type);
    IMethod m = type.getMethod("<init>", Stream.of(IPrimitiveType.INT));
    assertEquals(m.getDeclaringType().getElementName(), m.getElementName());
    assertEquals(IVoidType.DEFAULT, m.getReturnType());
    assertEquals(Collections.singletonList(IPrimitiveType.INT), m.parameters().collect(Collectors.toList()));
}
Also used : MavenJavaProject(org.springframework.ide.vscode.commons.maven.java.MavenJavaProject) IMethod(org.springframework.ide.vscode.commons.java.IMethod) IType(org.springframework.ide.vscode.commons.java.IType) Test(org.junit.Test)

Example 7 with IMethod

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

the class TypeUtil method getSetter.

public Optional<IMethod> getSetter(Type beanType, String propName) {
    try {
        String setterName = "set" + StringUtil.hyphensToCamelCase(propName, true);
        IType type = findType(beanType);
        return type.getMethods().filter(m -> setterName.equals(m.getElementName())).findFirst();
    } catch (Exception e) {
        Log.log(e);
    }
    return Optional.empty();
}
Also used : Arrays(java.util.Arrays) Provider(javax.inject.Provider) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) IMethod(org.springframework.ide.vscode.commons.java.IMethod) LazyProvider(org.springframework.ide.vscode.commons.util.LazyProvider) ArrayUtils.firstElement(org.springframework.ide.vscode.commons.util.ArrayUtils.firstElement) ArrayList(java.util.ArrayList) IJavaElement(org.springframework.ide.vscode.commons.java.IJavaElement) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Charset(java.nio.charset.Charset) ImmutableList(com.google.common.collect.ImmutableList) IField(org.springframework.ide.vscode.commons.java.IField) Locale(java.util.Locale) Flags(org.springframework.ide.vscode.commons.java.Flags) Map(java.util.Map) DeprecationUtil(org.springframework.ide.vscode.boot.metadata.util.DeprecationUtil) ValueProviderStrategy(org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy) ResourceHintProvider(org.springframework.ide.vscode.boot.metadata.ResourceHintProvider) ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) ImmutableSet(com.google.common.collect.ImmutableSet) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) Log(org.springframework.ide.vscode.commons.util.Log) Collection(java.util.Collection) ArrayUtils(org.springframework.ide.vscode.commons.util.ArrayUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) Assert(org.springframework.ide.vscode.commons.util.Assert) Flux(reactor.core.publisher.Flux) ArrayUtils.lastElement(org.springframework.ide.vscode.commons.util.ArrayUtils.lastElement) List(java.util.List) CollectionUtil(org.springframework.ide.vscode.commons.util.CollectionUtil) Stream(java.util.stream.Stream) EnumValueParser(org.springframework.ide.vscode.commons.util.EnumValueParser) MimeTypes(org.springframework.ide.vscode.commons.util.MimeTypes) Entry(java.util.Map.Entry) Optional(java.util.Optional) IType(org.springframework.ide.vscode.commons.java.IType) Collections(java.util.Collections) Deprecation(org.springframework.ide.vscode.boot.configurationmetadata.Deprecation) AlwaysFailingParser(org.springframework.ide.vscode.commons.util.AlwaysFailingParser) IType(org.springframework.ide.vscode.commons.java.IType)

Example 8 with IMethod

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

the class TypeUtil method getGetter.

public IJavaElement getGetter(Type beanType, String propName) {
    String getterName = "get" + StringUtil.hyphensToCamelCase(propName, true);
    IType type = findType(beanType);
    IMethod m = type.getMethod(getterName, Stream.empty());
    if (m.exists()) {
        return m;
    }
    return null;
}
Also used : IMethod(org.springframework.ide.vscode.commons.java.IMethod) IType(org.springframework.ide.vscode.commons.java.IType)

Example 9 with IMethod

use of org.springframework.ide.vscode.commons.java.IMethod 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 10 with IMethod

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

Aggregations

IMethod (org.springframework.ide.vscode.commons.java.IMethod)12 IType (org.springframework.ide.vscode.commons.java.IType)12 Test (org.junit.Test)10 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)10 IJavadoc (org.springframework.ide.vscode.commons.javadoc.IJavadoc)7 IField (org.springframework.ide.vscode.commons.java.IField)5 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 InetAddress (java.net.InetAddress)1 Charset (java.nio.charset.Charset)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1