List of usage examples for org.eclipse.jdt.internal.compiler.util SimpleSet includes
public boolean includes(Object object)
From source file:com.codenvy.ide.ext.java.server.internal.core.builder.ClasspathJar.java
License:Open Source License
public boolean isPackage(String qualifiedPackageName) { SimpleSet knownPackages = getKnownPackages(); return knownPackages.includes(qualifiedPackageName); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
public void cleanUpIndexes() { SimpleSet knownPaths = new SimpleSet(); IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope(); PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(this), scope, null, this); Index[] selectedIndexes = job.getIndexes(null); for (int i = 0, l = selectedIndexes.length; i < l; i++) { IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation(); knownPaths.add(IndexLocation);/*from w w w . ja v a2 s .c o m*/ } 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); } deleteIndexFiles(knownPaths); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
private void deleteIndexFiles(SimpleSet pathsToKeep) { File[] indexesFiles = getSavedIndexesDirectory().listFiles(); if (indexesFiles == null) return;//from w w w . j a v a2s. co m for (int i = 0, l = indexesFiles.length; i < l; i++) { String fileName = indexesFiles[i].getAbsolutePath(); if (pathsToKeep != null && pathsToKeep.includes(new FileIndexLocation(indexesFiles[i]))) continue; String suffix = ".index"; //$NON-NLS-1$ if (fileName.regionMatches(true, fileName.length() - suffix.length(), suffix, 0, suffix.length())) { if (VERBOSE || DEBUG) Util.verbose("Deleting index file " + indexesFiles[i]); //$NON-NLS-1$ indexesFiles[i].delete(); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java
License:Open Source License
private void initializeIndexLocations() { IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars(); // use a linked set to preserve the order during search: see bug 348507 LinkedHashSet locations = new LinkedHashSet(); IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern); if (focus == null) { for (int i = 0; i < projectsAndJars.length; i++) { IPath path = projectsAndJars[i]; Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); locations.add(indexManager.computeIndexLocation(path)); }/*from w w w . j a v a 2 s . c om*/ } 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(indexManager.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(indexManager.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(indexManager.computeIndexLocation(path)); } } } } } } } catch (JavaModelException e) { // ignored } } locations.remove(null); // Ensure no nulls this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.IntersectingPattern.java
License:Open Source License
public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException { if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); resetQuery();/*w ww . jav a 2 s .c om*/ SimpleSet intersectedNames = null; try { index.startQuery(); do { SearchPattern pattern = currentPattern(); EntryResult[] entries = pattern.queryIn(index); if (entries == null) return; SearchPattern decodedResult = pattern.getBlankPattern(); SimpleSet newIntersectedNames = new SimpleSet(3); for (int i = 0, l = entries.length; i < l; i++) { if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); EntryResult entry = entries[i]; decodedResult.decodeIndexKey(entry.getWord()); if (pattern.matchesDecodedKey(decodedResult)) { String[] names = entry.getDocumentNames(index); if (intersectedNames != null) { for (int j = 0, n = names.length; j < n; j++) if (intersectedNames.includes(names[j])) newIntersectedNames.add(names[j]); } else { for (int j = 0, n = names.length; j < n; j++) newIntersectedNames.add(names[j]); } } } if (newIntersectedNames.elementSize == 0) return; intersectedNames = newIntersectedNames; } while (hasNextQuery()); } finally { index.stopQuery(); } String containerPath = index.containerPath; char separator = index.separator; Object[] names = intersectedNames.values; for (int i = 0, l = names.length; i < l; i++) if (names[i] != null) acceptMatch((String) names[i], containerPath, separator, null/*no pattern*/, requestor, participant, scope, progressMonitor); // AndPatterns cannot provide the decoded result }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void reportDeclaration(ReferenceBinding typeBinding, int maxType, MatchLocator locator, SimpleSet knownTypes) throws CoreException { IType type = locator.lookupType(typeBinding); if (type == null) return; // case of a secondary type IResource resource = type.getResource(); boolean isBinary = type.isBinary(); IBinaryType info = null;//from w w w. ja v a2 s . c o m if (isBinary) { if (resource == null) resource = type.getJavaProject().getProject(); info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile) type.getClassFile(), resource); } while (maxType >= 0 && type != null) { if (!knownTypes.includes(type)) { if (isBinary) { locator.reportBinaryMemberDeclaration(resource, type, typeBinding, info, SearchMatch.A_ACCURATE); } else { if (typeBinding instanceof ParameterizedTypeBinding) typeBinding = ((ParameterizedTypeBinding) typeBinding).genericType(); ClassScope scope = ((SourceTypeBinding) typeBinding).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; int offset = typeDecl.sourceStart; this.match = new TypeDeclarationMatch(((JavaElement) type).resolved(typeBinding), SearchMatch.A_ACCURATE, offset, typeDecl.sourceEnd - offset + 1, locator.getParticipant(), resource); locator.report(this.match); } } knownTypes.add(type); } typeBinding = typeBinding.enclosingType(); IJavaElement parent = type.getParent(); if (parent instanceof IType) { type = (IType) parent; } else { type = null; } maxType--; } }
From source file:org.eclipse.ajdt.internal.core.builder.ClasspathJar.java
License:Open Source License
/** * Calculate and cache the package list available in the zipFile. * @param zipFile The zip file to use//from ww w. j a v a2s .c o m * @return A SimpleSet with the all the package names in the zipFile. */ static SimpleSet findPackageSet(ZipFile zipFile) { String zipFileName = zipFile.getName(); File zipFileObject = new File(zipFileName); long lastModified = zipFileObject.lastModified(); long fileSize = zipFileObject.length(); PackageCacheEntry cacheEntry = (PackageCacheEntry) PackageCache.get(zipFileName); if (cacheEntry != null && cacheEntry.lastModified == lastModified && cacheEntry.fileSize == fileSize) return cacheEntry.packageSet; SimpleSet packageSet = new SimpleSet(41); packageSet.add(""); //$NON-NLS-1$ nextEntry: for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { String fileName = ((ZipEntry) e.nextElement()).getName(); // add the package name & all of its parent packages int last = fileName.lastIndexOf('/'); while (last > 0) { // extract the package name String packageName = fileName.substring(0, last); if (packageSet.includes(packageName)) continue nextEntry; packageSet.add(packageName); last = packageName.lastIndexOf('/'); } } PackageCache.put(zipFileName, new PackageCacheEntry(lastModified, fileSize, packageSet)); return packageSet; }
From source file:org.eclipse.che.jdt.internal.core.search.indexing.IndexManager.java
License:Open Source License
public void cleanUpIndexes() { SimpleSet knownPaths = new SimpleSet(); IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope(); PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(this, javaProject), scope, null, this); Index[] selectedIndexes = job.getIndexes(null); for (int i = 0, l = selectedIndexes.length; i < l; i++) { IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation(); knownPaths.add(IndexLocation);/*from ww w .j a v a 2 s .c o m*/ } 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); } deleteIndexFiles(knownPaths); }
From source file:org.eclipse.che.jdt.internal.core.search.IndexSelector.java
License:Open Source License
private void initializeIndexLocations() { IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars(); // use a linked set to preserve the order during search: see bug 348507 LinkedHashSet locations = new LinkedHashSet(); IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern); if (focus == null) { for (int i = 0; i < projectsAndJars.length; i++) { IPath path = projectsAndJars[i]; Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); locations.add(indexManager.computeIndexLocation(path)); }/*from ww w . jav a 2 s . c o m*/ } 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); int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames); if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) { locations.add(indexManager.computeIndexLocation(path)); } if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) { 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(indexManager.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(indexManager.computeIndexLocation(path)); } } } } } } } catch (JavaModelException e) { // ignored } } locations.remove(null); // Ensure no nulls this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Connect type variable supertypes, and returns true if no problem was detected * @param typeParameters/*from w w w .j a v a2s. c o m*/ * @param checkForErasedCandidateCollisions */ protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) { /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 - We used to not bother with connecting type variables if source level is < 1.5. This creates problems in the reconciler if a 1.4 project references the generified API of a 1.5 project. The "current" project's source level cannot decide this question for some other project. Now, if we see type parameters at all, we assume that the concerned java element has some legitimate business with them. */ if (typeParameters == null || typeParameters.length == 0) return true; Map invocations = new HashMap(2); boolean noProblems = true; // preinitializing each type variable for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { TypeParameter typeParameter = typeParameters[i]; TypeVariableBinding typeVariable = typeParameter.binding; if (typeVariable == null) return false; typeVariable.superclass = getJavaLangObject(); typeVariable.superInterfaces = Binding.NO_SUPERINTERFACES; // set firstBound to the binding of the first explicit bound in parameter declaration typeVariable.firstBound = null; // first bound used to compute erasure } nextVariable: for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { TypeParameter typeParameter = typeParameters[i]; TypeVariableBinding typeVariable = typeParameter.binding; TypeReference typeRef = typeParameter.type; if (typeRef == null) continue nextVariable; boolean isFirstBoundTypeVariable = false; TypeBinding superType = this.kind == METHOD_SCOPE ? typeRef.resolveType((BlockScope) this, false/*no bound check*/) : typeRef.resolveType((ClassScope) this); if (superType == null) { typeVariable.tagBits |= TagBits.HierarchyHasProblems; } else { typeRef.resolvedType = superType; // hold onto the problem type firstBound: { switch (superType.kind()) { case Binding.ARRAY_TYPE: problemReporter().boundCannotBeArray(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; break firstBound; // do not keep first bound case Binding.TYPE_PARAMETER: isFirstBoundTypeVariable = true; TypeVariableBinding varSuperType = (TypeVariableBinding) superType; if (varSuperType.rank >= typeVariable.rank && varSuperType.declaringElement == typeVariable.declaringElement) { if (compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6) { problemReporter().forwardTypeVariableReference(typeParameter, varSuperType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; break firstBound; // do not keep first bound } } // 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; } } } } break; default: if (((ReferenceBinding) superType).isFinal()) { problemReporter().finalVariableBound(typeVariable, typeRef); } break; } ReferenceBinding superRefType = (ReferenceBinding) superType; if (!superType.isInterface()) { typeVariable.superclass = superRefType; } else { typeVariable.superInterfaces = new ReferenceBinding[] { superRefType }; } typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences; typeVariable.firstBound = superRefType; // first bound used to compute erasure } } TypeReference[] boundRefs = typeParameter.bounds; if (boundRefs != null) { nextBound: for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) { typeRef = boundRefs[j]; superType = this.kind == METHOD_SCOPE ? typeRef.resolveType((BlockScope) this, false) : typeRef.resolveType((ClassScope) this); if (superType == null) { typeVariable.tagBits |= TagBits.HierarchyHasProblems; continue nextBound; } else { typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences; boolean didAlreadyComplain = !typeRef.resolvedType.isValidBinding(); if (isFirstBoundTypeVariable && j == 0) { problemReporter().noAdditionalBoundAfterTypeVariable(typeRef); typeVariable.tagBits |= TagBits.HierarchyHasProblems; didAlreadyComplain = true; //continue nextBound; - keep these bounds to minimize secondary errors } else if (superType.isArrayType()) { if (!didAlreadyComplain) { problemReporter().boundCannotBeArray(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; } continue nextBound; } else { if (!superType.isInterface()) { if (!didAlreadyComplain) { problemReporter().boundMustBeAnInterface(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; } continue nextBound; } } // check against superclass if (checkForErasedCandidateCollisions && typeVariable.firstBound == typeVariable.superclass) { if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations, typeVariable, typeRef)) { continue nextBound; } } // check against superinterfaces ReferenceBinding superRefType = (ReferenceBinding) superType; for (int index = typeVariable.superInterfaces.length; --index >= 0;) { ReferenceBinding previousInterface = typeVariable.superInterfaces[index]; if (previousInterface == superRefType) { problemReporter().duplicateBounds(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; continue nextBound; } if (checkForErasedCandidateCollisions) { if (hasErasedCandidatesCollisions(superType, previousInterface, invocations, typeVariable, typeRef)) { continue nextBound; } } } int size = typeVariable.superInterfaces.length; System.arraycopy(typeVariable.superInterfaces, 0, typeVariable.superInterfaces = new ReferenceBinding[size + 1], 0, size); typeVariable.superInterfaces[size] = superRefType; } } } noProblems &= (typeVariable.tagBits & TagBits.HierarchyHasProblems) == 0; } return noProblems; }