summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
diff options
context:
space:
mode:
authorGravatar jeff2015-01-13 23:25:04 -0500
committerGravatar jeff2015-01-13 23:25:04 -0500
commit959cb5fd4f9586ec3bd265b452fe25fe1db82e3f (patch)
treebdd8a2c52c2fe053ba3460614bde8542e5378dbe /src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
parentgot rid of gradle in favor of ivy+ssjb (diff)
downloadenigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.gz
enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.xz
enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.zip
source format change
don't hate me too much if you were planning a big merge. =P
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java')
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java159
1 files changed, 64 insertions, 95 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
index 7ffd170..43c1749 100644
--- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
+++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java
@@ -36,159 +36,128 @@ import cuchaz.enigma.mapping.ConstructorEntry;
36import cuchaz.enigma.mapping.FieldEntry; 36import cuchaz.enigma.mapping.FieldEntry;
37import cuchaz.enigma.mapping.MethodEntry; 37import cuchaz.enigma.mapping.MethodEntry;
38 38
39public class SourceIndexBehaviorVisitor extends SourceIndexVisitor 39public class SourceIndexBehaviorVisitor extends SourceIndexVisitor {
40{ 40
41 private BehaviorEntry m_behaviorEntry; 41 private BehaviorEntry m_behaviorEntry;
42 42
43 public SourceIndexBehaviorVisitor( BehaviorEntry behaviorEntry ) 43 public SourceIndexBehaviorVisitor(BehaviorEntry behaviorEntry) {
44 {
45 m_behaviorEntry = behaviorEntry; 44 m_behaviorEntry = behaviorEntry;
46 } 45 }
47 46
48 @Override 47 @Override
49 public Void visitMethodDeclaration( MethodDeclaration node, SourceIndex index ) 48 public Void visitMethodDeclaration(MethodDeclaration node, SourceIndex index) {
50 { 49 return recurse(node, index);
51 return recurse( node, index );
52 } 50 }
53 51
54 @Override 52 @Override
55 public Void visitConstructorDeclaration( ConstructorDeclaration node, SourceIndex index ) 53 public Void visitConstructorDeclaration(ConstructorDeclaration node, SourceIndex index) {
56 { 54 return recurse(node, index);
57 return recurse( node, index );
58 } 55 }
59 56
60 @Override 57 @Override
61 public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) 58 public Void visitInvocationExpression(InvocationExpression node, SourceIndex index) {
62 { 59 MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE);
63 MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE );
64 60
65 // get the behavior entry 61 // get the behavior entry
66 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 62 ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName());
67 BehaviorEntry behaviorEntry = null; 63 BehaviorEntry behaviorEntry = null;
68 if( ref instanceof MethodReference ) 64 if (ref instanceof MethodReference) {
69 {
70 MethodReference methodRef = (MethodReference)ref; 65 MethodReference methodRef = (MethodReference)ref;
71 if( methodRef.isConstructor() ) 66 if (methodRef.isConstructor()) {
72 { 67 behaviorEntry = new ConstructorEntry(classEntry, ref.getSignature());
73 behaviorEntry = new ConstructorEntry( classEntry, ref.getSignature() ); 68 } else if (methodRef.isTypeInitializer()) {
74 } 69 behaviorEntry = new ConstructorEntry(classEntry);
75 else if( methodRef.isTypeInitializer() ) 70 } else {
76 { 71 behaviorEntry = new MethodEntry(classEntry, ref.getName(), ref.getSignature());
77 behaviorEntry = new ConstructorEntry( classEntry );
78 }
79 else
80 {
81 behaviorEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() );
82 } 72 }
83 } 73 }
84 if( behaviorEntry != null ) 74 if (behaviorEntry != null) {
85 {
86 // get the node for the token 75 // get the node for the token
87 AstNode tokenNode = null; 76 AstNode tokenNode = null;
88 if( node.getTarget() instanceof MemberReferenceExpression ) 77 if (node.getTarget() instanceof MemberReferenceExpression) {
89 {
90 tokenNode = ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(); 78 tokenNode = ((MemberReferenceExpression)node.getTarget()).getMemberNameToken();
91 } 79 } else if (node.getTarget() instanceof SuperReferenceExpression) {
92 else if( node.getTarget() instanceof SuperReferenceExpression )
93 {
94 tokenNode = node.getTarget(); 80 tokenNode = node.getTarget();
95 } 81 } else if (node.getTarget() instanceof ThisReferenceExpression) {
96 else if( node.getTarget() instanceof ThisReferenceExpression )
97 {
98 tokenNode = node.getTarget(); 82 tokenNode = node.getTarget();
99 } 83 }
100 if( tokenNode != null ) 84 if (tokenNode != null) {
101 { 85 index.addReference(tokenNode, behaviorEntry, m_behaviorEntry);
102 index.addReference( tokenNode, behaviorEntry, m_behaviorEntry );
103 } 86 }
104 } 87 }
105 88
106 return recurse( node, index ); 89 return recurse(node, index);
107 } 90 }
108 91
109 @Override 92 @Override
110 public Void visitMemberReferenceExpression( MemberReferenceExpression node, SourceIndex index ) 93 public Void visitMemberReferenceExpression(MemberReferenceExpression node, SourceIndex index) {
111 { 94 MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE);
112 MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); 95 if (ref != null) {
113 if( ref != null )
114 {
115 // make sure this is actually a field 96 // make sure this is actually a field
116 if( ref.getSignature().indexOf( '(' ) >= 0 ) 97 if (ref.getSignature().indexOf('(') >= 0) {
117 { 98 throw new Error("Expected a field here! got " + ref);
118 throw new Error( "Expected a field here! got " + ref );
119 } 99 }
120 100
121 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 101 ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName());
122 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); 102 FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName());
123 index.addReference( node.getMemberNameToken(), fieldEntry, m_behaviorEntry ); 103 index.addReference(node.getMemberNameToken(), fieldEntry, m_behaviorEntry);
124 } 104 }
125 105
126 return recurse( node, index ); 106 return recurse(node, index);
127 } 107 }
128 108
129 @Override 109 @Override
130 public Void visitSimpleType( SimpleType node, SourceIndex index ) 110 public Void visitSimpleType(SimpleType node, SourceIndex index) {
131 { 111 TypeReference ref = node.getUserData(Keys.TYPE_REFERENCE);
132 TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE ); 112 if (node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY) {
133 if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) 113 ClassEntry classEntry = new ClassEntry(ref.getInternalName());
134 { 114 index.addReference(node.getIdentifierToken(), classEntry, m_behaviorEntry);
135 ClassEntry classEntry = new ClassEntry( ref.getInternalName() );
136 index.addReference( node.getIdentifierToken(), classEntry, m_behaviorEntry );
137 } 115 }
138 116
139 return recurse( node, index ); 117 return recurse(node, index);
140 } 118 }
141 119
142 @Override 120 @Override
143 public Void visitParameterDeclaration( ParameterDeclaration node, SourceIndex index ) 121 public Void visitParameterDeclaration(ParameterDeclaration node, SourceIndex index) {
144 { 122 ParameterDefinition def = node.getUserData(Keys.PARAMETER_DEFINITION);
145 ParameterDefinition def = node.getUserData( Keys.PARAMETER_DEFINITION ); 123 ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName());
146 ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() );
147 MethodDefinition methodDef = (MethodDefinition)def.getMethod(); 124 MethodDefinition methodDef = (MethodDefinition)def.getMethod();
148 BehaviorEntry behaviorEntry; 125 BehaviorEntry behaviorEntry;
149 if( methodDef.isConstructor() ) 126 if (methodDef.isConstructor()) {
150 { 127 behaviorEntry = new ConstructorEntry(classEntry, methodDef.getSignature());
151 behaviorEntry = new ConstructorEntry( classEntry, methodDef.getSignature() ); 128 } else {
152 } 129 behaviorEntry = new MethodEntry(classEntry, methodDef.getName(), methodDef.getSignature());
153 else
154 {
155 behaviorEntry = new MethodEntry( classEntry, methodDef.getName(), methodDef.getSignature() );
156 } 130 }
157 ArgumentEntry argumentEntry = new ArgumentEntry( behaviorEntry, def.getPosition(), node.getName() ); 131 ArgumentEntry argumentEntry = new ArgumentEntry(behaviorEntry, def.getPosition(), node.getName());
158 index.addDeclaration( node.getNameToken(), argumentEntry ); 132 index.addDeclaration(node.getNameToken(), argumentEntry);
159 133
160 return recurse( node, index ); 134 return recurse(node, index);
161 } 135 }
162 136
163 @Override 137 @Override
164 public Void visitIdentifierExpression( IdentifierExpression node, SourceIndex index ) 138 public Void visitIdentifierExpression(IdentifierExpression node, SourceIndex index) {
165 { 139 MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE);
166 MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); 140 if (ref != null) {
167 if( ref != null ) 141 ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName());
168 { 142 FieldEntry fieldEntry = new FieldEntry(classEntry, ref.getName());
169 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 143 index.addReference(node.getIdentifierToken(), fieldEntry, m_behaviorEntry);
170 FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() );
171 index.addReference( node.getIdentifierToken(), fieldEntry, m_behaviorEntry );
172 } 144 }
173 145
174 return recurse( node, index ); 146 return recurse(node, index);
175 } 147 }
176 148
177 @Override 149 @Override
178 public Void visitObjectCreationExpression( ObjectCreationExpression node, SourceIndex index ) 150 public Void visitObjectCreationExpression(ObjectCreationExpression node, SourceIndex index) {
179 { 151 MemberReference ref = node.getUserData(Keys.MEMBER_REFERENCE);
180 MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); 152 if (ref != null) {
181 if( ref != null ) 153 ClassEntry classEntry = new ClassEntry(ref.getDeclaringType().getInternalName());
182 { 154 ConstructorEntry constructorEntry = new ConstructorEntry(classEntry, ref.getSignature());
183 ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); 155 if (node.getType() instanceof SimpleType) {
184 ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, ref.getSignature() );
185 if( node.getType() instanceof SimpleType )
186 {
187 SimpleType simpleTypeNode = (SimpleType)node.getType(); 156 SimpleType simpleTypeNode = (SimpleType)node.getType();
188 index.addReference( simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry ); 157 index.addReference(simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry);
189 } 158 }
190 } 159 }
191 160
192 return recurse( node, index ); 161 return recurse(node, index);
193 } 162 }
194} 163}