private ICompletionProposal[] openAndGetProposals(IFile file, int offset)
      throws PartInitException {
    // open JS editor on file
    editor = (ITextEditor) EditorTestHelper.openInEditor(file, "com.aptana.editor.js", true);
    ISourceViewer viewer = ((AbstractThemeableEditor) editor).getISourceViewer();

    EditorTestHelper.joinReconciler((SourceViewer) viewer, 100L, 2000L, 100L);

    // get proposals after "rocker."
    this.processor = new JSContentAssistProcessor((AbstractThemeableEditor) editor);
    ICompletionProposal[] proposals =
        processor.computeCompletionProposals(viewer, offset, '\0', false);
    return proposals;
  }
  protected void perfValidate(String filename, int iterations) throws Exception {
    // read in the file
    InputStream in =
        FileLocator.openStream(
            Platform.getBundle(JSCorePlugin.PLUGIN_ID),
            Path.fromPortableString("performance/" + filename),
            false);
    IFile file = project.createFile(filename, IOUtil.read(in));
    RebuildIndexJob job = new RebuildIndexJob(project.getURI());
    job.run(null);

    // Ok now actually validate the thing, the real work
    for (int i = 0; i < iterations; i++) {
      EditorTestHelper.joinBackgroundActivities();

      BuildContext context = new BuildContext(file);
      // Don't measure reading in string...
      context.getContents();

      startMeasuring();
      validator.buildFile(context, null);
      stopMeasuring();
    }
    commitMeasurements();
    assertPerformance();
  }
Esempio n. 3
0
 @After
 public void tearDown() throws Exception {
   if (editor != null) {
     EditorTestHelper.closeEditor(editor);
     editor = null;
   }
 }
  /**
   *
   *
   * <pre>
   * - We create a file with a function
   * - open the JS editor on it
   * - make some unsaved changes
   * - let it reconcile
   * - invoke CA to see that the unsaved contents are reflected in the CA
   * - close the editor without saving those changes
   * - wait for re-index of the underlying file to occur
   * - verify that the index now reflects underlying file's contents and not the unsaved changes.
   * </pre>
   *
   * @throws Exception
   */
  @Test
  public void testAPSTUD2944() throws Exception {
    // Create a test project and file
    project = createTestProject();
    IFile file = project.createFile("apstud2944.js", "function delete_me() {}\n");

    // open JS editor on file
    editor = (ITextEditor) EditorTestHelper.openInEditor(file, "com.aptana.editor.js", true);
    ISourceViewer viewer = ((AbstractThemeableEditor) editor).getISourceViewer();

    EditorTestHelper.joinReconciler((SourceViewer) viewer, 100L, 2000L, 100L);

    // Verify initial contents
    Index index = getIndexManager().getIndex(project.getURI());

    JSIndexQueryHelper _indexHelper = new JSIndexQueryHelper(project.getInnerProject());
    Collection<PropertyElement> projectGlobals = _indexHelper.getGlobals("apstud2944.js");
    assertContainsFunctions(projectGlobals, "delete_me");
    assertDoesntContainFunctions(projectGlobals, "foo");

    // Set the working copy contents to some new valid JS
    IDocument document = EditorTestHelper.getDocument(editor);
    document.set("function foo() { var eight = 8; }");

    // Wait for reconcile
    EditorTestHelper.joinReconciler((SourceViewer) viewer, 100L, 2000L, 100L);

    // get proposals at end of document
    this.processor = new JSContentAssistProcessor((AbstractThemeableEditor) editor);
    ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 33, '\0', false);

    // verify that CA contains elements from unsaved JS in document!
    assertContains(proposals, "foo");
    assertDoesntContain(proposals, "delete_me");

    // TODO Verify "eight" is in CA inside foo?

    // Close the editor without saving, make sure we end up indexing underlying content again!
    EditorTestHelper.closeEditor(editor);

    Thread.sleep(1000); // FIXME Is there anyway to tell when indexing happens and is finished?

    // Now verify that our index reflects the file's contents and not the unsaved contents of the
    // editor.
    assertContainsFunctions(projectGlobals, "delete_me");
    assertDoesntContainFunctions(projectGlobals, "foo");
  }
  public void testGetScopeWithMetaProjectNaturePrepended() throws Exception {
    setUpStandardScopes();

    project = new TestProject("scope_nature", new String[] {"com.aptana.projects.webnature"});

    IFile iFile =
        project.createFile(
            "project_scope.js",
            "if(Object.isUndefined(Effect))\nthrow(\"dragdrop.js requires including script.aculo.us' effects.js library\");");
    editor = (ITextEditor) EditorTestHelper.openInEditor(iFile, true);

    assertScope("meta.project.com.aptana.projects.webnature source.js keyword.control.js", 1);
    assertScope("meta.project.com.aptana.projects.webnature source.js support.class.js", 7);
  }
  protected void tearDown() throws Exception {
    if (editor != null) {
      EditorTestHelper.closeEditor(editor);
      editor = null;
    }

    if (file != null) {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }

    if (project != null) {
      project.delete();
      project = null;
    }

    manager = null;
    super.tearDown();
  }
  protected void perfValidate(String filename, int iterations) throws Exception {
    // read in the file
    URL url =
        FileLocator.find(
            Platform.getBundle(JSCorePlugin.PLUGIN_ID),
            Path.fromPortableString("performance/" + filename),
            null);
    File file = ResourceUtil.resourcePathToFile(url);
    IFileStore fileStore = EFS.getStore(file.toURI());

    // Ok now actually validate the thing, the real work
    for (int i = 0; i < iterations; i++) {
      EditorTestHelper.joinBackgroundActivities();

      // Force a re-parse every time so we're comparing apples to apples for JSLint
      BuildContext context =
          new FileStoreBuildContext(fileStore) {
            @Override
            protected ParseResult parse(
                String contentType, IParseState parseState, WorkingParseResult working)
                throws Exception {
              if (reparseEveryTime()) {
                return new JSParser().parse(parseState);
              }
              return super.parse(contentType, parseState, working);
            }
          };
      // Don't measure reading in string...
      context.getContents();

      startMeasuring();
      validator.buildFile(context, null);
      stopMeasuring();
    }
    commitMeasurements();
    assertPerformance();
  }
  protected void setUp() throws Exception {
    super.setUp();
    setUpBasicScopes();

    EditorTestHelper.closeAllEditors();
  }