1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.jdt.core.IPackageFragmentRoot; 15 import org.eclipse.jdt.internal.compiler.util.ObjectVector; 16 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; 17 18 21 public class PossibleMatchSet { 22 23 private SimpleLookupTable rootsToPossibleMatches = new SimpleLookupTable(5); 24 private int elementCount = 0; 25 26 public void add(PossibleMatch possibleMatch) { 27 IPath path = possibleMatch.openable.getPackageFragmentRoot().getPath(); 28 ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(path); 29 if (possibleMatches != null) { 30 if (possibleMatches.contains(possibleMatch)) return; 31 } else { 32 this.rootsToPossibleMatches.put(path, possibleMatches = new ObjectVector()); 33 } 34 35 possibleMatches.add(possibleMatch); 36 this.elementCount++; 37 } 38 public PossibleMatch[] getPossibleMatches(IPackageFragmentRoot[] roots) { 39 PossibleMatch[] result = new PossibleMatch[this.elementCount]; 40 int index = 0; 41 for (int i = 0, length = roots.length; i < length; i++) { 42 ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(roots[i].getPath()); 43 if (possibleMatches != null) { 44 possibleMatches.copyInto(result, index); 45 index += possibleMatches.size(); 46 } 47 } 48 if (index < this.elementCount) 49 System.arraycopy(result, 0, result = new PossibleMatch[index], 0, index); 50 return result; 51 } 52 public void reset() { 53 this.rootsToPossibleMatches = new SimpleLookupTable(5); 54 this.elementCount = 0; 55 } 56 } 57 | Popular Tags |