This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch add-simple-mock-driver
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 0249de02c114adde8086c810b136a8c8794db843
Author: julian <j.feina...@pragmaticminds.de>
AuthorDate: Thu Nov 1 12:09:28 2018 +0100

    [OPM] Several Sonar fixes and small refactorings.
---
 .../org/apache/plc4x/java/examples/helloplc4x/HelloOpm.java    |  8 +++-----
 .../java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java   | 10 ++++++++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git 
a/examples/hello-world-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloOpm.java
 
b/examples/hello-world-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloOpm.java
index 6ad1421..2925fe1 100644
--- 
a/examples/hello-world-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloOpm.java
+++ 
b/examples/hello-world-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloOpm.java
@@ -46,7 +46,7 @@ public class HelloOpm {
     private static final String PLC_FIELD_ADDRESS = "%DB225.DBW0:INT";
     private final PlcEntityManager entityManager;
 
-    public static void main(String[] args) throws OPMException, 
InterruptedException {
+    public static void main(String[] args) throws OPMException {
         HelloOpm helloOpm = new HelloOpm();
         // Do a fetch via connected entity
         helloOpm.readValueFromPlcUsingConnectedEntity();
@@ -65,10 +65,9 @@ public class HelloOpm {
      * If another method is called on the Entity all Fields are feched from 
the Plc first, and then the method is
      * invoked.
      *
-     * @throws InterruptedException
      * @throws OPMException
      */
-    public void readValueFromPlcUsingConnectedEntity() throws 
InterruptedException, OPMException {
+    public void readValueFromPlcUsingConnectedEntity() throws OPMException {
         // Fetch connected Entity
         DistanceSensor distanceSensor = 
entityManager.connect(DistanceSensor.class, ADDRESS);
         // Read shoot values a hundred times
@@ -83,10 +82,9 @@ public class HelloOpm {
      * <b>once</b> and injects them in the new instance. After the 
constructing this is a regular POJO with no fancy
      * functionality.
      *
-     * @throws InterruptedException
      * @throws OPMException
      */
-    public void readValueFromPlcUsingRead() throws InterruptedException, 
OPMException {
+    public void readValueFromPlcUsingRead() throws OPMException {
         // Read Entity from PLC
         DistanceSensor distanceSensor = 
entityManager.read(DistanceSensor.class, ADDRESS);
         System.out.println("Current distance: " + 
distanceSensor.getDistance());
diff --git 
a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
 
b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
index 35b074b..61a7c3b 100644
--- 
a/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
+++ 
b/plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/PlcEntityInterceptor.java
@@ -24,7 +24,6 @@ import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.SystemConfiguration;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.PlcConnection;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -64,6 +63,11 @@ public class PlcEntityInterceptor {
 
     private static final Configuration CONF = new SystemConfiguration();
     private static final long READ_TIMEOUT = 
CONF.getLong("org.apache.plc4x.java.opm.entity_manager.read_timeout", 1_000);
+
+    private PlcEntityInterceptor() {
+        throw new UnsupportedOperationException("This class is not to be 
instantiated");
+    }
+
     /**
      * Basic Intersector for all methods on the proxy object.
      * It checks if the invoked method is a getter and if so, only retrieves 
the requested field, forwarding to
@@ -134,6 +138,7 @@ public class PlcEntityInterceptor {
      * @param driverManager
      * @throws OPMException on various errors.
      */
+    @SuppressWarnings("squid:S1141") // Nested try blocks readability is okay, 
move to other method makes it imho worse
     static void refetchAllFields(Object proxy, PlcDriverManager driverManager, 
String address) throws OPMException {
         // Don't log o here as this would cause a second request against a plc 
so don't touch it, or if you log be aware of that
         Class<?> entityClass = proxy.getClass().getSuperclass();
@@ -162,7 +167,7 @@ public class PlcEntityInterceptor {
 
             // Fill all requested fields
             for (String fieldName : response.getFieldNames()) {
-                LOGGER.trace("Value for field " + fieldName + " is " + 
response.getObject(fieldName));
+                LOGGER.trace("Value for field {}  is {}", fieldName, 
response.getObject(fieldName));
                 String clazzFieldName = 
StringUtils.substringAfterLast(fieldName, ".");
                 try {
                     setField(entityClass, proxy, response, clazzFieldName, 
fieldName);
@@ -242,6 +247,7 @@ public class PlcEntityInterceptor {
         }
     }
 
+    @SuppressWarnings("squid:S3776") // Cognitive Complexity not too high, as 
highly structured
     private static Object getTyped(Class<?> clazz, PlcReadResponse response, 
String sourceFieldName) {
         LOGGER.debug("getTyped clazz: {}, response: {}, fieldName: {}", clazz, 
response, sourceFieldName);
         if (response.getResponseCode(sourceFieldName) != PlcResponseCode.OK) {

Reply via email to