Take inherited pojo properties into account

In yaml / properties editor.
This commit is contained in:
Kris De Volder
2018-10-22 16:49:39 -07:00
parent 8177a9c110
commit 248098112e
8 changed files with 167 additions and 4 deletions

View File

@@ -42,7 +42,6 @@ public class ClasspathListenerManager {
@Override
public void elementChanged(ElementChangedEvent event) {
logger.log("changeEvent = "+event);
visit(event.getDelta());
}

View File

@@ -573,7 +573,7 @@ public class TypeUtil {
private IType findType(String typeName) {
try {
if (javaProject!=null) {
if (javaProject!=null && typeName!=null) {
return javaProject.findType(typeName);
}
} catch (Exception e) {
@@ -587,6 +587,8 @@ public class TypeUtil {
}
private static final Map<String, ValueProviderStrategy> VALUE_HINTERS = new HashMap<>();
private static final Object JL_OBJECT = Object.class.getName();
static {
valueHints("java.nio.charset.Charset", new LazyProvider<String[]>() {
@Override
@@ -721,8 +723,8 @@ public class TypeUtil {
}
private Stream<IMethod> getGetterMethods(IType eclipseType) {
if (eclipseType != null && eclipseType.isClass()) {
return eclipseType.getMethods().filter(m -> {
if (eclipseType != null && eclipseType.isClass() && !JL_OBJECT.equals(eclipseType.getFullyQualifiedName())) {
Stream<IMethod> getters = eclipseType.getMethods().filter(m -> {
if (!isStatic(m) && isPublic(m)) {
String mname = m.getElementName();
if ((mname.startsWith("get") && mname.length() >= 4)
@@ -736,6 +738,9 @@ public class TypeUtil {
}
return false;
});
IType superType = findType(eclipseType.getSuperclassName());
Stream<IMethod> superGetters = getGetterMethods(superType);
return Stream.concat(getters, superGetters);
}
return Stream.empty();
}

View File

@@ -63,6 +63,23 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
////////////////////////////////////////////////////////////////////////////////////////
@Test public void inheritedPojoProperties() throws Exception {
//See https://github.com/spring-projects/sts4/issues/116
useProject(createPredefinedMavenProject("cloud-rabbit-project"));
Editor editor = newEditor(
"spring:\n" +
" cloud:\n" +
" stream:\n" +
" rabbit:\n" +
" bindings:\n" +
" input:\n" +
" consumer:\n" +
" auto-bind-dlq: true"
);
editor.assertProblems(/*NONE*/);
}
@Test public void bug_158348104() throws Exception {
//See: https://www.pivotaltracker.com/story/show/158348104
data("spring.activemq.close-timeout", "java.time.Duration", null, null);

View File

@@ -0,0 +1,25 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>cloud-rabbit-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cloud-rabbit-project</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,12 @@
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CloudRabbitProjectApplication {
public static void main(String[] args) {
SpringApplication.run(CloudRabbitProjectApplication.class, args);
}
}

View File

@@ -0,0 +1,9 @@
spring:
cloud:
stream:
rabbit:
bindings:
input:
consumer:
auto-bing-dlq: true

View File

@@ -0,0 +1,16 @@
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CloudRabbitProjectApplicationTests {
@Test
public void contextLoads() {
}
}