summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/SourceIndex.java
diff options
context:
space:
mode:
authorGravatar hg2014-07-27 00:52:28 -0400
committerGravatar hg2014-07-27 00:52:28 -0400
commit999c64037fb7251f87bd7b105231b3763e003c07 (patch)
tree291461c3c5bbf1e9c1c27dbacb87d982f8f578fa /src/cuchaz/enigma/analysis/SourceIndex.java
parentgot rid of temp debug traces (diff)
downloadenigma-fork-999c64037fb7251f87bd7b105231b3763e003c07.tar.gz
enigma-fork-999c64037fb7251f87bd7b105231b3763e003c07.tar.xz
enigma-fork-999c64037fb7251f87bd7b105231b3763e003c07.zip
made gui responsive to caret position and show identifier info
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndex.java')
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndex.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java
index a4b5329..ee92d1e 100644
--- a/src/cuchaz/enigma/analysis/SourceIndex.java
+++ b/src/cuchaz/enigma/analysis/SourceIndex.java
@@ -19,10 +19,12 @@ import jsyntaxpane.Token;
19import com.google.common.collect.BiMap; 19import com.google.common.collect.BiMap;
20import com.google.common.collect.HashBiMap; 20import com.google.common.collect.HashBiMap;
21 21
22public class SourceIndex implements Iterable<Map.Entry<Object,Token>> 22import cuchaz.enigma.mapping.Entry;
23
24public class SourceIndex implements Iterable<Map.Entry<Entry,Token>>
23{ 25{
24 private BiMap<Object,Token> m_entryToToken; 26 private BiMap<Entry,Token> m_entryToToken;
25 private BiMap<Token,Object> m_tokenToEntry; 27 private BiMap<Token,Entry> m_tokenToEntry;
26 28
27 public SourceIndex( ) 29 public SourceIndex( )
28 { 30 {
@@ -30,12 +32,12 @@ public class SourceIndex implements Iterable<Map.Entry<Object,Token>>
30 m_tokenToEntry = m_entryToToken.inverse(); 32 m_tokenToEntry = m_entryToToken.inverse();
31 } 33 }
32 34
33 public void add( Object entry, Token token ) 35 public void add( Entry entry, Token token )
34 { 36 {
35 m_entryToToken.put( entry, token ); 37 m_entryToToken.put( entry, token );
36 } 38 }
37 39
38 public Iterator<Map.Entry<Object,Token>> iterator( ) 40 public Iterator<Map.Entry<Entry,Token>> iterator( )
39 { 41 {
40 return m_entryToToken.entrySet().iterator(); 42 return m_entryToToken.entrySet().iterator();
41 } 43 }
@@ -45,12 +47,26 @@ public class SourceIndex implements Iterable<Map.Entry<Object,Token>>
45 return m_entryToToken.values(); 47 return m_entryToToken.values();
46 } 48 }
47 49
48 public Object getEntry( Token token ) 50 public Entry getEntry( Token token )
49 { 51 {
50 return m_tokenToEntry.get( token ); 52 return m_tokenToEntry.get( token );
51 } 53 }
52 54
53 public Object getToken( Object entry ) 55 public Entry getEntry( int pos )
56 {
57 // linear search is fast enough for now
58 for( Map.Entry<Entry,Token> entry : this )
59 {
60 Token token = entry.getValue();
61 if( pos >= token.start && pos <= token.end() )
62 {
63 return entry.getKey();
64 }
65 }
66 return null;
67 }
68
69 public Token getToken( Entry entry )
54 { 70 {
55 return m_entryToToken.get( entry ); 71 return m_entryToToken.get( entry );
56 } 72 }