示例#1
0
  @SuppressWarnings("unchecked")
  @Override
  protected void processSource(final ColoredSourceFile source) throws CoreException {

    try {
      textArea.setText(StrUtils.strFromInputStream(source.getResource().getContents()));
      int lines = textArea.getLineCount();
      int pages = (int) Math.ceil((double) lines / (double) (LINES_PER_PAGE / 2));
      final HashSet<IFeature> featuresOnPage[] = new HashSet[pages];

      ISourceFile ast = source.getAST();

      ast.accept(
          new ASTVisitor() {
            @Override
            public boolean visit(IASTNode node) {
              Set<IFeature> nodeColor = source.getColorManager().getColors(node);
              if (nodeColor.size() > 0)
                try {
                  int startLine = textArea.getLineOfOffset(node.getStartPosition());
                  int endLine =
                      textArea.getLineOfOffset(node.getStartPosition() + node.getLength());

                  addFeaturesToPages(startLine, endLine, nodeColor);
                } catch (BadLocationException e) {
                  e.printStackTrace();
                }
              return super.visit(node);
            }

            private void addFeaturesToPages(int startLine, int endLine, Set<IFeature> nodeColor) {
              for (int i = 0; i < featuresOnPage.length; i++) {
                int pageStart = i * (LINES_PER_PAGE / 2);
                int pageEnd = pageStart + LINES_PER_PAGE;
                if (startLine < pageEnd && endLine >= pageStart) {
                  HashSet<IFeature> pageColors = featuresOnPage[i];
                  if (pageColors == null) featuresOnPage[i] = pageColors = new HashSet<IFeature>();
                  pageColors.addAll(nodeColor);
                }
              }
            }
          });

      int stats[] = new int[6];
      for (int i = 0; i < featuresOnPage.length; i++) {
        HashSet<IFeature> pageColors = featuresOnPage[i];
        if (pageColors == null) stats[0]++;
        else stats[colorsToP(pageColors.size())]++;
      }
      print(source, stats);
      addToGlobal(stats);

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#2
0
  /** do not call from within a job */
  public void recheckFiles(List<ColoredSourceFile> files) {
    HashMap<IProject, List<ColoredSourceFile>> orderedFiles =
        new HashMap<IProject, List<ColoredSourceFile>>();
    for (ColoredSourceFile file : files) {
      List<ColoredSourceFile> projectFiles = orderedFiles.get(file.getResource().getProject());
      if (projectFiles == null) {
        projectFiles = new ArrayList<ColoredSourceFile>();
        orderedFiles.put(file.getResource().getProject(), projectFiles);
      }
      projectFiles.add(file);
    }

    for (Entry<IProject, List<ColoredSourceFile>> fileSet : orderedFiles.entrySet()) {
      WorkspaceJob op = new TypecheckFilesJob(fileSet.getKey(), fileSet.getValue(), this);
      op.setUser(true);
      op.schedule();
    }
  }