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

- Use getSpecification() also internally and avoid loops in every wrapped method

- Add private getAnnotationValueProvider() method
refs 1841
parent 58221030
No related branches found
No related tags found
No related merge requests found
......@@ -79,10 +79,10 @@ public final class AnnotationEntry {
/** Returns the name / "label" for a given annotation {@code clazz}. */
public String getSpecificationAnnotationName(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getAnnotationName(s);
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).getAnnotationName(specification);
}
return null;
......@@ -93,11 +93,11 @@ public final class AnnotationEntry {
*/
public void setSpecificationAnnotationName(String name,
Class<? extends IAnnotatedSpecification> clazz) throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setAnnotationName(name, s);
return;
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
getAnnotationValueProvider(clazz).setAnnotationName(name, specification);
}
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
......@@ -105,14 +105,11 @@ public final class AnnotationEntry {
/** Predicate if the given annotation can be edited. */
public boolean canEdit(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).canEdit(s);
} catch(Exception e) {
return false;
}
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).canEdit(specification);
}
return false;
......@@ -120,14 +117,10 @@ public final class AnnotationEntry {
/** Predicate if the given annotation can be edited. */
public boolean canEdit(Class<? extends IAnnotatedSpecification> clazz, String instanceKey) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).canEdit(s, instanceKey);
} catch(Exception e) {
return false;
}
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).canEdit(specification, instanceKey);
}
return false;
......@@ -136,13 +129,15 @@ public final class AnnotationEntry {
/** Returns the annotation value */
public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz,
String instanceKey) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).getAnnotationValue(s, instanceKey);
} catch(Exception e) {
return null;
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
try {
return getAnnotationValueProvider(clazz).getAnnotationValue(specification,
instanceKey);
} catch(Exception e) {
// Ignore exception
}
}
......@@ -154,13 +149,14 @@ public final class AnnotationEntry {
* support.
*/
public <V> V getSpecificationValue(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
try {
return providerSpecMapping.get(clazz).getAnnotationValue(s);
} catch(Exception e) {
// Ignore exception
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
try {
return getAnnotationValueProvider(clazz).getAnnotationValue(specification);
} catch(Exception e) {
// Ignore exception
}
}
......@@ -172,14 +168,14 @@ public final class AnnotationEntry {
*/
public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz,
String instanceKey) throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setAnnotationValue(value, s, instanceKey);
return;
}
}
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey);
} else {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
}
/**
......@@ -187,14 +183,14 @@ public final class AnnotationEntry {
*/
public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz,
String instanceKey) throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setAnnotationValue(value, s, instanceKey);
return;
}
}
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
getAnnotationValueProvider(clazz).setAnnotationValue(value, specification, instanceKey);
} else {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
}
/**
......@@ -202,14 +198,13 @@ public final class AnnotationEntry {
*/
public <V> void setSpecificationValue(V value, Class<? extends IAnnotatedSpecification> clazz)
throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setAnnotationValue(value, s);
return;
}
}
IAnnotatedSpecification specification = getSpecification(clazz);
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
if(specification != null) {
getAnnotationValueProvider(clazz).setAnnotationValue(value, specification);
} else {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
}
/**
......@@ -217,14 +212,14 @@ public final class AnnotationEntry {
*/
public void setSpecificationValue(String value, Class<? extends IAnnotatedSpecification> clazz)
throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
providerSpecMapping.get(clazz).setAnnotationValue(value, s);
return;
}
}
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
getAnnotationValueProvider(clazz).setAnnotationValue(value, specification);
} else {
throw new Exception("Could not find a AnnotationValueProvider for " + clazz.toString());
}
}
/**
......@@ -236,11 +231,12 @@ public final class AnnotationEntry {
*/
public EditingSupport createSpecificationEditElement(ColumnViewer viewer,
Class<? extends IAnnotatedSpecification> clazz, String instanceKey) throws Exception {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).createEditingSupport(viewer, clazz, s,
instanceKey);
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).createEditingSupport(viewer, clazz,
specification, instanceKey);
}
return null;
......@@ -254,10 +250,11 @@ public final class AnnotationEntry {
* latter case, this method returns current list of dynamic annotation instances.
*/
public Collection<String> getInstanceKeys(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).getInstanceKeys(s);
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).getInstanceKeys(specification);
}
return Collections.emptyList();
......@@ -271,10 +268,11 @@ public final class AnnotationEntry {
* {@link List} of admissible instance keys.
*/
public boolean allowsDynamicAnnotationInstances(Class<? extends IAnnotatedSpecification> clazz) {
for(IAnnotatedSpecification s : specificationsList) {
if(clazz.isInstance(s)) {
return providerSpecMapping.get(clazz).allowsDynamicAnnotationInstances();
}
IAnnotatedSpecification specification = getSpecification(clazz);
if(specification != null) {
return getAnnotationValueProvider(clazz).allowsDynamicAnnotationInstances();
}
return false;
......@@ -290,6 +288,13 @@ public final class AnnotationEntry {
return specificationsList;
}
/** Determine the value provider for the given annotation class. */
private IAnnotationValueProvider<IAnnotatedSpecification> getAnnotationValueProvider(
Class<? extends IAnnotatedSpecification> clazz) {
return providerSpecMapping.get(clazz);
}
/**
* Returns the {@link IAnnotatedSpecification} of a given {@code clazz} managed by this
* {@link AnnotationEntry}.
......
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