List of usage examples for org.eclipse.jdt.internal.compiler.util SimpleSet SimpleSet
public SimpleSet(int size)
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 www. j a v a2s .c o 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.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);//from w w w. j a va 2 s .co m 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; } } } // 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)); }//from www.ja v a2s . 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 a2 s . c o m 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.MatchLocator.java
License:Open Source License
/** * Visit the given resolved parse tree and report the nodes that match the search pattern. *//*ww w. j a v a 2 s . c o m*/ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResolve) throws CoreException { MatchingNodeSet nodeSet = this.currentPossibleMatch.nodeSet; boolean locatorMustResolve = this.patternLocator.mustResolve; if (nodeSet.mustResolve) this.patternLocator.mustResolve = true; if (BasicSearchEngine.VERBOSE) { System.out.println("Report matching: "); //$NON-NLS-1$ 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$ System.out.print(" - must resolve: " + mustResolve); //$NON-NLS-1$ System.out.print(" (locator: " + this.patternLocator.mustResolve); //$NON-NLS-1$ System.out.println(", nodeSet: " + nodeSet.mustResolve + ')'); //$NON-NLS-1$ System.out.println(" - fine grain flags=" //$NON-NLS-1$ + JavaSearchPattern.getFineGrainFlagString(this.patternLocator.fineGrain())); } if (mustResolve) { this.unitScope = unit.scope.compilationUnitScope(); // move the possible matching nodes that exactly match the search pattern to the matching nodes set Object[] nodes = nodeSet.possibleMatchingNodesSet.values; for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = (ASTNode) nodes[i]; if (node == null) continue; if (node instanceof ImportReference) { // special case for import refs: they don't know their binding // import ref cannot be in the hierarchy of a type if (this.hierarchyResolver != null) continue; ImportReference importRef = (ImportReference) node; Binding binding = (importRef.bits & ASTNode.OnDemand) != 0 ? this.unitScope.getImport( CharOperation.subarray(importRef.tokens, 0, importRef.tokens.length), true, importRef.isStatic()) : this.unitScope.getImport(importRef.tokens, false, importRef.isStatic()); 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$ } } else { this.unitScope = null; } if (nodeSet.matchingNodes.elementSize == 0) return; // no matching nodes were found this.methodHandles = new HashSet(); boolean matchedUnitContainer = (this.matchContainer & PatternLocator.COMPILATION_UNIT_CONTAINER) != 0; // report references in javadoc if (unit.javadoc != null) { ASTNode[] nodes = nodeSet.matchingNodes(unit.javadoc.sourceStart, unit.javadoc.sourceEnd); if (nodes != null) { if (!matchedUnitContainer) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { IJavaElement element = createPackageDeclarationHandle(unit); for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); if (encloses(element)) { this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/, level.intValue(), this); } } } } } if (matchedUnitContainer) { ImportReference pkg = unit.currentPackage; if (pkg != null && pkg.annotations != null) { IJavaElement element = createPackageDeclarationHandle(unit); if (element != null) { reportMatching(pkg.annotations, element, null, null, nodeSet, true, encloses(element)); } } ImportReference[] imports = unit.imports; if (imports != null) { for (int i = 0, l = imports.length; i < l; i++) { ImportReference importRef = imports[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(importRef); if (level != null) { this.patternLocator.matchReportImportRef(importRef, null /*no binding*/, createImportHandle(importRef), level.intValue(), this); } } } } TypeDeclaration[] types = unit.types; if (types != null) { for (int i = 0, l = types.length; i < l; i++) { if (nodeSet.matchingNodes.elementSize == 0) return; // reported all the matching nodes TypeDeclaration type = types[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(type); int accuracy = (level != null && matchedUnitContainer) ? level.intValue() : -1; reportMatching(type, null, accuracy, nodeSet, 1); } } // Clear handle cache this.methodHandles = null; this.bindings.removeKey(this.pattern); this.patternLocator.mustResolve = locatorMustResolve; }
From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java
License:Open Source License
protected AbstractImageBuilder(JavaBuilder javaBuilder, boolean buildStarting, State newState) { // local copies this.javaBuilder = javaBuilder; this.nameEnvironment = javaBuilder.nameEnvironment; this.sourceLocations = this.nameEnvironment.sourceLocations; this.notifier = javaBuilder.notifier; this.keepStoringProblemMarkers = true; // may get disabled when missing classfiles are encountered if (buildStarting) { this.newState = newState == null ? new State(javaBuilder) : newState; this.compiler = newCompiler(); this.workQueue = new WorkQueue(); this.problemSourceFiles = new ArrayList(3); if (this.javaBuilder.participants != null) { for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++) { if (this.javaBuilder.participants[i].isAnnotationProcessor()) { // initialize this set so the builder knows to gather CUs that define Annotation types // each Annotation processor participant is then asked to process these files AFTER // the compile loop. The normal dependency loop will then recompile all affected types this.filesWithAnnotations = new SimpleSet(1); break; }/*from w ww. j a v a2s.c o m*/ } } } }
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;/*from ww w . j a v a2 s . c o m*/ 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]); } 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/*from ww w . ja va2 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:net.sf.j2s.core.builder.NameEnvironment.java
License:Open Source License
void setNames(String[] typeNames, SourceFile[] additionalFiles) { // convert the initial typeNames to a set if (typeNames == null) { this.initialTypeNames = null; } else {//from w w w . j a va 2 s .c o m this.initialTypeNames = new SimpleSet(typeNames.length); for (int i = 0, l = typeNames.length; i < l; i++) this.initialTypeNames.add(typeNames[i]); } // map the additional source files by qualified type name if (additionalFiles == null) { this.additionalUnits = null; } else { this.additionalUnits = new SimpleLookupTable(additionalFiles.length); for (int i = 0, l = additionalFiles.length; i < l; i++) { SourceFile additionalUnit = additionalFiles[i]; if (additionalUnit != null) this.additionalUnits.put(additionalUnit.initialTypeName, additionalFiles[i]); } } for (int i = 0, l = this.sourceLocations.length; i < l; i++) this.sourceLocations[i].reset(); for (int i = 0, l = this.binaryLocations.length; i < l; i++) this.binaryLocations[i].reset(); }
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//w w w . jav a 2s . 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; }