diff options
author | Jim Hahn <jrh3@att.com> | 2019-07-11 10:10:17 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-07-11 10:10:17 -0400 |
commit | 7b5f7f8627d6e3cc267b4f7eefeb73d2efb31f96 (patch) | |
tree | 1110f031877f9eaed9a4604dfcbf65d4f290cd8e /gson/src/main | |
parent | 6b09b958c3de01b16207f480947b66882b0e9e3f (diff) |
Fix checkstyle issues in common/gson
Also deleted the checkstyle suppression file.
Change-Id: I6d310af32d6d4be9633a8f88745447f40a566af7
Issue-ID: POLICY-1074
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'gson/src/main')
-rw-r--r-- | gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java | 33 | ||||
-rw-r--r-- | gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java | 8 |
2 files changed, 33 insertions, 8 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java index c7b3bc98..174b4912 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java @@ -42,6 +42,11 @@ public class Adapter { private static final Pattern VALID_NAME_PAT = Pattern.compile("[a-zA-Z_]\\w*"); /** + * Factory to access objects. Overridden by junit tests. + */ + private static Factory factory = new Factory(); + + /** * Name of the property within the json structure containing the item. */ private final String propName; @@ -157,7 +162,7 @@ public class Adapter { * @return {@code true} if the field is managed by the walker, {@code false} otherwise */ public static boolean isManaged(Field field) { - return VALID_NAME_PAT.matcher(field.getName()).matches(); + return VALID_NAME_PAT.matcher(factory.getName(field)).matches(); } /** @@ -168,7 +173,7 @@ public class Adapter { * otherwise */ public static boolean isManaged(Method method) { - return VALID_NAME_PAT.matcher(method.getName()).matches(); + return VALID_NAME_PAT.matcher(factory.getName(method)).matches(); } /** @@ -185,7 +190,7 @@ public class Adapter { } // no name provided - use it as is - return (isManaged(field) ? field.getName() : null); + return (isManaged(field) ? factory.getName(field) : null); } /** @@ -204,7 +209,7 @@ public class Adapter { return null; } - String name = method.getName(); + String name = factory.getName(method); if (name.startsWith("get")) { return name.substring(3); @@ -238,7 +243,7 @@ public class Adapter { return null; } - String name = method.getName(); + String name = factory.getName(method); if (name.startsWith("set")) { return name.substring(3); @@ -284,7 +289,7 @@ public class Adapter { * @return the field fully qualified name */ public static String getQualifiedName(Field field) { - return (field.getDeclaringClass().getName() + "." + field.getName()); + return (field.getDeclaringClass().getName() + "." + factory.getName(field)); } /** @@ -294,7 +299,7 @@ public class Adapter { * @return the method's fully qualified name */ public static String getQualifiedName(Method method) { - return (method.getDeclaringClass().getName() + "." + method.getName()); + return (method.getDeclaringClass().getName() + "." + factory.getName(method)); } /** @@ -340,4 +345,18 @@ public class Adapter { return conv; } } + + /** + * Factory used to access various objects. + */ + public static class Factory { + + public String getName(Field field) { + return field.getName(); + } + + public String getName(Method method) { + return method.getName(); + } + } } diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java index 89e4f89d..ef4eaae3 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java @@ -241,7 +241,7 @@ public class ClassWalker { return; } - String name = Adapter.detmPropName(field); + String name = detmPropName(field); if (name == null) { // invalid name return; @@ -386,4 +386,10 @@ public class ClassWalker { private String getFqdn(Method method) { return (method.getDeclaringClass().getName() + "." + method.getName()); } + + // these may be overridden by junit tests + + protected String detmPropName(Field field) { + return Adapter.detmPropName(field); + } } |