use of com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector in project dsl-devkit by dsldevkit.
the class DefaultCheckImpl method internalValidate.
/**
* Executes all Check methods found.
*
* @param class1
* the class1
* @param object
* the object
* @param diagnostics
* the diagnostics
* @param context
* the context
* @return true, if successful
*/
protected final boolean internalValidate(final EClass class1, final EObject object, final DiagnosticChain diagnostics, final Map<Object, Object> context) {
initCheckMethodCache();
CheckMode checkMode = CheckMode.getCheckMode(context);
State internalState = new State();
internalState.chain = diagnostics;
internalState.currentObject = object;
internalState.checkMode = checkMode;
internalState.context = context;
ResourceValidationRuleSummaryEvent.Collector collector = traceSet.isEnabled(ResourceValidationRuleSummaryEvent.class) ? ResourceValidationRuleSummaryEvent.Collector.extractFromLoadOptions(object.eResource().getResourceSet()) : null;
Iterator<MethodWrapper> methods = methodsForType.get(object.getClass()).iterator();
while (methods.hasNext()) {
final MethodWrapper method = methods.next();
// FIXME the method name is actually not the real issue code
String ruleName = collector != null ? method.instance.getClass().getSimpleName() + '.' + method.method.getName() : null;
try {
traceStart(ruleName, object, collector);
method.invoke(internalState);
// CHECKSTYLE:OFF Yes, we really want to catch anything here. The method invoked is user-written code that may fail arbitrarily.
// If that happens, we want to exclude this check from all future executions! We catch Exception instead of InvocationTargetException
// because we may also get NullPointerException or ExceptionInInitializerError here, and catching those separately would mean we had
// to duplicate the logging and method removal.
} catch (Exception e) {
// CHECKSTYLE:ON
logCheckMethodFailure(method, internalState, e);
methods.remove();
} finally {
traceEnd(ruleName, object, collector);
}
}
return !internalState.hasErrors;
}
use of com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector in project dsl-devkit by dsldevkit.
the class AbstractDeclarativeValidValidator method traceEnd.
/**
* To be called by subclasses after having executed a rule previously registered with {@link #traceStart(String)}.
*
* @param rule
* executed rule
* @see #traceStart(String)
*/
protected void traceEnd(final String rule) {
if (traceSet.isEnabled(ResourceValidationRuleSummaryEvent.class)) {
EObject object = getCurrentObject();
ResourceValidationRuleSummaryEvent.Collector collector = getTraceCollector(object);
if (collector != null) {
collector.ruleEnded(rule, object);
}
}
}
use of com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector in project dsl-devkit by dsldevkit.
the class AbstractDeclarativeValidValidator method traceStart.
/**
* To be called by subclasses to indicate that a given validation rule is about to be executed and that its execution time should be traced.
*
* @param rule
* rule to be executed
* @see #traceEnd(String)
*/
protected void traceStart(final String rule) {
if (traceSet.isEnabled(ResourceValidationRuleSummaryEvent.class)) {
EObject object = getCurrentObject();
ResourceValidationRuleSummaryEvent.Collector collector = getTraceCollector(object);
if (collector != null) {
collector.ruleStarted(rule, object);
}
}
}
use of com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector in project dsl-devkit by dsldevkit.
the class AbstractDeclarativeValidValidator method getTraceCollector.
/**
* Returns the {@link ResourceValidationRuleSummaryEvent.Collector} to use for collecting trace data.
*
* @param object
* validated object to trace
* @return trace data collector or {@code null} if tracing is not enabled
*/
private ResourceValidationRuleSummaryEvent.Collector getTraceCollector(final EObject object) {
Map<Object, Object> context = getContext();
ResourceValidationRuleSummaryEvent.Collector collector = (Collector) context.get(ResourceValidationRuleSummaryEvent.Collector.class);
if (collector == null) {
collector = ResourceValidationRuleSummaryEvent.Collector.extractFromLoadOptions(object.eResource().getResourceSet());
context.put(ResourceValidationRuleSummaryEvent.Collector.class, collector);
}
return collector;
}
Aggregations