Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ICompilationUnit


public class ChangeText {

    public void inCompilationUnit(ICompilationUnit compilationUnit, int position, int length, String newText) throws JavaModelException {
        try {
            WorkingCopyOwner owner = DefaultWorkingCopyOwner.PRIMARY;
            ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(owner, null);
            IBuffer buffer = workingCopy.getBuffer();
            buffer.replace(position, length, newText);
            workingCopy.reconcile(ICompilationUnit.NO_AST, true, owner, null);
            compilationUnit.commitWorkingCopy(true, null);
        } finally {
            compilationUnit.discardWorkingCopy();
        }
    }
View Full Code Here


  public void run(IAction action) {
    IWorkingCopyManager manager = JavaUI.getWorkingCopyManager();
    IEditorInput editorInput = editor.getEditorInput();
    try {
      manager.connect(editorInput);
      ICompilationUnit workingCopy = manager.getWorkingCopy(editorInput);

      CreateDialog dialog = new CreateDialog(new Shell(), new BuilderGenerator());
      dialog.show(workingCopy);

      synchronized (workingCopy) {
        workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
      }

    } catch (JavaModelException e) {
      e.printStackTrace();
    } catch (CoreException e) {
View Full Code Here

    content
        .append(format("  public static void main(String[] args) throws Exception {%n"));
    content.append(format("    Thread.sleep(20);%n"));
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit = pkg.createCompilationUnit(className + ".java",
        content.toString(), true, null);

    tracker.setEnabled(false);
    launch("TestDisabled", pkg.getJavaProject().getElementName(),
        unit.getTypes()[0].getFullyQualifiedName(), ILaunchManager.DEBUG_MODE);

    assertTrue(tracker.getData().isEmpty());
  }
View Full Code Here

    content
        .append(format("  public static void main(String[] args) throws Exception {%n"));
    content.append(format("    Thread.sleep(100);%n")); // Sleep 100 millis.
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit = pkg.createCompilationUnit(className + ".java",
        content.toString(), true, null);

    MyDebugListener listener = new MyDebugListener();
    DebugPlugin.getDefault().addDebugEventListener(listener);
    tracker.setEnabled(true);

    // Launch the application:
    String configName = "TestEnabled";
    ILaunchConfiguration config = launch(configName,
        pkg.getJavaProject().getElementName(),
        unit.getTypes()[0].getFullyQualifiedName(), ILaunchManager.RUN_MODE);

    ILaunch launch = null;
    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    lock.lock();
View Full Code Here

    content
        .append(format("  public static void main(String[] args) throws Exception {%n"));
    content.append(format("    Thread.sleep(100);%n")); // Sleep 100 millis.
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit1 = pkg.createCompilationUnit(className1 + ".java",
        content.toString(), true, null);

    String className2 = "TestEnabled_MultipleLaunches2";
    content = new StringBuilder();
    content.append(format("package %s;%n", pkg.getElementName()));
    content.append(format("public class %s {%n", className2));
    content
        .append(format("  public static void main(String[] args) throws Exception {%n"));
    content.append(format("    Thread.sleep(200);%n")); // Sleep 200 millis.
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit2 = pkg.createCompilationUnit(className2 + ".java",
        content.toString(), true, null);

    MyDebugListener listener = new MyDebugListener();
    DebugPlugin.getDefault().addDebugEventListener(listener);
    tracker.setEnabled(true);

    // Launch two processes at the same time, running side by side:
    String configName1 = className1;
    ILaunchConfiguration config1 = launch(configName1,
        pkg.getJavaProject().getElementName(),
        unit1.getTypes()[0].getFullyQualifiedName(), ILaunchManager.RUN_MODE);
    String configName2 = className2;
    ILaunchConfiguration config2 = launch(configName2,
        pkg.getJavaProject().getElementName(),
        unit2.getTypes()[0].getFullyQualifiedName(), ILaunchManager.RUN_MODE);

    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    lock.lock();
    try {
View Full Code Here

    content.append(format("public class %s {%n", className));
    content.append(format("  public static void main(String[] args) {%n"));
    content.append(format("    System.out.println();%n")); // This is line 4
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit = pkg.createCompilationUnit(className + ".java",
        content.toString(), true, null);

    // Create a breakpoint at line 4:
    JDIDebugModel.createLineBreakpoint(unit.getResource(),
        unit.getType(className).getFullyQualifiedName(), 4, -1, -1, 0, true,
        null);

    final ISuspendResume[] suspendResume = new ISuspendResume[1];
    MyDebugListener listener = new MyDebugListener() {
      @Override
      public void handleDebugEvents(DebugEvent[] events) {
        super.handleDebugEvents(events);
        for (DebugEvent e : events) {
          if (e.getKind() == DebugEvent.SUSPEND) {
            synchronized (suspendResume) {
              suspendResume[0] = (ISuspendResume) e.getSource();
              suspendResume.notifyAll();
            }
          }
        }
      }
    };
    DebugPlugin.getDefault().addDebugEventListener(listener);

    // Launch in debug mode:
    tracker.setEnabled(true);
    ILaunchConfiguration config = launch(className,
        pkg.getJavaProject().getElementName(),
        unit.getTypes()[0].getFullyQualifiedName(), ILaunchManager.DEBUG_MODE);

    synchronized (suspendResume) {
      while (suspendResume[0] == null) {
        try {
          suspendResume.wait();
        } catch (InterruptedException e) {
          // Just keep looping..
        }
      }
    }
    suspendResume[0].resume();
    Thread.sleep(500);
    tracker.setEnabled(false);

    assertEquals(1, tracker.getData().size());
    LaunchEvent event = tracker.getData().iterator().next();
    assertEquals(listener.getLaunch(className), event.getLaunch());
    assertEquals(config, event.getLaunchConfiguration());
    assertEquals(1, event.getFilePaths().size());
    assertTrue(event.getFilePaths().contains(unit.getResource().getFullPath()));
    long preStart = listener.getProcessCreationTimeMillis(className) - 10;
    long start = event.getInterval().getStartMillis();
    long postStart = listener.getProcessCreationTimeMillis(className) + 10;
    long preEnd = listener.getProcessTerminationTimeMillis(className) - 10;
    long end = event.getInterval().getEndMillis();
View Full Code Here

    content.append(format("public class %s {%n", className1));
    content.append(format("  public %s() {%n", className1));
    content.append(format("    System.out.println();%n")); // This is line 4
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit1 = pkg.createCompilationUnit(className1 + ".java",
        content.toString(), true, null);

    // Create a breakpoint at line 4 in the above file:
    JDIDebugModel.createLineBreakpoint(unit1.getResource(),
        unit1.getType(className1).getFullyQualifiedName(), 4, -1, -1, 0, true,
        null);

    String className2 = "TestEnabledWithBreakpointsAndFiles2";
    content = new StringBuilder();
    content.append(format("package %s;%n", pkg.getElementName()));
    content.append(format("public class %s {%n", className2));
    content.append(format("  public static void main(String[] args) {%n"));
    content.append(format("    new %s();%n", className1)); // This is line 4
    content.append(format("  }%n"));
    content.append(format("}"));
    ICompilationUnit unit2 = pkg.createCompilationUnit(className2 + ".java",
        content.toString(), true, null);

    // Create a breakpoint at line 4 in the above file:
    JDIDebugModel.createLineBreakpoint(unit2.getResource(),
        unit2.getType(className2).getFullyQualifiedName(), 4, -1, -1, 0, true,
        null);

    final ISuspendResume[] suspendResume = new ISuspendResume[1];
    MyDebugListener listener = new MyDebugListener() {
      @Override
      public void handleDebugEvents(DebugEvent[] events) {
        super.handleDebugEvents(events);
        for (DebugEvent e : events) {
          if (e.getKind() == DebugEvent.SUSPEND) {
            suspendResume[0] = (ISuspendResume) e.getSource();
          }
        }
      }
    };
    DebugPlugin.getDefault().addDebugEventListener(listener);

    // Launch in debug mode:
    tracker.setEnabled(true);
    launch("TestEnabledWithBreakpointsAndFiles",
        pkg.getJavaProject().getElementName(),
        unit2.getType(className2).getFullyQualifiedName(),
        ILaunchManager.DEBUG_MODE);

    final Lock lock = new ReentrantLock();
    final Condition condition = lock.newCondition();
    lock.lock();
    try {
      // We had two breakpoints set, so we need to resume twice:
      while (suspendResume[0] == null) {
        condition.await(100, TimeUnit.MICROSECONDS);
      }
      suspendResume[0].resume();
      suspendResume[0] = null;
      condition.await(100, TimeUnit.MILLISECONDS);
      while (suspendResume[0] == null) {
        condition.await(100, TimeUnit.MILLISECONDS);
      }
      suspendResume[0].resume();
      condition.await(500, TimeUnit.MILLISECONDS);
    } finally {
      lock.unlock();
    }

    assertEquals(1, tracker.getData().size());
    LaunchEvent event = tracker.getData().iterator().next();
    assertEquals(2, event.getFilePaths().size());
    assertTrue(event.getFilePaths().contains(unit1.getResource().getFullPath()));
    assertTrue(event.getFilePaths().contains(unit2.getResource().getFullPath()));
  }
View Full Code Here

        pname = pname.substring(dot + 1);
     
      String eventTypeSig = Signature.createTypeSignature(pname, false);
     
      IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
      ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file.getFile());
      IType meType = unit.getType(className);
      IMember member = meType.getMethod(methodDesc.getName(),new String[] {eventTypeSig });
      JavaUI.revealInEditor(editor, (IJavaElement) member);
    }   
  }
View Full Code Here

        pname = pname.substring(dot + 1);
     
      String eventTypeSig = Signature.createTypeSignature(pname, false);
     
      IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
      ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file.getFile());
      String name = file.getName();
      dot = name.lastIndexOf('.');
      if (dot != -1)
        name = name.substring(0, dot);
      IType type = unit.getType(name);
     
      IMember member = type.getMethod(methodName,
          new String[] { eventTypeSig });
      JavaUI.revealInEditor(editor, (IJavaElement) member);
    }
View Full Code Here

    }
    return false;
  }
 
  private IType findDeclaringType(WidgetAdapter adapter){
    ICompilationUnit unit = adapter.getCompilationUnit();
    if(unit==null)
      return null;
    IJavaProject javaPrj= unit.getJavaProject();
    try{
      IJavaElement[] children = javaPrj.getChildren();
      for(IJavaElement child:children){
        if(child instanceof IPackageFragmentRoot){
          IPackageFragmentRoot root=(IPackageFragmentRoot) child;
          if(!root.isArchive()){
            IJavaElement[] children2 = root.getChildren();
            for(IJavaElement child2:children2){
              if(child2 instanceof IPackageFragment){
                IPackageFragment pkg=(IPackageFragment) child2;
                IJavaElement[] children3 = pkg.getChildren();
                for(IJavaElement child3:children3){
                  if(child3 instanceof ICompilationUnit){
                    ICompilationUnit icu=(ICompilationUnit)child3;
                    IType type2 = icu.getType(className);
                    if(icu.getElementName().equals((className+".java"))&&type2.exists()){
                      return type2;
                    }
                  }
                }
              }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ICompilationUnit

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.