Package org.eclipse.jdt.internal.core.search.indexing

Examples of org.eclipse.jdt.internal.core.search.indexing.IndexManager


     * It is required to initialize all fields that depends on a headless environment
     * only if the platform is running. Otherwise this breaks the ability to use
     * ASTParser in a non-headless environment.
     */
    if (Platform.isRunning()) {
      this.indexManager = new IndexManager();
      this.nonChainingJars = loadClasspathListCache(NON_CHAINING_JARS_CACHE);
      this.invalidArchives = loadClasspathListCache(INVALID_ARCHIVES_CACHE);
      String includeContainerReferencedLib = System.getProperty(RESOLVE_REFERENCED_LIBRARIES_FOR_CONTAINERS);
      this.resolveReferencedLibrariesForContainers = TRUE.equalsIgnoreCase(includeContainerReferencedLib);
    }
View Full Code Here


        // will need delta since this save (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38658)
        context.needDelta();
 
        // clean up indexes on workspace full save
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=52347)
        IndexManager manager = this.indexManager;
        if (manager != null
            // don't force initialization of workspace scope as we could be shutting down
            // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=93941)
            && this.workspaceScope != null) {
          manager.cleanUpIndexes();
        }
      }
      //$FALL-THROUGH$
      case ISaveContext.SNAPSHOT : {
        // clean up external folders on full save or snapshot
View Full Code Here

   
    public void forgetExternalTimestampsAndIndexes() {
      IClasspathEntry[] classpath = this.resolvedClasspath;
      if (classpath == null) return;
      JavaModelManager manager = JavaModelManager.getJavaModelManager();
      IndexManager indexManager = manager.indexManager;
      Map externalTimeStamps = manager.deltaState.getExternalLibTimeStamps();
      HashMap rootInfos = JavaModelManager.getDeltaState().otherRoots;
      for (int i = 0, length = classpath.length; i < length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
          IPath path = entry.getPath();
          if (rootInfos.get(path) == null) {
            externalTimeStamps.remove(path);
            indexManager.removeIndex(path); // force reindexing on next reference (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=250083 )
          }
        }
      }
    }
View Full Code Here

   *
   * @param indexLocation the location in the file system to the index
   * @since 3.2
   */
  public void removeIndex(IPath indexLocation){
    IndexManager manager = JavaModelManager.getIndexManager();
    manager.removeIndexPath(indexLocation);
  }
View Full Code Here

    if (file instanceof IResource) {
      containerPath = ((IResource)file).getProject().getFullPath();
    } else if (file == null) {
      containerPath = documentPath.removeLastSegments(1);
    }
    IndexManager manager = JavaModelManager.getIndexManager();
    // TODO (frederic) should not have to create index manually, should expose API that recreates index instead
    manager.ensureIndexExists(indexLocation, containerPath);
    manager.scheduleDocumentIndexing(document, containerPath, indexLocation, this);
    if (!indexLocation.equals(this.lastIndexLocation)) {
      manager.updateParticipant(indexLocation, containerPath);
      this.lastIndexLocation = indexLocation;
    }
  }
View Full Code Here

protected String[] getPathsOfDeclaringType() {
  if (this.typeQualification == null && this.typeSimpleName == null) return null;

  final PathCollector pathCollector = new PathCollector();
  IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
  IndexManager indexManager = JavaModelManager.getIndexManager();
  SearchPattern searchPattern = new TypeDeclarationPattern(
    this.typeSimpleName != null ? null : this.typeQualification, // use the qualification only if no simple name
    null, // do find member types
    this.typeSimpleName,
    IIndexConstants.TYPE_SUFFIX,
    this.pattern.getMatchRule());
  IndexQueryRequestor searchRequestor = new IndexQueryRequestor(){
    public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
      TypeDeclarationPattern record = (TypeDeclarationPattern)indexRecord;
      if (record.enclosingTypeNames != IIndexConstants.ONE_ZERO_CHAR) {  // filter out local and anonymous classes
        pathCollector.acceptIndexMatch(documentPath, indexRecord, participant, access);
      }
      return true;
    }
  };

  indexManager.performConcurrentJob(
    new PatternSearchJob(
      searchPattern,
      new JavaSearchParticipant(),
      scope,
      searchRequestor),
View Full Code Here

    }
    return true;
  }
  private void updateIndex(Openable element, IResourceDelta delta) {

    IndexManager indexManager = this.manager.indexManager;
    if (indexManager == null)
      return;

    switch (element.getElementType()) {
      case IJavaElement.JAVA_PROJECT :
        switch (delta.getKind()) {
          case IResourceDelta.ADDED :
            indexManager.indexAll(element.getJavaProject().getProject());
            break;
          case IResourceDelta.REMOVED :
            indexManager.removeIndexFamily(element.getJavaProject().getProject().getFullPath());
            // NB: Discarding index jobs belonging to this project was done during PRE_DELETE
            break;
          // NB: Update of index if project is opened, closed, or its java nature is added or removed
          //     is done in updateCurrentDeltaAndIndex
        }
        break;
      case IJavaElement.PACKAGE_FRAGMENT_ROOT :
        if (element instanceof JarPackageFragmentRoot) {
          JarPackageFragmentRoot root = (JarPackageFragmentRoot)element;
          // index jar file only once (if the root is in its declaring project)
          IPath jarPath = root.getPath();
          switch (delta.getKind()) {
            case IResourceDelta.ADDED:
              // index the new jar
              indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
              break;
            case IResourceDelta.CHANGED:
              // first remove the index so that it is forced to be re-indexed
              indexManager.removeIndex(jarPath);
              // then index the jar
              indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
              break;
            case IResourceDelta.REMOVED:
              // the jar was physically removed: remove the index
              indexManager.discardJobs(jarPath.toString());
              indexManager.removeIndex(jarPath);
              break;
          }
          break;
        }
        int kind = delta.getKind();
        if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED || (kind == IResourceDelta.CHANGED && (delta.getFlags() & IResourceDelta.LOCAL_CHANGED) != 0)) {
          PackageFragmentRoot root = (PackageFragmentRoot)element;
          updateRootIndex(root, CharOperation.NO_STRINGS, delta);
          break;
        }
        // don't break as packages of the package fragment root can be indexed below
        // $FALL-THROUGH$
      case IJavaElement.PACKAGE_FRAGMENT :
        switch (delta.getKind()) {
          case IResourceDelta.CHANGED:
            if ((delta.getFlags() & IResourceDelta.LOCAL_CHANGED) == 0)
              break;
            // $FALL-THROUGH$
          case IResourceDelta.ADDED:
          case IResourceDelta.REMOVED:
            IPackageFragment pkg = null;
            if (element instanceof IPackageFragmentRoot) {
              PackageFragmentRoot root = (PackageFragmentRoot)element;
              pkg = root.getPackageFragment(CharOperation.NO_STRINGS);
            } else {
              pkg = (IPackageFragment)element;
            }
            RootInfo rootInfo = rootInfo(pkg.getParent().getPath(), delta.getKind());
            boolean isSource =
              rootInfo == null // if null, defaults to source
              || rootInfo.entryKind == IClasspathEntry.CPE_SOURCE;
            IResourceDelta[] children = delta.getAffectedChildren();
            for (int i = 0, length = children.length; i < length; i++) {
              IResourceDelta child = children[i];
              IResource resource = child.getResource();
              // TODO (philippe) Why do this? Every child is added anyway as the delta is walked
              if (resource instanceof IFile) {
                String name = resource.getName();
                if (isSource) {
                  if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name)) {
                    Openable cu = (Openable)pkg.getCompilationUnit(name);
                    updateIndex(cu, child);
                  }
                } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(name)) {
                  Openable classFile = (Openable)pkg.getClassFile(name);
                  updateIndex(classFile, child);
                }
              }
            }
            break;
        }
        break;
      case IJavaElement.CLASS_FILE :
        IFile file = (IFile) delta.getResource();
        IJavaProject project = element.getJavaProject();
        PackageFragmentRoot root = element.getPackageFragmentRoot();
        IPath binaryFolderPath = root.isExternal() && !root.isArchive() ? root.resource().getFullPath() : root.getPath();
        // if the class file is part of the binary output, it has been created by
        // the java builder -> ignore
        try {
          if (binaryFolderPath.equals(project.getOutputLocation())) {
            break;
          }
        } catch (JavaModelException e) {
          // project doesn't exist: ignore
        }
        switch (delta.getKind()) {
          case IResourceDelta.CHANGED :
            // no need to index if the content has not changed
            int flags = delta.getFlags();
            if ((flags & IResourceDelta.CONTENT) == 0 && (flags & IResourceDelta.ENCODING) == 0)
              break;
            // $FALL-THROUGH$
          case IResourceDelta.ADDED :
            indexManager.addBinary(file, binaryFolderPath);
            break;
          case IResourceDelta.REMOVED :
            String containerRelativePath = Util.relativePath(file.getFullPath(), binaryFolderPath.segmentCount());
            indexManager.remove(containerRelativePath, binaryFolderPath);
            break;
        }
        break;
      case IJavaElement.COMPILATION_UNIT :
        file = (IFile) delta.getResource();
        switch (delta.getKind()) {
          case IResourceDelta.CHANGED :
            // no need to index if the content has not changed
            int flags = delta.getFlags();
            if ((flags & IResourceDelta.CONTENT) == 0 && (flags & IResourceDelta.ENCODING) == 0)
              break;
            // $FALL-THROUGH$
          case IResourceDelta.ADDED :
            indexManager.addSource(file, file.getProject().getFullPath(), getSourceElementParser(element));
            // Clean file from secondary types cache but do not update indexing secondary type cache as it will be updated through indexing itself
            this.manager.secondaryTypesRemoving(file, false);
            break;
          case IResourceDelta.REMOVED :
            indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
            // Clean file from secondary types cache and update indexing secondary type cache as indexing cannot remove secondary types from cache
            this.manager.secondaryTypesRemoving(file, true);
            break;
        }
    }
View Full Code Here

      // project doesn't exist
      return;
    }

    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    IndexManager indexManager = manager.indexManager;
    if (indexManager == null)
      return;
    DeltaProcessingState state = manager.deltaState;

    int newLength = newResolvedClasspath.length;
    int oldLength = this.oldResolvedClasspath == null ? 0 : this.oldResolvedClasspath.length;
    for (int i = 0; i < oldLength; i++) {
      int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]);
      if (index == -1) {
        // remote projects are not indexed in this project
        if (this.oldResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){
          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

/*
*  Compute the list of paths which are keying index files.
*/
private void initializeIndexLocations() {
  IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
  IndexManager manager = JavaModelManager.getIndexManager();
  SimpleSet locations = new SimpleSet();
  IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
  if (focus == null) {
    for (int i = 0; i < projectsAndJars.length; i++) {
      IPath path = projectsAndJars[i];
      Object target = JavaModel.getTarget(path, false/*don't check existence*/);
      if (target instanceof IFolder) // case of an external folder
        path = ((IFolder) target).getFullPath();
      locations.add(manager.computeIndexLocation(path));
    }
  } else {
    try {
      // See whether the state builder might be used to reduce the number of index locations
   
      // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
      int length = projectsAndJars.length;
      JavaProject[] projectsCanSeeFocus = new JavaProject[length];
      SimpleSet visitedProjects = new SimpleSet(length);
      int projectIndex = 0;
      SimpleSet externalLibsToCheck = new SimpleSet(length);
      ObjectVector superTypes = new ObjectVector();
      IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
      char[][][] focusQualifiedNames = null;
      boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
      if (isAutoBuilding && focus instanceof IJavaProject) {
        focusQualifiedNames = getQualifiedNames(superTypes);
      }
      IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
      for (int i = 0; i < length; i++) {
        IPath path = projectsAndJars[i];
        JavaProject project = (JavaProject) getJavaProject(path, model);
        if (project != null) {
          visitedProjects.add(project);
          if (canSeeFocus(focuses, project, focusQualifiedNames)) {
            locations.add(manager.computeIndexLocation(path));
            projectsCanSeeFocus[projectIndex++] = project;
          }
        } else {
          externalLibsToCheck.add(path);
        }
      }
      for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
        IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
        for (int j = entries.length; --j >= 0;) {
          IClasspathEntry entry = entries[j];
          if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = entry.getPath();
            if (externalLibsToCheck.remove(path) != null) {
              Object target = JavaModel.getTarget(path, false/*don't check existence*/);
              if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
              locations.add(manager.computeIndexLocation(path));
            }
          }
        }
      }
      // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
      if (externalLibsToCheck.elementSize > 0) {
        IJavaProject[] allProjects = model.getJavaProjects();
        for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
          JavaProject project = (JavaProject) allProjects[i];
          if (!visitedProjects.includes(project)) {
            IClasspathEntry[] entries = project.getResolvedClasspath();
            for (int j = entries.length; --j >= 0;) {
              IClasspathEntry entry = entries[j];
              if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath path = entry.getPath();
                if (externalLibsToCheck.remove(path) != null) {
                  Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                  if (target instanceof IFolder) // case of an external folder
                    path = ((IFolder) target).getFullPath();
                  locations.add(manager.computeIndexLocation(path));
                }
              }
            }
          }
        }
View Full Code Here

  /* embed constructs inside arrays so as to pass them to (inner) collector */
  final Queue queue = new Queue();
  final HashtableOfObject foundSuperNames = new HashtableOfObject(5);

  IndexManager indexManager = JavaModelManager.getIndexManager();

  /* use a special collector to collect paths and queue new subtype names */
  IndexQueryRequestor searchRequestor = new IndexQueryRequestor() {
    public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
      SuperTypeReferencePattern record = (SuperTypeReferencePattern)indexRecord;
      boolean isLocalOrAnonymous = record.enclosingTypeName == IIndexConstants.ONE_ZERO;
      pathRequestor.acceptPath(documentPath, isLocalOrAnonymous);
      char[] typeName = record.simpleName;
      if (documentPath.toLowerCase().endsWith(SUFFIX_STRING_class)) {
          int suffix = documentPath.length()-SUFFIX_STRING_class.length();
        HierarchyBinaryType binaryType = (HierarchyBinaryType)binariesFromIndexMatches.get(documentPath);
        if (binaryType == null){
          char[] enclosingTypeName = record.enclosingTypeName;
          if (isLocalOrAnonymous) {
            int lastSlash = documentPath.lastIndexOf('/');
            int lastDollar = documentPath.lastIndexOf('$');
            if (lastDollar == -1) {
              // malformed local or anonymous type: it doesn't contain a $ in its name
              // treat it as a top level type
              enclosingTypeName = null;
              typeName = documentPath.substring(lastSlash+1, suffix).toCharArray();
            } else {
              enclosingTypeName = documentPath.substring(lastSlash+1, lastDollar).toCharArray();
              typeName = documentPath.substring(lastDollar+1, suffix).toCharArray();
            }
          }
          binaryType = new HierarchyBinaryType(record.modifiers, record.pkgName, typeName, enclosingTypeName, record.typeParameterSignatures, record.classOrInterface);
          binariesFromIndexMatches.put(documentPath, binaryType);
        }
        binaryType.recordSuperType(record.superSimpleName, record.superQualification, record.superClassOrInterface);
      }
      if (!isLocalOrAnonymous // local or anonymous types cannot have subtypes outside the cu that define them
          && !foundSuperNames.containsKey(typeName)){
        foundSuperNames.put(typeName, typeName);
        queue.add(typeName);
      }
      return true;
    }
  };

  int superRefKind;
  try {
    superRefKind = type.isClass() ? SuperTypeReferencePattern.ONLY_SUPER_CLASSES : SuperTypeReferencePattern.ALL_SUPER_TYPES;
  } catch (JavaModelException e) {
    superRefKind = SuperTypeReferencePattern.ALL_SUPER_TYPES;
  }
  SuperTypeReferencePattern pattern =
    new SuperTypeReferencePattern(null, null, superRefKind, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
  MatchLocator.setFocus(pattern, type);
  SubTypeSearchJob job = new SubTypeSearchJob(
    pattern,
    new JavaSearchParticipant(), // java search only
    scope,
    searchRequestor);

  int ticks = 0;
  queue.add(type.getElementName().toCharArray());
  try {
    while (queue.start <= queue.end) {
      if (progressMonitor != null && progressMonitor.isCanceled()) return;

      // all subclasses of OBJECT are actually all types
      char[] currentTypeName = queue.retrieve();
      if (CharOperation.equals(currentTypeName, IIndexConstants.OBJECT))
        currentTypeName = null;

      // search all index references to a given supertype
      pattern.superSimpleName = currentTypeName;
      indexManager.performConcurrentJob(job, waitingPolicy, progressMonitor == null ? null : new NullProgressMonitor() {
        // don't report progress since this is too costly for deep hierarchies (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=34078 )
        // just handle isCanceled() (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=179511 )
        public void setCanceled(boolean value) {
          progressMonitor.setCanceled(value);
        }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.core.search.indexing.IndexManager

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.