Search in sources :

Example 1 with Collector

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;
}
Also used : Collector(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector) CheckMode(org.eclipse.xtext.validation.CheckMode) ResourceValidationRuleSummaryEvent(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Collector

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);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Collector(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector) ResourceValidationRuleSummaryEvent(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent)

Example 3 with Collector

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);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Collector(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector) ResourceValidationRuleSummaryEvent(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent)

Example 4 with Collector

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;
}
Also used : Collector(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector) Collector(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector) EObject(org.eclipse.emf.ecore.EObject) ResourceValidationRuleSummaryEvent(com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent)

Aggregations

ResourceValidationRuleSummaryEvent (com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent)4 Collector (com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector)4 EObject (org.eclipse.emf.ecore.EObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CheckMode (org.eclipse.xtext.validation.CheckMode)1