Example #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();
    }
  }
Example #2
0
 protected static Map<IProject, Collection<ColoredSourceFile>> groupByProject(
     Collection<ColoredSourceFile> files) {
   Map<IProject, Collection<ColoredSourceFile>> result =
       new HashMap<IProject, Collection<ColoredSourceFile>>();
   for (ColoredSourceFile file : files) {
     IProject project = file.getProject();
     Collection<ColoredSourceFile> projectFiles = result.get(project);
     if (projectFiles == null) {
       projectFiles = new HashSet<ColoredSourceFile>();
       result.put(project, projectFiles);
     }
     projectFiles.add(file);
   }
   return result;
 }
Example #3
0
 private void print(ColoredSourceFile source, int[] stats) {
   if (source != null) System.out.print(source.getName() + ": ");
   for (int i = 0; i < stats.length; i++) {
     System.out.print(stats[i] + " ");
   }
   System.out.println();
 }
  private void installCodeColoring() {
    if (fCodeColorManager == null && getSourceViewer() != null) {

      ColoredSourceFile source = getSourceFile();
      assert source.isColored();
      JDTColorManagerBridge colorManager = new JDTColorManagerBridge(source);

      fCodeColorManager = new ColoredHighlightingManager();
      fCodeColorManager.install(
          this,
          (JavaSourceViewer) getSourceViewer(),
          JavaPlugin.getDefault().getJavaTextTools().getColorManager(),
          getPreferenceStore(),
          colorManager);
    }
    if (fCodeColorManager != null) fCodeColorManager.fReconciler.scheduleJob();
  }
Example #5
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();
    }
  }
 public ColoredSourceFile getSourceFile() {
   ITypeRoot java = getInputJavaElement();
   assert java != null;
   assert java.getResource() instanceof IFile;
   IFile file = (IFile) java.getResource();
   if (file != null) {
     IFeatureModel featureModel;
     try {
       featureModel = FeatureModelManager.getInstance().getFeatureModel(file.getProject());
     } catch (FeatureModelNotFoundException e) {
       e.printStackTrace();
       assert false : e;
       return null;
     }
     return ColoredSourceFile.getColoredSourceFile(file, featureModel);
   }
   return null;
 }