@Test void getSpoonProperties() { final StubSpoon stub = Mockito.mock(StubSpoon.class); Mockito.when(stub.foo()).thenReturn("fooo"); Mockito.when(stub.getAnnotations()).thenReturn(List.of()); Mockito.when(stub.getDocComment()).thenReturn("docc"); Mockito.when(stub.getShortRepresentation()).thenReturn("text"); Mockito.when(stub.getPosition()).thenReturn(null); Mockito.when(stub.isImplicit()).thenReturn(false); Mockito.when(stub.getReferencedTypes()).thenReturn(Set.of()); Mockito.when(stub.getComments()).thenReturn(List.of()); Mockito.when(stub.getParent()).thenReturn(null); final List<Pair<Class<?>, Set<Pair<String, String>>>> props = spoonCodeInstrument.getSpoonProperties(stub); assertThat(props).containsExactlyInAnyOrder( new Pair<>(StubSpoon.class, Set.of(new Pair<>("foo(): String", "fooo"))), new Pair<>(CtElement.class, Set.of( new Pair<>("getDocComment(): String", "docc"), new Pair<>("getAnnotations(): List<CtAnnotation<? extends java.lang.annotation.Annotation>>", "[]"), new Pair<>("getShortRepresentation(): String", "text"), new Pair<>("getPosition(): SourcePosition", "null"), new Pair<>("isImplicit(): boolean", "false"), new Pair<>("getReferencedTypes(): Set<CtTypeReference<?>>", "[]"), new Pair<>("getParent(): CtElement", "null"), new Pair<>("getComments(): List<CtComment>", "[]"))) ); }
List<Pair<Class<?>, Set<Pair<String, String>>>> getSpoonProperties(final CtElement elt) { return getAllSpoonInterfaces(elt.getClass()) .map(inter -> new Pair<Class<?>, Set<Pair<String, String>>>(inter, Arrays.stream(inter.getDeclaredMethods()) .filter(m -> (m.isAnnotationPresent(PropertyGetter.class) || m.isAnnotationPresent(DerivedProperty.class)) && m.getParameterCount() == 0) .map(m -> { try { return new Pair<>(m.getName() + "(): " + prettyPrintType(m.getGenericReturnType()), String.valueOf(m.invoke(elt))); }catch(final IllegalAccessException | InvocationTargetException | NullPointerException ex) { return null; } }) .filter(entry -> entry != null) .collect(Collectors.toSet())) ) .filter(pair -> !pair.getValue().isEmpty()) .collect(Collectors.toList()); }
SpoonCodeInstrument extends JfxInstrument implements Initializable { List<Pair<Class<?>, Set<Pair<String, String>>>> getSpoonProperties(final CtElement elt) { return getAllSpoonInterfaces(elt.getClass()) .map(inter -> new Pair<Class<?>, Set<Pair<String, String>>>(inter, Arrays.stream(inter.getDeclaredMethods()) .filter(m -> (m.isAnnotationPresent(PropertyGetter.class) || m.isAnnotationPresent(DerivedProperty.class)) && m.getParameterCount() == 0) .map(m -> { try { return new Pair<>(m.getName() + "(): " + prettyPrintType(m.getGenericReturnType()), String.valueOf(m.invoke(elt))); }catch(final IllegalAccessException | InvocationTargetException | NullPointerException ex) { return null; } }) .filter(entry -> entry != null) .collect(Collectors.toSet())) ) .filter(pair -> !pair.getValue().isEmpty()) .collect(Collectors.toList()); } }
SpoonCodeInstrument extends JfxInstrument implements Initializable { List<Pair<Class<?>, Set<Pair<String, String>>>> getSpoonProperties(final CtElement elt) { return getAllSpoonInterfaces(elt.getClass()) .map(inter -> new Pair<Class<?>, Set<Pair<String, String>>>(inter, Arrays.stream(inter.getDeclaredMethods()) .filter(m -> (m.isAnnotationPresent(PropertyGetter.class) || m.isAnnotationPresent(DerivedProperty.class)) && m.getParameterCount() == 0) .map(m -> { try { return new Pair<>(m.getName() + "(): " + prettyPrintType(m.getGenericReturnType()), String.valueOf(m.invoke(elt))); }catch(final IllegalAccessException | InvocationTargetException | NullPointerException ex) { return null; } }) .filter(entry -> entry != null) .collect(Collectors.toSet())) ) .filter(pair -> !pair.getValue().isEmpty()) .collect(Collectors.toList()); }  }
SpoonCodeInstrument extends JfxInstrument implements Initializable { List<Pair<Class<?>, Set<Pair<String, String>>>> getSpoonProperties(final CtElement elt) { return getAllSpoonInterfaces(elt.getClass()) .map(inter -> new Pair<Class<?>, Set<Pair<String, String>>>(inter, Arrays.stream(inter.getDeclaredMethods()) .filter(m -> (m.isAnnotationPresent(PropertyGetter.class) || m.isAnnotationPresent(DerivedProperty.class)) && m.getParameterCount() == 0) .map(m -> { try { return new Pair<>(m.getName() + "(): " + prettyPrintType(m.getGenericReturnType()), String.valueOf(m.invoke(elt))); }catch(final IllegalAccessException | InvocationTargetException | NullPointerException ex) { return null; } }) .filter(entry -> entry != null) .collect(Collectors.toSet())) ) .filter(pair -> !pair.getValue().isEmpty()) .collect(Collectors.toList()); }  @Override void initialize(final URL url, final ResourceBundle res); }
SpoonCodeInstrument extends JfxInstrument implements Initializable { List<Pair<Class<?>, Set<Pair<String, String>>>> getSpoonProperties(final CtElement elt) { return getAllSpoonInterfaces(elt.getClass()) .map(inter -> new Pair<Class<?>, Set<Pair<String, String>>>(inter, Arrays.stream(inter.getDeclaredMethods()) .filter(m -> (m.isAnnotationPresent(PropertyGetter.class) || m.isAnnotationPresent(DerivedProperty.class)) && m.getParameterCount() == 0) .map(m -> { try { return new Pair<>(m.getName() + "(): " + prettyPrintType(m.getGenericReturnType()), String.valueOf(m.invoke(elt))); }catch(final IllegalAccessException | InvocationTargetException | NullPointerException ex) { return null; } }) .filter(entry -> entry != null) .collect(Collectors.toSet())) ) .filter(pair -> !pair.getValue().isEmpty()) .collect(Collectors.toList()); }  @Override void initialize(final URL url, final ResourceBundle res);  }