You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2018/09/13 20:46:15 UTC
svn commit: r1840866 - in /felix/trunk/scr: changelog.txt
src/main/java/org/apache/felix/scr/impl/inject/Annotations.java
src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java
Author: cziegeler
Date: Thu Sep 13 20:46:15 2018
New Revision: 1840866
URL: http://svn.apache.org/viewvc?rev=1840866&view=rev
Log:
FELIX-5927 : Single element Annotation type does not incorporate PREFIX_
Modified:
felix/trunk/scr/changelog.txt
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java
felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java
Modified: felix/trunk/scr/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scr/changelog.txt?rev=1840866&r1=1840865&r2=1840866&view=diff
==============================================================================
--- felix/trunk/scr/changelog.txt (original)
+++ felix/trunk/scr/changelog.txt Thu Sep 13 20:46:15 2018
@@ -1,3 +1,10 @@
+Changes in 2.1.8
+----------------
+** Bug
+ * [FELIX-5927] - Single element Annotation type does not incorporate PREFIX_
+ * [FELIX-5926] - Logger instance is not set for constructor and reference injection
+
+
Changes in 2.1.6
----------------
** Bug
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java?rev=1840866&r1=1840865&r2=1840866&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/inject/Annotations.java Thu Sep 13 20:46:15 2018
@@ -44,7 +44,7 @@ import org.osgi.service.component.Compon
public class Annotations
{
/** Capture all methods defined by the annotation interface */
- private static final Set<Method> ANNOTATION_METHODS = new HashSet<Method>();
+ private static final Set<Method> ANNOTATION_METHODS = new HashSet<>();
static
{
for(final Method m : Annotation.class.getMethods())
@@ -140,22 +140,22 @@ public class Annotations
{
final boolean isSingleElementAnn = isSingleElementAnnotation(clazz);
final String prefix = getPrefix(clazz);
- final Map<String, Object> m = new HashMap<String, Object>();
+ final Map<String, Object> m = new HashMap<>();
- final Map<String, Method> complexFields = new HashMap<String, Method>();
+ final Map<String, Method> complexFields = new HashMap<>();
for ( final Method method: clazz.getMethods() )
{
final String name = method.getName();
- final String key;
+ final String mapped;
if ( isSingleElementAnn && name.equals(VALUE_METHOD) )
{
- key = mapTypeNameToKey(clazz.getSimpleName());
+ mapped = mapTypeNameToKey(clazz.getSimpleName());
}
else
{
- final String mapped = mapIdentifierToKey(name);
- key = (prefix == null ? mapped : prefix.concat(mapped));
+ mapped = mapIdentifierToKey(name);
}
+ final String key = (prefix == null ? mapped : prefix.concat(mapped));
Object raw = props.get(key);
Class<?> returnType = method.getReturnType();
@@ -240,7 +240,7 @@ public class Annotations
private static Map<String, List<Map<String, Object>>> extractSubMaps(Collection<String> keys, Map<String, Object> map)
{
- Map<String, List<Map<String, Object>>> result = new HashMap<String, List<Map<String, Object>>>();
+ Map<String, List<Map<String, Object>>> result = new HashMap<>();
//Form a regexp to recognize all the keys as prefixes in the map keys.
StringBuilder b = new StringBuilder("(");
for (String key: keys)
@@ -262,7 +262,7 @@ public class Annotations
List<Map<String, Object>> subMapsForKey = result.get(key);
if (subMapsForKey == null)
{
- subMapsForKey = new ArrayList<Map<String, Object>>();
+ subMapsForKey = new ArrayList<>();
result.put(key, subMapsForKey);
}
//make sure there is room for the possible new submap
Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java?rev=1840866&r1=1840865&r2=1840866&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java Thu Sep 13 20:46:15 2018
@@ -133,7 +133,7 @@ public class AnnotationTest extends Test
private Map<String, Object> allValues()
{
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, Object> values = new HashMap<>();
values.put("bool", "true");
values.put("byt", 12l);
values.put("cha", 'c');
@@ -151,7 +151,7 @@ public class AnnotationTest extends Test
public void testA1NoValues() throws Exception
{
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, Object> values = new HashMap<>();
Object o = Annotations.toObject( A1.class, values, mockBundle(), false);
assertTrue("expected an A1", o instanceof A1);
@@ -245,7 +245,7 @@ public class AnnotationTest extends Test
public void testA1ArraysNoValues() throws Exception
{
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, Object> values = new HashMap<>();
Object o = Annotations.toObject( A1Arrays.class, values, mockBundle(), false);
assertTrue("expected an A1Arrays", o instanceof A1Arrays);
@@ -300,7 +300,7 @@ public class AnnotationTest extends Test
private Map<String, Object> arrayValues()
{
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, Object> values = new HashMap<>();
values.put("bool", new boolean[] {true, false});
values.put("byt", new byte[] {12, 3});
values.put("cha", new char[] {'c', 'h', 'a', 'r'});
@@ -325,7 +325,7 @@ public class AnnotationTest extends Test
public void testA1ArrayFromCollection() throws Exception
{
Map<String, Object> values = arrayValues();
- Map<String, Object> collectionValues = new HashMap<String, Object>();
+ Map<String, Object> collectionValues = new HashMap<>();
for (Map.Entry<String, Object> entry: values.entrySet())
{
collectionValues.put(entry.getKey(), toList(entry.getValue()));
@@ -336,7 +336,7 @@ public class AnnotationTest extends Test
private List<?> toList(Object value)
{
- List<Object> result = new ArrayList<Object>();
+ List<Object> result = new ArrayList<>();
for (int i = 0; i < Array.getLength(value); i++)
{
result.add(Array.get(value, i));
@@ -596,7 +596,7 @@ public class AnnotationTest extends Test
public void testOddClasses() throws Exception
{
- Map<String, Object> values = new HashMap<String, Object>();
+ Map<String, Object> values = new HashMap<>();
values.put("odd1", new Odd("one"));
values.put("odd2", Collections.singletonList(new Odd("two")));
values.put("odd3", new Odd[] {new Odd("three"), new Odd("four")});
@@ -642,6 +642,12 @@ public class AnnotationTest extends Test
String value();
}
+ public @interface SingleElementTest {
+ String PREFIX_ = "org.apache.";
+
+ String value();
+ }
+
public void testSingleElementAnnotation() throws Exception
{
assertFalse(Annotations.isSingleElementAnnotation(Map.class));
@@ -649,6 +655,7 @@ public class AnnotationTest extends Test
assertTrue(Annotations.isSingleElementAnnotation(SETest2.class));
assertFalse(Annotations.isSingleElementAnnotation(SETest3.class));
assertFalse(Annotations.isSingleElementAnnotation(SETest4.class));
+ assertTrue(Annotations.isSingleElementAnnotation(SingleElementTest.class));
}
public void testGetPrefix() throws Exception
@@ -664,13 +671,13 @@ public class AnnotationTest extends Test
public void testMappingWithPrefix() throws Exception
{
- final Map<String, Object> values = new HashMap<String, Object>();
+ final Map<String, Object> values = new HashMap<>();
values.put("foo", false);
values.put("org.apache.foo", true);
values.put("values", "false-values");
values.put("org.apache.values", "true-values");
values.put("value", "false-value");
- values.put("prefix.test", "true-value");
+ values.put("org.apache.prefix.test", "true-value");
final PrefixTest o = Annotations.toObject( PrefixTest.class, values, mockBundle(), true);
assertEquals("true-value", o.value());
@@ -679,6 +686,16 @@ public class AnnotationTest extends Test
assertEquals(true, o.foo());
}
+ public void testMappingWithPrefixSingleValue() throws Exception
+ {
+ final Map<String, Object> values = new HashMap<>();
+ values.put("value", "false-value");
+ values.put("org.apache.single.element.test", "true-value");
+
+ final SingleElementTest o = Annotations.toObject( SingleElementTest.class, values, mockBundle(), true);
+ assertEquals("true-value", o.value());
+ }
+
private void assertOdd(String expectedContent, Object actual) {
assertTrue("expected an Odd", actual instanceof Odd);
assertEquals("Expected Odd contents", expectedContent, ((Odd)actual).getContent());