private Set<String> checkPluginDependency(Collection<String> usedPlugins, Plugin p) {
    Map<String, VersionInfo> depends = p.getDependencies();
    Set<String> missingDependencies = new HashSet<String>();

    if (depends != null) {
      for (String name : depends.keySet()) {
        if (!usedPlugins.contains(name)) {
          missingDependencies.add(name);
          Set<String> transitiveMissingDependencies =
              checkPluginDependency(usedPlugins, SlimEngine.getFullEngine().getPlugin(name));
          missingDependencies.addAll(transitiveMissingDependencies);
        }
      }
    }

    return missingDependencies;
  }
  @Override
  public void checkForErrors(ASMDocument document, List<AbstractError> errors) {
    Pattern usePattern = Pattern.compile("^[\\s]*[uU][sS][eE][\\s]+");

    Set<String> usedPlugins = new HashSet<String>();
    Map<String, Integer> usePositions = new HashMap<String, Integer>();
    Map<String, Integer> lengths = new HashMap<String, Integer>();

    for (int i = 0; i < document.getNumberOfLines(); i++) {
      try {
        int pos = document.getLineOffset(i);
        String line = document.get(pos, document.getLineLength(i));
        Matcher useMatcher = usePattern.matcher(line);
        if (useMatcher.find()) {
          String pluginName = useMatcher.replaceFirst("").trim();
          Plugin p = SlimEngine.getFullEngine().getPlugin(pluginName);

          if (p == null) {
            p = SlimEngine.getFullEngine().getPlugin(pluginName + "Plugins");
            if (p == null) p = SlimEngine.getFullEngine().getPlugin(pluginName + "Plugin");
          }

          if (p != null) {
            if (usedPlugins.add(p.getName())) {
              usePositions.put(p.getName(), pos + useMatcher.end());
              lengths.put(p.getName(), pluginName.length());

              if (p instanceof PackagePlugin)
                usedPlugins.addAll(((PackagePlugin) p).getEnclosedPluginNames());
            }
          } else
            errors.add(
                new SimpleError(
                    "Plugin not found",
                    "Plugin '" + pluginName + "' cannot be found.",
                    pos + useMatcher.end(),
                    pluginName.length(),
                    CLASSNAME,
                    NO_PLUGIN));
        }
      } catch (BadLocationException e) {
      }
    }
    for (String pluginName : usedPlugins) {
      Plugin p = SlimEngine.getFullEngine().getPlugin(pluginName);
      Set<String> missingDependencies = checkPluginDependency(usedPlugins, p);
      if (!missingDependencies.isEmpty()) {
        String descr = "";
        for (String missingDependency : missingDependencies) {
          if (!descr.isEmpty()) descr += ", ";
          descr += missingDependency;
        }
        descr = pluginName + " requires " + descr;
        errors.add(
            new SimpleError(
                "Plugin Dependency Error",
                descr,
                usePositions.get(pluginName),
                lengths.get(pluginName),
                CLASSNAME,
                DEPENDENCY));
      }
    }
  }