From ad57f4ef285bc1b22feeffd4728faf72874471b3 Mon Sep 17 00:00:00 2001
From: Alexander Diewald <diewald@fortiss.org>
Date: Tue, 1 Oct 2019 10:53:45 +0200
Subject: [PATCH] Simplify the retrieval of derived values

Issue-Ref: 3822
Issue-Url: https://af3-developer.fortiss.org/issues/3822
Signed-off-by: Alexander Diewald <diewald@fortiss.org>
---
 .../tooling/base/model/base/impl/.ratings     |  2 +-
 .../impl/DerivedAnnotationBaseStaticImpl.java | 23 ++++++++-----------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/.ratings b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/.ratings
index 7faaf1e79..20e8a8ac8 100644
--- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/.ratings
+++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/.ratings
@@ -1,2 +1,2 @@
-DerivedAnnotationBaseStaticImpl.java 0b5a8e36f66c937b1659f0b73a0cf0428337e364 GREEN
+DerivedAnnotationBaseStaticImpl.java d1b98d0c06b781fe297f63b0bfdc5dc72fe462c0 YELLOW
 LibraryElementBaseStaticImpl.java 13222726153d5159994866795b059a4cc3522434 GREEN
diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/DerivedAnnotationBaseStaticImpl.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/DerivedAnnotationBaseStaticImpl.java
index 0b5a8e36f..d1b98d0c0 100644
--- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/DerivedAnnotationBaseStaticImpl.java
+++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/model/base/impl/DerivedAnnotationBaseStaticImpl.java
@@ -37,21 +37,18 @@ public class DerivedAnnotationBaseStaticImpl {
 	 * @return See above.
 	 */
 	public static <T> T getValue(IDerivedAnnotation<T> annotation) {
-		T derivedValue = null;
-		if(annotation.getUserAnnotatedValue() != null) {
-			if(annotation.isUserAnnotatedValuePreferred()) {
-				// User annotated value is available and preferred -> return it
-				return annotation.getUserAnnotatedValue();
-			}
-			derivedValue = annotation.getDerivedValue();
-			if(derivedValue == null) {
-				// Derived value would be preferred, but it is not available -> return user
-				// annotated value
-				return annotation.getUserAnnotatedValue();
+		T derivedValue = annotation.getDerivedValue();
+		if(annotation.isUserAnnotatedValuePreferred() || derivedValue == null) {
+			// User annotated value is preferred, or the derived value is not available
+			// --> return user annotated value
+			T userAnnotatedValue = annotation.getUserAnnotatedValue();
+			if(userAnnotatedValue != null) {
+				// Only return the user annotated value if it is present, or a derived value is not
+				// present.
+				return userAnnotatedValue;
 			}
 		}
 
-		// Use cached result of derived value if it is available
-		return derivedValue != null ? derivedValue : annotation.getDerivedValue();
+		return derivedValue;
 	}
 }
-- 
GitLab