List of usage examples for org.eclipse.jdt.internal.compiler.util SimpleSet add
public Object add(Object object)
From source file:com.codenvy.ide.ext.java.server.internal.core.builder.ClasspathJar.java
License:Open Source License
/** * Calculate and cache the package list available in the zipFile. * * @param jar//from ww w . j a v a 2 s.co m * The ClasspathJar to use * @return A SimpleSet with the all the package names in the zipFile. */ static SimpleSet findPackageSet(ClasspathJar jar) { String zipFileName = jar.zipFilename; SimpleSet packageSet = new SimpleSet(41); packageSet.add(""); //$NON-NLS-1$ nextEntry: for (Enumeration e = jar.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); String[] splittedName = Util.splitOn('/', packageName, 0, packageName.length()); for (String s : splittedName) { if (!org.eclipse.jdt.internal.core.util.Util.isValidFolderNameForPackage(s, "1.7", "1.7")) { continue nextEntry; } } if (packageSet.addIfNotIncluded(packageName) == null) continue nextEntry; // already existed last = packageName.lastIndexOf('/'); } } return packageSet; }
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 . j av a 2s . com 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.IndexSelector.java
License:Open Source License
private static IJavaElement[] getFocusedElementsAndTypes(SearchPattern pattern, IJavaElement focusElement, ObjectVector superTypes) throws JavaModelException { if (pattern instanceof MethodPattern) { // For method pattern, it needs to walk along the focus type super hierarchy // and add jars/projects of all the encountered types. IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE); MethodPattern methodPattern = (MethodPattern) pattern; 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; }//from w ww.jav a2s . c o m } } // Rebuilt a contiguous array IJavaElement[] focuses = new IJavaElement[focusSet.elementSize]; Object[] values = focusSet.values; int count = 0; for (int i = values.length; --i >= 0;) { if (values[i] != null) { focuses[count++] = (IJavaElement) values[i]; } } return focuses; } if (focusElement == null) return new IJavaElement[0]; return new IJavaElement[] { focusElement }; }
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)); }// w w w . j av a2 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); 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();/*from w ww . j a v a 2 s .com*/ 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;/* w w w .j a va 2 s. c om*/ 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:net.sf.j2s.core.builder.AbstractImageBuilder.java
License:Open Source License
protected CompilationParticipantResult[] notifyParticipants(SourceFile[] unitsAboutToCompile) { CompilationParticipantResult[] results = new CompilationParticipantResult[unitsAboutToCompile.length]; for (int i = unitsAboutToCompile.length; --i >= 0;) results[i] = new CompilationParticipantResult(unitsAboutToCompile[i]); // TODO (kent) do we expect to have more than one participant? // and if so should we pass the generated files from the each processor to the others to process? // and what happens if some participants do not expect to be called with only a few files, after seeing 'all' the files? for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++) this.javaBuilder.participants[i].buildStarting(results, this instanceof BatchImageBuilder); SimpleSet uniqueFiles = null; CompilationParticipantResult[] toAdd = null; int added = 0; for (int i = results.length; --i >= 0;) { CompilationParticipantResult result = results[i]; if (result == null) continue; IFile[] deletedGeneratedFiles = result.deletedFiles; if (deletedGeneratedFiles != null) deleteGeneratedFiles(deletedGeneratedFiles); IFile[] addedGeneratedFiles = result.addedFiles; if (addedGeneratedFiles != null) { for (int j = addedGeneratedFiles.length; --j >= 0;) { SourceFile sourceFile = findSourceFile(addedGeneratedFiles[j], true); if (sourceFile == null) continue; if (uniqueFiles == null) { uniqueFiles = new SimpleSet(unitsAboutToCompile.length + 3); for (int f = unitsAboutToCompile.length; --f >= 0;) uniqueFiles.add(unitsAboutToCompile[f]); }/*from w w w .j a va 2s . c om*/ if (uniqueFiles.addIfNotIncluded(sourceFile) == sourceFile) { CompilationParticipantResult newResult = new CompilationParticipantResult(sourceFile); // is there enough room to add all the addedGeneratedFiles.length ? if (toAdd == null) { toAdd = new CompilationParticipantResult[addedGeneratedFiles.length]; } else { int length = toAdd.length; if (added == length) System.arraycopy(toAdd, 0, toAdd = new CompilationParticipantResult[length + addedGeneratedFiles.length], 0, length); } toAdd[added++] = newResult; } } } } if (added > 0) { int length = results.length; System.arraycopy(results, 0, results = new CompilationParticipantResult[length + added], 0, length); System.arraycopy(toAdd, 0, results, length, added); } return results; }
From source file:net.sf.j2s.core.builder.ClasspathJar.java
License:Open Source License
/** * Calculate and cache the package list available in the zipFile. * @param jar The ClasspathJar to use/*ww w. java2 s. c o m*/ * @return A SimpleSet with the all the package names in the zipFile. */ static SimpleSet findPackageSet(ClasspathJar jar) { String zipFileName = jar.zipFilename; long lastModified = jar.lastModified(); long fileSize = new File(zipFileName).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 = jar.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.addIfNotIncluded(packageName) == null) continue nextEntry; // already existed last = packageName.lastIndexOf('/'); } } PackageCache.put(zipFileName, new PackageCacheEntry(lastModified, fileSize, packageSet)); return packageSet; }
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 w ww. j a v a 2s. com * @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 w w w.ja v a 2 s . co 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); }