Esempio n. 1
0
 /**
  * Answer true if the resource has any enabled validators.
  *
  * @param resource a file, folder or project.
  * @param isManual if true then the validator must be turned on for manual validation. If false
  *     then the isManualValidation setting isn't used to filter out validators.
  * @param isBuild if true then the validator must be turned on for build based validation. If
  *     false then the isBuildValidation setting isn't used to filter out validators.
  */
 public boolean hasValidators(IResource resource, boolean isManual, boolean isBuild) {
   if (resource instanceof IProject) {
     IProject project = (IProject) resource;
     return ValManager.getDefault().getValidators(project).length > 0;
   } else if (resource instanceof IFolder) {
     IFolder folder = (IFolder) resource;
     HasValidatorVisitor v = new HasValidatorVisitor(isManual, isBuild);
     return v.hasValidator(folder);
   } else {
     ContentTypeWrapper ctw = new ContentTypeWrapper();
     for (Validator val : ValManager.getDefault().getValidators(resource.getProject())) {
       if (Friend.shouldValidate(val, resource, isManual, isBuild, ctw)) return true;
     }
   }
   return false;
 }
Esempio n. 2
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);
  }