Ejemplo n.º 1
0
  /**
   * Accept a visitor for all the validators that are enabled for the given project, resource, and
   * validation mode.
   *
   * @param valType the type of validation request
   */
  public void accept(
      IValidatorVisitor visitor,
      IProject project,
      IResource resource,
      ValType valType,
      ValOperation operation,
      IProgressMonitor monitor) {

    if (isDisabled(project)) return;

    Map<String, IValidatorGroupListener[]> groupListeners =
        new HashMap<String, IValidatorGroupListener[]>();

    ValProperty vp = getValProperty(resource, valType, _configNumber.get());
    if (vp != null) {
      BitSet bs = vp.getConfigSet();
      for (Validator val : getValidators(project)) {
        if (!monitor.isCanceled()) {
          if (!bs.get(_idManager.getIndex(val.getId()))) continue;
          if (operation.isSuspended(val, project)) continue;
          Validator.V2 v2 = val.asV2Validator();
          if (v2 != null) {
            notifyGroupListenersStarting(
                resource, operation.getState(), monitor, groupListeners, v2);
          }
          try {
            visitor.visit(val, project, valType, operation, monitor);
          } catch (Exception e) {
            ValidationPlugin.getPlugin().handleException(e);
          }
        }
      }
      notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners);
      return;
    }

    vp = new ValProperty();
    vp.setConfigNumber(_configNumber.get());
    ContentTypeWrapper ctw = new ContentTypeWrapper();
    for (Validator val : getValidators(project)) {
      if (!monitor.isCanceled()) {
        if (!ValidatorProjectManager.get().shouldValidate(val, project, valType)) continue;
        if (Friend.shouldValidate(val, resource, valType, ctw)) {
          vp.getConfigSet().set(_idManager.getIndex(val.getId()));
          // we do the suspend check after figuring out if it needs to be validated, because we save
          // this information for the session.
          if (operation.isSuspended(val, project)) continue;
          Validator.V2 v2 = val.asV2Validator();
          if (v2 != null) {
            notifyGroupListenersStarting(
                resource, operation.getState(), monitor, groupListeners, v2);
          }
          try {
            visitor.visit(val, project, valType, operation, monitor);
          } catch (Exception e) {
            ValidationPlugin.getPlugin().handleException(e);
          }
        }
      }
    }
    notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners);
    putValProperty(vp, resource, valType);
  }