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

- Provide non-recursive, correct implementation of type-based annotation entry filter

- Fix NPE in case a filter actually strikes
parent bb75095d
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -81,8 +80,8 @@ public class AnnotationValueService extends
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
List<? extends IModelElement> allChildren =
getAllChildren(root, element.getClass(),
annotationProvider.excludeModelElementTypeFromAnnotatedSpecification());
getAllChildren(root, element.getClass(), annotationProvider
.excludeModelElementTypeFromAnnotatedSpecification());
for(final IModelElement e : allChildren) {
IAnnotatedSpecification annotatedSpecification =
......@@ -128,40 +127,28 @@ public class AnnotationValueService extends
/**
* Returns all children from element of the given type and filters out children of the given
* filterOut list
* {@code modelElementTypesExcludedFromAnnotatedSpecification} list.
*/
private <S, T> List<? extends IModelElement> getAllChildren(EObject element,
Class<? extends IModelElement> type, List<Class<? extends EObject>> modelElementTypesExcludedFromAnnotatedSpecification) {
Class<? extends IModelElement> type,
List<Class<? extends EObject>> modelElementTypesExcludedFromAnnotatedSpecification) {
List<? extends IModelElement> results = new ArrayList<IModelElement>();
if(modelElementTypesExcludedFromAnnotatedSpecification != null)
getAllChildren2(element, type, modelElementTypesExcludedFromAnnotatedSpecification, results);
else
results = EcoreUtils.getChildrenWithType(element, type);
return results;
}
/** depth search for desired elements */
@SuppressWarnings("unchecked")
private <T, S> void getAllChildren2(EObject element, Class<? extends IModelElement> type,
List<Class<? extends EObject>> modelElementTypesExcludedFromAnnotatedSpecification, final List<T> results) {
EList<EObject> eContents = element.eContents();
for(EObject o : eContents) {
if(type.isInstance(o)) {
results.add((T)o);
getAllChildren2(o, type, modelElementTypesExcludedFromAnnotatedSpecification, results);
} else {
boolean filter = false;
List<? extends IModelElement> results = EcoreUtils.getChildrenWithType(element, type);
if(modelElementTypesExcludedFromAnnotatedSpecification != null) {
List<IModelElement> toRemove = new ArrayList<IModelElement>();
for(IModelElement modelElement : results) {
for(Class<?> c : modelElementTypesExcludedFromAnnotatedSpecification) {
if(c.isInstance(o))
filter = true;
if(c.isInstance(modelElement)) {
toRemove.add(modelElement);
break;
}
}
if(!filter)
getAllChildren2(o, type, modelElementTypesExcludedFromAnnotatedSpecification, results);
}
results.removeAll(toRemove);
}
return results;
}
/** {@inheritDoc} */
......
......@@ -63,7 +63,12 @@ public class AnnotationLabelProvider extends ColumnLabelProvider {
if(element instanceof AnnotationEntry) {
AnnotationEntry annotationEntry = (AnnotationEntry)element;
Object value = annotationEntry.getSpecificationValue(specClass, instanceKey);
Object value = null;
try {
value = annotationEntry.getSpecificationValue(specClass, instanceKey);
} catch(Exception e) {
// Ignore. Return "" in this case.
}
if(value != null) {
return value.toString();
}
......
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