Package org.eclipse.jdt.internal.core

Examples of org.eclipse.jdt.internal.core.PackageFragmentRoot


  // create a temporary info
  IBinaryType info;
  try {
    PackageFragment pkg = (PackageFragment) classFile.getParent();
    PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent();
    if (root.isArchive()) {
      // class file in a jar
      String classFileName = classFile.getElementName();
      String classFilePath = Util.concatWith(pkg.names, classFileName, '/');
      ZipFile zipFile = null;
      try {
View Full Code Here


  }

  private static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
    if (jarSeparator != -1) {
      String jarMemento = new String(fileName, 0, jarSeparator);
      PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
      if (pkgEnd == jarSeparator)
        return root.getPackageFragment(CharOperation.NO_STRINGS);
      char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
      char[][] compoundName = CharOperation.splitOn('/', pkgName);
      return root.getPackageFragment(CharOperation.toStrings(compoundName));
    } else {
      Path path = new Path(new String(fileName, 0, pkgEnd));
      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
      IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
      IJavaElement element = JavaCore.create(folder);
      if (element == null) return null;
      switch (element.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
          return (IPackageFragment) element;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
          return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
        case IJavaElement.JAVA_PROJECT:
          PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
          if (root == null) return null;
          return root.getPackageFragment(CharOperation.NO_STRINGS);
      }
      return null;
    }
  }
View Full Code Here

      case IJavaElement.JAVA_PROJECT:
      case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        return false;

      case IJavaElement.PACKAGE_FRAGMENT:
        PackageFragmentRoot root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        IResource resource = ((PackageFragment) element).resource();
        return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars());

      case IJavaElement.COMPILATION_UNIT:
        root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        resource = element.getResource();
        if (resource == null)
          return false;
        if (isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars()))
          return true;
        return isExcluded(element.getParent());

      default:
        IJavaElement cu = element.getAncestor(IJavaElement.COMPILATION_UNIT);
View Full Code Here

     * This method change sourcemapper only if source path is not set on the  IPackageFragmentRoot
     * @param root
     */
    public static void installSourceMapper(final IPackageFragmentRoot root) {
        try {
            PackageFragmentRoot packageFragmentRoot = ((PackageFragmentRoot) root);
      if (!isSourceAttached(packageFragmentRoot) && (!isFromJRE(root) || WojServicesHelper.getDefault().isSunSupported())) {
                SourceMapper sourceMapper = packageFragmentRoot.getSourceMapper();
        if(sourceMapper == null ||!(sourceMapper instanceof WojSourceMapper)) {
                    packageFragmentRoot.setSourceMapper(newWojSourceMapper());
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
View Full Code Here

    }
    return false;
  }
 
  public static boolean isSourceAttached(IJavaElement javaElement)  {
    PackageFragmentRoot pfr = (PackageFragmentRoot) PDEJavaModelUtil.getPackageFragmentRoot(javaElement);
    if(pfr != null) {
      return isSourceAttached((PackageFragmentRoot)pfr);
    }
    return false;
  }
View Full Code Here

  }

  public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
    if (jarSeparator != -1) {
      String jarMemento = new String(fileName, 0, jarSeparator);
      PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
      if (pkgEnd == jarSeparator)
        return root.getPackageFragment(CharOperation.NO_STRINGS);
      char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
      char[][] compoundName = CharOperation.splitOn('/', pkgName);
      return root.getPackageFragment(CharOperation.toStrings(compoundName));
    } else {
      Path path = new Path(new String(fileName, 0, pkgEnd));
      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
      IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
      IJavaElement element = JavaCore.create(folder);
      if (element == null) return null;
      switch (element.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
          return (IPackageFragment) element;
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
          return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
        case IJavaElement.JAVA_PROJECT:
          PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
          if (root == null) return null;
          return root.getPackageFragment(CharOperation.NO_STRINGS);
      }
      return null;
    }
  }
View Full Code Here

      case IJavaElement.JAVA_PROJECT:
      case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        return false;

      case IJavaElement.PACKAGE_FRAGMENT:
        PackageFragmentRoot root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        IResource resource = ((PackageFragment) element).resource();
        return resource != null && isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars());

      case IJavaElement.COMPILATION_UNIT:
        root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        resource = element.getResource();
        if (resource == null)
          return false;
        if (isExcluded(resource, root.fullInclusionPatternChars(), root.fullExclusionPatternChars()))
          return true;
        return isExcluded(element.getParent());

      default:
        IJavaElement cu = element.getAncestor(IJavaElement.COMPILATION_UNIT);
View Full Code Here

* @throws JavaModelException May happen if some Java Model info are not available
*/
public void add(IJavaElement element) throws JavaModelException {
  IPath containerPath = null;
  String containerPathToString = null;
  PackageFragmentRoot root = null;
  int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
  switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
      // a workspace sope should be used
      break;
    case IJavaElement.JAVA_PROJECT:
      add((JavaProject)element, null, includeMask, new HashSet(2), new HashSet(2), null);
      break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
      root = (PackageFragmentRoot)element;
      IPath rootPath = root.internalPath();
      containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
      containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
      IResource rootResource = root.resource();
      String projectPath = root.getJavaProject().getPath().toString();
      if (rootResource != null && rootResource.isAccessible()) {
        String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
        add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
      } else {
        add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
      }
      break;
    case IJavaElement.PACKAGE_FRAGMENT:
      root = (PackageFragmentRoot)element.getParent();
      projectPath = root.getJavaProject().getPath().toString();
      if (root.isArchive()) {
        String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
        containerPath = root.getPath();
        containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
        add(projectPath, relativePath, containerPathToString, true/*package*/, null);
      } else {
        IResource resource = ((JavaElement) element).resource();
        if (resource != null) {
          if (resource.isAccessible()) {
            containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath();
          } else {
            // for working copies, get resource container full path
            containerPath = resource.getParent().getFullPath();
          }
          containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
          String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
          add(projectPath, relativePath, containerPathToString, true/*package*/, null);
        }
      }
      break;
    default:
      // remember sub-cu (or sub-class file) java elements
      if (element instanceof IMember) {
        if (this.elements == null) {
          this.elements = new ArrayList();
        }
        this.elements.add(element);
      }
      root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
      projectPath = root.getJavaProject().getPath().toString();
      String relativePath;
      if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
        containerPath = root.getParent().getPath();
        relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/);
      } else {
        containerPath = root.internalPath();
        relativePath = getPath(element, true/*relative path*/).toString();
      }
      containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
      add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
  }

  if (root != null)
    addEnclosingProjectOrJar(root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}
View Full Code Here

  // create a temporary info
  IBinaryType info;
  try {
    PackageFragment pkg = (PackageFragment) classFile.getParent();
    PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent();
    if (root.isArchive()) {
      // class file in a jar
      String classFileName = classFile.getElementName();
      String classFilePath = Util.concatWith(pkg.names, classFileName, '/');
      ZipFile zipFile = null;
      try {
View Full Code Here

  int length = roots.length;
  ClasspathLocation[] cpLocations = new ClasspathLocation[length];
  int index = 0;
  JavaModelManager manager = JavaModelManager.getJavaModelManager();
  for (int i = 0; i < length; i++) {
    PackageFragmentRoot root = (PackageFragmentRoot) roots[i];
    IPath path = root.getPath();
    try {
      if (root.isArchive()) {
        ZipFile zipFile = manager.getZipFile(path);
        cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
      } else {
        Object target = JavaModel.getTarget(path, true);
        if (target == null) {
          // target doesn't exist any longer
          // just resize cpLocations
          System.arraycopy(cpLocations, 0, cpLocations = new ClasspathLocation[cpLocations.length-1], 0, index);
        } else if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
          cpLocations[index++] = new ClasspathSourceDirectory((IContainer)target, root.fullExclusionPatternChars(), root.fullInclusionPatternChars());
        } else {
          cpLocations[index++] = ClasspathLocation.forBinaryFolder((IContainer) target, false, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet());
        }
      }
    } catch (CoreException e1) {
      // problem opening zip file or getting root kind
      // consider root corrupt and ignore
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.core.PackageFragmentRoot

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.