Exemplo n.º 1
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
   CTestPlugin.getDefault().getLog().addLogListener(this);
   CCorePlugin.getIndexManager().reindex(cproject);
   boolean joined =
       CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR);
   assertTrue(joined);
   astCache = new RefactoringASTCache();
 }
Exemplo n.º 2
0
  protected void assertContentAssistResults(
      int offset,
      int length,
      String[] expected,
      boolean isCompletion,
      boolean isTemplate,
      boolean filterResults,
      int compareType)
      throws Exception {
    if (CTestPlugin.getDefault().isDebugging()) {
      System.out.println("\n\n\n\n\nTesting " + this.getClass().getName());
    }

    // Call the CContentAssistProcessor
    ISourceViewer sourceViewer = EditorTestHelper.getSourceViewer((AbstractTextEditor) fEditor);
    String contentType =
        TextUtilities.getContentType(
            sourceViewer.getDocument(), ICPartitions.C_PARTITIONING, offset, true);
    boolean isCode = IDocument.DEFAULT_CONTENT_TYPE.equals(contentType);
    ContentAssistant assistant = new ContentAssistant();
    CContentAssistProcessor processor =
        new CContentAssistProcessor(fEditor, assistant, contentType);
    long startTime = System.currentTimeMillis();
    sourceViewer.setSelectedRange(offset, length);
    Object[] results =
        isCompletion
            ? (Object[]) processor.computeCompletionProposals(sourceViewer, offset)
            : (Object[]) processor.computeContextInformation(sourceViewer, offset);
    long endTime = System.currentTimeMillis();
    assertTrue(results != null);

    if (filterResults) {
      if (isTemplate) {
        results = filterResultsKeepTemplates(results);
      } else {
        results = filterResults(results, isCode);
      }
    }
    String[] resultStrings = toStringArray(results, compareType);
    Arrays.sort(expected);
    Arrays.sort(resultStrings);

    if (CTestPlugin.getDefault().isDebugging()) {
      System.out.println("Time (ms): " + (endTime - startTime));
      for (String proposal : resultStrings) {
        System.out.println("Result: " + proposal);
      }
    }

    boolean allFound = true; // for the time being, let's be optimistic

    for (String element : expected) {
      boolean found = false;
      for (String proposal : resultStrings) {
        if (element.equals(proposal)) {
          found = true;
          if (CTestPlugin.getDefault().isDebugging()) {
            System.out.println("Lookup success for " + element);
          }
          break;
        }
      }
      if (!found) {
        allFound = false;
        if (CTestPlugin.getDefault().isDebugging()) {
          System.out.println("Lookup failed for " + element); // $NON-NLS-1$
        }
      }
    }

    if (!allFound) {
      assertEquals("Missing results!", toString(expected), toString(resultStrings));
    } else if (doCheckExtraResults()) {
      assertEquals("Extra results!", toString(expected), toString(resultStrings));
    }
  }