Exemple #1
0
  /** APSTUD-4116 */
  @Test
  public void testFunctionDocumentationWithoutParamTag() {
    TestBuildContext myContext = new TestBuildContext("indexing/functionDocsWithoutParam.js");

    try {
      IParseRootNode ast = myContext.getAST();
      JSFileIndexingParticipant indexParticipant = new JSFileIndexingParticipant();
      Index index = getIndex();

      indexParticipant.processParseResults(myContext, index, ast, new NullProgressMonitor());
      JSIndexQueryHelper queryHelper = new JSIndexQueryHelper(index);

      Collection<PropertyElement> types =
          queryHelper.getGlobals("functionDocsWithoutParam.js", "abc");
      assertNotNull(types);
      assertTrue("Expected at least a single property for 'abc'", !types.isEmpty());

      PropertyElement property = types.iterator().next();
      assertTrue("Expected a FunctionElement", property instanceof FunctionElement);

      FunctionElement function = (FunctionElement) property;
      List<String> parameters = function.getParameterNames();
      assertNotNull(parameters);
      assertEquals("Expected 3 parameters for 'abc'", 3, parameters.size());

      assertEquals("Expected parameter 1's name to be 'a'", "a", parameters.get(0));
      assertEquals("Expected parameter 2's name to be 'b'", "b", parameters.get(1));
      assertEquals("Expected parameter 3's name to be 'c'", "c", parameters.get(2));
    } catch (CoreException e) {
      fail(e.getMessage());
    }
  }
Exemple #2
0
  /** APSTUD-4117 */
  @Test
  public void testFunctionDocumentationWithoutReturnTag() {
    TestBuildContext myContext = new TestBuildContext("indexing/functionDocsWithoutReturn.js");

    try {
      IParseRootNode ast = myContext.getAST();
      JSFileIndexingParticipant indexParticipant = new JSFileIndexingParticipant();
      Index index = getIndex();

      indexParticipant.processParseResults(myContext, index, ast, new NullProgressMonitor());
      JSIndexQueryHelper queryHelper = new JSIndexQueryHelper(index);

      Collection<PropertyElement> types =
          queryHelper.getGlobals("functionDocsWithoutReturn.js", "abc");
      assertNotNull(types);
      assertTrue("Expected at least a single property for 'abc'", !types.isEmpty());

      PropertyElement property = types.iterator().next();
      assertTrue("Expected a FunctionElement", property instanceof FunctionElement);

      FunctionElement function = (FunctionElement) property;
      List<String> returnTypes = function.getReturnTypeNames();
      assertNotNull(returnTypes);
      assertEquals("Expected a single return type for 'abc'", 1, returnTypes.size());
      assertEquals("Expected 'Number' return type", "Number", returnTypes.get(0));
    } catch (CoreException e) {
      fail(e.getMessage());
    }
  }
  /**
   *
   *
   * <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");
  }