|
From: David C. <dc...@us...> - 2005-10-02 22:57:02
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8784/src/org/rubypeople/rdt/internal/core/symbols Added Files: Location.java SymbolIndex.java ClassSymbol.java Log Message: Refactored RubyBuilder into several smaller classes. Wrote UTs for a few of them. Began work on a SymbolIndex. --- NEW FILE: ClassSymbol.java --- package org.rubypeople.rdt.internal.core.symbols; public class ClassSymbol { private final String className; public ClassSymbol(String className) { this.className = className; } public boolean equals(Object obj) { if (!(obj instanceof ClassSymbol)) return false; ClassSymbol that = (ClassSymbol) obj; return that.className.equals(this.className); } public int hashCode() { return className.hashCode(); } } --- NEW FILE: Location.java --- package org.rubypeople.rdt.internal.core.symbols; import org.eclipse.core.runtime.Path; public class Location { private final Path sourcePath; private final int line; private final int column; public Location(Path sourcePath, int line, int column) { this.sourcePath = sourcePath; this.line = line; this.column = column; } public String toString() { return sourcePath+": " + line + "("+column+")"; } public boolean forSource(Path path) { return sourcePath.equals(path); } } --- NEW FILE: SymbolIndex.java --- package org.rubypeople.rdt.internal.core.symbols; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.jruby.lexer.yacc.ISourcePosition; public class SymbolIndex { private Map index = new HashMap(); public void add(ClassSymbol symbol, Location location) { Set locations = (Set) index.get(symbol); if (locations == null) { locations = new HashSet(); index.put(symbol, locations); } locations.add(location); } public Set find(ClassSymbol symbol) { Set locations = (Set) index.get(symbol); if (locations == null) return Collections.EMPTY_SET; return Collections.unmodifiableSet(locations); } public void flush(IPath foo_path) { // flush only relevant bits for (Iterator indexIter = index.entrySet().iterator(); indexIter.hasNext();) { Map.Entry entry = (Map.Entry) indexIter.next(); Set locations = (Set) entry.getValue(); for (Iterator locationIter = locations.iterator(); locationIter.hasNext();) { Location location = (Location) locationIter.next(); locationIter.remove(); } if (locations.isEmpty()) indexIter.remove(); } } // DSC DO public void add(ClassSymbol symbol, IFile file, ISourcePosition position) { // TODO Auto-generated method stub } } |