|
From: David C. <dc...@us...> - 2005-11-12 19:16:08
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25492/src/org/rubypeople/rdt/internal/core/symbols Modified Files: Location.java SymbolIndex.java Log Message: 1) refactored RubyBuilder again, this time with better unit tests. 2) refactored Location (and SymbolIndex) to be IFile based, rather than IPath based. 3) general improvement on maintainence of the SymbolIndex. Index: Location.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/Location.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Location.java 23 Oct 2005 19:43:34 -0000 1.4 --- Location.java 12 Nov 2005 19:15:59 -0000 1.5 *************** *** 12,35 **** package org.rubypeople.rdt.internal.core.symbols; ! import org.eclipse.core.runtime.IPath; ! import org.eclipse.core.runtime.Path; import org.jruby.lexer.yacc.ISourcePosition; public class Location { - private final IPath sourcePath; private final ISourcePosition position; ! public Location(IPath sourcePath, ISourcePosition position) { ! this.sourcePath = sourcePath; this.position = position; } public String toString() { ! return sourcePath+": " + position; } ! public boolean forSource(Path path) { ! return sourcePath.equals(path); } --- 12,34 ---- package org.rubypeople.rdt.internal.core.symbols; ! import org.eclipse.core.resources.IFile; import org.jruby.lexer.yacc.ISourcePosition; public class Location { private final ISourcePosition position; + private final IFile sourceFile; ! public Location(IFile sourceFile, ISourcePosition position) { ! this.sourceFile = sourceFile; this.position = position; } public String toString() { ! return sourceFile+": " + position; } ! public boolean forSource(IFile file) { ! return sourceFile.equals(file); } *************** *** 39,52 **** Location that = (Location) obj; ! return this.sourcePath.equals(that.sourcePath) && this.position.equals(that.position); } public int hashCode() { ! return sourcePath.hashCode() * position.hashCode(); } public String getFilename() { ! return sourcePath.toOSString(); } --- 38,51 ---- Location that = (Location) obj; ! return this.sourceFile.equals(that.sourceFile) && this.position.equals(that.position); } public int hashCode() { ! return sourceFile.hashCode() * position.hashCode(); } public String getFilename() { ! return sourceFile.getLocation().toOSString(); } *************** *** 55,61 **** } ! public IPath getSourcePath() { ! return sourcePath ; } } --- 54,60 ---- } ! public IFile getSourceFile() { ! return sourceFile; } } Index: SymbolIndex.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/SymbolIndex.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SymbolIndex.java 23 Oct 2005 22:24:27 -0000 1.8 --- SymbolIndex.java 12 Nov 2005 19:15:59 -0000 1.9 *************** *** 22,45 **** import org.eclipse.core.resources.IFile; ! import org.eclipse.core.runtime.IPath; import org.jruby.lexer.yacc.ISourcePosition; public class SymbolIndex { private Map index = Collections.synchronizedMap(new HashMap()); private static boolean verbose; public void add(Symbol symbol, Location location) { ! Set locations = (Set) index.get(symbol); ! if (locations == null) { ! locations = new HashSet(); ! index.put(symbol, locations); } - locations.add(location); } public void add(Symbol symbol, IFile file, ISourcePosition position) { ! SymbolIndex.log("Adding Symbol: " + symbol) ; ! add(symbol, new Location(file.getFullPath(), position)); } --- 22,49 ---- import org.eclipse.core.resources.IFile; ! import org.eclipse.core.resources.IProject; import org.jruby.lexer.yacc.ISourcePosition; public class SymbolIndex { + private Map index = Collections.synchronizedMap(new HashMap()); private static boolean verbose; public void add(Symbol symbol, Location location) { ! if (verbose) ! log("Adding " + symbol + " at " + location); ! synchronized(index) { ! Set locations = (Set) index.get(symbol); ! if (locations == null) { ! locations = new HashSet(); ! index.put(symbol, locations); ! } ! locations.add(location); } } public void add(Symbol symbol, IFile file, ISourcePosition position) { ! add(symbol, new Location(file, position)); } *************** *** 76,82 **** } ! public void flush(IPath foo_path) { ! SymbolIndex.log("Flushing all Symbols with path: " + foo_path) ; synchronized (index) { for (Iterator indexIter = index.entrySet().iterator(); indexIter.hasNext();) { --- 80,114 ---- } ! public void flush(IFile fileToFlush) { ! if (verbose) ! log("Flushing all Symbols with path: " + fileToFlush) ; + flush(new PathEqualsPredicate(fileToFlush)); + } + + public static void setVerbose(boolean verbose) { + SymbolIndex.verbose = verbose; + } + + private static boolean isVerbose() { + return verbose; + } + + private static void log(String message) { + if (!SymbolIndex.isVerbose()) { + return ; + } + System.out.println(message) ; + } + + public void flush(IProject project) { + if (verbose) + log("Flushing all Symbols for project: " + project) ; + + flush(new ContainedByProject(project)); + + } + + private void flush(Predicate predicate) { synchronized (index) { for (Iterator indexIter = index.entrySet().iterator(); indexIter.hasNext();) { *************** *** 86,91 **** for (Iterator locationIter = locations.iterator(); locationIter.hasNext();) { Location location = (Location) locationIter.next(); ! if (location.getSourcePath() == foo_path) { ! locationIter.remove(); } } --- 118,126 ---- for (Iterator locationIter = locations.iterator(); locationIter.hasNext();) { Location location = (Location) locationIter.next(); ! if (predicate.evaluate(location.getSourceFile())) { ! locationIter.remove(); ! ! if (verbose) ! log("Removing " + location); } } *************** *** 97,115 **** } ! public static void setVerbose(boolean verbose) { ! SymbolIndex.verbose = verbose; ! } ! ! public static boolean isVerbose() { ! return verbose; } ! ! public static void log(String message) { ! if (!SymbolIndex.isVerbose()) { ! return ; ! } ! System.out.println(message) ; } } --- 132,164 ---- } ! ! private static class PathEqualsPredicate implements Predicate { ! private final IFile fileToFlush; ! ! public PathEqualsPredicate(IFile file) { ! this.fileToFlush = file; ! } ! ! public boolean evaluate(Object object) { ! return object.equals(fileToFlush); ! } } ! ! interface Predicate { ! boolean evaluate(Object object); } + private static class ContainedByProject implements Predicate { + + private final IProject project; + + public ContainedByProject(IProject project) { + this.project = project; + } + public boolean evaluate(Object object) { + IFile file = (IFile) object; + return file.getProject().equals(project); + } + } } |