diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings index 5bf3fb2d32a2758402ad3592279282df8767007e..1cb52fd79da225689f71cea11d2bb63608fc2ce4 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/.ratings @@ -1,6 +1,6 @@ AnnotationInstSpec.java b4f2ed47a8984e751e04049de5bdb3cad2c0a933 GREEN -DerivedAnnotationValueProviderBase.java 15da44b7b92b7fd351aa48422ff5957a2ce34e35 GREEN +DerivedAnnotationValueProviderBase.java afedd21d3469127bbb20adb34c191b5c9c980f6c YELLOW EStructuralFeatureDescriptor.java 2e14df3830d854bc1693382727b2033b23d0051c GREEN -EStructuralFeatureValueProviderBase.java 71c418486bc6c46bc468e18c92b21f6b537706db GREEN -IAnnotationValueProvider.java d093cb522e7c484420331f0c77690bebe7e131b4 GREEN +EStructuralFeatureValueProviderBase.java 287facbbce47c16d892bae82a214f64ceeef2263 YELLOW +IAnnotationValueProvider.java 08e0e5f66dc97865e9ac03e1ac646af332845e14 YELLOW ValueProviderBase.java e4e866840845346ec99a4304048f5327c4890996 GREEN diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java index 15da44b7b92b7fd351aa48422ff5957a2ce34e35..afedd21d3469127bbb20adb34c191b5c9c980f6c 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/DerivedAnnotationValueProviderBase.java @@ -98,7 +98,7 @@ public abstract class DerivedAnnotationValueProviderBase<T extends IDerivedAnnot /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> U getAnnotationValue(T specification) throws Exception { + public <U> U getAnnotationValue(T specification) { U calculatedValue = (U)specification.getValue(); if(calculatedValue != null) { return calculatedValue; diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java index 71c418486bc6c46bc468e18c92b21f6b537706db..287facbbce47c16d892bae82a214f64ceeef2263 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/EStructuralFeatureValueProviderBase.java @@ -280,7 +280,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <U> U getAnnotationValue(T specification) throws Exception { + public <U> U getAnnotationValue(T specification) { return (U)specification .eGet(getEStructuralFeatureDescriptor().getEStructuralFeature(specification)); } diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java index d093cb522e7c484420331f0c77690bebe7e131b4..08e0e5f66dc97865e9ac03e1ac646af332845e14 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/annotation/valueprovider/IAnnotationValueProvider.java @@ -64,10 +64,10 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> public class AnnotationActionEntry { /** Scope defining the {@link AnnotationEntry}s to apply the corresponding action to. */ public enum ActionScope { - /** All {@link AnnotationEntry}s that are matching the selected filter. */ - ALL_VISIBLE_ITEMS, - /** Apply the action only to the selected item. */ - SINGLE_ITEM + /** All {@link AnnotationEntry}s that are matching the selected filter. */ + ALL_VISIBLE_ITEMS, + /** Apply the action only to the selected item. */ + SINGLE_ITEM } /** Name of the associated action, i.e. its entry. */ @@ -292,7 +292,7 @@ public interface IAnnotationValueProvider<T extends IAnnotatedSpecification> public boolean canEdit(T specification); /** Returns the value of the annotation. */ - public <U> U getAnnotationValue(T specification) throws Exception; + public <U> U getAnnotationValue(T specification); /** * Sets a new value for the annotation. diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/.ratings b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/.ratings index 4acda03632b3c0e352844e4515ee49993883ae8c..8ace18c1f25488d017d18215335879753e7c769e 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/.ratings +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/.ratings @@ -1,5 +1,5 @@ AngleUtils.java 462551eae71738ff51f92c9906bff9a21a375d2b GREEN -AnnotationUtils.java 41e25bcdd2906f7fa511223a20cbd09a1391a23c GREEN +AnnotationUtils.java 1da750d19d92658b0bdf6bc18ceb18aa667e557b YELLOW BaseMathUtils.java 65f6c39b641cba3c984a38f42b1bbf7dbf3287a3 GREEN BaseModelElementUtils.java b8775b7a462efc168cf79a017aa3377a782d10f6 GREEN ConstraintsBaseUtils.java bba938b43756ce6f35c338f6cef21c3ab5d49a9d GREEN diff --git a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/AnnotationUtils.java b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/AnnotationUtils.java index 41e25bcdd2906f7fa511223a20cbd09a1391a23c..1da750d19d92658b0bdf6bc18ceb18aa667e557b 100644 --- a/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/AnnotationUtils.java +++ b/org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/AnnotationUtils.java @@ -85,6 +85,24 @@ public class AnnotationUtils { modelElement.getSpecifications().add(newAnnotation); } + /** + * Returns the value of type {@code U} specified for the given {@link IModelElement} by the + * given annotation {@code clazz}. + */ + public static <T extends IAnnotatedSpecification, U> U + getAnnotationValue(IModelElement modelElement, Class<T> clazz, Class<U> valueType) { + IAnnotationValueProvider<T> annValProvider = + getAnnotationValueProvider(modelElement, clazz); + T annotation = getAnnotation(modelElement, clazz); + U value = annValProvider.getAnnotationValue(annotation); + if(value != null && !valueType.isAssignableFrom(value.getClass())) { + throw new IllegalArgumentException("The value of the annotation " + + clazz.getSimpleName() + " of the model element " + modelElement + + " is not of the expected type " + valueType.getSimpleName()); + } + return value; + } + /** * <p> * Returns the annotation of a given {@code Class<T>} from a given {@code modelElement}. If the @@ -150,10 +168,11 @@ public class AnnotationUtils { * Annotation type. * @return The corresponding value provider or {@code null} if none is found. */ - public static IAnnotationValueProvider<IAnnotatedSpecification> getAnnotationValueProvider( - IModelElement element, Class<IAnnotatedSpecification> annotationType) { + @SuppressWarnings("unchecked") + public static <T extends IAnnotatedSpecification> IAnnotationValueProvider<T> + getAnnotationValueProvider(IModelElement element, Class<T> annotationType) { AnnotationEntry annEntry = AnnotationValueService.getInstance().getAnnotationEntry(element); - return annEntry.getAnnotationValueProvider(annotationType); + return (IAnnotationValueProvider<T>)annEntry.getAnnotationValueProvider(annotationType); } /**