Skip to content
Snippets Groups Projects
Commit 2b59d358 authored by Simon Barner's avatar Simon Barner
Browse files

- EStructuralFeatureValueProviderBase: Gracefully handle the case that...

- EStructuralFeatureValueProviderBase: Gracefully handle the case that instance keys returned by getInstanceKeys() are not backed by a EStructuralFeatureValue
- Concrete value providers may use this to implement an overlay of e.g. derived/computed annotations onto a concrete IAnnotationSpecification that consists of one or more EAttributes
refs 1841
parent fdde6fd1
No related branches found
No related tags found
No related merge requests found
...@@ -107,14 +107,32 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -107,14 +107,32 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
handlesMultipleEstructuralFeatures = true; handlesMultipleEstructuralFeatures = true;
} }
/**
* Returns the {@link EStructuralFeatureDescriptor} for a given {@code instanceKey}, or throws
* an exception, if the key is unknown.
*
*/
protected EStructuralFeatureDescriptor getEStructuralFeatureDescriptor(String instanceKey)
throws Exception {
EStructuralFeatureDescriptor fd = structuralFeatureDescriptorMap.get(instanceKey);
if(fd == null) {
throw new Exception("Instance key " + instanceKey +
" is unknown for annotation provider " +
annotatedSpecificationEClass.getInstanceClassName() + ".");
}
return fd;
}
/** /**
* Sets a value for a {@link IAnnotatedSpecification} from a {@link String} representation of * Sets a value for a {@link IAnnotatedSpecification} from a {@link String} representation of
* the input. * the input.
*/ */
private <V> void private <V> void
setAnnotationValueFromString(String value, T specification, String instanceKey) { setAnnotationValueFromString(String value, T specification, String instanceKey)
throws Exception {
EStructuralFeatureDescriptor fd = structuralFeatureDescriptorMap.get(instanceKey); EStructuralFeatureDescriptor fd = getEStructuralFeatureDescriptor(instanceKey);
specification.eSet( specification.eSet(
fd.getStructuralFeature(), fd.getStructuralFeature(),
...@@ -142,8 +160,8 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -142,8 +160,8 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
setAnnotationValueFromString((String)value, specification, instanceKey); setAnnotationValueFromString((String)value, specification, instanceKey);
} else { } else {
specification.eSet(structuralFeatureDescriptorMap.get(instanceKey) specification.eSet(getEStructuralFeatureDescriptor(instanceKey).getStructuralFeature(),
.getStructuralFeature(), value); value);
} }
} }
...@@ -166,7 +184,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -166,7 +184,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
} }
EStructuralFeature structuralFeature = EStructuralFeature structuralFeature =
structuralFeatureDescriptorMap.get(instanceKey).getStructuralFeature(); getEStructuralFeatureDescriptor(instanceKey).getStructuralFeature();
if(structuralFeature instanceof EAttribute) { if(structuralFeature instanceof EAttribute) {
setAnnotationValueFromString(value, specification, instanceKey); setAnnotationValueFromString(value, specification, instanceKey);
...@@ -189,7 +207,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -189,7 +207,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception { public <U> U getAnnotationValue(T specification, String instanceKey) throws Exception {
return (U)specification.eGet(structuralFeatureDescriptorMap.get(instanceKey) return (U)specification.eGet(getEStructuralFeatureDescriptor(instanceKey)
.getStructuralFeature()); .getStructuralFeature());
} }
...@@ -205,7 +223,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -205,7 +223,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
* {@link #getAnnotatedSpecificationForModelElement(IModelElement)}. * {@link #getAnnotatedSpecificationForModelElement(IModelElement)}.
*/ */
protected Object createStructuralFeatureInstance(String instanceKey) throws Exception { protected Object createStructuralFeatureInstance(String instanceKey) throws Exception {
EStructuralFeatureDescriptor fd = structuralFeatureDescriptorMap.get(instanceKey); EStructuralFeatureDescriptor fd = getEStructuralFeatureDescriptor(instanceKey);
if(fd.getStructuralFeature() instanceof EAttribute) { if(fd.getStructuralFeature() instanceof EAttribute) {
...@@ -246,7 +264,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -246,7 +264,7 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
} else { } else {
throw new Exception( throw new Exception(
"createStructuralFeatureInstance() is not supported / has not been implemented the annotation type " + "createStructuralFeatureInstance() is not supported / has not been implemented the annotation type " +
fd.getStructuralFeature().getEType().getName() + "."); fd.getStructuralFeature().getName() + ".");
} }
} }
...@@ -258,8 +276,8 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp ...@@ -258,8 +276,8 @@ public abstract class EStructuralFeatureValueProviderBase<T extends IAnnotatedSp
// Create and set structural feature implementing the annotation // Create and set structural feature implementing the annotation
Object structuralFeatureVal = createStructuralFeatureInstance(instanceKey); Object structuralFeatureVal = createStructuralFeatureInstance(instanceKey);
if(structuralFeatureVal != null) { if(structuralFeatureVal != null) {
specification.eSet(structuralFeatureDescriptorMap.get(instanceKey) specification.eSet(getEStructuralFeatureDescriptor(instanceKey).getStructuralFeature(),
.getStructuralFeature(), structuralFeatureVal); structuralFeatureVal);
} }
} }
......
...@@ -215,7 +215,15 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple ...@@ -215,7 +215,15 @@ public abstract class ValueProviderBase<T extends IAnnotatedSpecification> imple
decorateAnnotationSpecification(specification); decorateAnnotationSpecification(specification);
} else { } else {
for(String key : getInstanceKeys(specification)) { for(String key : getInstanceKeys(specification)) {
decorateAnnotationSpecification(specification, key); try {
decorateAnnotationSpecification(specification, key);
} catch(Exception e) {
// Some of the keys might not be backed by an implementation that needs to
// "decorate" the underlying specification object (e.g., a custom key that
// represents a calculated, volatile value. Hence, just ignore invalid keys
// during this setup phase. The other methods (get/set/...) will throw an
// Exception on invalid keys.
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment