Пример #1
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());
    }
  }
Пример #2
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());
    }
  }
  /**
   *
   *
   * <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");
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
   */
  public Object[] getChildren(Object parentElement) {
    List<? extends Object> result = Collections.emptyList();

    if (parentElement instanceof JSElement) {
      JSElement root = (JSElement) parentElement;

      // @formatter:off
      result =
          CollectionsUtil.newList(
              new ClassGroupElement(
                  Messages.JSIndexViewContentProvider_WorkspaceGroupLabel,
                  JSIndexQueryHelper.getJSCoreIndex()),
              new ClassGroupElement(
                  Messages.JSIndexViewContentProvider_ProjectGroupLabel, root.getIndex()));
      // @formatter:on
    } else if (parentElement instanceof ClassGroupElement) {
      ClassGroupElement group = (ClassGroupElement) parentElement;

      result = group.getClasses();
    } else if (parentElement instanceof ClassElement) {
      TypeElement type = (ClassElement) parentElement;
      // NOTE: have to do this "temp" acrobatics to make the compiler happy, due to use of generics
      // and differing
      // return types when grabbing properties vs events
      List<Object> temp = new ArrayList<Object>();

      temp.addAll(type.getProperties());
      temp.addAll(type.getEvents());

      result = temp;
    } else if (parentElement instanceof EventElement) {
      EventElement event = (EventElement) parentElement;

      result = event.getProperties();
    }

    return result.toArray(new Object[result.size()]);
  }
Пример #5
0
 /**
  * getIndex
  *
  * @return
  */
 protected Index getIndex() {
   return JSIndexQueryHelper.getJSCoreIndex();
 }