/** * @param matchList a List of SearchMatch * @param status the status to report errors. * @return a SearchResultGroup[], grouped by SearchMatch#getResource() */ public static SearchResultGroup[] groupByCu( List<SearchMatch> matchList, RefactoringStatus status) { Map<IResource, List<SearchMatch>> grouped = new HashMap<IResource, List<SearchMatch>>(); boolean hasPotentialMatches = false; boolean hasNonCuMatches = false; for (SearchMatch searchMatch : matchList) { if (searchMatch.getAccuracy() == SearchMatch.A_INACCURATE) hasPotentialMatches = true; if (!grouped.containsKey(searchMatch.getResource())) grouped.put(searchMatch.getResource(), new ArrayList<SearchMatch>(1)); grouped.get(searchMatch.getResource()).add(searchMatch); } for (Iterator<IResource> iter = grouped.keySet().iterator(); iter.hasNext(); ) { IResource resource = iter.next(); IModelElement element = DLTKCore.create(resource); if (!(element instanceof ISourceModule)) { iter.remove(); hasNonCuMatches = true; } } SearchResultGroup[] result = new SearchResultGroup[grouped.keySet().size()]; int i = 0; for (IResource resource : grouped.keySet()) { List<SearchMatch> searchMatches = grouped.get(resource); SearchMatch[] matchArray = searchMatches.toArray(new SearchMatch[searchMatches.size()]); result[i] = new SearchResultGroup(resource, matchArray); i++; } addStatusErrors(status, hasPotentialMatches, hasNonCuMatches); return result; }
public void acceptSearchMatch(SearchMatch match) { if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) { hasPotentialMatches = true; } if (fLastResource != match.getResource()) { fLastResource = match.getResource(); resources.add(fLastResource); } }
public void process(IProject project, String pattern) { // test code, right now, I used the PHPSearchEngine class cut from another project ///////// Note: there is an real library API org.eclipse.php.internal.core.util.PHPSearchEngine. // I need to check details System.out.println("begining a iteration for pattern " + pattern); String elementName = null; SearchMatch[] newMatches = null; SearchMatch[] matches = PHPSearchEngine.findMethodCall(pattern, PHPSearchEngine.createProjectScope(project)); // must distinguish between method declaration and method call!!!! IModelElement iModelElement; Object obj = null; if (matches.length > 0) { for (SearchMatch match : matches) { obj = match.getElement(); if (obj instanceof IModelElement) { iModelElement = (IModelElement) obj; elementName = iModelElement.getElementName(); System.out.println( "iModelElement.getElementName() = " + elementName + " --path= " + iModelElement.getPath().toString()); if (!elementName.equals( pattern)) { // avoid recursive, or iterative method, temp implementation, should be // modified!!!! pattern = elementName; System.out.println("begining next iteration"); process(project, pattern); System.out.println("return from an iteration"); } else { // it is recursive/iterative, we regard it as the top level method call (temp // implementation!!!!!) System.out.println( "Top Level(recursive reason): " + "iModelElement.getElementName() = " + elementName + " --path= " + iModelElement.getPath().toString()); } } } } else { // if there is no callers, then means it is the top level System.out.println("Top Level(real reason): " + "pattern = " + pattern); } System.out.println("end of an iteration"); }