Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3491/src/org/rubypeople/rdt/internal/core/symbols Modified Files: SymbolIndex.java ClassSymbol.java SearchResult.java Added Files: Symbol.java MethodSymbol.java ISymbolTypes.java Log Message: added indexing of method definitions Index: SearchResult.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/SearchResult.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SearchResult.java 23 Oct 2005 19:46:31 -0000 1.1 --- SearchResult.java 23 Oct 2005 22:24:27 -0000 1.2 *************** *** 15,22 **** public class SearchResult { private static final int ODD_PRIME_NUMBER = 37; ! private ClassSymbol symbol ; private Location location ; ! public SearchResult(ClassSymbol symbol, Location location) { this.location = location ; this.symbol = symbol ; --- 15,22 ---- public class SearchResult { private static final int ODD_PRIME_NUMBER = 37; ! private Symbol symbol ; private Location location ; ! public SearchResult(Symbol symbol, Location location) { this.location = location ; this.symbol = symbol ; *************** *** 27,31 **** } ! public ClassSymbol getSymbol() { return symbol; } --- 27,31 ---- } ! public Symbol getSymbol() { return symbol; } --- NEW FILE: Symbol.java --- package org.rubypeople.rdt.internal.core.symbols; public abstract class Symbol implements ISymbolTypes { private static int ODD_PRIME_NUMBER = 23 ; private int fType ; protected final String name; public Symbol(String name, int symbolType) { fType = symbolType ; this.name = name ; } public int getType() { return fType; } public String getName() { return this.name ; } public int hashCode() { return ODD_PRIME_NUMBER * name.hashCode() + fType ; } public boolean equals(Object obj) { if (!(obj instanceof Symbol)) return false; Symbol that = (Symbol) obj; return that.fType == this.fType && that.name.equals(this.name); } } --- NEW FILE: MethodSymbol.java --- package org.rubypeople.rdt.internal.core.symbols; public class MethodSymbol extends Symbol { public MethodSymbol(String name) { super(name, METHOD_SYMBOL); } public String toString() { return "Method [" + this.getName() + "]"; } } Index: ClassSymbol.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/ClassSymbol.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ClassSymbol.java 23 Oct 2005 19:42:58 -0000 1.4 --- ClassSymbol.java 23 Oct 2005 22:24:27 -0000 1.5 *************** *** 12,41 **** 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 String getName() { - return this.className ; - } - - public int hashCode() { - return className.hashCode(); - } - public String toString() { ! return "Class [" + className + "]"; } } --- 12,23 ---- package org.rubypeople.rdt.internal.core.symbols; ! public class ClassSymbol extends Symbol { public ClassSymbol(String className) { ! super(className, CLASS_SYMBOL) ; } public String toString() { ! return "Class [" + this.getName() + "]"; } } Index: SymbolIndex.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/SymbolIndex.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SymbolIndex.java 23 Oct 2005 19:44:46 -0000 1.7 --- SymbolIndex.java 23 Oct 2005 22:24:27 -0000 1.8 *************** *** 30,34 **** private static boolean verbose; ! public void add(ClassSymbol symbol, Location location) { Set locations = (Set) index.get(symbol); if (locations == null) { --- 30,34 ---- private static boolean verbose; ! public void add(Symbol symbol, Location location) { Set locations = (Set) index.get(symbol); if (locations == null) { *************** *** 39,48 **** } ! public void add(ClassSymbol symbol, IFile file, ISourcePosition position) { SymbolIndex.log("Adding Symbol: " + symbol) ; add(symbol, new Location(file.getFullPath(), position)); } ! public Set find(ClassSymbol symbol) { Set locations = (Set) index.get(symbol); if (locations == null) --- 39,48 ---- } ! public void add(Symbol symbol, IFile file, ISourcePosition position) { SymbolIndex.log("Adding Symbol: " + symbol) ; add(symbol, new Location(file.getFullPath(), position)); } ! public Set find(Symbol symbol) { Set locations = (Set) index.get(symbol); if (locations == null) *************** *** 54,58 **** * returns a set of SearchResult instances as opposed to find(symbol), which returns locations */ ! public Set find(String regExp) throws PatternSyntaxException { Pattern pattern = Pattern.compile(regExp); Set searchResults = new HashSet() ; --- 54,58 ---- * returns a set of SearchResult instances as opposed to find(symbol), which returns locations */ ! public Set find(String regExp, int symbolType) throws PatternSyntaxException { Pattern pattern = Pattern.compile(regExp); Set searchResults = new HashSet() ; *************** *** 60,64 **** for (Iterator indexIter = index.entrySet().iterator(); indexIter.hasNext();) { Map.Entry entry = (Map.Entry) indexIter.next(); ! ClassSymbol symbol = (ClassSymbol) entry.getKey() ; if (pattern.matcher(symbol.getName()).find()) { Set foundLocations = (Set)entry.getValue() ; --- 60,67 ---- for (Iterator indexIter = index.entrySet().iterator(); indexIter.hasNext();) { Map.Entry entry = (Map.Entry) indexIter.next(); ! Symbol symbol = (Symbol) entry.getKey() ; ! if (symbol.getType() != symbolType) { ! continue ; ! } if (pattern.matcher(symbol.getName()).find()) { Set foundLocations = (Set)entry.getValue() ; --- NEW FILE: ISymbolTypes.java --- package org.rubypeople.rdt.internal.core.symbols; public interface ISymbolTypes { public static int CLASS_SYMBOL = 0 ; public static int METHOD_SYMBOL = 1 ; } |