Package org.eclipse.jdt.internal.compiler.util

Examples of org.eclipse.jdt.internal.compiler.util.SimpleSet


}
/*
* Removes unused indexes from disk.
*/
public void cleanUpIndexes() {
  SimpleSet knownPaths = new SimpleSet();
  IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope();
  PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null);
  Index[] selectedIndexes = job.getIndexes(null);
  for (int i = 0, l = selectedIndexes.length; i < l; i++) {
    IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation();
    knownPaths.add(IndexLocation);
  }

  if (this.indexStates != null) {
    Object[] keys = this.indexStates.keyTable;
    IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize];
    int count = 0;
    for (int i = 0, l = keys.length; i < l; i++) {
      IndexLocation key = (IndexLocation) keys[i];
      if (key != null && !knownPaths.includes(key))
        locations[count++] = key;
    }
    if (count > 0)
      removeIndexesState(locations);
  }
View Full Code Here


    String selector = new String(methodPattern.selector);
    int parameterCount = methodPattern.parameterCount;
    ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null);
    IType[] allTypes = superHierarchy.getAllSupertypes(type);
    int length = allTypes.length;
    SimpleSet focusSet = new SimpleSet(length+1);
    if (focusElement != null) focusSet.add(focusElement);
    for (int i=0; i<length; i++) {
      IMethod[] methods = allTypes[i].getMethods();
      int mLength = methods.length;
      for (int m=0; m<mLength; m++) {
        if (parameterCount == methods[m].getNumberOfParameters() && methods[m].getElementName().equals(selector)) {
          IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
          IJavaElement element = root.isArchive() ? root : root.getParent();
          focusSet.add(element);
          if (superTypes != null) superTypes.add(allTypes[i]);
          break;
        }
      }
    }
View Full Code Here

      // 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

    }
    PackageDeclarationPattern pkgPattern = (PackageDeclarationPattern) searchPattern;
    boolean isWorkspaceScope = this.scope == JavaModelManager.getJavaModelManager().getWorkspaceScope();
    IPath[] scopeProjectsAndJars =  isWorkspaceScope ? null : this.scope.enclosingProjectsAndJars();
    int scopeLength = isWorkspaceScope ? 0 : scopeProjectsAndJars.length;
    SimpleSet packages = new SimpleSet();
    for (int i = 0, length = projects.length; i < length; i++) {
      IJavaProject javaProject = projects[i];
      if (this.progressMonitor != null) {
        if (this.progressMonitor.isCanceled()) throw new OperationCanceledException();
        this.progressWorked++;
        if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
      }
      // Verify that project belongs to the scope
      if (!isWorkspaceScope) {
        boolean found = false;
        for (int j=0; j<scopeLength; j++) {
          if (javaProject.getPath().equals(scopeProjectsAndJars[j])) {
            found = true;
            break;
          }
        }
        if (!found) continue;
      }
      // Get all project package fragment names
      this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
      IPackageFragment[] packageFragments = this.nameLookup.findPackageFragments(new String(pkgPattern.pkgName), false, true);
      int pLength = packageFragments == null ? 0 : packageFragments.length;
      // Report matches avoiding duplicate names
      for (int p=0; p<pLength; p++) {
        IPackageFragment fragment = packageFragments[p];
        if (packages.addIfNotIncluded(fragment) == null) continue;
        if (encloses(fragment)) {
          IResource resource = fragment.getResource();
          if (resource == null) // case of a file in an external jar
            resource = javaProject.getProject();
          try {
View Full Code Here

        this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this);
      } else {
        nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
      }
    }
    nodeSet.possibleMatchingNodesSet = new SimpleSet(3);
    if (BasicSearchEngine.VERBOSE) {
      int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.elementSize;
      System.out.print("  - node set: accurate="+size); //$NON-NLS-1$
      size = nodeSet.possibleMatchingNodesSet==null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize;
      System.out.println(", possible="+size); //$NON-NLS-1$
View Full Code Here

                }
              }
              // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335751
              if (compilerOptions().complianceLevel > ClassFileConstants.JDK1_6) {
                if (typeVariable.rank >= varSuperType.rank && varSuperType.declaringElement == typeVariable.declaringElement) {
                  SimpleSet set = new SimpleSet(typeParameters.length);
                  set.add(typeVariable);
                  ReferenceBinding superBinding = varSuperType;
                  while (superBinding instanceof TypeVariableBinding) {
                    if (set.includes(superBinding)) {
                      problemReporter().hierarchyCircularity(typeVariable, varSuperType, typeRef);
                      typeVariable.tagBits |= TagBits.HierarchyHasProblems;
                      break firstBound; // do not keep first bound
                    } else {
                      set.add(superBinding);
                      superBinding = ((TypeVariableBinding)superBinding).superclass;
                    }
                  }
                }
              }
View Full Code Here

                    mostSpecificExceptions = current.thrownExceptions;
                  }
                  int mostSpecificLength = mostSpecificExceptions.length;
                  ReferenceBinding[] nextExceptions = getFilteredExceptions(next);
                  int nextLength = nextExceptions.length;
                  SimpleSet temp = new SimpleSet(mostSpecificLength);
                  boolean changed = false;
                  nextException : for (int t = 0; t < mostSpecificLength; t++) {
                    ReferenceBinding exception = mostSpecificExceptions[t];
                    for (int s = 0; s < nextLength; s++) {
                      ReferenceBinding nextException = nextExceptions[s];
                      if (exception.isCompatibleWith(nextException)) {
                        temp.add(exception);
                        continue nextException;
                      } else if (nextException.isCompatibleWith(exception)) {
                        temp.add(nextException);
                        changed = true;
                        continue nextException;
                      } else {
                        changed = true;
                      }
                    }
                  }
                  if (changed) {
                    mostSpecificExceptions = temp.elementSize == 0 ? Binding.NO_EXCEPTIONS : new ReferenceBinding[temp.elementSize];
                    temp.asArray(mostSpecificExceptions);
                  }
                }
              }
            }
          }
View Full Code Here

      }
    }
  }

  if (!isInconsistent) return null; // hierarchy is consistent so no collisions are possible
  SimpleSet copy = null;
  for (int i = 0; i < nextPosition; i++) {
    ReferenceBinding current = interfacesToVisit[i];
    if (current.isValidBinding()) {
      TypeBinding erasure = current.erasure();
      for (int j = i + 1; j < nextPosition; j++) {
        ReferenceBinding next = interfacesToVisit[j];
        if (next.isValidBinding() && next.erasure() == erasure) {
          if (copy == null)
            copy = new SimpleSet(nextPosition);
          copy.add(interfacesToVisit[i]);
          copy.add(interfacesToVisit[j]);
        }
      }
    }
  }
  return copy;
View Full Code Here

}

void checkForRedundantSuperinterfaces(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
  if (superInterfaces == Binding.NO_SUPERINTERFACES) return;

  SimpleSet interfacesToCheck = new SimpleSet(superInterfaces.length);
  SimpleSet redundantInterfaces = null// bark but once.
  for (int i = 0, l = superInterfaces.length; i < l; i++) {
    ReferenceBinding toCheck = superInterfaces[i];
    for (int j = 0; j < l; j++) {
      ReferenceBinding implementedInterface = superInterfaces[j];
      if (i != j && toCheck.implementsInterface(implementedInterface, true)) {
        if (redundantInterfaces == null) {
          redundantInterfaces = new SimpleSet(3);
        } else if (redundantInterfaces.includes(implementedInterface)) {
          continue;
        }
        redundantInterfaces.add(implementedInterface);
        TypeReference[] refs = this.type.scope.referenceContext.superInterfaces;
        for (int r = 0, rl = refs.length; r < rl; r++) {
          if (refs[r].resolvedType == toCheck) {
            problemReporter().redundantSuperInterface(this.type, refs[j], implementedInterface, toCheck);
            break; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911
          }
        }
      }
    }
    interfacesToCheck.add(toCheck);
  }

  ReferenceBinding[] itsInterfaces = null;
  SimpleSet inheritedInterfaces = new SimpleSet(5);
  ReferenceBinding superType = superclass;
  while (superType != null && superType.isValidBinding()) {
    if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
      for (int i = 0, l = itsInterfaces.length; i < l; i++) {
        ReferenceBinding inheritedInterface = itsInterfaces[i];
        if (!inheritedInterfaces.includes(inheritedInterface) && inheritedInterface.isValidBinding()) {
          if (interfacesToCheck.includes(inheritedInterface)) {
            if (redundantInterfaces == null) {
              redundantInterfaces = new SimpleSet(3);
            } else if (redundantInterfaces.includes(inheritedInterface)) {
              continue;
            }
            redundantInterfaces.add(inheritedInterface);
            TypeReference[] refs = this.type.scope.referenceContext.superInterfaces;
            for (int r = 0, rl = refs.length; r < rl; r++) {
              if (refs[r].resolvedType == inheritedInterface) {
                problemReporter().redundantSuperInterface(this.type, refs[r], inheritedInterface, superType);
                break;
              }
            }
          } else {
            inheritedInterfaces.add(inheritedInterface);
          }
        }
      }
    }
    superType = superType.superclass();
  }

  int nextPosition = inheritedInterfaces.elementSize;
  if (nextPosition == 0) return;
  ReferenceBinding[] interfacesToVisit = new ReferenceBinding[nextPosition];
  inheritedInterfaces.asArray(interfacesToVisit);
  for (int i = 0; i < nextPosition; i++) {
    superType = interfacesToVisit[i];
    if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
      int itsLength = itsInterfaces.length;
      if (nextPosition + itsLength >= interfacesToVisit.length)
        System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
      for (int a = 0; a < itsLength; a++) {
        ReferenceBinding inheritedInterface = itsInterfaces[a];
        if (!inheritedInterfaces.includes(inheritedInterface) && inheritedInterface.isValidBinding()) {
          if (interfacesToCheck.includes(inheritedInterface)) {
            if (redundantInterfaces == null) {
              redundantInterfaces = new SimpleSet(3);
            } else if (redundantInterfaces.includes(inheritedInterface)) {
              continue;
            }
            redundantInterfaces.add(inheritedInterface);
            TypeReference[] refs = this.type.scope.referenceContext.superInterfaces;
            for (int r = 0, rl = refs.length; r < rl; r++) {
              if (refs[r].resolvedType == inheritedInterface) {
                problemReporter().redundantSuperInterface(this.type, refs[r], inheritedInterface, superType);
                break;
              }
            }
          } else {
            inheritedInterfaces.add(inheritedInterface);
            interfacesToVisit[nextPosition++] = inheritedInterface;
          }
        }
      }
    }
View Full Code Here

  } else {
    superInterfaces = (ReferenceBinding[]) superIfcList.toArray(new ReferenceBinding[superIfcList.size()]);
    superInterfaces = Sorting.sortTypes(superInterfaces);
  }
 
  SimpleSet skip = findSuperinterfaceCollisions(superclass, superInterfaces);
  int len = superInterfaces.length;
  for (int i = len-1; i >= 0; i--) {
    superType = superInterfaces[i];
    if (superType.isValidBinding()) {
      if (skip != null && skip.includes(superType)) continue;

      MethodBinding[] methods = superType.unResolvedMethods();
      nextMethod : for (int m = methods.length; --m >= 0;) { // Interface methods are all abstract public
        MethodBinding inheritedMethod = methods[m];
        MethodBinding[] existingMethods = (MethodBinding[]) this.inheritedMethods.get(inheritedMethod.selector);
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.util.SimpleSet

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.