From bffcff9715d279cb3f224d0c7184943fd385656d Mon Sep 17 00:00:00 2001
From: Simon Barner <barner@fortiss.org>
Date: Thu, 5 Feb 2015 12:54:06 +0000
Subject: [PATCH] - Factor out creation of Exception to
 raiseCouldNotFindAnnotationValueProviderException(clazz); refs 2255

---
 .../base/annotation/AnnotationEntry.java      | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java
index d0ee25c8b..b8d79ccfa 100644
--- a/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java
+++ b/org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/annotation/AnnotationEntry.java
@@ -86,6 +86,15 @@ public final class AnnotationEntry {
 		return specification != null && specification.getSpecificationOf() != null;
 	}
 
+	/**
+	 * Helper method used to raise an {@link Exception} in case an {@link IAnnotationValueProvider}
+	 * could not be found for the {@link IAnnotatedSpecification} represented by {@code clazz}.
+	 */
+	private void raiseCouldNotFindAnnotationValueProviderException(
+			Class<? extends IAnnotatedSpecification> clazz) throws Exception {
+		throw new Exception("Could not find an AnnotationValueProvider for " + clazz.toString());
+	}
+
 	/** Adds a new tuple {@link IAnnotationValueProvider} {@link IAnnotatedSpecification}. */
 	public void addNewSpecification(IAnnotationValueProvider<IAnnotatedSpecification> provider,
 			IAnnotatedSpecification spec) {
@@ -117,7 +126,7 @@ public final class AnnotationEntry {
 			getAnnotationValueProvider(clazz).setAnnotationName(name, specification);
 		}
 
-		throw new Exception("Could not find an AnnotationValueProvider for " + clazz.toString());
+		raiseCouldNotFindAnnotationValueProviderException(clazz);
 	}
 
 	/** Predicate if the given annotation can be edited. */
@@ -189,9 +198,7 @@ public final class AnnotationEntry {
 		if(isOperationEnabled(specification)) {
 			getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey);
 		} else {
-			// TODO(VA) The following exception and message are repeated many times. Would be worth
-			// factorizing? e.g., using a method "couldNotFindProviderExn(Class clazz)"
-			throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
+			raiseCouldNotFindAnnotationValueProviderException(clazz);
 		}
 	}
 
@@ -207,7 +214,7 @@ public final class AnnotationEntry {
 		if(isOperationEnabled(specification)) {
 			getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey);
 		} else {
-			throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
+			raiseCouldNotFindAnnotationValueProviderException(clazz);
 		}
 	}
 
@@ -219,7 +226,7 @@ public final class AnnotationEntry {
 		if(isOperationEnabled(specification)) {
 			getAnnotationValueProvider(clazz).setAnnotationValue(value, specification);
 		} else {
-			throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
+			raiseCouldNotFindAnnotationValueProviderException(clazz);
 		}
 	}
 
@@ -235,7 +242,7 @@ public final class AnnotationEntry {
 		if(isOperationEnabled(specification)) {
 			getAnnotationValueProvider(clazz).setAnnotationValue(value, specification);
 		} else {
-			throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
+			raiseCouldNotFindAnnotationValueProviderException(clazz);
 		}
 	}
 
-- 
GitLab