public void testNegativeSystemLibrarySourceLocation() throws Exception {
    IClasspathEntry[] cpes = get14Project().getRawClasspath();
    IClasspathEntry lib = null;
    for (int i = 0; i < cpes.length; i++) {
      if (cpes[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        if (cpes[i].getPath().equals(new Path(JRE_CONTAINER_1_4_CPE_NAME))) {
          lib = cpes[i];
          break;
        }
      }
    }
    assertNotNull("Could not find JRE_CONTAINER entry", lib);

    IPackageFragmentRoot[] roots = get14Project().findPackageFragmentRoots(lib);
    Object source = null;
    for (int i = 0; i < roots.length; i++) {
      IPackageFragmentRoot root = roots[i];
      IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);
      source = location.findSourceElement("xyz.abc.Object");
      if (source != null) {
        break;
      }
    }

    assertNull("Should not find source", source);
  }
 public void testProjectLocationMemento() throws Exception {
   IJavaSourceLocation location = new JavaProjectSourceLocation(get14Project());
   String memento = location.getMemento();
   IJavaSourceLocation restored = new JavaProjectSourceLocation();
   restored.initializeFrom(memento);
   assertEquals("project locations should be equal", location, restored);
 }
 public void testEmptyPackageFragmentRootLocationMemento() throws Exception {
   IJavaSourceLocation location = new PackageFragmentRootSourceLocation();
   String memento = location.getMemento();
   IJavaSourceLocation restored = new PackageFragmentRootSourceLocation();
   restored.initializeFrom(memento);
   assertEquals("root locations should be equal", location, restored);
 }
 public void testDirectoryLocationMemento() throws Exception {
   File dir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
   IJavaSourceLocation location = new DirectorySourceLocation(dir);
   String memento = location.getMemento();
   IJavaSourceLocation restored = new DirectorySourceLocation();
   restored.initializeFrom(memento);
   assertEquals("directory locations should be equal", location, restored);
 }
 public void testPackageFragmentRootLocationMemento() throws Exception {
   IResource res = get14Project().getProject().getFolder("src");
   IPackageFragmentRoot root = get14Project().getPackageFragmentRoot(res);
   IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);
   String memento = location.getMemento();
   IJavaSourceLocation restored = new PackageFragmentRootSourceLocation();
   restored.initializeFrom(memento);
   assertEquals("root locations should be equal", location, restored);
 }
 public void testArchiveLocationMemento() throws Exception {
   IVMInstall vm = JavaRuntime.getDefaultVMInstall();
   IJavaSourceLocation location =
       new ArchiveSourceLocation(
           JavaRuntime.getLibraryLocations(vm)[0].getSystemLibraryPath().toOSString(), null);
   String memento = location.getMemento();
   IJavaSourceLocation restored = new ArchiveSourceLocation();
   restored.initializeFrom(memento);
   assertEquals("archive locations should be equal", location, restored);
 }
  public void testNegativeSourceFolderSourceLocation() throws Exception {
    IResource res = get14Project().getProject().getFolder("src");
    IPackageFragmentRoot root = get14Project().getPackageFragmentRoot(res);
    IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);

    Object source = location.findSourceElement("DoesNotExist");
    assertNull("Should not have found source", source);

    source = location.findSourceElement("org.eclipse.DoesNotExist");
    assertNull("Should not have found source", source);
  }
  public void testPositiveSourceFolderSourceLocation() throws Exception {
    IResource res = get14Project().getProject().getFolder("src");
    IPackageFragmentRoot root = get14Project().getPackageFragmentRoot(res);
    IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);

    Object source = location.findSourceElement("Breakpoints");
    assertTrue("Did not find source for 'Breakpoints'", source instanceof ICompilationUnit);
    ICompilationUnit cu = (ICompilationUnit) source;
    assertEquals("Did not find source for 'Breakpoints'", cu.getElementName(), "Breakpoints.java");

    source = location.findSourceElement("org.eclipse.debug.tests.targets.InfiniteLoop");
    assertTrue("Did not find source for 'InfiniteLoop'", source instanceof ICompilationUnit);
    cu = (ICompilationUnit) source;
    assertEquals("Did not find source for 'Breakpoints'", cu.getElementName(), "InfiniteLoop.java");
  }
  public void testPositiveSystemLibrarySourceLocation() throws Exception {
    IClasspathEntry[] cpes = get14Project().getRawClasspath();
    IClasspathEntry lib = null;
    for (int i = 0; i < cpes.length; i++) {
      if (cpes[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        if (cpes[i].getPath().equals(new Path(JRE_CONTAINER_1_4_CPE_NAME))) {
          lib = cpes[i];
          break;
        }
      }
    }
    assertNotNull("Could not find JRE_CONTAINER entry", lib);

    IPackageFragmentRoot[] roots = get14Project().findPackageFragmentRoots(lib);
    Object source = null;
    for (int i = 0; i < roots.length; i++) {
      IPackageFragmentRoot root = roots[i];
      IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);
      source = location.findSourceElement("java.lang.Object");
      if (source != null) {
        break;
      }
    }

    assertTrue("Did not find source for 'Object'", source instanceof IClassFile);
    IClassFile cf = (IClassFile) source;
    assertEquals("Did not find source for 'Object'", "Object.class", cf.getElementName());

    for (int i = 0; i < roots.length; i++) {
      IPackageFragmentRoot root = roots[i];
      IJavaSourceLocation location = new PackageFragmentRootSourceLocation(root);
      source = location.findSourceElement("java.util.Vector$1");
      if (source != null) {
        break;
      }
    }
    assertTrue("Did not find source for 'Vector$1'", source instanceof IClassFile);
    cf = (IClassFile) source;
    assertEquals("Did not find source for 'Vector$1'", "Vector$1.class", cf.getElementName());
  }