Examples of IPackageFragmentRoot


Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

    this.oldResolvedClasspath = oldResolvedClasspath;
  }
 
  private void addClasspathDeltas(JavaElementDelta delta, IPackageFragmentRoot[] roots, int flag) {
    for (int i = 0; i < roots.length; i++) {
      IPackageFragmentRoot root = roots[i];
      delta.changed(root, flag);
      if ((flag & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0
          || (flag & IJavaElementDelta.F_SOURCEATTACHED) != 0
          || (flag & IJavaElementDelta.F_SOURCEDETACHED) != 0){
        try {
          root.close();
        } catch (JavaModelException e) {
          // ignore
        }
      }
    }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

       roots = (IPackageFragmentRoot[]) allOldRoots.get(this.project);
    }
    if (roots != null) {
      removedRoots = new HashMap();
      for (int i = 0; i < roots.length; i++) {
        IPackageFragmentRoot root = roots[i];
        removedRoots.put(root.getPath(), root);
      }
    }

    int newLength = newResolvedClasspath.length;
    int oldLength = this.oldResolvedClasspath.length;   
    for (int i = 0; i < oldLength; i++) {
      int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]);
      if (index == -1) {
        // remote project changes
        if (this.oldResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
          result |= HAS_PROJECT_CHANGE;
          continue;
        }

        IPackageFragmentRoot[] pkgFragmentRoots = null;
        if (removedRoots != null) {
          IPackageFragmentRoot oldRoot = (IPackageFragmentRootremovedRoots.get(this.oldResolvedClasspath[i].getPath());
          if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
            pkgFragmentRoots = new IPackageFragmentRoot[] { oldRoot };
          }
        }
        if (pkgFragmentRoots == null) {
          try {
            ObjectVector accumulatedRoots = new ObjectVector();
            HashSet rootIDs = new HashSet(5);
            rootIDs.add(this.project.rootID());
            this.project.computePackageFragmentRoots(
              this.oldResolvedClasspath[i],
              accumulatedRoots,
              rootIDs,
              null, // inside original project
              false, // don't check existency
              false, // don't retrieve exported roots
              null); /*no reverse map*/
            pkgFragmentRoots = new IPackageFragmentRoot[accumulatedRoots.size()];
            accumulatedRoots.copyInto(pkgFragmentRoots);
          } catch (JavaModelException e) {
            pkgFragmentRoots =  new IPackageFragmentRoot[] {};
          }
        }
        addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
        result |= HAS_DELTA;
      } else {
        // remote project changes
        if (this.oldResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
          result |= HAS_PROJECT_CHANGE;
          continue;
        }       
        if (index != i) { //reordering of the classpath
          addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]),  IJavaElementDelta.F_REORDER);
          result |= HAS_DELTA;
        }
       
        // check source attachment
        IPath newSourcePath = newResolvedClasspath[index].getSourceAttachmentPath();
        int sourceAttachmentFlags = getSourceAttachmentDeltaFlag(this.oldResolvedClasspath[i].getSourceAttachmentPath(), newSourcePath);
        IPath oldRootPath = this.oldResolvedClasspath[i].getSourceAttachmentRootPath();
        IPath newRootPath = newResolvedClasspath[index].getSourceAttachmentRootPath();
        int sourceAttachmentRootFlags = getSourceAttachmentDeltaFlag(oldRootPath, newRootPath);
        int flags = sourceAttachmentFlags | sourceAttachmentRootFlags;
        if (flags != 0) {
          addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), flags);
          result |= HAS_DELTA;
        } else {
          if (oldRootPath == null && newRootPath == null) {
            // if source path is specified and no root path, it needs to be recomputed dynamically
            // force detach source on jar package fragment roots (source will be lazily computed when needed)
            IPackageFragmentRoot[] computedRoots = this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]);
            for (int j = 0; j < computedRoots.length; j++) {
              IPackageFragmentRoot root = computedRoots[j];
              // force detach source on jar package fragment roots (source will be lazily computed when needed)
              try {
                root.close();
              } catch (JavaModelException e) {
                // ignore
              }
            }
          }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

      break;
    case IJavaElement.JAVA_PROJECT:
      add((JavaProject)element, null, includeMask, new HashSet(2), null);
      break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
      IPackageFragmentRoot root = (IPackageFragmentRoot)element;
      IPath rootPath = root.getPath();
      containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
      containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
      IResource rootResource = root.getResource();
      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 = (IPackageFragmentRoot)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 = element.getResource();
        if (resource != null) {
          if (resource.isAccessible()) {
            containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath();
          } 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 = (IPackageFragmentRoot) 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 segmet*/);
      } else {
        containerPath = root.getPath();
        relativePath = getPath(element, true/*relative path*/).toString();
      }
      containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
      add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

        searchedElement = searchedElement.getParent();
      }
    }
    return false;
  }
  IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
  if (root != null && root.isArchive()) {
    // external or internal jar
    IPath rootPath = root.getPath();
    String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString();
    IPath relativePath = getPath(element, true/*relative path*/);
    return indexOf(rootPathToString, relativePath.toString()) >= 0;
  }
  // resource in workspace
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

 
  private synchronized void computeAllRootPaths(IType type) {
    if (this.areRootPathsComputed) {
      return;
    }
    IPackageFragmentRoot root = (IPackageFragmentRoot) type.getPackageFragment().getParent();
    final HashSet tempRoots = new HashSet();
    long time = 0;
    if (VERBOSE) {
      System.out.println("compute all root paths for " + root.getElementName()); //$NON-NLS-1$
      time = System.currentTimeMillis();
    }
    final HashSet firstLevelPackageNames = new HashSet();
    boolean containsADefaultPackage = false;

    if (root.isArchive()) {
      JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
      IJavaProject project = jarPackageFragmentRoot.getJavaProject();
      String sourceLevel = null;
      String complianceLevel = null;
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      ZipFile zip = null;
      try {
        zip = manager.getZipFile(jarPackageFragmentRoot.getPath());
        for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
          ZipEntry entry = (ZipEntry) entries.nextElement();
          String entryName = entry.getName();
          if (!entry.isDirectory()) {
            int index = entryName.indexOf('/');
            if (index != -1 && Util.isClassFileName(entryName)) {
              String firstLevelPackageName = entryName.substring(0, index);
              if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
                if (sourceLevel == null) {
                  sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
                  complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
                }
                IStatus status = JavaConventions.validatePackageName(firstLevelPackageName, sourceLevel, complianceLevel);
                if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
                  firstLevelPackageNames.add(firstLevelPackageName);
                }
              }
            } else if (Util.isClassFileName(entryName)) {
              containsADefaultPackage = true;
            }           
          }
        }
      } catch (CoreException e) {
        // ignore
      } finally {
        manager.closeZipFile(zip); // handle null case
      }
    } else {
      Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), root.getPath(), true);
      if (target instanceof IResource) {
        IResource resource = (IResource) target;
        if (resource instanceof IContainer) {
          try {
            IResource[] members = ((IContainer) resource).members();
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

  String packageName = this.pkgName == null ? null : Util.concatWith(this.pkgName, '.');
  IJavaProject project = parentElement.getJavaProject();
  if (this.pkgName == null || (this.pkgName.length > 0 && JavaConventions.validatePackageName(packageName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR)) {
    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, packageName);
  }
  IPackageFragmentRoot root = (IPackageFragmentRoot) getParentElement();
  if (root.isReadOnly()) {
    return new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, root);
  }
  IContainer parentFolder = (IContainer) root.getResource();
  int i;
  for (i = 0; i < this.pkgName.length; i++) {
    IResource subFolder = parentFolder.findMember(this.pkgName[i]);
    if (subFolder != null) {
      if (subFolder.getType() != IResource.FOLDER) {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

        } catch (JavaModelException e) {
          // working copy doesn't exist -> ignore
        }
       
        // add root of package fragment to cache
        IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
        String[] pkgName = pkg.names;
        Object existing = this.packageFragments.get(pkgName);
        if (existing == null || existing == JavaProjectElementInfo.NO_ROOTS) {
          this.packageFragments.put(pkgName, root);
          // ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

  private void findAllTypes(String prefix, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) {
    int count= this.packageFragmentRoots.length;
    for (int i= 0; i < count; i++) {
      if (requestor.isCanceled())
        return;
      IPackageFragmentRoot root= this.packageFragmentRoots[i];
      IJavaElement[] packages= null;
      try {
        packages= root.getChildren();
      } catch (JavaModelException npe) {
        continue; // the root is not present, continue;
      }
      if (packages != null) {
        for (int j= 0, packageCount= packages.length; j < packageCount; j++) {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

*/   
    IResource possibleFragment = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (possibleFragment == null) {
      //external jar
      for (int i = 0; i < this.packageFragmentRoots.length; i++) {
        IPackageFragmentRoot root = this.packageFragmentRoots[i];
        if (!root.isExternal()) {
          continue;
        }
        IPath rootPath = root.getPath();
        int matchingCount = rootPath.matchingFirstSegments(path);
        if (matchingCount != 0) {
          String name = path.toOSString();
          // + 1 is for the File.separatorChar
          name = name.substring(rootPath.toOSString().length() + 1, name.length());
          name = name.replace(File.separatorChar, '.');
          IJavaElement[] list = null;
          try {
            list = root.getChildren();
          } catch (JavaModelException npe) {
            continue; // the package fragment root is not present;
          }
          int elementCount = list.length;
          for (int j = 0; j < elementCount; j++) {
            IPackageFragment packageFragment = (IPackageFragment) list[j];
            if (nameMatches(name, packageFragment, false)) {
              return packageFragment;
            }
          }
        }
      }
    } else {
      IJavaElement fromFactory = JavaCore.create(possibleFragment);
      if (fromFactory == null) {
        return null;
      }
      switch (fromFactory.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
          return (IPackageFragment) fromFactory;
        case IJavaElement.JAVA_PROJECT:
          // default package in a default root
          JavaProject project = (JavaProject) fromFactory;
          try {
            IClasspathEntry entry = project.getClasspathEntryFor(path);
            if (entry != null) {
              IPackageFragmentRoot root =
                project.getPackageFragmentRoot(project.getResource());
              Object defaultPkgRoot = this.packageFragments.get(CharOperation.NO_STRINGS);
              if (defaultPkgRoot == null) {
                return null;
              }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.IPackageFragmentRoot

    String matchName= partialMatch ? name.toLowerCase() : name;
    if (pkg == null) {
      findAllTypes(matchName, partialMatch, acceptFlags, requestor);
      return;
    }
    IPackageFragmentRoot root= (IPackageFragmentRoot) pkg.getParent();
    try {

      // look in working copies first
      int firstDot = -1;
      String topLevelTypeName = null;
      int packageFlavor= root.getKind();
      if (this.typesInWorkingCopies != null || packageFlavor == IPackageFragmentRoot.K_SOURCE) {
        firstDot = matchName.indexOf('.');
        if (!partialMatch)
          topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.