Package org.eclipse.jdt.internal.ui.javaeditor

Examples of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor


     * selected (to emulate that the user is working on that), then when filter
     * on save the data should indicate that the user has spent x amount of time
     * working on the method, not any of the Runnable's.
     */

    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);

    StringBuilder builder = new StringBuilder();
    builder.append("void aMethod() {");
    builder.append("  new Runnable() { ");
    builder.append("    public void run(){");
    builder.append("      new Runnable() {");
    builder.append("        public void run() {}");
    builder.append("      };");
    builder.append("    } ");
    builder.append("  };");
    builder.append("}");

    String content = document.get();
    int offset = content.indexOf("{") + 1;
    int len = 0;
    document.replace(offset, len, builder.toString());

    content = document.get();
    offset = content.indexOf("Runnable", content.indexOf("Runnable") + 1);
    len = "Runnable".length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();

View Full Code Here


    builder.append(format("public class %s {", newClassName));
    builder.append(format("}%n"));
    ICompilationUnit myUnit = pkg.createCompilationUnit(newClassName + ".java",
        builder.toString(), true, null);

    JavaEditor editor = closeAndOpenEditor(myUnit);

    // Set the editor to select the package declaration:
    int offset = getDocument(editor).get().indexOf(pkg.getElementName());
    int len = pkg.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));
    // Make sure we got the selection right:
    assertEquals(IJavaElement.PACKAGE_DECLARATION,
        getElementAtOffset(editor).getElementType());

    // Run the tracker to capture the event:
View Full Code Here

   *
   * @see #testFilter_deletedElement_mainType()
   */
  @Test
  public void testFilter_deletedElement_typeMembers() throws Exception {
    final JavaEditor editor = closeAndOpenEditor();
    final IDocument document = getDocument(editor);

    // Place a field in the body of the class, note that we don't want to add
    // errors to the class:

    String field = "private int aVeryUniqueFieldName = 0;";
    int offset = document.get().lastIndexOf('}') - 1;
    int len = 0;
    document.replace(offset, len, field);

    // Set the editor to select the field:
    offset = document.get().indexOf(field);
    len = field.length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    // Run the tracker to capture the event:
    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();
View Full Code Here

   * import statement , we show that a user spent x amount of time on the type
   * root (ITypeRoot) element, (a.k.a the Java file).
   */
  @Test
  public void testFilter_existingElement_importStatement() throws Exception {
    final JavaEditor editor = closeAndOpenEditor();
    final IDocument document = getDocument(editor);
    String importStatement = "import java.util.*;";
    int offset = document.get().indexOf(";") + 1; // Position after package
    // declaration
    int len = 0;
    document.replace(offset, len, importStatement);

    offset = document.get().indexOf(importStatement);
    len = importStatement.length();
    ITextSelection selection = new TextSelection(offset, len);
    editor.getSelectionProvider().setSelection(selection);

    long preStart = System.currentTimeMillis();
    tracker.setEnabled(true);
    long postStart = System.currentTimeMillis();

View Full Code Here

   * Test an event on a static initialiser. This event should not be filtered on
   * save.
   */
  @Test
  public void testFilter_existingElement_initializer() throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);
    String staticName = "static";
    String methodText = staticName + " {}";
    int offset = document.get().indexOf("{") + 1;
    int len = 0;
    document.replace(offset, len, methodText);

    offset = document.get().indexOf(staticName);
    len = staticName.length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    IJavaElement element = getElementAtOffset(editor);
    // Check we got the selection right
    assertEquals(IJavaElement.INITIALIZER, element.getElementType());

View Full Code Here

   * on the method's first non-anonymous parent.
   */
  @Test
  public void testFilter_existingElement_methodParentIsAnonymous()
      throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);

    StringBuilder anonymous = new StringBuilder();
    anonymous.append("void aMethod() {");
    anonymous.append("  new Runnable() { ");
    anonymous.append("    public void run(){");
    anonymous.append("      new Runnable() {");
    anonymous.append("        public void run() {}");
    anonymous.append("      };");
    anonymous.append("    } ");
    anonymous.append("  };");
    anonymous.append("}");

    int offset = document.get().indexOf("{") + 1;
    int len = 0;
    document.replace(offset, len, anonymous.toString());

    String content = document.get();
    offset = content.indexOf("run", content.indexOf("run") + 1);
    len = "run".length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    IJavaElement element = getElementAtOffset(editor);
    // Make sure we got the selection right:
    assertEquals("run", element.getElementName());

View Full Code Here

   * event should not be filtered on save.
   */
  @Test
  public void testFilter_existingElement_methodParentNotAnonymous()
      throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);
    String methodName = "aMethodName";
    String methodText = format("void %s() {}", methodName);
    int offset = document.get().indexOf("{") + 1;
    int length = 0;
    document.replace(offset, length, methodText);

    offset = document.get().indexOf(methodName);
    length = methodName.length();
    ITextSelection selection = new TextSelection(offset, length);
    editor.getSelectionProvider().setSelection(selection);

    IJavaElement element = getElementAtOffset(editor);
    // Make sure we got the selection right:
    assertEquals(IJavaElement.METHOD, element.getElementType());

View Full Code Here

   * package declaration , we show that a user spent x amount of time on the
   * main type element.
   */
  @Test
  public void testFilter_existingElement_packageDeclaration() throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);
    int offset = document.get().indexOf(pkg.getElementName());
    int len = pkg.getElementName().length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    IJavaElement element = getElementAtOffset(editor);
    // Make sure we got the selection right:
    assertEquals(IJavaElement.PACKAGE_DECLARATION, element.getElementType());

View Full Code Here

   * we show the user has spent x amount of time on the type's first
   * non-anonymous parent.
   */
  @Test
  public void testFilter_existingElement_typeAnonymous() throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);
    StringBuilder anonymous = new StringBuilder();
    anonymous.append("void aMethod() {");
    anonymous.append("  new Runnable() { ");
    anonymous.append("    public void run(){");
    anonymous.append("    } ");
    anonymous.append("  };");
    anonymous.append("}");

    int offset = document.get().indexOf("{") + 1;
    int len = 0;
    document.replace(offset, len, anonymous.toString());

    offset = document.get().indexOf("Runnable");
    len = "Runnable".length();
    ITextSelection selection = new TextSelection(offset, len);
    editor.getSelectionProvider().setSelection(selection);

    IJavaElement element = getElementAtOffset(editor);
    // Check that we got the selection right:
    assertEquals(IJavaElement.TYPE, element.getElementType());

View Full Code Here

  /**
   * Test an event on an inner class. This event should be not filtered on save.
   */
  @Test
  public void testFilter_existingElement_typeInner() throws Exception {
    JavaEditor editor = closeAndOpenEditor();
    IDocument document = getDocument(editor);
    String innerClassName = "anInnerClassName";
    String innerClassText = format("%nstatic class %s {}", innerClassName);
    int offset = document.get().indexOf("{") + 1;
    int len = 0;
    document.replace(offset, len, innerClassText);

    offset = document.get().indexOf(innerClassName);
    len = innerClassName.length();
    editor.getSelectionProvider().setSelection(new TextSelection(offset, len));

    IJavaElement element = getElementAtOffset(editor);
    assertEquals(IJavaElement.TYPE, element.getElementType());

    long preStart = System.currentTimeMillis();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.