コード例 #1
0
  /**
   * Run analysis on a resource (e.g. File or Folder) Will descend to members of folder
   *
   * @param atu the resource
   * @param indent number of levels of nesting/recursion for prettyprinting
   * @param includes contains header files include paths from the Preference page
   * @return true if an error was encountered
   * @throws InterruptedException
   */
  public boolean runResource(
      IProgressMonitor monitor, ICElement ce, int indent, List<String> includes)
      throws InterruptedException {
    indent += INDENT_INCR;
    ScanReturn results;
    boolean foundError = false;

    if (!monitor.isCanceled()) {
      if (ce instanceof ITranslationUnit) {
        IResource res = ce.getResource(); // null if not part of C
        // project in ws
        // cdt40: eventually shd be able to deal with just tu;
        // tu.getResource() can always work later...
        if (res instanceof IFile) { // shd always be true (but might be
          // null)
          IFile file = (IFile) res;
          String filename = file.getName();
          // String fn2 = ce.getElementName();// shd be filename too
          // cdt40
          boolean cpp = isCPPproject(ce);
          // if (AnalysisUtil.validForAnalysis(filename,cpp)) {

          if (validForAnalysis(filename, cpp)) {
            if (traceOn) {
              println(getSpaces(indent) + "file: " + filename); // $NON-NLS-1$
            }
            results = analyse(monitor, (ITranslationUnit) ce, includes);

            foundError = foundError || results == null || results.wasError();
            if (foundError) {
              int stopHere = 0;
              System.out.println(
                  "found error on " //$NON-NLS-1$
                      + file.getName()
                      + " "
                      + stopHere); //$NON-NLS-1$
            }
            if (traceOn) {
              println(
                  "******** RunAnalyseBase, analysis complete; ScanReturn=" //$NON-NLS-1$
                      + results);
            }
            if (results != null) {
              // apply markers to the file
              processResults(results, file);
            }

          } else {
            if (traceOn) {
              println(getSpaces(indent) + "---omit: not valid file: " + filename); // $NON-NLS-1$
            }
          }
          return foundError;
        }
      } else if (ce instanceof ICContainer) {
        ICContainer container = (ICContainer) ce;
        try {
          ICElement[] mems = container.getChildren();
          for (int i = 0; i < mems.length; i++) {
            if (monitor.isCanceled()) {
              // this is usually hit while processing normal
              // analysis of e.g. container
              throw new InterruptedException();
            }
            boolean err = runResource(monitor, mems[i], indent, includes);
            foundError = foundError || err;
          }
        } catch (CoreException e) {
          e.printStackTrace();
        }

      } else if (ce instanceof ICProject) {
        ICProject proj = (ICProject) ce;
        try {
          ICElement[] mems = proj.getChildren();
          for (int i = 0; i < mems.length; i++) {
            if (monitor.isCanceled()) {
              // this is usually hit while processing normal
              // analysis of e.g. container
              throw new InterruptedException();
            }
            boolean err = runResource(monitor, mems[i], indent, includes);
            foundError = foundError || err;
          }
        } catch (CoreException e) {
          e.printStackTrace();
        }
      }
      // container could be project or folder
    } // end if !monitor.isCanceled()
    else {
      String name = ""; // $NON-NLS-1$
      // cdt40
      name = ce.getElementName();
      // String p=ce.getPath().toString();

      System.out.println(
          "Cancelled by User, aborting analysis on subsequent files... " //$NON-NLS-1$
              + name);
      throw new InterruptedException();
    }

    return foundError;
  }
コード例 #2
0
 protected void processResults(ScanReturn results, IResource resource) {
   List<Artifact> artifacts = results.getArtifactList();
   visitor.visitFile(resource, artifacts);
 }
コード例 #3
0
  public ScanReturn analyse(IProgressMonitor monitor, ITranslationUnit tu, List<String> includes) {
    if (traceOn) {
      println("RunAnalyseBase.analyse()..."); // $NON-NLS-1$
    }
    // ScanReturn nr = null;
    String errMsg = null;

    monitor.subTask(Messages.RunAnalyseHandlerBase_42);

    String rawPath = tu.getLocationURI().toString();
    if (traceOn) {
      println("RunAnalyseBase:              file = " + rawPath); // $NON-NLS-1$
    }

    monitor.subTask(Messages.RunAnalyseHandlerBase_on + rawPath);

    ScanReturn scanReturn = doArtifactAnalysis(tu, includes);
    monitor.worked(1);
    if (traceOn) {
      println("Artifact analysis complete..."); // $NON-NLS-1$
    }
    int numArtifacts = scanReturn.getArtifactList().size();
    cumulativeArtifacts = cumulativeArtifacts + numArtifacts;

    if (traceOn) {
      System.out.println(
          "Artifacts found for " //$NON-NLS-1$
              + tu.getResource().getProjectRelativePath()
              + ": "
              + numArtifacts); //$NON-NLS-1$
    }
    if (traceOn) {
      System.out.println("   Total # found: " + cumulativeArtifacts); // $NON-NLS-1$
    }

    if (scanReturn == null) {
      System.out.println(
          "ScanReturn result is NULL.  No results for " //$NON-NLS-1$
              + tu.getResource().getProjectRelativePath());
      errMsg =
          "Error: No results were returned from analysis of " //$NON-NLS-1$
              + tu.getResource().getProjectRelativePath();
      MessageDialog.openError(shell, "Error in Analysis", errMsg); // $NON-NLS-1$
    } else {
      if (traceOn) {
        System.out.println(
            "RunAnalyzeBase: ScanReturn received for " //$NON-NLS-1$
                + tu.getElementName());
      }
    }

    if (scanReturn != null) {
      boolean wasError = scanReturn.wasError();
      if (traceOn) {
        System.out.println("error occurred =" + wasError); // $NON-NLS-1$
      }
      if (wasError) {
        System.out.println("RunAnalyseBase.analyse...Error..."); // $NON-NLS-1$
      }
    }
    return scanReturn;
  }