]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Slight re-organization of code to prevent one unnecessary diagnostic message
authorhoharri <hoharri@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 10:13:13 +0000 (10:13 +0000)
committerhoharri <hoharri@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 10 May 2011 10:13:13 +0000 (10:13 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20854 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.objmap/src/org/simantics/objmap/annotations/factories/RelatedValueRuleFactory.java

index 37cd981291ed0adcaa34902153448a48830d8c96..828bb59fb9226bd9a2f91b07ce3ec16699eacf6b 100644 (file)
@@ -33,12 +33,15 @@ import org.simantics.objmap.rules.range.IRangeAccessor;
 public class RelatedValueRuleFactory implements IFieldRuleFactory {\r
 \r
     @Override\r
-    public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {\r
-        RelatedValue annotation = (RelatedValue)_annotation;\r
+    public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException,\r
+            ValidationException, ServiceException {\r
+        RelatedValue annotation = (RelatedValue) _annotation;\r
         Class<? extends ValueAdapter> adapterClass = annotation.adapter();\r
         IRangeAccessor<Object> rangeAccessor = new FieldAccessor<Object>(field);\r
-        Resource valueType = DataTypeUtils.dataTypeOfClass(g, field.getType());\r
-        if(adapterClass != IdentityAdapter.class)\r
+        Resource valueType;\r
+        if (adapterClass == IdentityAdapter.class) {\r
+            valueType = DataTypeUtils.dataTypeOfClass(g, field.getType());\r
+        } else {\r
             try {\r
                 ValueAdapter adapter = adapterClass.newInstance();\r
                 rangeAccessor = new AdaptedRangeAccessor(rangeAccessor, adapter);\r
@@ -47,14 +50,9 @@ public class RelatedValueRuleFactory implements IFieldRuleFactory {
                 throw new RuntimeException(e);\r
             } catch (IllegalAccessException e) {\r
                 throw new RuntimeException(e);\r
-            }            \r
-        return new ValueRule(\r
-                new RelatedValueAccessor(\r
-                        g.getResource(annotation.value()), \r
-                        valueType\r
-                ),\r
-                rangeAccessor\r
-        );\r
+            }\r
+        }\r
+        return new ValueRule(new RelatedValueAccessor(g.getResource(annotation.value()), valueType), rangeAccessor);\r
     }\r
 \r
 }\r