Search in sources :

Example 1 with CheckMode

use of org.eclipse.xtext.validation.CheckMode 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 CheckMode

use of org.eclipse.xtext.validation.CheckMode in project xtext-eclipse by eclipse.

the class MarkerUpdaterImpl method processDelta.

private void processDelta(Delta delta, /* @Nullable */
ResourceSet resourceSet, IProgressMonitor monitor) throws OperationCanceledException {
    URI uri = delta.getUri();
    IResourceUIValidatorExtension validatorExtension = getResourceUIValidatorExtension(uri);
    IMarkerContributor markerContributor = getMarkerContributor(uri);
    CheckMode normalAndFastMode = CheckMode.NORMAL_AND_FAST;
    for (Pair<IStorage, IProject> pair : mapper.getStorages(uri)) {
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (pair.getFirst() instanceof IFile) {
            IFile file = (IFile) pair.getFirst();
            if (EXTERNAL_PROJECT_NAME.equals(file.getProject().getName())) {
                // skip the marker processing of that file, as the user can't react on any markers anyway.
                continue;
            }
            if (delta.getNew() != null) {
                if (resourceSet == null)
                    throw new IllegalArgumentException("resourceSet may not be null for changed resources.");
                Resource resource = resourceSet.getResource(uri, true);
                if (validatorExtension != null) {
                    validatorExtension.updateValidationMarkers(file, resource, normalAndFastMode, monitor);
                }
                if (markerContributor != null) {
                    markerContributor.updateMarkers(file, resource, monitor);
                }
            } else {
                if (validatorExtension != null) {
                    validatorExtension.deleteValidationMarkers(file, normalAndFastMode, monitor);
                } else {
                    deleteAllValidationMarker(file, normalAndFastMode, monitor);
                }
                if (markerContributor != null) {
                    markerContributor.deleteMarkers(file, monitor);
                } else {
                    deleteAllContributedMarkers(file, monitor);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMarkerContributor(org.eclipse.xtext.ui.markers.IMarkerContributor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) CheckMode(org.eclipse.xtext.validation.CheckMode) IResourceUIValidatorExtension(org.eclipse.xtext.ui.validation.IResourceUIValidatorExtension) IStorage(org.eclipse.core.resources.IStorage) URI(org.eclipse.emf.common.util.URI) IProject(org.eclipse.core.resources.IProject)

Aggregations

CheckMode (org.eclipse.xtext.validation.CheckMode)2 ResourceValidationRuleSummaryEvent (com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent)1 Collector (com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent.Collector)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IStorage (org.eclipse.core.resources.IStorage)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IMarkerContributor (org.eclipse.xtext.ui.markers.IMarkerContributor)1 IResourceUIValidatorExtension (org.eclipse.xtext.ui.validation.IResourceUIValidatorExtension)1