diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourcedAst.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourcedAst.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/cuchaz/enigma/analysis/SourcedAst.java b/src/cuchaz/enigma/analysis/SourcedAst.java index 04c6f03..52a3453 100644 --- a/src/cuchaz/enigma/analysis/SourcedAst.java +++ b/src/cuchaz/enigma/analysis/SourcedAst.java | |||
| @@ -13,7 +13,10 @@ package cuchaz.enigma.analysis; | |||
| 13 | import java.io.IOException; | 13 | import java.io.IOException; |
| 14 | import java.util.HashMap; | 14 | import java.util.HashMap; |
| 15 | 15 | ||
| 16 | import javassist.bytecode.Descriptor; | ||
| 17 | |||
| 16 | import com.google.common.collect.Maps; | 18 | import com.google.common.collect.Maps; |
| 19 | import com.sun.source.tree.ClassTree; | ||
| 17 | import com.sun.source.tree.CompilationUnitTree; | 20 | import com.sun.source.tree.CompilationUnitTree; |
| 18 | import com.sun.source.tree.ImportTree; | 21 | import com.sun.source.tree.ImportTree; |
| 19 | import com.sun.source.tree.Tree; | 22 | import com.sun.source.tree.Tree; |
| @@ -34,7 +37,7 @@ public class SourcedAst | |||
| 34 | m_positions = m_trees.getSourcePositions(); | 37 | m_positions = m_trees.getSourcePositions(); |
| 35 | m_classNameIndex = Maps.newHashMap(); | 38 | m_classNameIndex = Maps.newHashMap(); |
| 36 | 39 | ||
| 37 | // index all the class names | 40 | // index all the class names from package imports |
| 38 | for( ImportTree importTree : m_tree.getImports() ) | 41 | for( ImportTree importTree : m_tree.getImports() ) |
| 39 | { | 42 | { |
| 40 | // ignore static imports for now | 43 | // ignore static imports for now |
| @@ -44,9 +47,9 @@ public class SourcedAst | |||
| 44 | } | 47 | } |
| 45 | 48 | ||
| 46 | // get the full and simple class names | 49 | // get the full and simple class names |
| 47 | String fullName = importTree.getQualifiedIdentifier().toString(); | 50 | String fullName = Descriptor.toJvmName( importTree.getQualifiedIdentifier().toString() ); |
| 48 | String simpleName = fullName; | 51 | String simpleName = fullName; |
| 49 | String[] parts = fullName.split( "\\." ); | 52 | String[] parts = fullName.split( "/" ); |
| 50 | if( parts.length > 0 ) | 53 | if( parts.length > 0 ) |
| 51 | { | 54 | { |
| 52 | simpleName = parts[parts.length - 1]; | 55 | simpleName = parts[parts.length - 1]; |
| @@ -54,6 +57,18 @@ public class SourcedAst | |||
| 54 | 57 | ||
| 55 | m_classNameIndex.put( simpleName, fullName ); | 58 | m_classNameIndex.put( simpleName, fullName ); |
| 56 | } | 59 | } |
| 60 | |||
| 61 | // index the self class using the package name | ||
| 62 | String packageName = Descriptor.toJvmName( m_tree.getPackageName().toString() ); | ||
| 63 | for( Tree typeTree : m_tree.getTypeDecls() ) | ||
| 64 | { | ||
| 65 | if( typeTree instanceof ClassTree ) | ||
| 66 | { | ||
| 67 | ClassTree classTree = (ClassTree)typeTree; | ||
| 68 | String className = classTree.getSimpleName().toString(); | ||
| 69 | m_classNameIndex.put( className, packageName + "/" + className ); | ||
| 70 | } | ||
| 71 | } | ||
| 57 | } | 72 | } |
| 58 | 73 | ||
| 59 | public int getStart( Tree node ) | 74 | public int getStart( Tree node ) |