Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IPackageFragmentRoot


                  adapterCode, true, monitor);
            }
            monitor.worked(1);

            monitor.subTask("Check for adaptee package");
            IPackageFragmentRoot pkgRoot = (IPackageFragmentRoot) pkg
                .getParent();
            String pkgname = pkg.getElementName();
            // pkgRoot.open(monitor);
            IPackageFragment adapteePkg = pkgRoot
                .createPackageFragment(pkgname + "."
                    + "adaptee", true, monitor);

            monitor.subTask("Insert adaptee with functionality");
            /* Insert the adaptee class */
 
View Full Code Here


        rootPositions.put(packageFragmentRoots[i], i);
      }
      for (int i = 0, length = workingCopies.length; i < length; i++) {
        ICompilationUnit workingCopy = workingCopies[i];
        PackageFragment pkg = (PackageFragment) workingCopy.getParent();
        IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
        int rootPosition = rootPositions.get(root);
        if (rootPosition == -1)
          continue; // working copy is not visible from this project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169970)
        HashMap typeMap = (HashMap) this.typesInWorkingCopies.get(pkg);
        if (typeMap == null) {
View Full Code Here

  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

*/
    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();
        if (rootPath.isPrefixOf(path)) {
          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

  JavaModelManager manager = JavaModelManager.getJavaModelManager();
  if (classFile.isOpen())
    return (ClassFileReader) manager.getInfo(type);

  PackageFragment pkg = (PackageFragment) type.getPackageFragment();
  IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
  try {
    if (!root.isArchive())
      return Util.newClassFileReader(((JavaElement) type).resource());

    ZipFile zipFile = null;
    try {
      IPath zipPath = root.getPath();
      if (JavaModelManager.ZIP_ACCESS_VERBOSE)
        System.out.println("(" + Thread.currentThread() + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$  //$NON-NLS-2$
      zipFile = manager.getZipFile(zipPath);
      String classFileName = classFile.getElementName();
      String path = Util.concatWith(pkg.names, classFileName, '/');
View Full Code Here

  private synchronized void computeAllRootPaths(IType type) {
    if (this.areRootPathsComputed) {
      return;
    }
    IPackageFragmentRoot root = (IPackageFragmentRoot) type.getPackageFragment().getParent();
    IPath pkgFragmentRootPath = root.getPath();
    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;
    boolean containsJavaSource = !pkgFragmentRootPath.equals(this.sourcePath); // used to optimize zip file reading only if source path and root path are equals, otherwise assume that attachment contains Java source

    String sourceLevel = null;
    String complianceLevel = null;
    if (root.isArchive()) {
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      ZipFile zip = null;
      try {
        zip = manager.getZipFile(pkgFragmentRootPath);
        for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) {
          ZipEntry entry = (ZipEntry) entries.nextElement();
          String entryName = entry.getName();
          if (!entry.isDirectory()) {
            if (Util.isClassFileName(entryName)) {
              int index = entryName.indexOf('/');
              if (index != -1) {
                String firstLevelPackageName = entryName.substring(0, index);
                if (!firstLevelPackageNames.contains(firstLevelPackageName)) {
                  if (sourceLevel == null) {
                    IJavaProject project = root.getJavaProject();
                    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 {
                containsADefaultPackage = true;
              }
            } else if (!containsJavaSource && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(entryName)) {
              containsJavaSource = true;
            }
          }
        }
      } catch (CoreException e) {
        // ignore
      } finally {
        manager.closeZipFile(zip); // handle null case
      }
    } else {
      Object target = JavaModel.getTarget(root.getPath(), true);
      if (target instanceof IResource) {
        IResource resource = (IResource) target;
        if (resource instanceof IContainer) {
          try {
            IResource[] members = ((IContainer) resource).members();
            for (int i = 0, max = members.length; i < max; i++) {
              IResource member = members[i];
              String resourceName = member.getName();
              if (member.getType() == IResource.FOLDER) {
                if (sourceLevel == null) {
                  IJavaProject project = root.getJavaProject();
                  sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
                  complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
                }
                IStatus status = JavaConventions.validatePackageName(resourceName, sourceLevel, complianceLevel);
                if (status.isOK() || status.getSeverity() == IStatus.WARNING) {
View Full Code Here

    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

       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
        int entryKind = this.oldResolvedClasspath[i].getEntryKind();
        if (entryKind == IClasspathEntry.CPE_PROJECT) {
          result |= HAS_PROJECT_CHANGE;
          continue;
        }
        if (entryKind == IClasspathEntry.CPE_LIBRARY) {
          result |= HAS_LIBRARY_CHANGE;
        }

        IPackageFragmentRoot[] pkgFragmentRoots = null;
        if (removedRoots != null) {
          PackageFragmentRoot oldRoot = (PackageFragmentRootremovedRoots.get(this.oldResolvedClasspath[i].getPath());
          if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
            pkgFragmentRoots = new PackageFragmentRoot[] { 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 retrieve exported roots
              null); /*no reverse map*/
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335986
            // When a package fragment's corresponding resource is removed from the project,
            // IJavaProject#computePackageFragmentRoots() doesn't include that entry. Hence
            // the cache become necessary in such cases. Add the cache to the accumulatedRoots
            // only when it's not already present.
            RootInfo rootInfo = (RootInfo) state.oldRoots.get(this.oldResolvedClasspath[i].getPath());
            if (rootInfo != null && rootInfo.cache != null) {
              IPackageFragmentRoot oldRoot = rootInfo.cache;
              boolean found = false;
              for (int j = 0; j < accumulatedRoots.size(); j++) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) accumulatedRoots.elementAt(j);
                if (!root.getPath().equals(oldRoot.getPath())) {
                  found = true;
                  break;
                }
              }
              if (!found)
                accumulatedRoots.add(oldRoot);
            }

            pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
            accumulatedRoots.copyInto(pkgFragmentRoots);
          } catch (JavaModelException e) {
            pkgFragmentRoots =  new PackageFragmentRoot[] {};
          }
        }
        addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
      } 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);
        }

        // 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);
        } 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

    if (rootIDs.contains(rootID)) return;

    IPath projectPath = this.project.getFullPath();
    IPath entryPath = resolvedEntry.getPath();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPackageFragmentRoot root = null;

    switch(resolvedEntry.getEntryKind()){

      // source folder
      case IClasspathEntry.CPE_SOURCE :
View Full Code Here

    IPackageFragmentRoot[] allRoots = this.getAllPackageFragmentRoots();
    if (!path.isAbsolute()) {
      throw new IllegalArgumentException(Messages.path_mustBeAbsolute);
    }
    for (int i= 0; i < allRoots.length; i++) {
      IPackageFragmentRoot classpathRoot= allRoots[i];
      if (classpathRoot.getPath().equals(path)) {
        return classpathRoot;
      }
    }
    return null;
  }
View Full Code Here

TOP

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

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.