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;
}
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);
}
}
}
}
}
Aggregations