diff options
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndexVisitor.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/SourceIndexVisitor.java | 271 |
1 files changed, 138 insertions, 133 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndexVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexVisitor.java index 2a26c85..5a64e4e 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexVisitor.java | |||
| @@ -42,7 +42,6 @@ import com.strobel.decompiler.languages.java.ast.ContinueStatement; | |||
| 42 | import com.strobel.decompiler.languages.java.ast.DoWhileStatement; | 42 | import com.strobel.decompiler.languages.java.ast.DoWhileStatement; |
| 43 | import com.strobel.decompiler.languages.java.ast.EmptyStatement; | 43 | import com.strobel.decompiler.languages.java.ast.EmptyStatement; |
| 44 | import com.strobel.decompiler.languages.java.ast.EnumValueDeclaration; | 44 | import com.strobel.decompiler.languages.java.ast.EnumValueDeclaration; |
| 45 | import com.strobel.decompiler.languages.java.ast.Expression; | ||
| 46 | import com.strobel.decompiler.languages.java.ast.ExpressionStatement; | 45 | import com.strobel.decompiler.languages.java.ast.ExpressionStatement; |
| 47 | import com.strobel.decompiler.languages.java.ast.FieldDeclaration; | 46 | import com.strobel.decompiler.languages.java.ast.FieldDeclaration; |
| 48 | import com.strobel.decompiler.languages.java.ast.ForEachStatement; | 47 | import com.strobel.decompiler.languages.java.ast.ForEachStatement; |
| @@ -101,289 +100,344 @@ import cuchaz.enigma.mapping.MethodEntry; | |||
| 101 | public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void> | 100 | public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void> |
| 102 | { | 101 | { |
| 103 | @Override | 102 | @Override |
| 104 | public Void visitComment( Comment node, SourceIndex index ) | 103 | public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) |
| 105 | { | 104 | { |
| 105 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | ||
| 106 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | ||
| 107 | MethodEntry methodEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() ); | ||
| 108 | if( node.getTarget() instanceof MemberReferenceExpression ) | ||
| 109 | { | ||
| 110 | index.add( ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(), methodEntry ); | ||
| 111 | } | ||
| 112 | |||
| 106 | return recurse( node, index ); | 113 | return recurse( node, index ); |
| 107 | } | 114 | } |
| 108 | 115 | ||
| 109 | @Override | 116 | @Override |
| 110 | public Void visitPatternPlaceholder( AstNode node, Pattern pattern, SourceIndex index ) | 117 | public Void visitMemberReferenceExpression( MemberReferenceExpression node, SourceIndex index ) |
| 111 | { | 118 | { |
| 119 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | ||
| 120 | if( ref != null ) | ||
| 121 | { | ||
| 122 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | ||
| 123 | FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); | ||
| 124 | index.add( node.getMemberNameToken(), fieldEntry ); | ||
| 125 | } | ||
| 126 | |||
| 112 | return recurse( node, index ); | 127 | return recurse( node, index ); |
| 113 | } | 128 | } |
| 114 | 129 | ||
| 115 | @Override | 130 | @Override |
| 116 | public Void visitInvocationExpression( InvocationExpression node, SourceIndex index ) | 131 | public Void visitSimpleType( SimpleType node, SourceIndex index ) |
| 117 | { | 132 | { |
| 118 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | 133 | TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE ); |
| 119 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | 134 | if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) |
| 120 | MethodEntry methodEntry = new MethodEntry( classEntry, ref.getName(), ref.getSignature() ); | ||
| 121 | if( node.getTarget() instanceof MemberReferenceExpression ) | ||
| 122 | { | 135 | { |
| 123 | index.add( ((MemberReferenceExpression)node.getTarget()).getMemberNameToken(), methodEntry ); | 136 | index.add( node.getIdentifierToken(), new ClassEntry( ref.getInternalName() ) ); |
| 124 | } | 137 | } |
| 125 | 138 | ||
| 126 | return recurse( node, index ); | 139 | return recurse( node, index ); |
| 127 | } | 140 | } |
| 128 | 141 | ||
| 129 | @Override | 142 | @Override |
| 130 | public Void visitTypeReference( TypeReferenceExpression node, SourceIndex index ) | 143 | public Void visitMethodDeclaration( MethodDeclaration node, SourceIndex index ) |
| 131 | { | 144 | { |
| 145 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 146 | |||
| 147 | // static initializers don't have identifier tokens | ||
| 148 | if( !def.getName().equals( "<clinit>" ) ) | ||
| 149 | { | ||
| 150 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 151 | MethodEntry methodEntry = new MethodEntry( classEntry, def.getName(), def.getSignature() ); | ||
| 152 | index.add( node.getNameToken(), methodEntry ); | ||
| 153 | } | ||
| 154 | |||
| 132 | return recurse( node, index ); | 155 | return recurse( node, index ); |
| 133 | } | 156 | } |
| 134 | 157 | ||
| 135 | @Override | 158 | @Override |
| 136 | public Void visitJavaTokenNode( JavaTokenNode node, SourceIndex index ) | 159 | public Void visitConstructorDeclaration( ConstructorDeclaration node, SourceIndex index ) |
| 137 | { | 160 | { |
| 161 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 162 | index.add( node.getNameToken(), new ClassEntry( def.getDeclaringType().getInternalName() ) ); | ||
| 163 | |||
| 138 | return recurse( node, index ); | 164 | return recurse( node, index ); |
| 139 | } | 165 | } |
| 140 | 166 | ||
| 141 | @Override | 167 | @Override |
| 142 | public Void visitMemberReferenceExpression( MemberReferenceExpression node, SourceIndex index ) | 168 | public Void visitParameterDeclaration( ParameterDeclaration node, SourceIndex index ) |
| 143 | { | 169 | { |
| 144 | MemberReference ref = node.getUserData( Keys.MEMBER_REFERENCE ); | 170 | ParameterDefinition def = node.getUserData( Keys.PARAMETER_DEFINITION ); |
| 145 | if( ref != null ) | 171 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); |
| 146 | { | 172 | MethodDefinition methodDef = (MethodDefinition)def.getMethod(); |
| 147 | ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); | 173 | MethodEntry methodEntry = new MethodEntry( classEntry, methodDef.getName(), methodDef.getSignature() ); |
| 148 | FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); | 174 | ArgumentEntry argumentEntry = new ArgumentEntry( methodEntry, def.getPosition(), def.getName() ); |
| 149 | index.add( node.getMemberNameToken(), fieldEntry ); | 175 | index.add( node.getNameToken(), argumentEntry ); |
| 150 | } | ||
| 151 | 176 | ||
| 152 | return recurse( node, index ); | 177 | return recurse( node, index ); |
| 153 | } | 178 | } |
| 154 | 179 | ||
| 155 | @Override | 180 | @Override |
| 156 | public Void visitIdentifier( Identifier node, SourceIndex index ) | 181 | public Void visitFieldDeclaration( FieldDeclaration node, SourceIndex index ) |
| 157 | { | 182 | { |
| 183 | FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION ); | ||
| 184 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 185 | FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() ); | ||
| 186 | assert( node.getVariables().size() == 1 ); | ||
| 187 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | ||
| 188 | index.add( variable.getNameToken(), fieldEntry ); | ||
| 189 | |||
| 158 | return recurse( node, index ); | 190 | return recurse( node, index ); |
| 159 | } | 191 | } |
| 160 | 192 | ||
| 161 | @Override | 193 | @Override |
| 162 | public Void visitNullReferenceExpression( NullReferenceExpression node, SourceIndex index ) | 194 | public Void visitTypeDeclaration( TypeDeclaration node, SourceIndex index ) |
| 163 | { | 195 | { |
| 196 | TypeDefinition def = node.getUserData( Keys.TYPE_DEFINITION ); | ||
| 197 | index.add( node.getNameToken(), new ClassEntry( def.getInternalName() ) ); | ||
| 198 | |||
| 164 | return recurse( node, index ); | 199 | return recurse( node, index ); |
| 165 | } | 200 | } |
| 166 | 201 | ||
| 202 | private Void recurse( AstNode node, SourceIndex index ) | ||
| 203 | { | ||
| 204 | // TEMP: show the tree | ||
| 205 | System.out.println( getIndent( node ) + node.getClass().getSimpleName() + dumpUserData( node ) + " " + node.getRegion() ); | ||
| 206 | |||
| 207 | for( final AstNode child : node.getChildren() ) | ||
| 208 | { | ||
| 209 | child.acceptVisitor( this, index ); | ||
| 210 | } | ||
| 211 | return null; | ||
| 212 | } | ||
| 213 | |||
| 214 | private String dumpUserData( AstNode node ) | ||
| 215 | { | ||
| 216 | StringBuilder buf = new StringBuilder(); | ||
| 217 | for( Key<?> key : Keys.ALL_KEYS ) | ||
| 218 | { | ||
| 219 | Object val = node.getUserData( key ); | ||
| 220 | if( val != null ) | ||
| 221 | { | ||
| 222 | buf.append( String.format( " [%s=%s]", key, val ) ); | ||
| 223 | } | ||
| 224 | } | ||
| 225 | return buf.toString(); | ||
| 226 | } | ||
| 227 | |||
| 228 | private String getIndent( AstNode node ) | ||
| 229 | { | ||
| 230 | StringBuilder buf = new StringBuilder(); | ||
| 231 | int depth = getDepth( node ); | ||
| 232 | for( int i = 0; i < depth; i++ ) | ||
| 233 | { | ||
| 234 | buf.append( "\t" ); | ||
| 235 | } | ||
| 236 | return buf.toString(); | ||
| 237 | } | ||
| 238 | |||
| 239 | private int getDepth( AstNode node ) | ||
| 240 | { | ||
| 241 | int depth = -1; | ||
| 242 | while( node != null ) | ||
| 243 | { | ||
| 244 | depth++; | ||
| 245 | node = node.getParent(); | ||
| 246 | } | ||
| 247 | return depth; | ||
| 248 | } | ||
| 249 | |||
| 250 | // OVERRIDES WE DON'T CARE ABOUT | ||
| 251 | |||
| 167 | @Override | 252 | @Override |
| 168 | public Void visitThisReferenceExpression( ThisReferenceExpression node, SourceIndex index ) | 253 | public Void visitComment( Comment node, SourceIndex index ) |
| 169 | { | 254 | { |
| 170 | return recurse( node, index ); | 255 | return recurse( node, index ); |
| 171 | } | 256 | } |
| 172 | 257 | ||
| 173 | @Override | 258 | @Override |
| 174 | public Void visitSuperReferenceExpression( SuperReferenceExpression node, SourceIndex index ) | 259 | public Void visitPatternPlaceholder( AstNode node, Pattern pattern, SourceIndex index ) |
| 175 | { | 260 | { |
| 176 | return recurse( node, index ); | 261 | return recurse( node, index ); |
| 177 | } | 262 | } |
| 178 | 263 | ||
| 179 | @Override | 264 | @Override |
| 180 | public Void visitClassOfExpression( ClassOfExpression node, SourceIndex index ) | 265 | public Void visitTypeReference( TypeReferenceExpression node, SourceIndex index ) |
| 181 | { | 266 | { |
| 182 | return recurse( node, index ); | 267 | return recurse( node, index ); |
| 183 | } | 268 | } |
| 184 | 269 | ||
| 185 | @Override | 270 | @Override |
| 186 | public Void visitBlockStatement( BlockStatement node, SourceIndex index ) | 271 | public Void visitJavaTokenNode( JavaTokenNode node, SourceIndex index ) |
| 187 | { | 272 | { |
| 188 | return recurse( node, index ); | 273 | return recurse( node, index ); |
| 189 | } | 274 | } |
| 190 | 275 | ||
| 191 | @Override | 276 | @Override |
| 192 | public Void visitExpressionStatement( ExpressionStatement node, SourceIndex index ) | 277 | public Void visitIdentifier( Identifier node, SourceIndex index ) |
| 193 | { | 278 | { |
| 194 | return recurse( node, index ); | 279 | return recurse( node, index ); |
| 195 | } | 280 | } |
| 196 | 281 | ||
| 197 | @Override | 282 | @Override |
| 198 | public Void visitBreakStatement( BreakStatement node, SourceIndex index ) | 283 | public Void visitNullReferenceExpression( NullReferenceExpression node, SourceIndex index ) |
| 199 | { | 284 | { |
| 200 | return recurse( node, index ); | 285 | return recurse( node, index ); |
| 201 | } | 286 | } |
| 202 | 287 | ||
| 203 | @Override | 288 | @Override |
| 204 | public Void visitContinueStatement( ContinueStatement node, SourceIndex index ) | 289 | public Void visitThisReferenceExpression( ThisReferenceExpression node, SourceIndex index ) |
| 205 | { | 290 | { |
| 206 | return recurse( node, index ); | 291 | return recurse( node, index ); |
| 207 | } | 292 | } |
| 208 | 293 | ||
| 209 | @Override | 294 | @Override |
| 210 | public Void visitDoWhileStatement( DoWhileStatement node, SourceIndex index ) | 295 | public Void visitSuperReferenceExpression( SuperReferenceExpression node, SourceIndex index ) |
| 211 | { | 296 | { |
| 212 | return recurse( node, index ); | 297 | return recurse( node, index ); |
| 213 | } | 298 | } |
| 214 | 299 | ||
| 215 | @Override | 300 | @Override |
| 216 | public Void visitEmptyStatement( EmptyStatement node, SourceIndex index ) | 301 | public Void visitClassOfExpression( ClassOfExpression node, SourceIndex index ) |
| 217 | { | 302 | { |
| 218 | return recurse( node, index ); | 303 | return recurse( node, index ); |
| 219 | } | 304 | } |
| 220 | 305 | ||
| 221 | @Override | 306 | @Override |
| 222 | public Void visitIfElseStatement( IfElseStatement node, SourceIndex index ) | 307 | public Void visitBlockStatement( BlockStatement node, SourceIndex index ) |
| 223 | { | 308 | { |
| 224 | return recurse( node, index ); | 309 | return recurse( node, index ); |
| 225 | } | 310 | } |
| 226 | 311 | ||
| 227 | @Override | 312 | @Override |
| 228 | public Void visitLabelStatement( LabelStatement node, SourceIndex index ) | 313 | public Void visitExpressionStatement( ExpressionStatement node, SourceIndex index ) |
| 229 | { | 314 | { |
| 230 | return recurse( node, index ); | 315 | return recurse( node, index ); |
| 231 | } | 316 | } |
| 232 | 317 | ||
| 233 | @Override | 318 | @Override |
| 234 | public Void visitLabeledStatement( LabeledStatement node, SourceIndex index ) | 319 | public Void visitBreakStatement( BreakStatement node, SourceIndex index ) |
| 235 | { | 320 | { |
| 236 | return recurse( node, index ); | 321 | return recurse( node, index ); |
| 237 | } | 322 | } |
| 238 | 323 | ||
| 239 | @Override | 324 | @Override |
| 240 | public Void visitReturnStatement( ReturnStatement node, SourceIndex index ) | 325 | public Void visitContinueStatement( ContinueStatement node, SourceIndex index ) |
| 241 | { | 326 | { |
| 242 | return recurse( node, index ); | 327 | return recurse( node, index ); |
| 243 | } | 328 | } |
| 244 | 329 | ||
| 245 | @Override | 330 | @Override |
| 246 | public Void visitSwitchStatement( SwitchStatement node, SourceIndex index ) | 331 | public Void visitDoWhileStatement( DoWhileStatement node, SourceIndex index ) |
| 247 | { | 332 | { |
| 248 | return recurse( node, index ); | 333 | return recurse( node, index ); |
| 249 | } | 334 | } |
| 250 | 335 | ||
| 251 | @Override | 336 | @Override |
| 252 | public Void visitSwitchSection( SwitchSection node, SourceIndex index ) | 337 | public Void visitEmptyStatement( EmptyStatement node, SourceIndex index ) |
| 253 | { | 338 | { |
| 254 | return recurse( node, index ); | 339 | return recurse( node, index ); |
| 255 | } | 340 | } |
| 256 | 341 | ||
| 257 | @Override | 342 | @Override |
| 258 | public Void visitCaseLabel( CaseLabel node, SourceIndex index ) | 343 | public Void visitIfElseStatement( IfElseStatement node, SourceIndex index ) |
| 259 | { | 344 | { |
| 260 | return recurse( node, index ); | 345 | return recurse( node, index ); |
| 261 | } | 346 | } |
| 262 | 347 | ||
| 263 | @Override | 348 | @Override |
| 264 | public Void visitThrowStatement( ThrowStatement node, SourceIndex index ) | 349 | public Void visitLabelStatement( LabelStatement node, SourceIndex index ) |
| 265 | { | 350 | { |
| 266 | return recurse( node, index ); | 351 | return recurse( node, index ); |
| 267 | } | 352 | } |
| 268 | 353 | ||
| 269 | @Override | 354 | @Override |
| 270 | public Void visitCatchClause( CatchClause node, SourceIndex index ) | 355 | public Void visitLabeledStatement( LabeledStatement node, SourceIndex index ) |
| 271 | { | 356 | { |
| 272 | return recurse( node, index ); | 357 | return recurse( node, index ); |
| 273 | } | 358 | } |
| 274 | 359 | ||
| 275 | @Override | 360 | @Override |
| 276 | public Void visitAnnotation( Annotation node, SourceIndex index ) | 361 | public Void visitReturnStatement( ReturnStatement node, SourceIndex index ) |
| 277 | { | 362 | { |
| 278 | return recurse( node, index ); | 363 | return recurse( node, index ); |
| 279 | } | 364 | } |
| 280 | 365 | ||
| 281 | @Override | 366 | @Override |
| 282 | public Void visitNewLine( NewLineNode node, SourceIndex index ) | 367 | public Void visitSwitchStatement( SwitchStatement node, SourceIndex index ) |
| 283 | { | 368 | { |
| 284 | return recurse( node, index ); | 369 | return recurse( node, index ); |
| 285 | } | 370 | } |
| 286 | 371 | ||
| 287 | @Override | 372 | @Override |
| 288 | public Void visitVariableDeclaration( VariableDeclarationStatement node, SourceIndex index ) | 373 | public Void visitSwitchSection( SwitchSection node, SourceIndex index ) |
| 289 | { | 374 | { |
| 290 | return recurse( node, index ); | 375 | return recurse( node, index ); |
| 291 | } | 376 | } |
| 292 | 377 | ||
| 293 | @Override | 378 | @Override |
| 294 | public Void visitVariableInitializer( VariableInitializer node, SourceIndex index ) | 379 | public Void visitCaseLabel( CaseLabel node, SourceIndex index ) |
| 295 | { | 380 | { |
| 296 | return recurse( node, index ); | 381 | return recurse( node, index ); |
| 297 | } | 382 | } |
| 298 | 383 | ||
| 299 | @Override | 384 | @Override |
| 300 | public Void visitText( TextNode node, SourceIndex index ) | 385 | public Void visitThrowStatement( ThrowStatement node, SourceIndex index ) |
| 301 | { | 386 | { |
| 302 | return recurse( node, index ); | 387 | return recurse( node, index ); |
| 303 | } | 388 | } |
| 304 | 389 | ||
| 305 | @Override | 390 | @Override |
| 306 | public Void visitImportDeclaration( ImportDeclaration node, SourceIndex index ) | 391 | public Void visitCatchClause( CatchClause node, SourceIndex index ) |
| 307 | { | 392 | { |
| 308 | return recurse( node, index ); | 393 | return recurse( node, index ); |
| 309 | } | 394 | } |
| 310 | 395 | ||
| 311 | @Override | 396 | @Override |
| 312 | public Void visitSimpleType( SimpleType node, SourceIndex index ) | 397 | public Void visitAnnotation( Annotation node, SourceIndex index ) |
| 313 | { | 398 | { |
| 314 | TypeReference ref = node.getUserData( Keys.TYPE_REFERENCE ); | ||
| 315 | if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) | ||
| 316 | { | ||
| 317 | index.add( node.getIdentifierToken(), new ClassEntry( ref.getInternalName() ) ); | ||
| 318 | } | ||
| 319 | |||
| 320 | return recurse( node, index ); | 399 | return recurse( node, index ); |
| 321 | } | 400 | } |
| 322 | 401 | ||
| 323 | @Override | 402 | @Override |
| 324 | public Void visitMethodDeclaration( MethodDeclaration node, SourceIndex index ) | 403 | public Void visitNewLine( NewLineNode node, SourceIndex index ) |
| 325 | { | 404 | { |
| 326 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 327 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 328 | MethodEntry methodEntry = new MethodEntry( classEntry, def.getName(), def.getSignature() ); | ||
| 329 | index.add( node.getNameToken(), methodEntry ); | ||
| 330 | |||
| 331 | return recurse( node, index ); | 405 | return recurse( node, index ); |
| 332 | } | 406 | } |
| 333 | 407 | ||
| 334 | @Override | 408 | @Override |
| 335 | public Void visitInitializerBlock( InstanceInitializer node, SourceIndex index ) | 409 | public Void visitVariableDeclaration( VariableDeclarationStatement node, SourceIndex index ) |
| 336 | { | 410 | { |
| 337 | return recurse( node, index ); | 411 | return recurse( node, index ); |
| 338 | } | 412 | } |
| 339 | 413 | ||
| 340 | @Override | 414 | @Override |
| 341 | public Void visitConstructorDeclaration( ConstructorDeclaration node, SourceIndex index ) | 415 | public Void visitVariableInitializer( VariableInitializer node, SourceIndex index ) |
| 342 | { | 416 | { |
| 343 | MethodDefinition def = node.getUserData( Keys.METHOD_DEFINITION ); | ||
| 344 | index.add( node.getNameToken(), new ClassEntry( def.getDeclaringType().getInternalName() ) ); | ||
| 345 | |||
| 346 | return recurse( node, index ); | 417 | return recurse( node, index ); |
| 347 | } | 418 | } |
| 348 | 419 | ||
| 349 | @Override | 420 | @Override |
| 350 | public Void visitTypeParameterDeclaration( TypeParameterDeclaration node, SourceIndex index ) | 421 | public Void visitText( TextNode node, SourceIndex index ) |
| 351 | { | 422 | { |
| 352 | return recurse( node, index ); | 423 | return recurse( node, index ); |
| 353 | } | 424 | } |
| 354 | 425 | ||
| 355 | @Override | 426 | @Override |
| 356 | public Void visitParameterDeclaration( ParameterDeclaration node, SourceIndex index ) | 427 | public Void visitImportDeclaration( ImportDeclaration node, SourceIndex index ) |
| 357 | { | 428 | { |
| 358 | ParameterDefinition def = node.getUserData( Keys.PARAMETER_DEFINITION ); | ||
| 359 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 360 | MethodDefinition methodDef = (MethodDefinition)def.getMethod(); | ||
| 361 | MethodEntry methodEntry = new MethodEntry( classEntry, methodDef.getName(), methodDef.getSignature() ); | ||
| 362 | ArgumentEntry argumentEntry = new ArgumentEntry( methodEntry, def.getPosition(), def.getName() ); | ||
| 363 | index.add( node.getNameToken(), argumentEntry ); | ||
| 364 | |||
| 365 | return recurse( node, index ); | 429 | return recurse( node, index ); |
| 366 | } | 430 | } |
| 367 | 431 | ||
| 368 | @Override | 432 | @Override |
| 369 | public Void visitFieldDeclaration( FieldDeclaration node, SourceIndex index ) | 433 | public Void visitInitializerBlock( InstanceInitializer node, SourceIndex index ) |
| 370 | { | 434 | { |
| 371 | FieldDefinition def = node.getUserData( Keys.FIELD_DEFINITION ); | ||
| 372 | ClassEntry classEntry = new ClassEntry( def.getDeclaringType().getInternalName() ); | ||
| 373 | FieldEntry fieldEntry = new FieldEntry( classEntry, def.getName() ); | ||
| 374 | assert( node.getVariables().size() == 1 ); | ||
| 375 | VariableInitializer variable = node.getVariables().firstOrNullObject(); | ||
| 376 | index.add( variable.getNameToken(), fieldEntry ); | ||
| 377 | |||
| 378 | return recurse( node, index ); | 435 | return recurse( node, index ); |
| 379 | } | 436 | } |
| 380 | 437 | ||
| 381 | @Override | 438 | @Override |
| 382 | public Void visitTypeDeclaration( TypeDeclaration node, SourceIndex index ) | 439 | public Void visitTypeParameterDeclaration( TypeParameterDeclaration node, SourceIndex index ) |
| 383 | { | 440 | { |
| 384 | TypeDefinition def = node.getUserData( Keys.TYPE_DEFINITION ); | ||
| 385 | index.add( node.getNameToken(), new ClassEntry( def.getInternalName() ) ); | ||
| 386 | |||
| 387 | return recurse( node, index ); | 441 | return recurse( node, index ); |
| 388 | } | 442 | } |
| 389 | 443 | ||
| @@ -450,7 +504,6 @@ public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void> | |||
| 450 | @Override | 504 | @Override |
| 451 | public Void visitIdentifierExpression( IdentifierExpression node, SourceIndex index ) | 505 | public Void visitIdentifierExpression( IdentifierExpression node, SourceIndex index ) |
| 452 | { | 506 | { |
| 453 | // TODO | ||
| 454 | return recurse( node, index ); | 507 | return recurse( node, index ); |
| 455 | } | 508 | } |
| 456 | 509 | ||
| @@ -567,52 +620,4 @@ public class SourceIndexVisitor implements IAstVisitor<SourceIndex, Void> | |||
| 567 | { | 620 | { |
| 568 | return recurse( node, index ); | 621 | return recurse( node, index ); |
| 569 | } | 622 | } |
| 570 | |||
| 571 | private Void recurse( AstNode node, SourceIndex index ) | ||
| 572 | { | ||
| 573 | // TEMP: show the tree | ||
| 574 | System.out.println( getIndent( node ) + node.getClass().getSimpleName() + dumpUserData( node ) + " " + node.getRegion() ); | ||
| 575 | |||
| 576 | for( final AstNode child : node.getChildren() ) | ||
| 577 | { | ||
| 578 | child.acceptVisitor( this, index ); | ||
| 579 | } | ||
| 580 | return null; | ||
| 581 | } | ||
| 582 | |||
| 583 | private String dumpUserData( AstNode node ) | ||
| 584 | { | ||
| 585 | StringBuilder buf = new StringBuilder(); | ||
| 586 | for( Key<?> key : Keys.ALL_KEYS ) | ||
| 587 | { | ||
| 588 | Object val = node.getUserData( key ); | ||
| 589 | if( val != null ) | ||
| 590 | { | ||
| 591 | buf.append( String.format( " [%s=%s]", key, val ) ); | ||
| 592 | } | ||
| 593 | } | ||
| 594 | return buf.toString(); | ||
| 595 | } | ||
| 596 | |||
| 597 | private String getIndent( AstNode node ) | ||
| 598 | { | ||
| 599 | StringBuilder buf = new StringBuilder(); | ||
| 600 | int depth = getDepth( node ); | ||
| 601 | for( int i = 0; i < depth; i++ ) | ||
| 602 | { | ||
| 603 | buf.append( "\t" ); | ||
| 604 | } | ||
| 605 | return buf.toString(); | ||
| 606 | } | ||
| 607 | |||
| 608 | private int getDepth( AstNode node ) | ||
| 609 | { | ||
| 610 | int depth = -1; | ||
| 611 | while( node != null ) | ||
| 612 | { | ||
| 613 | depth++; | ||
| 614 | node = node.getParent(); | ||
| 615 | } | ||
| 616 | return depth; | ||
| 617 | } | ||
| 618 | } | 623 | } |