Esempio n. 1
0
  private void processDelta(ICElementDelta delta, Set<IResource> handled) throws CoreException {
    final int flags = delta.getFlags();

    final boolean hasChildren = (flags & ICElementDelta.F_CHILDREN) != 0;
    if (hasChildren) {
      for (ICElementDelta child : delta.getAffectedChildren()) {
        processDelta(child, handled);
      }
    }

    final ICElement element = delta.getElement();
    switch (element.getElementType()) {
      case ICElement.C_UNIT:
        ITranslationUnit tu = (ITranslationUnit) element;
        if (!tu.isWorkingCopy()) {
          handled.add(element.getResource());
          switch (delta.getKind()) {
            case ICElementDelta.CHANGED:
              if ((flags & ICElementDelta.F_CONTENT) != 0) {
                fChanged.add(tu);
              }
              break;
            case ICElementDelta.ADDED:
              fChanged.add(tu);
              break;
            case ICElementDelta.REMOVED:
              fRemoved.add(tu);
              break;
          }
        }
        break;
      case ICElement.C_CCONTAINER:
        ICContainer folder = (ICContainer) element;
        if (delta.getKind() == ICElementDelta.ADDED) {
          handled.add(element.getResource());
          collectSources(folder, fChanged);
        }
        break;
    }

    if (!sSuppressPotentialTUs) {
      // Always look at the children of the resource delta (bug 343538)
      final IResourceDelta[] rDeltas = delta.getResourceDeltas();
      processResourceDelta(rDeltas, element, handled);
    }
  }
Esempio n. 2
0
  /**
   * Run the analysis on the current selection (file, container, or multiple-selection)
   *
   * @param monitor progress monitor on which to report progress.
   * @param indent indent amount, in number of spaces, used only for debug printing.
   * @param includes
   * @return true if any errors were found.
   * @throws InterruptedException
   */
  @SuppressWarnings("unchecked")
  // on Iterator
  protected boolean runResources(IProgressMonitor monitor, int indent, List<String> includes)
      throws InterruptedException {
    boolean foundError = false;
    // First, count files so we know how much work to do.
    // note this is number of files of any type, not necessarily number of
    // files that will be analyzed.
    int count = countFilesSelected();

    monitor.beginTask(Messages.RunAnalyseHandlerBase_29, count);
    if (traceOn) {
      System.out.println("RAHB.runResources(): using selection: " + selection); // $NON-NLS-1$
    }
    // Get elements of a possible multiple selection
    IStructuredSelection lastSel = AnalysisDropdownHandler.getInstance().getLastSelection();
    Iterator<IStructuredSelection> iter = lastSel.iterator(); // fix analysis
    // selection
    // bug
    // 327122

    while (iter.hasNext()) {
      if (monitor.isCanceled()) {
        // this is usually caught here while processing
        // multiple-selection of files
        throw new InterruptedException();
      }
      Object obj = iter.next(); // piece of selection
      // It can be a Project, Folder, File, etc...
      if (obj instanceof IAdaptable) {
        // ICElement covers folders and translationunits
        // If fortran file (*.f*) and Photran not installed, ce is null
        // and we ignore it (first) here.
        final ICElement ce = (ICElement) ((IAdaptable) obj).getAdapter(ICElement.class); // cdt40
        if (ce != null) {
          // cdt40
          // IASTTranslationUnit atu = tu.getAST(); not yet
          boolean err = runResource(monitor, ce, indent, includes);
          if (traceOn) {
            System.out.println(
                "Error (err="
                    + err
                    + ")running analysis on "
                    + ce.getResource().getName()); // $NON-NLS-1$ //$NON-NLS-2$
          }
        }
      }
    }
    monitor.done();
    return foundError;
  }
  private List<CPElementGroup> createGroups(ICElement element, List<CPElement> cPaths) {
    // create resource groups
    List<CPElementGroup> resourceGroups = new ArrayList<CPElementGroup>(5);
    fTopGroup = new CPElementGroup(element.getResource());
    resourceGroups.add(fTopGroup);
    // add containers first so that they appear at top of list
    for (int i = 0; i < cPaths.size(); i++) {
      CPElement cpelement = cPaths.get(i);
      switch (cpelement.getEntryKind()) {
        case IPathEntry.CDT_CONTAINER:
          fTopGroup.addChild(cpelement);
          break;
      }
    }
    for (int i = 0; i < cPaths.size(); i++) {
      CPElement cpelement = cPaths.get(i);
      switch (cpelement.getEntryKind()) {
        case IPathEntry.CDT_INCLUDE:
        case IPathEntry.CDT_INCLUDE_FILE:
        case IPathEntry.CDT_MACRO:
        case IPathEntry.CDT_MACRO_FILE:
          CPElementGroup resGroup = new CPElementGroup(cpelement.getResource());
          int ndx = resourceGroups.indexOf(resGroup);
          if (ndx == -1) {
            resourceGroups.add(resGroup);
          } else {
            resGroup = resourceGroups.get(ndx);
          }
          resGroup.addChild(cpelement);
      }
    }

    // place each path in its appropriate inherited group (or not if
    // excluded)
    for (int i = 0; i < cPaths.size(); i++) {
      CPElement cpelement = cPaths.get(i);
      switch (cpelement.getEntryKind()) {
        case IPathEntry.CDT_INCLUDE:
        case IPathEntry.CDT_INCLUDE_FILE:
        case IPathEntry.CDT_MACRO:
        case IPathEntry.CDT_MACRO_FILE:
          addPathToResourceGroups(cpelement, null, resourceGroups);
      }
    }
    return resourceGroups;
  }
Esempio n. 4
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;
  }