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; ...@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification; import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement; import org.fortiss.tooling.base.model.element.IModelElement;
...@@ -81,8 +80,8 @@ public class AnnotationValueService extends ...@@ -81,8 +80,8 @@ public class AnnotationValueService extends
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) { for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
List<? extends IModelElement> allChildren = List<? extends IModelElement> allChildren =
getAllChildren(root, element.getClass(), getAllChildren(root, element.getClass(), annotationProvider
annotationProvider.excludeModelElementTypeFromAnnotatedSpecification()); .excludeModelElementTypeFromAnnotatedSpecification());
for(final IModelElement e : allChildren) { for(final IModelElement e : allChildren) {
IAnnotatedSpecification annotatedSpecification = IAnnotatedSpecification annotatedSpecification =
...@@ -128,40 +127,28 @@ public class AnnotationValueService extends ...@@ -128,40 +127,28 @@ public class AnnotationValueService extends
/** /**
* Returns all children from element of the given type and filters out children of the given * 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, 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>(); List<? extends IModelElement> results = EcoreUtils.getChildrenWithType(element, type);
if(modelElementTypesExcludedFromAnnotatedSpecification != null) if(modelElementTypesExcludedFromAnnotatedSpecification != null) {
getAllChildren2(element, type, modelElementTypesExcludedFromAnnotatedSpecification, results); List<IModelElement> toRemove = new ArrayList<IModelElement>();
else for(IModelElement modelElement : results) {
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;
for(Class<?> c : modelElementTypesExcludedFromAnnotatedSpecification) { for(Class<?> c : modelElementTypesExcludedFromAnnotatedSpecification) {
if(c.isInstance(o)) if(c.isInstance(modelElement)) {
filter = true; toRemove.add(modelElement);
break;
}
} }
if(!filter)
getAllChildren2(o, type, modelElementTypesExcludedFromAnnotatedSpecification, results);
} }
results.removeAll(toRemove);
} }
return results;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
......
...@@ -63,7 +63,12 @@ public class AnnotationLabelProvider extends ColumnLabelProvider { ...@@ -63,7 +63,12 @@ public class AnnotationLabelProvider extends ColumnLabelProvider {
if(element instanceof AnnotationEntry) { if(element instanceof AnnotationEntry) {
AnnotationEntry annotationEntry = (AnnotationEntry)element; 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) { if(value != null) {
return value.toString(); 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