Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IClasspathEntry


      paths.add(projectPath);

      // Add project libraries paths
      IClasspathEntry[] entries = javaProject.getResolvedClasspath();
      for (int j = 0, eLength = entries.length; j < eLength; j++) {
        IClasspathEntry entry = entries[j];
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
          IPath path = entry.getPath();
          Object target = JavaModel.getTarget(path, false/*don't check existence*/);
          if (target instanceof IFolder) // case of an external folder
            path = ((IFolder) target).getFullPath();
          paths.add(entry.getPath());
        }
      }
    }
    result = new IPath[paths.size()];
    paths.toArray(result);
View Full Code Here


  public static HashSet getExternalFolders(IClasspathEntry[] classpath) {
    if (classpath == null)
      return null;
    HashSet folders = null;
    for (int i = 0; i < classpath.length; i++) {
      IClasspathEntry entry = classpath[i];
      if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IPath entryPath = entry.getPath();
        if (isExternalFolderPath(entryPath)) {
          if (folders == null)
            folders = new HashSet();
          folders.add(entryPath);
        }
        IPath attachmentPath = entry.getSourceAttachmentPath();
        if (isExternalFolderPath(attachmentPath)) {
          if (folders == null)
            folders = new HashSet();
          folders.add(attachmentPath);
        }
View Full Code Here

          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) {
View Full Code Here

      IClasspathEntry[] entries = javaProject.getRawClasspath();
      int length = entries.length;
      IClasspathEntry[] sourceEntries = new IClasspathEntry[length];
      int sourceEntriesNumber = 0;
      for (int i = 0; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
          sourceEntries[sourceEntriesNumber++] = entry;
      }
      if (sourceEntriesNumber == 0) {
        IPath projectPath = javaProject.getPath();
        for (int i = 0; i < length; i++) {
          IClasspathEntry entry = entries[i];
          if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) {
            // the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
            // ensure a job exists to index it as a binary folder
            this.manager.indexLibrary(projectPath, this.project);
            return true;
          }
        }

        // nothing to index but want to save an empty index file so its not 'rebuilt' when part of a search request
        Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
        if (index != null)
          this.manager.saveIndex(index);
        return true;
      }
      if (sourceEntriesNumber != length)
        System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber);

      Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
      if (index == null) return true;
      monitor = index.monitor;
      if (monitor == null) return true; // index got deleted since acquired

      monitor.enterRead(); // ask permission to read

      String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
      int max = paths == null ? 0 : paths.length;
      final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
      final String OK = "OK"; //$NON-NLS-1$
      final String DELETED = "DELETED"; //$NON-NLS-1$
      if (paths != null) {
        for (int i = 0; i < max; i++)
          indexedFileNames.put(paths[i], DELETED);
      }
      final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();

      IWorkspaceRoot root = this.project.getWorkspace().getRoot();
      for (int i = 0; i < sourceEntriesNumber; i++) {
        if (this.isCancelled) return false;

        IClasspathEntry entry = sourceEntries[i];
        IResource sourceFolder = root.findMember(entry.getPath());
        if (sourceFolder != null) {

          // collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
          final HashSet outputs = new HashSet();
          if (sourceFolder.getType() == IResource.PROJECT) {
View Full Code Here

  private int classpathContains(IClasspathEntry[] list, IClasspathEntry entry) {
    IPath[] exclusionPatterns = entry.getExclusionPatterns();
    IPath[] inclusionPatterns = entry.getInclusionPatterns();
    int listLen = list == null ? 0 : list.length;
    nextEntry: for (int i = 0; i < listLen; i++) {
      IClasspathEntry other = list[i];
      if (other.getContentKind() == entry.getContentKind()
        && other.getEntryKind() == entry.getEntryKind()
        && other.isExported() == entry.isExported()
        && other.getPath().equals(entry.getPath())) {
          // check custom outputs
          IPath entryOutput = entry.getOutputLocation();
          IPath otherOutput = other.getOutputLocation();
          if (entryOutput == null) {
            if (otherOutput != null)
              continue;
          } else {
            if (!entryOutput.equals(otherOutput))
              continue;
          }

          // check inclusion patterns
          IPath[] otherIncludes = other.getInclusionPatterns();
          if (inclusionPatterns != otherIncludes) {
              if (inclusionPatterns == null) continue;
            int includeLength = inclusionPatterns.length;
            if (otherIncludes == null || otherIncludes.length != includeLength)
              continue;
            for (int j = 0; j < includeLength; j++) {
              // compare toStrings instead of IPaths
              // since IPath.equals is specified to ignore trailing separators
              if (!inclusionPatterns[j].toString().equals(otherIncludes[j].toString()))
                continue nextEntry;
            }
          }
          // check exclusion patterns
          IPath[] otherExcludes = other.getExclusionPatterns();
          if (exclusionPatterns != otherExcludes) {
              if (exclusionPatterns == null) continue;
            int excludeLength = exclusionPatterns.length;
            if (otherExcludes == null || otherExcludes.length != excludeLength)
              continue;
View Full Code Here

    if (resource != null && resource.getType() == IResource.FOLDER) {
      IFolder folder = (IFolder) resource;
      // only changes if it actually existed
      IClasspathEntry[] classpath = this.project.getExpandedClasspath();
      for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        IPath path = classpath[i].getPath();
        if (entry.getEntryKind() != IClasspathEntry.CPE_PROJECT && path.isPrefixOf(location) && !path.equals(location)) {
          IPackageFragmentRoot[] roots = this.project.computePackageFragmentRoots(classpath[i]);
          PackageFragmentRoot root = (PackageFragmentRoot) roots[0];
          // now the output location becomes a package fragment - along with any subfolders
          ArrayList folders = new ArrayList();
          folders.add(folder);
View Full Code Here

        result |= HAS_DELTA;

        // reset containers that are no longer on the classpath
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=139446)
        for (int i = 0, length = this.oldRawClasspath.length; i < length; i++) {
          IClasspathEntry entry = this.oldRawClasspath[i];
          if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (classpathContains(newRawClasspath, entry) == -1)
              manager.containerPut(this.project, entry.getPath(), null);
          }
        }
      }

      // if no changes to resolved classpath, nothing more to do
View Full Code Here

          continue;
        }

        // Remove the .java files from the index for a source folder
        // For a lib folder or a .jar file, remove the corresponding index if not shared.
        IClasspathEntry oldEntry = this.oldResolvedClasspath[i];
        final IPath path = oldEntry.getPath();
        int changeKind = this.oldResolvedClasspath[i].getEntryKind();
        switch (changeKind) {
          case IClasspathEntry.CPE_SOURCE:
            char[][] inclusionPatterns = ((ClasspathEntry)oldEntry).fullInclusionPatternChars();
            char[][] exclusionPatterns = ((ClasspathEntry)oldEntry).fullExclusionPatternChars();
            indexManager.removeSourceFolderFromIndex(this.project, path, inclusionPatterns, exclusionPatterns);
            break;
          case IClasspathEntry.CPE_LIBRARY:
            if (state.otherRoots.get(path) == null) { // if root was not shared
              indexManager.discardJobs(path.toString());
              indexManager.removeIndex(path);
              // TODO (kent) we could just remove the in-memory index and have the indexing check for timestamps
            }
            break;
        }
      }
    }

    for (int i = 0; i < newLength; i++) {
      int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]);
      if (index == -1) {
        // remote projects are not indexed in this project
        if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){
          continue;
        }

        // Request indexing
        int entryKind = newResolvedClasspath[i].getEntryKind();
        switch (entryKind) {
          case IClasspathEntry.CPE_LIBRARY:
            boolean pathHasChanged = true;
            IPath newPath = newResolvedClasspath[i].getPath();
            for (int j = 0; j < oldLength; j++) {
              IClasspathEntry oldEntry = this.oldResolvedClasspath[j];
              if (oldEntry.getPath().equals(newPath)) {
                pathHasChanged = false;
                break;
              }
            }
            if (pathHasChanged) {
              indexManager.indexLibrary(newPath, this.project.getProject());
            }
            break;
          case IClasspathEntry.CPE_SOURCE:
            IClasspathEntry entry = newResolvedClasspath[i];
            IPath path = entry.getPath();
            char[][] inclusionPatterns = ((ClasspathEntry)entry).fullInclusionPatternChars();
            char[][] exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
            indexManager.indexSourceFolder(this.project, path, inclusionPatterns, exclusionPatterns);
            break;
        }
View Full Code Here

        }
      }
    }

    // recreate the CP entry
    IClasspathEntry entry = null;
    switch (kind) {

      case IClasspathEntry.CPE_PROJECT :
        entry = new ClasspathEntry(
                        IPackageFragmentRoot.K_SOURCE,
View Full Code Here

    int sourceEntryCount = 0;
    boolean disableExclusionPatterns = JavaCore.DISABLED.equals(javaProject.getOption(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, true));
    boolean disableCustomOutputLocations = JavaCore.DISABLED.equals(javaProject.getOption(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, true));

    for (int i = 0 ; i < length; i++) {
      IClasspathEntry resolvedEntry = classpath[i];
      if (disableExclusionPatterns &&
              ((resolvedEntry.getInclusionPatterns() != null && resolvedEntry.getInclusionPatterns().length > 0)
              || (resolvedEntry.getExclusionPatterns() != null && resolvedEntry.getExclusionPatterns().length > 0))) {
        return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_EXCLUSION_PATTERNS, javaProject, resolvedEntry.getPath());
      }
      switch(resolvedEntry.getEntryKind()){
        case IClasspathEntry.CPE_SOURCE :
          sourceEntryCount++;

          IPath customOutput;
          if ((customOutput = resolvedEntry.getOutputLocation()) != null) {

            if (disableCustomOutputLocations) {
              return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS, javaProject, resolvedEntry.getPath());
            }
            // ensure custom output is in project
            if (customOutput.isAbsolute()) {
              if (!javaProject.getPath().isPrefixOf(customOutput)) {
                return new JavaModelStatus(IJavaModelStatusConstants.PATH_OUTSIDE_PROJECT, javaProject, customOutput.toString());
              }
            } else {
              return new JavaModelStatus(IJavaModelStatusConstants.RELATIVE_PATH, customOutput);
            }

            // ensure custom output doesn't conflict with other outputs
            // check exact match
            if (Util.indexOfMatchingPath(customOutput, outputLocations, outputCount) != -1) {
              continue; // already found
            }
            // accumulate all outputs, will check nesting once all available (to handle ordering issues)
            outputLocations[outputCount++] = customOutput;
          }
      }
    }
    // check nesting across output locations
    for (int i = 1 /*no check for default output*/ ; i < outputCount; i++) {
      IPath customOutput = outputLocations[i];
      int index;
      // check nesting
      if ((index = Util.indexOfEnclosingPath(customOutput, outputLocations, outputCount)) != -1 && index != i) {
        if (index == 0) {
          // custom output is nested in project's output: need to check if all source entries have a custom
          // output before complaining
          if (potentialNestedOutput == null) potentialNestedOutput = customOutput;
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInOutput, new String[] {customOutput.makeRelative().toString(), outputLocations[index].makeRelative().toString()}));
        }
      }
    }
    // allow custom output nesting in project's output if all source entries have a custom output
    if (sourceEntryCount <= outputCount-1) {
        allowNestingInOutputLocations[0] = true;
    } else if (potentialNestedOutput != null) {
      return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInOutput, new String[] {potentialNestedOutput.makeRelative().toString(), outputLocations[0].makeRelative().toString()}));
    }

    for (int i = 0 ; i < length; i++) {
      IClasspathEntry resolvedEntry = classpath[i];
      IPath path = resolvedEntry.getPath();
      int index;
      switch(resolvedEntry.getEntryKind()){

        case IClasspathEntry.CPE_SOURCE :
          hasSource = true;
          if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
            allowNestingInOutputLocations[index] = true;
          }
          break;

        case IClasspathEntry.CPE_LIBRARY:
          Object target = JavaModel.getTarget(path, false/*don't check resource existence*/);
          hasLibFolder |= target instanceof IContainer;
          if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
            allowNestingInOutputLocations[index] = true;
          }
          break;
      }
    }
    if (!hasSource && !hasLibFolder) { // if no source and no lib folder, then allowed
      for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
    }

    // check all entries
    for (int i = 0 ; i < length; i++) {
      IClasspathEntry entry = classpath[i];
      if (entry == null) continue;
      IPath entryPath = entry.getPath();
      int kind = entry.getEntryKind();

      // no further check if entry coincidates with project or output location
      if (entryPath.equals(projectPath)){
        // complain if self-referring project entry
        if (kind == IClasspathEntry.CPE_PROJECT){
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, Messages.bind(Messages.classpath_cannotReferToItself, entryPath.makeRelative().toString()));
        }
        // tolerate nesting output in src if src==prj
        continue;
      }

      // allow nesting source entries in each other as long as the outer entry excludes the inner one
      if (kind == IClasspathEntry.CPE_SOURCE
          || (kind == IClasspathEntry.CPE_LIBRARY && (JavaModel.getTarget(entryPath, false/*don't check existence*/) instanceof IContainer))) {
        for (int j = 0; j < classpath.length; j++){
          IClasspathEntry otherEntry = classpath[j];
          if (otherEntry == null) continue;
          int otherKind = otherEntry.getEntryKind();
          IPath otherPath = otherEntry.getPath();
          if (entry != otherEntry
            && (otherKind == IClasspathEntry.CPE_SOURCE
                || (otherKind == IClasspathEntry.CPE_LIBRARY
                    && (JavaModel.getTarget(otherPath, false/*don't check existence*/) instanceof IContainer)))) {
            char[][] inclusionPatterns, exclusionPatterns;
            if (otherPath.isPrefixOf(entryPath)
                && !otherPath.equals(entryPath)
                && !Util.isExcluded(entryPath.append("*"), inclusionPatterns = ((ClasspathEntry)otherEntry).fullInclusionPatternChars(), exclusionPatterns = ((ClasspathEntry)otherEntry).fullExclusionPatternChars(), false)) { //$NON-NLS-1$
              String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);
              if (Util.isExcluded(entryPath, inclusionPatterns, exclusionPatterns, false)) {
                return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_mustEndWithSlash, new String[] {exclusionPattern, entryPath.makeRelative().toString()}));
              } else {
                if (otherKind == IClasspathEntry.CPE_SOURCE) {
                  exclusionPattern += '/';
                  if (!disableExclusionPatterns) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInEntry, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString(), exclusionPattern}));
                  } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInEntryNoExclusion, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString(), exclusionPattern}));
                  }
                } else {
                  return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInLibrary, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString()}));
                }
              }
            }
          }
        }
      }

      // prevent nesting output location inside entry unless enclosing is a source entry which explicitly exclude the output location
      char[][] inclusionPatterns = ((ClasspathEntry)entry).fullInclusionPatternChars();
      char[][] exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
      for (int j = 0; j < outputCount; j++){
        IPath currentOutput = outputLocations[j];
        if (entryPath.equals(currentOutput)) continue;
        if (entryPath.isPrefixOf(currentOutput)) {
            if (kind != IClasspathEntry.CPE_SOURCE || !Util.isExcluded(currentOutput, inclusionPatterns, exclusionPatterns, true)) {
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInEntry, new String[] {currentOutput.makeRelative().toString(), entryPath.makeRelative().toString()}));
            }
        }
      }

      // prevent nesting entry inside output location - when distinct from project or a source folder
      for (int j = 0; j < outputCount; j++){
        if (allowNestingInOutputLocations[j]) continue;
        IPath currentOutput = outputLocations[j];
        if (currentOutput.isPrefixOf(entryPath)) {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInOutput, new String[] {entryPath.makeRelative().toString(), currentOutput.makeRelative().toString()}));
        }
      }
    }
    // ensure that no specific output is coincidating with another source folder (only allowed if matching current source folder)
    // 36465 - for 2.0 backward compatibility, only check specific output locations (the default can still coincidate)
    // perform one separate iteration so as to not take precedence over previously checked scenarii (in particular should
    // diagnose nesting source folder issue before this one, for example, [src]"Project/", [src]"Project/source/" and output="Project/" should
    // first complain about missing exclusion pattern
    for (int i = 0 ; i < length; i++) {
      IClasspathEntry entry = classpath[i];
      if (entry == null) continue;
      IPath entryPath = entry.getPath();
      int kind = entry.getEntryKind();

      // Build some common strings for status message
      boolean isProjectRelative = projectName.equals(entryPath.segment(0));
      String entryPathMsg = isProjectRelative ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString();

      if (kind == IClasspathEntry.CPE_SOURCE) {
        IPath output = entry.getOutputLocation();
        if (output == null) continue; // 36465 - for 2.0 backward compatibility, only check specific output locations (the default can still coincidate)
        // if (output == null) output = projectOutputLocation; // if no specific output, still need to check using default output (this line would check default output)
        for (int j = 0; j < length; j++) {
          IClasspathEntry otherEntry = classpath[j];
          if (otherEntry == entry) continue;

          // Build some common strings for status message
          boolean opStartsWithProject = projectName.equals(otherEntry.getPath().segment(0));
          String otherPathMsg = opStartsWithProject ? otherEntry.getPath().removeFirstSegments(1).toString() : otherEntry.getPath().makeRelative().toString();

          switch (otherEntry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE :
              if (otherEntry.getPath().equals(output)) {
                return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotUseDistinctSourceFolderAsOutput, new String[] {entryPathMsg, otherPathMsg, projectName}));
              }
              break;
            case IClasspathEntry.CPE_LIBRARY :
              if (otherEntry.getPath().equals(output)) {
                return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotUseLibraryAsOutput, new String[] {entryPathMsg, otherPathMsg, projectName}));
              }
          }
        }
      }
View Full Code Here

TOP

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

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.