Skip to content
Snippets Groups Projects
Commit 68c90ba6 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

bugfix

refs 504
parent 3e7f2de8
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.internal;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.postRefreshNotification;
import java.util.ArrayList;
......@@ -58,7 +59,7 @@ import org.fortiss.tooling.kernel.ui.service.IMarkerService;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 4F42D5352BEE034F1D749E50A2E29437
* @ConQAT.Rating YELLOW Hash: EFDAD4F40879A52F009A2D9DCFAC4181
*/
public class MarkerService implements IMarkerService, IPersistencyServiceListener,
ILightweightLabelDecorator {
......@@ -148,7 +149,12 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
if(top == null) {
return Collections.emptyList();
}
return getCacheEntry(top).getCachedList(element);
CacheEntry ce = getCacheEntry(top);
Collection<IConstraintViolation<? extends EObject>> coll = ce.getCachedList(element);
if(coll.isEmpty()) {
return ce.getChildCachedList(element);
}
return coll;
}
/** {@inheritDoc} */
......@@ -273,9 +279,7 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
}
}
/**
* Marker service cache entry.
*/
/** Marker service cache entry. */
private static class CacheEntry {
/** Stores the mapping from model elements to violation lists. */
......@@ -286,6 +290,10 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
private final Map<EObject, ESeverity> highestSeverityMap =
new ConcurrentHashMap<EObject, ESeverity>();
/** Stores the child causing the highest severity value for each cached element. */
private final Map<EObject, EObject> highestSeverityChildMap =
new ConcurrentHashMap<EObject, EObject>();
/** Stores the top-level element. */
private ITopLevelElement topElement;
......@@ -331,9 +339,11 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
List<IConstraintViolation<? extends EObject>> list = violationsMap.get(eo);
if(list.isEmpty()) {
highestSeverityMap.put(eo, ESeverity.lowest());
highestSeverityChildMap.remove(eo);
} else {
Collections.sort(list, IConstraintViolation.SEVERITY_COMPARATOR);
highestSeverityMap.put(eo, list.get(0).getSeverity());
highestSeverityChildMap.put(eo, list.get(0).getSource());
}
}
// project severity to parent
......@@ -345,13 +355,18 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
/** Recursively projects highest severity from children to parents. */
private ESeverity computeHighestSeverity(EObject element) {
ESeverity severity = getHighestSeverity(element);
EObject causingChild = highestSeverityChildMap.get(element);
for(EObject child : element.eContents()) {
ESeverity childSeverity = computeHighestSeverity(child);
if(ESeverity.getIntSeverity(severity) > ESeverity.getIntSeverity(childSeverity)) {
severity = childSeverity;
causingChild = child;
}
}
highestSeverityMap.put(element, severity);
if(causingChild != null) {
highestSeverityChildMap.put(element, causingChild);
}
return severity;
}
......@@ -365,6 +380,14 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
return list;
}
/** Returns the cached list of child causing the violation of the given element. */
public List<IConstraintViolation<? extends EObject>> getChildCachedList(EObject element) {
if(!highestSeverityChildMap.containsKey(element)) {
return emptyList();
}
return getCachedList(highestSeverityChildMap.get(element));
}
/** Returns all violations of the given severity. */
public List<IConstraintViolation<? extends EObject>> getAllViolationsWithSeverity(
ESeverity severity) {
......@@ -387,6 +410,7 @@ public class MarkerService implements IMarkerService, IPersistencyServiceListene
}
for(EObject eo : highestSeverityMap.keySet()) {
highestSeverityMap.put(eo, ESeverity.lowest());
highestSeverityChildMap.remove(eo);
}
}
}
......
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