Merge branch 'master' of github.com:spring-projects/sts4

This commit is contained in:
Kris De Volder
2018-09-07 13:20:52 -07:00
11 changed files with 126 additions and 39 deletions

View File

@@ -62,12 +62,19 @@ Example entry:
private JSONObject getHandlerMethod() {
JSONObject details = getDetails();
return details == null ? null : details.getJSONObject("handlerMethod");
if (details != null) {
if (details.has("handlerMethod")) {
return details.getJSONObject("handlerMethod");
} else if (details.has("handlerFunction")) {
//TODO: handler function for the Router bean
}
}
return null;
}
private JSONObject getRequestMappingConditions() {
JSONObject details = getDetails();
return details == null ? null : details.getJSONObject("requestMappingConditions");
return details == null ? null : details.optJSONObject("requestMappingConditions");
}
@Override

View File

@@ -12,7 +12,9 @@ package org.springframework.ide.vscode.commons.boot.app.cli;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
@@ -20,6 +22,8 @@ import org.junit.Test;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMappingsParser20;
import com.google.common.collect.ImmutableSet;
public class Boot2xRequestMappingsTest {
@Test
@@ -27,13 +31,62 @@ public class Boot2xRequestMappingsTest {
String json = IOUtils.toString(Boot2xRequestMappingsTest.class.getResourceAsStream("/live-rm-beans/rms-boot2-web.json"));
Collection<RequestMapping> rms = RequestMappingsParser20.parse(new JSONObject(json));
assertEquals(10, rms.size());
ImmutableSet<String> expected = ImmutableSet.of(
"/error",
"/actuator",
"/actuator/health",
"/actuator/info",
"/hello",
"/qq",
"/pp"
);
assertEquals(expected,
rms.stream()
.flatMap(rm -> Arrays.stream(rm.getSplitPath()))
.collect(Collectors.toSet())
);
}
@Test
public void testWebFluxAnnotationRms() throws Exception {
String json = IOUtils.toString(Boot2xRequestMappingsTest.class.getResourceAsStream("/live-rm-beans/rms-boot2-webflux.json"));
Collection<RequestMapping> rms = RequestMappingsParser20.parse(new JSONObject(json));
assertEquals(7, rms.size());
ImmutableSet<String> expected = ImmutableSet.of(
"/actuator",
"/actuator/health",
"/actuator/info",
"/hello",
"/pp",
"/qq"
);
assertEquals(expected,
rms.stream()
.flatMap(rm -> Arrays.stream(rm.getSplitPath()))
.collect(Collectors.toSet())
);
}
@Test
public void testWebFluxAnnotationRmsFunctional() throws Exception {
String json = IOUtils.toString(Boot2xRequestMappingsTest.class.getResourceAsStream("/live-rm-beans/rms-boot2-webflux-functional.json"));
Collection<RequestMapping> rms = RequestMappingsParser20.parse(new JSONObject(json));
assertEquals(6, rms.size());
ImmutableSet<String> expected = ImmutableSet.of(
"/actuator",
"/actuator/health",
"/actuator/info"
);
assertEquals(expected,
rms.stream()
.flatMap(rm -> Arrays.stream(rm.getSplitPath()))
.collect(Collectors.toSet())
);
}
}

View File

@@ -20,6 +20,7 @@ import java.util.stream.Stream;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.springframework.ide.vscode.commons.util.CollectorUtil;
import com.google.common.collect.ImmutableList;
@@ -34,28 +35,31 @@ import com.google.common.collect.ImmutableList;
*/
public abstract class AnnotationHierarchies {
private AnnotationHierarchies() {
}
protected static boolean ignoreAnnotation(String fqname) {
return fqname.startsWith("java."); //mostly intended to capture java.lang.annotation.* types. But really it should be
//safe to ignore any type defined by the JRE since it can't possibly be inheriting from a spring annotation.
};
public static Collection<ITypeBinding> getDirectSuperAnnotations(ITypeBinding typeBinding) {
IAnnotationBinding[] annotations = typeBinding.getAnnotations();
if (annotations!=null && annotations.length!=0) {
ImmutableList.Builder<ITypeBinding> superAnnotations = ImmutableList.builder();
for (IAnnotationBinding ab : annotations) {
ITypeBinding sa = ab.getAnnotationType();
if (sa!=null) {
if (!ignoreAnnotation(sa.getQualifiedName())) {
superAnnotations.add(sa);
try {
IAnnotationBinding[] annotations = typeBinding.getAnnotations();
if (annotations != null && annotations.length != 0) {
ImmutableList.Builder<ITypeBinding> superAnnotations = ImmutableList.builder();
for (IAnnotationBinding ab : annotations) {
ITypeBinding sa = ab.getAnnotationType();
if (sa != null) {
if (!ignoreAnnotation(sa.getQualifiedName())) {
superAnnotations.add(sa);
}
}
}
return superAnnotations.build();
}
return superAnnotations.build();
}
catch (AbortCompilation e) {
// ignore this, it is most likely caused by broken source code, a broken classpath, or some optional dependencies not being on the classpath
}
return ImmutableList.of();
}

View File

@@ -33,8 +33,6 @@ import com.google.common.collect.ImmutableList;
*/
public class AnnotationHierarchyAwareLookup<T> {
private static final boolean DEBUG = false;
private static class Binding<T> {
T value;
boolean isOverriding;