1 package spoon.support.builder; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 import java.util.Map ; 7 import java.util.Set ; 8 import java.util.Stack ; 9 import java.util.TreeMap ; 10 import java.util.TreeSet ; 11 12 import org.eclipse.jdt.internal.compiler.ASTVisitor; 13 import org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression; 14 import org.eclipse.jdt.internal.compiler.ast.ASTNode; 15 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; 16 import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; 17 import org.eclipse.jdt.internal.compiler.ast.Annotation; 18 import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration; 19 import org.eclipse.jdt.internal.compiler.ast.Argument; 20 import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression; 21 import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer; 22 import org.eclipse.jdt.internal.compiler.ast.ArrayReference; 23 import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; 24 import org.eclipse.jdt.internal.compiler.ast.AssertStatement; 25 import org.eclipse.jdt.internal.compiler.ast.Assignment; 26 import org.eclipse.jdt.internal.compiler.ast.BinaryExpression; 27 import org.eclipse.jdt.internal.compiler.ast.Block; 28 import org.eclipse.jdt.internal.compiler.ast.BreakStatement; 29 import org.eclipse.jdt.internal.compiler.ast.CaseStatement; 30 import org.eclipse.jdt.internal.compiler.ast.CastExpression; 31 import org.eclipse.jdt.internal.compiler.ast.CharLiteral; 32 import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; 33 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; 34 import org.eclipse.jdt.internal.compiler.ast.CompoundAssignment; 35 import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression; 36 import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; 37 import org.eclipse.jdt.internal.compiler.ast.ContinueStatement; 38 import org.eclipse.jdt.internal.compiler.ast.DoStatement; 39 import org.eclipse.jdt.internal.compiler.ast.DoubleLiteral; 40 import org.eclipse.jdt.internal.compiler.ast.EqualExpression; 41 import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; 42 import org.eclipse.jdt.internal.compiler.ast.Expression; 43 import org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral; 44 import org.eclipse.jdt.internal.compiler.ast.FalseLiteral; 45 import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; 46 import org.eclipse.jdt.internal.compiler.ast.FieldReference; 47 import org.eclipse.jdt.internal.compiler.ast.FloatLiteral; 48 import org.eclipse.jdt.internal.compiler.ast.ForStatement; 49 import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; 50 import org.eclipse.jdt.internal.compiler.ast.IfStatement; 51 import org.eclipse.jdt.internal.compiler.ast.Initializer; 52 import org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression; 53 import org.eclipse.jdt.internal.compiler.ast.IntLiteral; 54 import org.eclipse.jdt.internal.compiler.ast.Javadoc; 55 import org.eclipse.jdt.internal.compiler.ast.LabeledStatement; 56 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; 57 import org.eclipse.jdt.internal.compiler.ast.LongLiteral; 58 import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; 59 import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; 60 import org.eclipse.jdt.internal.compiler.ast.MessageSend; 61 import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; 62 import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; 63 import org.eclipse.jdt.internal.compiler.ast.NullLiteral; 64 import org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression; 65 import org.eclipse.jdt.internal.compiler.ast.OperatorIds; 66 import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; 67 import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; 68 import org.eclipse.jdt.internal.compiler.ast.PostfixExpression; 69 import org.eclipse.jdt.internal.compiler.ast.PrefixExpression; 70 import org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression; 71 import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; 72 import org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference; 73 import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; 74 import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; 75 import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; 76 import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; 77 import org.eclipse.jdt.internal.compiler.ast.Statement; 78 import org.eclipse.jdt.internal.compiler.ast.StringLiteral; 79 import org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation; 80 import org.eclipse.jdt.internal.compiler.ast.SuperReference; 81 import org.eclipse.jdt.internal.compiler.ast.SwitchStatement; 82 import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement; 83 import org.eclipse.jdt.internal.compiler.ast.ThisReference; 84 import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; 85 import org.eclipse.jdt.internal.compiler.ast.TrueLiteral; 86 import org.eclipse.jdt.internal.compiler.ast.TryStatement; 87 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; 88 import org.eclipse.jdt.internal.compiler.ast.TypeParameter; 89 import org.eclipse.jdt.internal.compiler.ast.TypeReference; 90 import org.eclipse.jdt.internal.compiler.ast.UnaryExpression; 91 import org.eclipse.jdt.internal.compiler.ast.WhileStatement; 92 import org.eclipse.jdt.internal.compiler.ast.Wildcard; 93 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 94 import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; 95 import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; 96 import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; 97 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 98 import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding; 99 import org.eclipse.jdt.internal.compiler.lookup.ClassScope; 100 import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; 101 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; 102 import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; 103 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; 104 import org.eclipse.jdt.internal.compiler.lookup.MethodScope; 105 import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; 106 import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; 107 import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; 108 import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; 109 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 110 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; 111 import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; 112 import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding; 113 114 import spoon.reflect.Factory; 115 import spoon.reflect.code.BinaryOperatorKind; 116 import spoon.reflect.code.CtArrayAccess; 117 import spoon.reflect.code.CtAssert; 118 import spoon.reflect.code.CtAssignment; 119 import spoon.reflect.code.CtBinaryOperator; 120 import spoon.reflect.code.CtBlock; 121 import spoon.reflect.code.CtBreak; 122 import spoon.reflect.code.CtCase; 123 import spoon.reflect.code.CtCatch; 124 import spoon.reflect.code.CtConditional; 125 import spoon.reflect.code.CtContinue; 126 import spoon.reflect.code.CtDo; 127 import spoon.reflect.code.CtExpression; 128 import spoon.reflect.code.CtFieldAccess; 129 import spoon.reflect.code.CtFor; 130 import spoon.reflect.code.CtForEach; 131 import spoon.reflect.code.CtIf; 132 import spoon.reflect.code.CtInvocation; 133 import spoon.reflect.code.CtLiteral; 134 import spoon.reflect.code.CtLocalVariable; 135 import spoon.reflect.code.CtLoop; 136 import spoon.reflect.code.CtNewArray; 137 import spoon.reflect.code.CtNewClass; 138 import spoon.reflect.code.CtOperatorAssignment; 139 import spoon.reflect.code.CtReturn; 140 import spoon.reflect.code.CtStatement; 141 import spoon.reflect.code.CtSwitch; 142 import spoon.reflect.code.CtSynchronized; 143 import spoon.reflect.code.CtTargetedExpression; 144 import spoon.reflect.code.CtThrow; 145 import spoon.reflect.code.CtTry; 146 import spoon.reflect.code.CtUnaryOperator; 147 import spoon.reflect.code.CtVariableAccess; 148 import spoon.reflect.code.CtWhile; 149 import spoon.reflect.code.UnaryOperatorKind; 150 import spoon.reflect.declaration.CtAnnotation; 151 import spoon.reflect.declaration.CtAnonymousExecutable; 152 import spoon.reflect.declaration.CtClass; 153 import spoon.reflect.declaration.CtConstructor; 154 import spoon.reflect.declaration.CtElement; 155 import spoon.reflect.declaration.CtExecutable; 156 import spoon.reflect.declaration.CtField; 157 import spoon.reflect.declaration.CtGenericElement; 158 import spoon.reflect.declaration.CtInterface; 159 import spoon.reflect.declaration.CtMethod; 160 import spoon.reflect.declaration.CtPackage; 161 import spoon.reflect.declaration.CtParameter; 162 import spoon.reflect.declaration.CtSimpleType; 163 import spoon.reflect.declaration.CtType; 164 import spoon.reflect.declaration.CtTypedElement; 165 import spoon.reflect.declaration.CtVariable; 166 import spoon.reflect.declaration.ModifierKind; 167 import spoon.reflect.reference.CtArrayTypeReference; 168 import spoon.reflect.reference.CtExecutableReference; 169 import spoon.reflect.reference.CtFieldReference; 170 import spoon.reflect.reference.CtLocalVariableReference; 171 import spoon.reflect.reference.CtPackageReference; 172 import spoon.reflect.reference.CtParameterReference; 173 import spoon.reflect.reference.CtTypeParameterReference; 174 import spoon.reflect.reference.CtTypeReference; 175 import spoon.reflect.reference.CtVariableReference; 176 import spoon.reflect.visitor.CtInheritanceScanner; 177 import spoon.reflect.visitor.Query; 178 import spoon.support.query.TypeFilter; 179 import spoon.template.Template; 180 181 184 public class JDTTreeBuilder extends ASTVisitor { 185 186 public class ASTPair { 187 public CtElement element; 188 189 public ASTNode node; 190 191 public ASTPair(CtElement element, ASTNode node) { 192 super(); 193 this.element = element; 194 this.node = node; 195 } 196 } 197 198 public class BuilderContext { 199 Stack <String > annotationValueName = new Stack <String >(); 200 201 Stack <CtElement> arguments = new Stack <CtElement>(); 202 203 Stack <CtElement> arrayInitializer = new Stack <CtElement>(); 204 205 List <CtTypeReference> casts = new ArrayList <CtTypeReference>(); 206 207 CompilationUnitDeclaration compilationunitdeclaration; 208 209 List <CtSimpleType<?>> createdTypes = new ArrayList <CtSimpleType<?>>(); 210 211 Stack <CtTry> finallyzer = new Stack <CtTry>(); 212 213 boolean forinit = false; 214 215 boolean forupdate = false; 216 217 Stack <String > label = new Stack <String >(); 218 219 boolean selector = false; 220 221 224 Stack <ASTPair> stack = new Stack <ASTPair>(); 225 226 Stack <CtTargetedExpression> target = new Stack <CtTargetedExpression>(); 227 228 public void addCreatedType(CtSimpleType<?> type) { 229 createdTypes.add(type); 230 } 231 232 @SuppressWarnings ("unchecked") 233 void enter(CtElement e, ASTNode node) { 234 stack.push(new ASTPair(e, node)); 235 if (compilationunitdeclaration != null) { 237 e 238 .setPosition(factory 239 .Core() 240 .createSourcePosition( 241 new File (new String ( 242 compilationunitdeclaration 243 .getFileName())), 244 node.sourceStart, 245 node.sourceEnd, 246 compilationunitdeclaration.compilationResult.lineSeparatorPositions)); 247 } 248 ASTPair pair = stack.peek(); 249 CtElement current = pair.element; 250 251 if (current instanceof CtExpression) { 252 while (!casts.isEmpty()) 253 ((CtExpression<?>) current).getTypeCasts().add( 254 casts.remove(0)); 255 } 256 if (current instanceof CtStatement && !context.label.isEmpty()) { 257 ((CtStatement) current).setLabel(context.label.pop()); 258 } 259 260 if (e instanceof CtTypedElement && node instanceof Expression) { 261 if (((CtTypedElement<?>) e).getType() == null) 262 ((CtTypedElement<?>) e) 263 .setType(references 264 .getTypeReference(((Expression) node).resolvedType)); 265 } 266 267 } 268 269 void exit(ASTNode node) { 270 ASTPair pair = stack.pop(); 271 if (pair.node != node) 272 throw new RuntimeException ("Unconsistant Stack " + node); 273 CtElement current = pair.element; 274 if (!stack.isEmpty()) { 275 current.setParent(stack.peek().element); 276 exiter.child = current; 277 exiter.scan(stack.peek().element); 278 } 279 } 280 281 public List <CtSimpleType<?>> getCreatedTypes() { 282 return createdTypes; 283 } 284 285 public boolean isArgument(CtElement e) { 286 return arguments.size() > 0 && arguments.peek() == e; 287 } 288 289 private void popArgument(CtElement e) { 290 if (arguments.pop() != e) 291 throw new RuntimeException ("Unconsistant stack"); 292 } 293 294 private void pushArgument(CtElement e) { 295 arguments.push(e); 296 } 297 } 298 299 @SuppressWarnings ("unchecked") 300 public class ParentExiter extends CtInheritanceScanner { 301 CtElement child; 302 303 @Override 304 public void scanCtElement(CtElement e) { 305 if (child instanceof CtAnnotation 306 && context.annotationValueName.isEmpty()) { 307 e.getAnnotations().add((CtAnnotation) child); 308 return; 309 } 310 } 311 312 @Override 313 public <R> void scanCtExecutable(CtExecutable<R> e) { 314 if (child instanceof CtParameter) { 315 e.getParameters().add((CtParameter<?>) child); 316 return; 317 } else if (child instanceof CtBlock) { 318 e.setBody((CtBlock<R>) child); 319 return; 320 } 321 super.scanCtExecutable(e); 322 } 323 324 @Override 325 public void scanCtGenericElement(CtGenericElement e) { 326 return; 327 } 328 329 @Override 330 public void scanCtLoop(CtLoop loop) { 331 if (loop.getBody() == null && child instanceof CtStatement) { 332 loop.setBody((CtStatement) child); 333 } 334 super.scanCtLoop(loop); 335 } 336 337 @Override 338 public <T> void scanCtSimpleType(CtSimpleType<T> t) { 339 if (child instanceof CtSimpleType) { 340 if (t.getNestedTypes().contains(child)) { 341 t.getNestedTypes().remove(child); 342 } 343 t.getNestedTypes().add((CtSimpleType<?>) child); 344 return; 345 } else if (child instanceof CtField) { 346 t.getFields().add((CtField<?>) child); 347 return; 348 } else if (child instanceof CtConstructor) { 349 return; 350 } 351 super.scanCtSimpleType(t); 352 } 353 354 @Override 355 public <T, E extends CtExpression<?>> void scanCtTargetedExpression( 356 CtTargetedExpression<T, E> targetedExpression) { 357 if (!context.target.isEmpty() 358 && context.target.peek() == targetedExpression) { 359 targetedExpression.setTarget((E) child); 360 return; 361 } 362 super.scanCtTargetedExpression(targetedExpression); 363 } 364 365 @Override 366 public <T> void scanCtType(CtType<T> type) { 367 if (child instanceof CtMethod) { 368 type.getMethods().add((CtMethod<?>) child); 369 return; 370 } 371 super.scanCtType(type); 372 } 373 374 @Override 375 public <T> void scanCtVariable(CtVariable<T> v) { 376 if (child instanceof CtExpression && !context.arguments.isEmpty() 377 && context.arguments.peek() == v) { 378 v.setDefaultExpression((CtExpression<T>) child); 379 return; 380 } 381 super.scanCtVariable(v); 382 } 383 384 @Override 385 public <A extends java.lang.annotation.Annotation > void visitCtAnnotation( 386 CtAnnotation<A> annotation) { 387 String name = context.annotationValueName.peek(); 388 Object value = child; 389 390 if (value instanceof CtVariableAccess) 391 value = ((CtVariableAccess) value).getVariable(); 392 if (value instanceof CtFieldReference 393 && ((CtFieldReference) value).getSimpleName().equals( 394 "class")) { 395 value = ((CtFieldReference) value).getType(); 396 } 397 398 if (!context.arrayInitializer.isEmpty() 399 && context.arrayInitializer.peek() == annotation) { 400 if (annotation.getElementValues().containsKey(name)) { 402 ((ArrayList ) annotation.getElementValues().get(name)) 403 .add(value); 404 } else { 405 ArrayList lst = new ArrayList (); 406 lst.add(value); 407 annotation.getElementValues().put(name, lst); 408 } 409 } else { 410 annotation.getElementValues().put(name, value); 411 } 412 super.visitCtAnnotation(annotation); 413 } 414 415 @Override 416 public void visitCtAnonymousExecutable(CtAnonymousExecutable e) { 417 if (child instanceof CtBlock) { 418 e.setBody((CtBlock) child); 419 return; 420 } 421 super.visitCtAnonymousExecutable(e); 422 } 423 424 @Override 425 public <T, E extends CtExpression<?>> void visitCtArrayAccess( 426 CtArrayAccess<T, E> arrayAccess) { 427 if (context.arguments.size() > 0 428 && context.arguments.peek() == arrayAccess) { 429 arrayAccess.setIndexExpression((CtExpression<Integer >) child); 430 return; 431 } else if (arrayAccess.getTarget() == null) { 432 arrayAccess.setTarget((E) child); 433 return; 434 } 435 super.visitCtArrayAccess(arrayAccess); 436 } 437 438 @Override 439 public <T> void visitCtAssert(CtAssert<T> asserted) { 440 if (child instanceof CtExpression) 441 if (!context.arguments.isEmpty() 442 && context.arguments.peek() == asserted) { 443 asserted.setExpression((CtExpression<T>) child); 444 return; 445 } else { 446 asserted.setAssertExpression((CtExpression<Boolean >) child); 447 return; 448 } 449 super.visitCtAssert(asserted); 450 } 451 452 @Override 453 public <T, A extends T> void visitCtAssignment( 454 CtAssignment<T, A> assignement) { 455 if (assignement.getAssigned() == null) { 456 assignement.setAssigned((CtExpression<T>) child); 457 return; 458 } else if (assignement.getAssignment() == null) { 459 assignement.setAssignment((CtExpression<A>) child); 460 return; 461 } 462 super.visitCtAssignment(assignement); 463 } 464 465 @Override 466 public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) { 467 if (child instanceof CtExpression) 468 if (operator.getLeftHandOperand() == null) { 469 operator.setLeftHandOperand((CtExpression<?>) child); 470 return; 471 } else if (operator.getRightHandOperand() == null) { 472 operator.setRightHandOperand((CtExpression<?>) child); 473 return; 474 } 475 super.visitCtBinaryOperator(operator); 476 } 477 478 @Override 479 public <R> void visitCtBlock(CtBlock<R> block) { 480 if (child instanceof CtStatement) { 481 block.getStatements().add((CtStatement) child); 482 return; 483 } 484 super.visitCtBlock(block); 485 } 486 487 @Override 488 public <E> void visitCtCase(CtCase<E> caseStatement) { 489 if (context.selector && caseStatement.getCaseExpression() == null 490 && child instanceof CtExpression) { 491 caseStatement.setCaseExpression((CtExpression<E>) child); 492 return; 493 } else if (child instanceof CtStatement) { 494 caseStatement.getStatements().add((CtStatement) child); 495 return; 496 } 497 super.visitCtCase(caseStatement); 498 } 499 500 @Override 501 public void visitCtCatch(CtCatch catchBlock) { 502 if (child instanceof CtBlock) { 503 catchBlock.setBody((CtBlock) child); 504 return; 505 } else if (child instanceof CtLocalVariable) { 506 catchBlock 507 .setParameter((CtLocalVariable<? extends Throwable >) child); 508 return; 509 } 510 super.visitCtCatch(catchBlock); 511 } 512 513 @Override 514 public <T> void visitCtClass(CtClass<T> ctClass) { 515 if (child instanceof CtConstructor) { 516 ctClass.getConstructors().add((CtConstructor) child); 517 return; 518 } 519 if (child instanceof CtAnonymousExecutable) { 520 ctClass.getAnonymousExecutables().add( 521 (CtAnonymousExecutable) child); 522 } 523 super.visitCtClass(ctClass); 524 } 525 526 @Override 527 public <T> void visitCtConditional(CtConditional<T> conditional) { 528 if (child instanceof CtExpression) { 529 if (conditional.getCondition() == null) { 530 conditional.setCondition((CtExpression<Boolean >) child); 531 } else if (conditional.getThenExpression() == null) { 532 conditional.setThenExpression((CtExpression<T>) child); 533 } else if (conditional.getElseExpression() == null) { 534 conditional.setElseExpression((CtExpression<T>) child); 535 } 536 } 537 super.visitCtConditional(conditional); 538 } 539 540 @Override 541 public void visitCtDo(CtDo doLoop) { 542 if (child instanceof CtExpression 543 && doLoop.getLoopingExpression() == null) { 544 doLoop.setLoopingExpression((CtExpression<Boolean >) child); 545 return; 546 } 547 super.visitCtDo(doLoop); 548 } 549 550 @Override 551 public <T> void visitCtField(CtField<T> f) { 552 if (f.getDefaultExpression() == null 553 && child instanceof CtExpression) { 554 f.setDefaultExpression((CtExpression<T>) child); 555 return; 556 } 557 super.visitCtField(f); 558 } 559 560 @Override 561 public void visitCtFor(CtFor forLoop) { 562 if (context.forinit && child instanceof CtStatement) { 563 forLoop.getForInit().add((CtStatement) child); 564 return; 565 } 566 if (forLoop.getExpression() == null 567 && child instanceof CtExpression) { 568 forLoop.setExpression((CtExpression<Boolean >) child); 569 return; 570 } 571 if (context.forupdate && child instanceof CtStatement) { 572 forLoop.getForUpdate().add((CtStatement) child); 573 return; 574 } 575 super.visitCtFor(forLoop); 576 } 577 578 @Override 579 public void visitCtForEach(CtForEach foreach) { 580 if (foreach.getVariable() == null && child instanceof CtVariable) { 581 foreach.setVariable((CtLocalVariable<?>) child); 582 return; 583 } else if (foreach.getExpression() == null 584 && child instanceof CtExpression) { 585 foreach.setExpression((CtExpression<?>) child); 586 return; 587 } else if (child instanceof CtStatement) { 588 foreach.setBody((CtStatement) child); 589 return; 590 } 591 super.visitCtForEach(foreach); 592 } 593 594 @Override 595 public void visitCtIf(CtIf ifElement) { 596 if (ifElement.getCondition() == null 597 && child instanceof CtExpression) { 598 ifElement.setCondition((CtExpression<Boolean >) child); 599 return; 600 } else if (child instanceof CtStatement) { 601 if (ifElement.getThenStatement() == null) { 602 ifElement.setThenStatement((CtStatement) child); 603 return; 604 } else if (ifElement.getElseStatement() == null) { 605 ifElement.setElseStatement((CtStatement) child); 606 return; 607 } 608 } 609 super.visitCtIf(ifElement); 610 } 611 612 @Override 613 public <T> void visitCtInvocation(CtInvocation<T> invocation) { 614 if (context.isArgument(invocation) && child instanceof CtExpression) { 615 invocation.getArguments().add((CtExpression<?>) child); 616 return; 617 } else if (child instanceof CtExpression) { 618 invocation.setTarget((CtExpression<?>) child); 619 return; 620 } 621 super.visitCtInvocation(invocation); 622 } 623 624 @Override 625 public <T> void visitCtNewArray(CtNewArray<T> newArray) { 626 if (context.isArgument(newArray)) { 627 newArray.getDimensionExpressions().add( 628 (CtExpression<Integer >) child); 629 return; 630 } else if (child instanceof CtExpression) { 631 newArray.getElements().add((CtExpression<?>) child); 632 return; 633 } 634 } 635 636 @Override 637 public <T> void visitCtNewClass(CtNewClass<T> newClass) { 638 if (context.isArgument(newClass) && child instanceof CtExpression) { 639 newClass.getArguments().add((CtExpression<?>) child); 640 return; 641 } else if (child instanceof CtClass) { 642 newClass.setAnonymousClass((CtClass<?>) child); 643 ((CtClass<?>) child).setSuperclass(newClass.getType()); 644 return; 645 } 646 super.visitCtNewClass(newClass); 647 } 648 649 @Override 650 public void visitCtPackage(CtPackage ctPackage) { 651 if (!template) { 652 if (ctPackage.getTypes().contains(child)) { 653 ctPackage.getTypes().remove(child); 654 } 655 ctPackage.getTypes().add((CtSimpleType<?>) child); 656 context.addCreatedType((CtSimpleType<?>) child); 657 return; 658 } else if (child instanceof CtClass) { 659 factory.Template().add((CtClass<? extends Template>) child); 660 return; 661 } 662 super.visitCtPackage(ctPackage); 663 } 664 665 @Override 666 public <R> void visitCtReturn(CtReturn<R> returnStatement) { 667 if (child instanceof CtExpression) { 668 returnStatement.setReturnedExpression((CtExpression<R>) child); 669 return; 670 } 671 super.visitCtReturn(returnStatement); 672 } 673 674 @Override 675 public <E> void visitCtSwitch(CtSwitch<E> switchStatement) { 676 if (switchStatement.getSelector() == null 677 && child instanceof CtExpression) { 678 switchStatement.setSelector((CtExpression<E>) child); 679 return; 680 } 681 if (child instanceof CtCase) { 682 switchStatement.getCases().add((CtCase) child); 683 return; 684 } 685 super.visitCtSwitch(switchStatement); 686 } 687 688 @Override 689 public void visitCtSynchronized(CtSynchronized synchro) { 690 if (synchro.getExpression() == null 691 && child instanceof CtExpression) { 692 synchro.setExpression((CtExpression<?>) child); 693 return; 694 } 695 if (synchro.getBlock() == null && child instanceof CtBlock) { 696 synchro.setBlock((CtBlock) child); 697 return; 698 } 699 super.visitCtSynchronized(synchro); 700 } 701 702 @Override 703 public void visitCtThrow(CtThrow throwStatement) { 704 if (throwStatement.getThrownExpression() == null) { 705 throwStatement 706 .setThrownExpression((CtExpression<? extends Throwable >) child); 707 return; 708 } 709 super.visitCtThrow(throwStatement); 710 } 711 712 @Override 713 public void visitCtTry(CtTry tryBlock) { 714 if (child instanceof CtBlock) { 715 if (!context.finallyzer.isEmpty() 716 && context.finallyzer.peek() == tryBlock) 717 tryBlock.setFinalizer((CtBlock) child); 718 else 719 tryBlock.setBody((CtBlock) child); 720 return; 721 } else if (child instanceof CtCatch) { 722 tryBlock.getCatchers().add((CtCatch) child); 723 return; 724 } 725 super.visitCtTry(tryBlock); 726 } 727 728 @Override 729 public <T> void visitCtUnaryOperator(CtUnaryOperator<T> operator) { 730 if (operator.getOperand() == null && child instanceof CtExpression) { 731 operator.setOperand((CtExpression<T>) child); 732 return; 733 } 734 super.visitCtUnaryOperator(operator); 735 } 736 737 @Override 738 public void visitCtWhile(CtWhile whileLoop) { 739 if (whileLoop.getLoopingExpression() == null 740 && child instanceof CtExpression) { 741 whileLoop.setLoopingExpression((CtExpression<Boolean >) child); 742 return; 743 } 744 super.visitCtWhile(whileLoop); 745 } 746 }; 747 748 public class ReferenceBuilder { 749 750 Map <String , CtTypeReference<?>> basestypes = new TreeMap <String , CtTypeReference<?>>(); 751 752 boolean bounds = false; 753 754 public CtTypeReference getBoundedTypeReference(TypeBinding binding) { 755 bounds = true; 756 CtTypeReference ref = getTypeReference(binding); 757 bounds = false; 758 return ref; 759 } 760 761 @SuppressWarnings ("unchecked") 762 public CtExecutableReference getExecutableReference(MethodBinding exec) { 763 CtExecutableReference ref = factory.Core() 764 .createExecutableReference(); 765 ref.setDeclaringType(getTypeReference(exec.declaringClass)); 766 ref.setType(getTypeReference(exec.returnType)); 767 ref.setSimpleName(new String (exec.selector)); 768 ref.setStatic(exec.isStatic()); 769 if (exec.parameters != null) { 770 for (TypeBinding b : exec.parameters) 771 ref.getParameterTypes().add(getTypeReference(b)); 772 } 773 if (exec.typeVariables != null) { 774 for (TypeVariableBinding b : exec.typeVariables) 775 ref.getActualTypeArguments().add(getTypeReference(b)); 776 } 777 778 return ref; 779 } 780 781 public CtPackageReference getPackageReference(PackageBinding reference) { 782 String name = new String (reference.shortReadableName()); 783 if (name.length() == 0) 784 return null; 785 CtPackageReference ref = factory.Core().createPackageReference(); 786 ref.setSimpleName(name); 787 return ref; 788 } 789 790 @SuppressWarnings ("unchecked") 791 public CtTypeReference getTypeReference(TypeBinding binding) { 792 CtTypeReference ref = null; 793 if (binding == null) 794 return null; 795 if (binding instanceof RawTypeBinding) { 796 ref = getTypeReference(((ParameterizedTypeBinding) binding).type); 797 } else if (binding instanceof ParameterizedTypeBinding) { 798 ref = getTypeReference(((ParameterizedTypeBinding) binding).type); 799 if (((ParameterizedTypeBinding) binding).arguments != null) 800 for (TypeBinding b : ((ParameterizedTypeBinding) binding).arguments) { 801 ref.getActualTypeArguments().add(getTypeReference(b)); 802 } 803 } else if (binding instanceof BinaryTypeBinding) { 804 ref = factory.Core().createTypeReference(); 805 if (binding.enclosingType() != null) { 806 ref.setDeclaringType(getTypeReference(binding 807 .enclosingType())); 808 } else { 809 ref.setPackage(getPackageReference(binding.getPackage())); 810 } 811 ref.setSimpleName(new String (binding.sourceName())); 812 813 } else if (binding instanceof TypeVariableBinding) { 814 ref = factory.Core().createTypeParameterReference(); 815 if (binding instanceof CaptureBinding) { 816 ref.setSimpleName("?"); 817 bounds = true; 818 } else { 819 ref.setSimpleName(new String (binding.sourceName())); 820 } 821 if (bounds 822 && ((TypeVariableBinding) binding).firstBound != null) { 823 bounds = false; 824 ((CtTypeParameterReference) ref) 825 .getBounds() 826 .add( 827 getTypeReference(((TypeVariableBinding) binding).firstBound)); 828 } 829 if (binding instanceof CaptureBinding) 830 bounds = false; 831 832 } else if (binding instanceof BaseTypeBinding) { 833 String name = new String (binding.sourceName()); 834 ref = basestypes.get(name); 835 if (ref == null) { 836 ref = factory.Core().createTypeReference(); 837 ref.setSimpleName(name); 838 basestypes.put(name, ref); 839 } 840 } else if (binding instanceof WildcardBinding) { 841 CtTypeParameterReference reference = factory.Core() 842 .createTypeParameterReference(); 843 reference.setSimpleName("?"); 844 if (((WildcardBinding) binding).boundKind == Wildcard.SUPER) 845 reference.setUpper(false); 846 847 if (((WildcardBinding) binding).bound != null) 848 reference 849 .getBounds() 850 .add( 851 getTypeReference(((WildcardBinding) binding).bound)); 852 ref = reference; 853 } else if (binding instanceof SourceTypeBinding) { 854 ref = factory.Core().createTypeReference(); 855 if (binding.isAnonymousType()) { 856 ref.setSimpleName(""); 857 } else { 858 ref.setSimpleName(new String (binding.sourceName())); 859 if (binding.enclosingType() != null) 860 ref.setDeclaringType(getTypeReference(binding 861 .enclosingType())); 862 else 863 ref 864 .setPackage(getPackageReference(binding 865 .getPackage())); 866 } 867 } else if (binding instanceof ArrayBinding) { 868 CtArrayTypeReference arrayref = factory.Core() 869 .createArrayTypeReference(); 870 ref = arrayref; 871 for (int i = 1; i < binding.dimensions(); i++) { 872 CtArrayTypeReference tmp = factory.Core() 873 .createArrayTypeReference(); 874 arrayref.setComponentType(tmp); 875 arrayref = tmp; 876 } 877 arrayref.setComponentType(getTypeReference(binding 878 .leafComponentType())); 879 } else { 880 throw new RuntimeException ("Unkown TypeBinding"); 881 } 882 return ref; 883 } 884 885 @SuppressWarnings ("unchecked") 886 public CtVariableReference getVariableReference(VariableBinding varbin) { 887 888 if (varbin instanceof FieldBinding) { 889 CtFieldReference ref = factory.Core().createFieldReference(); 890 ref.setSimpleName(new String (varbin.name)); 891 ref.setType(getTypeReference(varbin.type)); 892 893 if (((FieldBinding) varbin).declaringClass != null) 894 ref 895 .setDeclaringType(getTypeReference(((FieldBinding) varbin).declaringClass)); 896 else { 897 ref.setDeclaringType(ref.getType()); 898 } 899 ref.setFinal(varbin.isFinal()); 900 ref 901 .setStatic((varbin.modifiers & ClassFileConstants.AccStatic) != 0); 902 return ref; 903 } else if (varbin instanceof LocalVariableBinding) { 904 if (((LocalVariableBinding) varbin).declaration instanceof Argument 905 && ((LocalVariableBinding) varbin).declaringScope instanceof MethodScope) { 906 CtParameterReference ref = factory.Core() 907 .createParameterReference(); 908 ref.setSimpleName(new String (varbin.name)); 909 ref.setType(getTypeReference(varbin.type)); 910 ref 911 .setDeclaringExecutable(getExecutableReference(((AbstractMethodDeclaration) ((MethodScope) ((LocalVariableBinding) varbin).declaringScope) 912 .referenceContext()).binding)); 913 return ref; 914 } else { 915 CtLocalVariableReference ref = factory.Core() 916 .createLocalVariableReference(); 917 ref.setSimpleName(new String (varbin.name)); 918 CtTypeReference ref2 = getTypeReference(varbin.type); 919 ref.setType(ref2); 920 ref.setDeclaration(getLocalVariableDeclaration(ref 921 .getSimpleName())); 922 return ref; 923 } 924 } else { 925 throw new RuntimeException ("Unknow VariableBinding"); 926 } 927 } 928 } 929 930 public static String cleanJavadoc(String doc) { 931 StringBuffer ret = new StringBuffer (); 932 String [] docs = doc.split("\n"); 933 for (int i = 1; i < docs.length - 1; i++) { 934 ret.append(docs[i].substring(docs[i].indexOf('*') + 1)); 935 ret.append("\n"); 936 } 937 return ret.toString(); 938 } 939 940 public static Set <ModifierKind> getModifier(int mod) { 941 Set <ModifierKind> ret = new TreeSet <ModifierKind>(); 942 if ((mod & ClassFileConstants.AccPublic) != 0) 943 ret.add(ModifierKind.PUBLIC); 944 if ((mod & ClassFileConstants.AccPrivate) != 0) 945 ret.add(ModifierKind.PRIVATE); 946 if ((mod & ClassFileConstants.AccProtected) != 0) 947 ret.add(ModifierKind.PROTECTED); 948 if ((mod & ClassFileConstants.AccStatic) != 0) 949 ret.add(ModifierKind.STATIC); 950 if ((mod & ClassFileConstants.AccFinal) != 0) 951 ret.add(ModifierKind.FINAL); 952 if ((mod & ClassFileConstants.AccSynchronized) != 0) 953 ret.add(ModifierKind.SYNCHRONIZED); 954 if ((mod & ClassFileConstants.AccVolatile) != 0) 955 ret.add(ModifierKind.VOLATILE); 956 if ((mod & ClassFileConstants.AccTransient) != 0) 957 ret.add(ModifierKind.TRANSIENT); 958 if ((mod & ClassFileConstants.AccAbstract) != 0) 959 ret.add(ModifierKind.ABSTRACT); 960 if ((mod & ClassFileConstants.AccStrictfp) != 0) 961 ret.add(ModifierKind.STRICTFP); 962 return ret; 963 } 964 965 968 public static final int searchLineNumber(int[] startLineIndexes, 969 int position) { 970 if (startLineIndexes == null) 971 return 1; 972 int length = startLineIndexes.length; 973 if (length == 0) 974 return 1; 975 int g = 0, d = length - 1; 976 int m = 0, start; 977 while (g <= d) { 978 m = (g + d) / 2; 979 if (position < (start = startLineIndexes[m])) { 980 d = m - 1; 981 } else if (position > start) { 982 g = m + 1; 983 } else { 984 return m + 1; 985 } 986 } 987 if (position < startLineIndexes[m]) { 988 return m + 1; 989 } 990 return m + 2; 991 } 992 993 BuilderContext context = new BuilderContext(); 994 995 ParentExiter exiter = new ParentExiter(); 996 997 Factory factory; 998 999 ReferenceBuilder references = new ReferenceBuilder(); 1000 1001 public boolean template = false; 1002 1003 public JDTTreeBuilder(Factory factory) { 1004 super(); 1005 this.factory = factory; 1006 } 1007 1008 CtSimpleType<?> createType(TypeDeclaration typeDeclaration) { 1009 CtSimpleType type = null; 1010 if ((typeDeclaration.modifiers & ClassFileConstants.AccAnnotation) != 0) { 1011 type = factory.Core().createAnnotationType(); 1012 } else if ((typeDeclaration.modifiers & ClassFileConstants.AccEnum) != 0) { 1013 type = factory.Core().createEnum(); 1014 } else if ((typeDeclaration.modifiers & ClassFileConstants.AccInterface) != 0) { 1015 CtInterface<?> interf = factory.Core().createInterface(); 1016 if (typeDeclaration.superInterfaces != null) { 1017 for (TypeReference ref : typeDeclaration.superInterfaces) { 1018 interf.getSuperInterfaces().add( 1019 references.getTypeReference(ref.resolvedType)); 1020 } 1021 } 1022 if (typeDeclaration.typeParameters != null) 1023 for (TypeParameter p : typeDeclaration.typeParameters) { 1024 interf.getFormalTypeParameters().add( 1025 references.getBoundedTypeReference(p.binding)); 1026 } 1027 type = interf; 1028 } else { 1029 CtClass<?> cl = factory.Core().createClass(); 1030 if (typeDeclaration.superclass != null) { 1031 cl 1032 .setSuperclass(references 1033 .getTypeReference(typeDeclaration.superclass.resolvedType)); 1034 } 1035 if (typeDeclaration.superInterfaces != null) { 1036 for (TypeReference ref : typeDeclaration.superInterfaces) { 1037 cl.getSuperInterfaces().add( 1038 references.getTypeReference(ref.resolvedType)); 1039 } 1040 } 1041 if (typeDeclaration.typeParameters != null) 1042 for (TypeParameter p : typeDeclaration.typeParameters) { 1043 cl.getFormalTypeParameters().add( 1044 references.getBoundedTypeReference(p.binding)); 1045 } 1046 type = cl; 1047 } 1048 type.setSimpleName(new String (typeDeclaration.name)); 1049 type.setModifiers(getModifier(typeDeclaration.modifiers)); 1051 1053 return type; 1054 } 1055 1056 @Override 1057 public void endVisit(AllocationExpression allocationExpression, 1058 BlockScope scope) { 1059 context.exit(allocationExpression); 1060 } 1061 1062 @Override 1063 public void endVisit(AND_AND_Expression and_and_Expression, BlockScope scope) { 1064 context.exit(and_and_Expression); 1065 } 1066 1067 @Override 1068 public void endVisit(AnnotationMethodDeclaration annotationTypeDeclaration, 1069 ClassScope classScope) { 1070 context.exit(annotationTypeDeclaration); 1071 } 1072 1073 public void endVisit(Argument argument, BlockScope scope) { 1074 context.exit(argument); 1075 } 1076 1077 @Override 1078 public void endVisit(ArrayAllocationExpression arrayAllocationExpression, 1079 BlockScope scope) { 1080 context.exit(arrayAllocationExpression); 1081 } 1082 1083 @Override 1084 public void endVisit(ArrayInitializer arrayInitializer, BlockScope scope) { 1085 if (!context.arrayInitializer.isEmpty()) { 1086 context.arrayInitializer.pop(); 1087 } else { 1088 context.exit(arrayInitializer); 1089 } 1090 } 1091 1092 @Override 1093 public void endVisit(ArrayReference arrayReference, BlockScope scope) { 1094 context.exit(arrayReference); 1095 } 1096 1097 @Override 1098 public void endVisit(ArrayTypeReference arrayTypeReference, BlockScope scope) { 1099 context.exit(arrayTypeReference); 1100 } 1101 1102 @Override 1103 public void endVisit(AssertStatement assertStatement, BlockScope scope) { 1104 context.exit(assertStatement); 1105 } 1106 1107 @Override 1108 public void endVisit(Assignment assignment, BlockScope scope) { 1109 context.exit(assignment); 1110 } 1111 1112 @Override 1113 public void endVisit(BinaryExpression binaryExpression, BlockScope scope) { 1114 context.exit(binaryExpression); 1115 } 1116 1117 @Override 1118 public void endVisit(Block block, BlockScope scope) { 1119 context.exit(block); 1120 } 1121 1122 @Override 1123 public void endVisit(BreakStatement breakStatement, BlockScope scope) { 1124 context.exit(breakStatement); 1125 } 1126 1127 @Override 1128 public void endVisit(CaseStatement caseStatement, BlockScope scope) { 1129 context.exit(caseStatement); 1130 } 1131 1132 @Override 1133 public void endVisit(CharLiteral charLiteral, BlockScope scope) { 1134 context.exit(charLiteral); 1135 } 1136 1137 @Override 1138 public void endVisit(ClassLiteralAccess classLiteral, BlockScope scope) { 1139 context.exit(classLiteral); 1140 } 1141 1142 @Override 1143 public void endVisit(CompoundAssignment compoundAssignment, BlockScope scope) { 1144 context.exit(compoundAssignment); 1145 } 1146 1147 @Override 1148 public void endVisit(ConditionalExpression conditionalExpression, 1149 BlockScope scope) { 1150 context.exit(conditionalExpression); 1151 } 1152 1153 public void endVisit(ConstructorDeclaration constructorDeclaration, 1154 ClassScope scope) { 1155 context.exit(constructorDeclaration); 1156 if (context.stack.peek().node == constructorDeclaration) 1157 context.exit(constructorDeclaration); 1158 } 1159 1160 @Override 1161 public void endVisit(ContinueStatement continueStatement, BlockScope scope) { 1162 context.exit(continueStatement); 1163 } 1164 1165 @Override 1166 public void endVisit(DoStatement doStatement, BlockScope scope) { 1167 context.exit(doStatement); 1168 } 1169 1170 @Override 1171 public void endVisit(DoubleLiteral doubleLiteral, BlockScope scope) { 1172 context.exit(doubleLiteral); 1173 } 1174 1175 @Override 1176 public void endVisit(EqualExpression equalExpression, BlockScope scope) { 1177 context.exit(equalExpression); 1178 } 1179 1180 @Override 1181 public void endVisit(ExplicitConstructorCall explicitConstructor, 1182 BlockScope scope) { 1183 context.exit(explicitConstructor); 1184 } 1185 1186 public void endVisit(ExtendedStringLiteral extendedStringLiteral, 1187 BlockScope scope) { 1188 context.exit(extendedStringLiteral); 1189 } 1190 1191 @Override 1192 public void endVisit(FalseLiteral falseLiteral, BlockScope scope) { 1193 context.exit(falseLiteral); 1194 } 1195 1196 public void endVisit(FieldDeclaration fieldDeclaration, MethodScope scope) { 1197 context.exit(fieldDeclaration); 1198 } 1199 1200 @SuppressWarnings ("unchecked") 1201 public void endVisit(FieldReference fieldReference, BlockScope scope) { 1202 context.exit(fieldReference); 1203 } 1204 1205 @Override 1206 public void endVisit(FloatLiteral floatLiteral, BlockScope scope) { 1207 context.exit(floatLiteral); 1208 } 1209 1210 public void endVisit(ForeachStatement forStatement, BlockScope scope) { 1211 context.exit(forStatement); 1212 } 1213 1214 @Override 1215 public void endVisit(ForStatement forStatement, BlockScope scope) { 1216 context.exit(forStatement); 1217 } 1218 1219 @Override 1220 public void endVisit(IfStatement ifStatement, BlockScope scope) { 1221 context.exit(ifStatement); 1222 } 1223 1224 @Override 1225 public void endVisit(Initializer initializer, MethodScope scope) { 1226 context.exit(initializer); 1227 } 1228 1229 @Override 1230 public void endVisit(InstanceOfExpression instanceOfExpression, 1231 BlockScope scope) { 1232 context.exit(instanceOfExpression); 1233 } 1234 1235 @Override 1236 public void endVisit(IntLiteral intLiteral, BlockScope scope) { 1237 context.exit(intLiteral); 1238 } 1239 1240 @Override 1241 public void endVisit(LocalDeclaration localDeclaration, BlockScope scope) { 1242 context.exit(localDeclaration); 1243 } 1244 1245 public void endVisit(LongLiteral longLiteral, BlockScope scope) { 1246 context.exit(longLiteral); 1247 } 1248 1249 @Override 1250 public void endVisit(MarkerAnnotation annotation, BlockScope scope) { 1251 context.exit(annotation); 1252 } 1253 1254 @Override 1255 public void endVisit(MemberValuePair pair, BlockScope scope) { 1256 if (!context.annotationValueName.pop().equals(new String (pair.name))) { 1257 throw new RuntimeException ("Unconsistant Stack"); 1258 } 1259 } 1260 1261 @Override 1262 public void endVisit(MessageSend messageSend, BlockScope scope) { 1263 context.exit(messageSend); 1264 } 1265 1266 public void endVisit(MethodDeclaration methodDeclaration, ClassScope scope) { 1267 context.exit(methodDeclaration); 1269 if (context.stack.peek().node == methodDeclaration) 1270 context.exit(methodDeclaration); 1271 } 1272 1273 public void endVisit(NormalAnnotation annotation, BlockScope scope) { 1274 context.exit(annotation); 1275 } 1276 1277 @Override 1278 public void endVisit(NullLiteral nullLiteral, BlockScope scope) { 1279 context.exit(nullLiteral); 1280 } 1281 1282 @Override 1283 public void endVisit(OR_OR_Expression or_or_Expression, BlockScope scope) { 1284 context.exit(or_or_Expression); 1285 } 1286 1287 @Override 1288 public void endVisit( 1289 ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference, 1290 ClassScope scope) { 1291 context.exit(parameterizedQualifiedTypeReference); 1292 } 1293 1294 @Override 1295 public void endVisit( 1296 ParameterizedSingleTypeReference parameterizedSingleTypeReference, 1297 BlockScope scope) { 1298 context.exit(parameterizedSingleTypeReference); 1299 } 1300 1301 @Override 1302 public void endVisit( 1303 ParameterizedSingleTypeReference parameterizedSingleTypeReference, 1304 ClassScope scope) { 1305 context.exit(parameterizedSingleTypeReference); 1306 } 1307 1308 @Override 1309 public void endVisit(PostfixExpression postfixExpression, BlockScope scope) { 1310 context.exit(postfixExpression); 1311 } 1312 1313 @Override 1314 public void endVisit(PrefixExpression prefixExpression, BlockScope scope) { 1315 context.exit(prefixExpression); 1316 } 1317 1318 @Override 1319 public void endVisit( 1320 QualifiedAllocationExpression qualifiedAllocationExpression, 1321 BlockScope scope) { 1322 endVisit((AllocationExpression) qualifiedAllocationExpression, scope); 1323 } 1324 1325 public void endVisit(QualifiedNameReference qualifiedNameReference, 1326 BlockScope scope) { 1327 if (context.stack.peek().node == qualifiedNameReference) 1328 context.exit(qualifiedNameReference); 1329 } 1330 1331 @Override 1332 public void endVisit(QualifiedThisReference qualifiedThisReference, 1333 BlockScope scope) { 1334 endVisit((ThisReference) qualifiedThisReference, scope); 1335 } 1336 1337 @Override 1338 public void endVisit(ReturnStatement returnStatement, BlockScope scope) { 1339 context.exit(returnStatement); 1340 } 1341 1342 @Override 1343 public void endVisit(SingleMemberAnnotation annotation, BlockScope scope) { 1344 if (!context.annotationValueName.pop().equals("value")) { 1345 throw new RuntimeException ("unconsistant Stack"); 1346 } 1347 context.exit(annotation); 1348 } 1349 1350 @Override 1351 public void endVisit(SingleNameReference singleNameReference, 1352 BlockScope scope) { 1353 if (context.stack.peek().node == singleNameReference) 1354 context.exit(singleNameReference); 1355 } 1356 1357 @Override 1358 public void endVisit(SingleTypeReference singleTypeReference, 1359 BlockScope scope) { 1360 context.exit(singleTypeReference); 1361 } 1362 1363 @Override 1364 public void endVisit(SingleTypeReference singleTypeReference, 1365 ClassScope scope) { 1366 context.exit(singleTypeReference); 1367 } 1368 1369 @Override 1370 public void endVisit(StringLiteral stringLiteral, BlockScope scope) { 1371 context.exit(stringLiteral); 1372 } 1373 1374 @Override 1375 public void endVisit(StringLiteralConcatenation literal, BlockScope scope) { 1376 context.exit(literal); 1377 } 1378 1379 @Override 1380 public void endVisit(SuperReference superReference, BlockScope scope) { 1381 context.exit(superReference); 1382 } 1383 1384 @Override 1385 public void endVisit(SwitchStatement switchStatement, BlockScope scope) { 1386 context.exit(switchStatement); 1387 } 1388 1389 @Override 1390 public void endVisit(SynchronizedStatement synchronizedStatement, 1391 BlockScope scope) { 1392 context.exit(synchronizedStatement); 1393 } 1394 1395 @Override 1396 public void endVisit(ThisReference thisReference, BlockScope scope) { 1397 context.exit(thisReference); 1398 } 1399 1400 public void endVisit(ThrowStatement throwStatement, BlockScope scope) { 1401 context.exit(throwStatement); 1402 } 1403 1404 @Override 1405 public void endVisit(TrueLiteral trueLiteral, BlockScope scope) { 1406 context.exit(trueLiteral); 1407 } 1408 1409 @Override 1410 public void endVisit(TryStatement tryStatement, BlockScope scope) { 1411 context.exit(tryStatement); 1412 } 1413 1414 @Override 1415 public void endVisit(TypeDeclaration localTypeDeclaration, BlockScope scope) { 1416 context.exit(localTypeDeclaration); 1417 } 1418 1419 @Override 1420 public void endVisit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { 1421 while (!context.stack.isEmpty() 1422 && context.stack.peek().node == memberTypeDeclaration) { 1423 context.exit(memberTypeDeclaration); 1424 } 1425 } 1426 1427 @Override 1428 public void endVisit(TypeDeclaration typeDeclaration, 1429 CompilationUnitScope scope) { 1430 while (!context.stack.isEmpty() 1431 && context.stack.peek().node == typeDeclaration) { 1432 context.exit(typeDeclaration); 1433 } 1434 context.compilationunitdeclaration = null; 1435 } 1436 1437 @Override 1438 public void endVisit(UnaryExpression unaryExpression, BlockScope scope) { 1439 context.exit(unaryExpression); 1440 } 1441 1442 @Override 1443 public void endVisit(WhileStatement whileStatement, BlockScope scope) { 1444 context.exit(whileStatement); 1445 } 1446 1447 BinaryOperatorKind getBinaryOperatorKind(int bits) { 1448 switch (bits) { 1450 case OperatorIds.EQUAL_EQUAL: 1451 return BinaryOperatorKind.EQ; 1452 case OperatorIds.LESS_EQUAL: 1453 return BinaryOperatorKind.LE; 1454 case OperatorIds.GREATER_EQUAL: 1455 return BinaryOperatorKind.GE; 1456 case OperatorIds.NOT_EQUAL: 1457 return BinaryOperatorKind.NE; 1458 case OperatorIds.LEFT_SHIFT: 1459 return BinaryOperatorKind.SL; 1460 case OperatorIds.RIGHT_SHIFT: 1461 return BinaryOperatorKind.SR; 1462 case OperatorIds.UNSIGNED_RIGHT_SHIFT: 1463 return BinaryOperatorKind.USR; 1464 case OperatorIds.OR_OR: 1465 return BinaryOperatorKind.OR; 1466 case OperatorIds.AND_AND: 1467 return BinaryOperatorKind.AND; 1468 case OperatorIds.PLUS: 1469 return BinaryOperatorKind.PLUS; 1470 case OperatorIds.MINUS: 1471 return BinaryOperatorKind.MINUS; 1472 case OperatorIds.NOT: 1473 return BinaryOperatorKind.NE; 1474 case OperatorIds.REMAINDER: 1475 return BinaryOperatorKind.MOD; 1476 case OperatorIds.XOR: 1477 return BinaryOperatorKind.BITXOR; 1478 case OperatorIds.AND: 1479 return BinaryOperatorKind.BITAND; 1480 case OperatorIds.MULTIPLY: 1481 return BinaryOperatorKind.MUL; 1482 case OperatorIds.OR: 1483 return BinaryOperatorKind.BITOR; 1484 case OperatorIds.DIVIDE: 1485 return BinaryOperatorKind.DIV; 1486 case OperatorIds.GREATER: 1487 return BinaryOperatorKind.GT; 1488 case OperatorIds.LESS: 1489 return BinaryOperatorKind.LT; 1490 case OperatorIds.QUESTIONCOLON: 1491 throw new RuntimeException ("Unknow operator"); 1492 case OperatorIds.EQUAL: 1493 return BinaryOperatorKind.EQ; 1494 } 1495 return null; 1496 } 1497 1498 public List <CtSimpleType<?>> getCreatedTypes() { 1499 return context.getCreatedTypes(); 1500 } 1501 1502 public String getJavaDoc(Javadoc javadoc, 1503 CompilationUnitDeclaration declaration) { 1504 if (javadoc != null) { 1505 String s = new String (declaration.compilationResult.compilationUnit 1506 .getContents(), javadoc.sourceStart, javadoc.sourceEnd 1507 - javadoc.sourceStart + 1); 1508 return cleanJavadoc(s); 1509 } 1510 return null; 1511 } 1512 1513 @SuppressWarnings ("unchecked") 1514 protected <T> CtLocalVariable<T> getLocalVariableDeclaration( 1515 final String name) { 1516 List <CtElement> reversedElements = new ArrayList <CtElement>(); 1517 for (ASTPair element : context.stack) { 1518 reversedElements.add(0, element.element); 1519 } 1520 1521 for (CtElement element : reversedElements) { 1522 1524 List <CtLocalVariable> var = Query.getElements(element, 1525 new TypeFilter<CtLocalVariable>(CtLocalVariable.class) { 1526 @Override 1527 public boolean matches(CtLocalVariable element) { 1528 return name.equals(element.getSimpleName()) 1529 && super.matches(element); 1530 } 1531 }); 1532 1533 if (var.size() > 0) { 1534 return var.get(0); 1535 } 1536 } 1537 throw new IllegalStateException ( 1538 "Could not find declaration for local variable " + name); 1539 } 1540 1541 UnaryOperatorKind getUnaryOperator(int op) { 1542 switch (op) { 1543 case OperatorIds.PLUS: 1544 return UnaryOperatorKind.POS; 1545 case OperatorIds.MINUS: 1546 return UnaryOperatorKind.NEG; 1547 case OperatorIds.NOT: 1548 return UnaryOperatorKind.NOT; 1549 case OperatorIds.TWIDDLE: 1550 return UnaryOperatorKind.COMPL; 1551 } 1552 return null; 1553 } 1554 1555 @SuppressWarnings ("unchecked") 1556 @Override 1557 public boolean visit(AllocationExpression allocationExpression, 1558 BlockScope scope) { 1559 CtNewClass<?> c = factory.Core().createNewClass(); 1560 if (allocationExpression.type != null) 1561 c.setType(references 1562 .getTypeReference(allocationExpression.type.resolvedType)); 1563 c.setExecutable(references 1564 .getExecutableReference(allocationExpression.binding)); 1565 c.getExecutable().setType( 1566 (CtTypeReference) c.getExecutable().getDeclaringType()); 1567 context.enter(c, allocationExpression); 1568 1569 if (allocationExpression.enclosingInstance() != null) { 1570 context.target.push(c); 1571 allocationExpression.enclosingInstance().traverse(this, scope); 1572 context.target.pop(); 1573 } 1574 1575 context.pushArgument(c); 1576 if (allocationExpression.arguments != null) { 1577 for (Expression e : allocationExpression.arguments) 1578 e.traverse(this, scope); 1579 } 1580 context.popArgument(c); 1581 return false; 1582 } 1583 1584 @Override 1585 public boolean visit(AND_AND_Expression and_and_Expression, BlockScope scope) { 1586 CtBinaryOperator op = factory.Core().createBinaryOperator(); 1587 op 1588 .setKind(getBinaryOperatorKind((and_and_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); 1589 context.enter(op, and_and_Expression); 1590 return true; } 1592 1593 @SuppressWarnings ("unchecked") 1594 @Override 1595 public boolean visit(AnnotationMethodDeclaration annotationTypeDeclaration, 1596 ClassScope classScope) { 1597 CtField<?> f = factory.Core().createField(); 1598 f.setSimpleName(new String (annotationTypeDeclaration.selector)); 1599 f 1600 .setType(references 1601 .getTypeReference(annotationTypeDeclaration.binding.returnType)); 1602 context.enter(f, annotationTypeDeclaration); 1603 1604 if (annotationTypeDeclaration.annotations != null) { 1605 int annotationsLength = annotationTypeDeclaration.annotations.length; 1606 for (int i = 0; i < annotationsLength; i++) 1607 annotationTypeDeclaration.annotations[i].traverse(this, 1608 annotationTypeDeclaration.scope); 1609 } 1610 1611 if (annotationTypeDeclaration.defaultValue != null) { 1612 annotationTypeDeclaration.defaultValue.traverse(this, 1613 annotationTypeDeclaration.scope); 1614 } 1615 return false; 1616 } 1617 1618 @SuppressWarnings ("unchecked") 1619 public boolean visit(Argument argument, BlockScope scope) { 1620 CtParameter<?> p = factory.Core().createParameter(); 1621 p.setSimpleName(new String (argument.name)); 1622 p.setVarArgs(argument.isVarArgs()); 1623 p.setModifiers(getModifier(argument.modifiers)); 1624 if (argument.type != null) 1625 p.setType(references.getTypeReference(argument.type.resolvedType)); 1626 context.enter(p, argument); 1627 if (argument.initialization != null) 1628 argument.initialization.traverse(this, scope); 1629 1630 if (argument.annotations != null) 1631 for (Annotation a : argument.annotations) 1632 a.traverse(this, scope); 1633 return false; 1634 } 1635 1636 @SuppressWarnings ("unchecked") 1637 @Override 1638 public boolean visit(ArrayAllocationExpression arrayAllocationExpression, 1639 BlockScope scope) { 1640 CtNewArray<?> array = factory.Core().createNewArray(); 1641 array.setType(references 1642 .getTypeReference(arrayAllocationExpression.resolvedType)); 1643 1644 context.enter(array, arrayAllocationExpression); 1645 1646 context.pushArgument(array); 1647 if (arrayAllocationExpression.dimensions != null) 1648 for (Expression e : arrayAllocationExpression.dimensions) 1649 if (e != null) 1650 e.traverse(this, scope); 1651 context.popArgument(array); 1652 1653 if (arrayAllocationExpression.initializer != null 1654 && arrayAllocationExpression.initializer.expressions != null) { 1655 for (Expression e : arrayAllocationExpression.initializer.expressions) 1656 e.traverse(this, scope); 1657 } 1658 return false; 1659 } 1660 1661 @Override 1662 public boolean visit(ArrayInitializer arrayInitializer, BlockScope scope) { 1663 1664 if (context.annotationValueName.isEmpty()) { 1665 CtNewArray array = factory.Core().createNewArray(); 1666 context.enter(array, arrayInitializer); 1667 } else { 1668 context.arrayInitializer.push(context.stack.peek().element); 1669 } 1670 return super.visit(arrayInitializer, scope); 1671 } 1672 1673 @Override 1674 public boolean visit(ArrayReference arrayReference, BlockScope scope) { 1675 CtArrayAccess a = factory.Core().createArrayAccess(); 1676 context.enter(a, arrayReference); 1677 arrayReference.receiver.traverse(this, scope); 1678 context.arguments.push(a); 1679 arrayReference.position.traverse(this, scope); 1680 context.arguments.pop(); 1681 return false; 1682 } 1683 1684 @Override 1685 public boolean visit(ArrayTypeReference arrayTypeReference, BlockScope scope) { 1686 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 1687 l 1688 .setValue(references 1689 .getTypeReference(arrayTypeReference.resolvedType)); 1690 context.enter(l, arrayTypeReference); 1691 return true; 1692 } 1693 1694 @Override 1695 public boolean visit(AssertStatement assertStatement, BlockScope scope) { 1696 CtAssert a = factory.Core().createAssert(); 1697 context.enter(a, assertStatement); 1698 assertStatement.assertExpression.traverse(this, scope); 1699 context.arguments.push(a); 1700 if (assertStatement.exceptionArgument != null) { 1701 assertStatement.exceptionArgument.traverse(this, scope); 1702 } 1703 context.arguments.pop(); 1704 return false; 1705 } 1706 1707 @Override 1708 public boolean visit(Assignment assignment, BlockScope scope) { 1709 CtAssignment assign = factory.Core().createAssignment(); 1710 context.enter(assign, assignment); 1711 return true; 1712 } 1713 1714 @Override 1715 public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { 1716 CtBinaryOperator<?> op = factory.Core().createBinaryOperator(); 1717 op 1718 .setKind(getBinaryOperatorKind((binaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); 1719 context.enter(op, binaryExpression); 1720 return true; 1721 } 1722 1723 @Override 1724 public boolean visit(Block block, BlockScope scope) { 1725 CtBlock<?> b = factory.Core().createBlock(); 1726 context.enter(b, block); 1727 return true; 1728 } 1729 1730 @Override 1731 public boolean visit(BreakStatement breakStatement, BlockScope scope) { 1732 CtBreak b = factory.Core().createBreak(); 1733 if (breakStatement.label != null) 1734 b.setTargetLabel(new String (breakStatement.label)); 1735 context.enter(b, breakStatement); 1736 return true; 1737 } 1738 1739 @Override 1740 public boolean visit(CaseStatement caseStatement, BlockScope scope) { 1741 CtCase c = factory.Core().createCase(); 1742 context.enter(c, caseStatement); 1743 1744 if (caseStatement.constantExpression != null) { 1745 context.selector = true; 1746 caseStatement.constantExpression.traverse(this, scope); 1747 context.selector = false; 1748 } 1749 return false; 1750 } 1751 1752 @Override 1753 public boolean visit(CastExpression castExpression, BlockScope scope) { 1754 context.casts.add(references 1755 .getTypeReference(castExpression.resolvedType)); 1756 castExpression.expression.traverse(this, scope); 1757 return false; 1758 } 1759 1760 @Override 1761 public boolean visit(CharLiteral charLiteral, BlockScope scope) { 1762 CtLiteral<Character > l = factory.Core().createLiteral(); 1763 l.setValue(charLiteral.constant.charValue()); 1764 context.enter(l, charLiteral); 1765 return true; 1766 } 1767 1768 @SuppressWarnings ("unchecked") 1769 @Override 1770 public boolean visit(ClassLiteralAccess classLiteral, BlockScope scope) { 1771 CtTypeReference ref = references 1772 .getTypeReference(classLiteral.targetType); 1773 CtFieldReference fr = factory.Core().createFieldReference(); 1774 fr.setSimpleName("class"); 1775 fr.setType(ref); 1776 fr.setDeclaringType(ref); 1777 1778 CtFieldAccess<Class > fa = factory.Core().createFieldAccess(); 1779 fa.setType(ref); 1780 fa.setVariable(fr); 1781 1782 context.enter(fa, classLiteral); 1783 1784 return true; 1785 } 1786 1787 @Override 1788 public boolean visit(CompoundAssignment compoundAssignment, BlockScope scope) { 1789 CtOperatorAssignment a = factory.Core().createOperatorAssignment(); 1790 a.setKind(getBinaryOperatorKind(compoundAssignment.operator)); 1791 context.enter(a, compoundAssignment); 1792 return super.visit(compoundAssignment, scope); 1793 } 1794 1795 @Override 1796 public boolean visit(ConditionalExpression conditionalExpression, 1797 BlockScope scope) { 1798 CtConditional c = factory.Core().createConditional(); 1799 context.enter(c, conditionalExpression); 1800 return super.visit(conditionalExpression, scope); 1801 } 1802 1803 @SuppressWarnings ("unchecked") 1804 public boolean visit(ConstructorDeclaration constructorDeclaration, 1805 ClassScope scope) { 1806 CtConstructor c = factory.Core().createConstructor(); 1807 c.setModifiers(getModifier(constructorDeclaration.modifiers)); 1808 1809 c.setDocComment(getJavaDoc(constructorDeclaration.javadoc, scope 1810 .referenceCompilationUnit())); 1811 1812 context.enter(c, constructorDeclaration); 1813 1814 if (constructorDeclaration.annotations != null) { 1815 int annotationsLength = constructorDeclaration.annotations.length; 1816 for (int i = 0; i < annotationsLength; i++) 1817 constructorDeclaration.annotations[i].traverse(this, 1818 constructorDeclaration.scope); 1819 } 1820 1821 context.pushArgument(c); 1822 if (constructorDeclaration.arguments != null) { 1823 int argumentLength = constructorDeclaration.arguments.length; 1824 for (int i = 0; i < argumentLength; i++) 1825 constructorDeclaration.arguments[i].traverse(this, 1826 constructorDeclaration.scope); 1827 } 1828 context.popArgument(c); 1829 1830 if (constructorDeclaration.thrownExceptions != null) { 1831 for (TypeReference r : constructorDeclaration.thrownExceptions) 1832 c.getThrownTypes().add( 1833 references.getTypeReference(r.resolvedType)); 1834 } 1835 1836 if (!constructorDeclaration.isAbstract()) { 1838 CtBlock<?> b = factory.Core().createBlock(); 1839 context.enter(b, constructorDeclaration); 1840 } 1841 1842 if (constructorDeclaration.constructorCall != null) 1843 constructorDeclaration.constructorCall.traverse(this, 1844 constructorDeclaration.scope); 1845 1846 if (constructorDeclaration.statements != null) { 1847 for (Statement s : constructorDeclaration.statements) 1848 s.traverse(this, constructorDeclaration.scope); 1849 } 1850 return false; 1851 } 1852 1853 @Override 1854 public boolean visit(ContinueStatement continueStatement, BlockScope scope) { 1855 CtContinue c = factory.Core().createContinue(); 1856 context.enter(c, continueStatement); 1857 return true; 1858 } 1859 1860 @Override 1861 public boolean visit(DoStatement doStatement, BlockScope scope) { 1862 CtDo d = factory.Core().createDo(); 1863 context.enter(d, doStatement); 1864 return true; 1865 } 1866 1867 @Override 1868 public boolean visit(DoubleLiteral doubleLiteral, BlockScope scope) { 1869 CtLiteral<Double > d = factory.Core().createLiteral(); 1870 d.setValue(doubleLiteral.constant.doubleValue()); 1871 context.enter(d, doubleLiteral); 1872 return true; 1873 } 1874 1875 @Override 1876 public boolean visit(EqualExpression equalExpression, BlockScope scope) { 1877 CtBinaryOperator op = factory.Core().createBinaryOperator(); 1878 op 1879 .setKind(getBinaryOperatorKind((equalExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); 1880 context.enter(op, equalExpression); 1881 return true; } 1883 1884 @SuppressWarnings ("unchecked") 1885 @Override 1886 public boolean visit(ExplicitConstructorCall explicitConstructor, 1887 BlockScope scope) { 1888 CtInvocation inv = factory.Core().createInvocation(); 1889 inv.setExecutable(references 1890 .getExecutableReference(explicitConstructor.binding)); 1891 inv.getExecutable().setType(inv.getExecutable().getDeclaringType()); 1892 inv.setType(inv.getExecutable().getType()); 1893 1894 context.enter(inv, explicitConstructor); 1895 1896 if (explicitConstructor.qualification != null) { 1897 explicitConstructor.qualification.traverse(this, scope); 1898 } 1899 if (explicitConstructor.typeArguments != null) { 1900 for (int i = 0, typeArgumentsLength = explicitConstructor.typeArguments.length; i < typeArgumentsLength; i++) { 1901 explicitConstructor.typeArguments[i].traverse(this, scope); 1902 } 1903 } 1904 1905 context.arguments.push(inv); 1906 if (explicitConstructor.arguments != null) { 1907 for (int i = 0, argumentLength = explicitConstructor.arguments.length; i < argumentLength; i++) 1908 explicitConstructor.arguments[i].traverse(this, scope); 1909 } 1910 context.arguments.pop(); 1911 1912 return false; 1913 } 1914 1915 public boolean visit(ExtendedStringLiteral extendedStringLiteral, 1916 BlockScope scope) { 1917 CtLiteral<String > l = factory.Core().createLiteral(); 1918 l.setValue(new String (extendedStringLiteral.source())); 1919 context.enter(l, extendedStringLiteral); 1920 return true; 1921 } 1922 1923 @Override 1924 public boolean visit(FalseLiteral falseLiteral, BlockScope scope) { 1925 CtLiteral<Boolean > l = factory.Core().createLiteral(); 1926 l.setValue(false); 1927 context.enter(l, falseLiteral); 1928 return true; 1929 } 1930 1931 @SuppressWarnings ("unchecked") 1932 @Override 1933 public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { 1934 CtField<?> field = factory.Core().createField(); 1935 field.setSimpleName(new String (fieldDeclaration.name)); 1936 if (fieldDeclaration.type != null) 1937 field.setType(references 1938 .getTypeReference(fieldDeclaration.type.resolvedType)); 1939 field.setModifiers(getModifier(fieldDeclaration.modifiers)); 1940 1941 field.setDocComment(getJavaDoc(fieldDeclaration.javadoc, scope 1942 .referenceCompilationUnit())); 1943 1944 context.enter(field, fieldDeclaration); 1945 1946 if (fieldDeclaration.annotations != null) { 1947 int annotationsLength = fieldDeclaration.annotations.length; 1948 for (int i = 0; i < annotationsLength; i++) 1949 fieldDeclaration.annotations[i].traverse(this, scope); 1950 } 1951 1952 if (fieldDeclaration.initialization != null) 1953 fieldDeclaration.initialization.traverse(this, scope); 1954 return false; 1955 } 1956 1957 @SuppressWarnings ("unchecked") 1958 public boolean visit(FieldReference fieldReference, BlockScope scope) { 1959 CtFieldAccess<?> acc = factory.Core().createFieldAccess(); 1960 acc 1961 .setVariable(references 1962 .getVariableReference(fieldReference.binding)); 1963 acc.setType(references.getTypeReference(fieldReference.resolvedType)); 1964 if (fieldReference.receiverType instanceof ArrayBinding 1965 && new String (fieldReference.token).equals("length")) { 1966 acc.getVariable().setDeclaringType( 1967 references.getTypeReference(fieldReference.receiverType)); 1968 } 1969 context.enter(acc, fieldReference); 1970 1971 context.target.push(acc); 1972 fieldReference.receiver.traverse(this, scope); 1973 context.target.pop(); 1974 return false; 1975 } 1976 1977 @Override 1978 public boolean visit(FloatLiteral floatLiteral, BlockScope scope) { 1979 CtLiteral<Float > l = factory.Core().createLiteral(); 1980 l.setValue(floatLiteral.constant.floatValue()); 1981 context.enter(l, floatLiteral); 1982 return true; 1983 } 1984 1985 @Override 1986 public boolean visit(ForeachStatement forStatement, BlockScope scope) { 1987 CtForEach fe = factory.Core().createForEach(); 1988 context.enter(fe, forStatement); 1989 return true; 1990 } 1991 1992 @Override 1993 public boolean visit(ForStatement forStatement, BlockScope scope) { 1994 CtFor for1 = factory.Core().createFor(); 1995 context.enter(for1, forStatement); 1996 1997 if (forStatement.initializations != null) { 1998 context.forinit = true; 1999 int initializationsLength = forStatement.initializations.length; 2000 for (int i = 0; i < initializationsLength; i++) 2001 forStatement.initializations[i].traverse(this, scope); 2002 context.forinit = false; 2003 } 2004 if (forStatement.condition != null) 2005 forStatement.condition.traverse(this, scope); 2006 2007 if (forStatement.increments != null) { 2008 context.forupdate = true; 2009 int incrementsLength = forStatement.increments.length; 2010 for (int i = 0; i < incrementsLength; i++) 2011 forStatement.increments[i].traverse(this, scope); 2012 context.forupdate = false; 2013 } 2014 if (forStatement.action != null) 2015 forStatement.action.traverse(this, scope); 2016 2017 return false; 2018 } 2019 2020 @Override 2021 public boolean visit(IfStatement ifStatement, BlockScope scope) { 2022 CtIf ifs = factory.Core().createIf(); 2023 context.enter(ifs, ifStatement); 2024 return super.visit(ifStatement, scope); 2025 } 2026 2027 @Override 2028 public boolean visit(Initializer initializer, MethodScope scope) { 2029 CtAnonymousExecutable b = factory.Core().createAnonymousExecutable(); 2030 if (initializer.isStatic()) 2031 b.getModifiers().add(ModifierKind.STATIC); 2032 context.enter(b, initializer); 2033 return true; 2034 } 2035 2036 @Override 2037 public boolean visit(InstanceOfExpression instanceOfExpression, 2038 BlockScope scope) { 2039 CtBinaryOperator op = factory.Core().createBinaryOperator(); 2040 op.setKind(BinaryOperatorKind.INSTANCEOF); 2041 context.enter(op, instanceOfExpression); 2042 return true; 2043 } 2044 2045 @SuppressWarnings ("unchecked") 2046 @Override 2047 public boolean visit(IntLiteral intLiteral, BlockScope scope) { 2048 CtLiteral<Integer > l = factory.Core().createLiteral(); 2049 l.setType(references.getTypeReference(intLiteral.resolvedType)); 2050 l.setValue(intLiteral.value); 2051 context.enter(l, intLiteral); 2052 return true; 2053 } 2054 2055 @Override 2056 public boolean visit(LabeledStatement labeledStatement, BlockScope scope) { 2057 context.label.push(new String (labeledStatement.label)); 2058 return true; 2059 } 2060 2061 @SuppressWarnings ("unchecked") 2062 @Override 2063 public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) { 2064 CtLocalVariable<?> v = factory.Core().createLocalVariable(); 2065 v.setSimpleName(new String (localDeclaration.name)); 2066 v.setType(references 2067 .getTypeReference(localDeclaration.type.resolvedType)); 2068 v.setModifiers(getModifier(localDeclaration.modifiers)); 2069 context.enter(v, localDeclaration); 2070 2071 if (localDeclaration.initialization != null) { 2072 context.arguments.push(v); 2073 localDeclaration.initialization.traverse(this, scope); 2074 context.arguments.pop(); 2075 } 2076 return false; 2077 } 2078 2079 @SuppressWarnings ("unchecked") 2080 @Override 2081 public boolean visit(LongLiteral longLiteral, BlockScope scope) { 2082 CtLiteral<Long > l = factory.Core().createLiteral(); 2083 l.setValue(longLiteral.constant.longValue()); 2084 l.setType(references.getTypeReference(longLiteral.resolvedType)); 2085 context.enter(l, longLiteral); 2086 return true; 2087 } 2088 2089 @SuppressWarnings ("unchecked") 2090 @Override 2091 public boolean visit(MarkerAnnotation annotation, BlockScope scope) { 2092 CtAnnotation a = factory.Core().createAnnotation(); 2093 a.setAnnotationType(references 2094 .getTypeReference(annotation.resolvedType)); 2095 context.enter(a, annotation); 2096 return true; 2097 } 2098 2099 @SuppressWarnings ("unchecked") 2100 @Override 2101 public boolean visit(MemberValuePair pair, BlockScope scope) { 2102 context.annotationValueName.push(new String (pair.name)); 2103 return true; 2104 } 2105 2106 @SuppressWarnings ("unchecked") 2107 @Override 2108 public boolean visit(MessageSend messageSend, BlockScope scope) { 2109 CtInvocation<?> inv = factory.Core().createInvocation(); 2110 if (messageSend.binding != null) 2111 inv.setExecutable(references 2112 .getExecutableReference(messageSend.binding)); 2113 context.enter(inv, messageSend); 2117 if (!(messageSend.receiver.getClass().equals(ThisReference.class))) 2118 messageSend.receiver.traverse(this, scope); 2119 context.pushArgument(inv); 2120 if (messageSend.arguments != null) 2121 for (Expression e : messageSend.arguments) { 2122 e.traverse(this, scope); 2123 } 2124 context.popArgument(inv); 2125 return false; 2126 } 2127 2128 @SuppressWarnings ("unchecked") 2129 @Override 2130 public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { 2131 CtMethod<?> m = factory.Core().createMethod(); 2132 m.setSimpleName(new String (methodDeclaration.selector)); 2133 m.setType(references 2134 .getTypeReference(methodDeclaration.returnType.resolvedType)); 2135 m.setModifiers(getModifier(methodDeclaration.modifiers)); 2136 if (methodDeclaration.thrownExceptions != null) { 2137 for (TypeReference r : methodDeclaration.thrownExceptions) 2138 m.getThrownTypes().add( 2139 references.getTypeReference(r.resolvedType)); 2140 } 2141 for (TypeBinding b : methodDeclaration.binding.typeVariables) 2142 m.getFormalTypeParameters().add( 2143 references.getBoundedTypeReference(b)); 2144 2145 m.setDocComment(getJavaDoc(methodDeclaration.javadoc, scope 2146 .referenceCompilationUnit())); 2147 2148 context.enter(m, methodDeclaration); 2149 2150 if (methodDeclaration.annotations != null) 2151 for (Annotation a : methodDeclaration.annotations) 2152 a.traverse(this, methodDeclaration.scope); 2153 2154 if (methodDeclaration.arguments != null) 2155 for (Argument a : methodDeclaration.arguments) 2156 a.traverse(this, methodDeclaration.scope); 2157 2158 if (!methodDeclaration.isAbstract()) { 2160 CtBlock<?> b = factory.Core().createBlock(); 2161 context.enter(b, methodDeclaration); 2162 } 2163 2164 if (methodDeclaration.statements != null) { 2165 for (Statement s : methodDeclaration.statements) 2166 s.traverse(this, methodDeclaration.scope); 2167 } 2168 return false; 2169 } 2170 2171 @SuppressWarnings ("unchecked") 2172 @Override 2173 public boolean visit(NormalAnnotation annotation, BlockScope scope) { 2174 CtAnnotation a = factory.Core().createAnnotation(); 2175 a.setAnnotationType(references 2176 .getTypeReference(annotation.resolvedType)); 2177 context.enter(a, annotation); 2178 return true; 2179 } 2180 2181 @SuppressWarnings ("unchecked") 2182 @Override 2183 public boolean visit(NullLiteral nullLiteral, BlockScope scope) { 2184 CtLiteral<?> lit = factory.Core().createLiteral(); 2185 CtTypeReference ref = factory.Core().createTypeReference(); 2186 ref.setSimpleName(CtTypeReference.nulltype); 2187 lit.setType(ref); 2188 context.enter(lit, nullLiteral); 2189 return true; 2190 } 2191 2192 @Override 2193 public boolean visit(OR_OR_Expression or_or_Expression, BlockScope scope) { 2194 CtBinaryOperator op = factory.Core().createBinaryOperator(); 2195 op 2196 .setKind(getBinaryOperatorKind((or_or_Expression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); 2197 context.enter(op, or_or_Expression); 2198 return true; 2199 } 2200 2201 @Override 2202 public boolean visit( 2203 ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference, 2204 ClassScope scope) { 2205 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 2206 l 2207 .setValue(references 2208 .getBoundedTypeReference(parameterizedQualifiedTypeReference.resolvedType)); 2209 context.enter(l, parameterizedQualifiedTypeReference); 2210 return true; 2211 } 2212 2213 @Override 2214 public boolean visit( 2215 ParameterizedSingleTypeReference parameterizedSingleTypeReference, 2216 BlockScope scope) { 2217 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 2218 l 2219 .setValue(references 2220 .getBoundedTypeReference(parameterizedSingleTypeReference.resolvedType)); 2221 context.enter(l, parameterizedSingleTypeReference); 2222 return true; 2223 } 2224 2225 @Override 2226 public boolean visit( 2227 ParameterizedSingleTypeReference parameterizedSingleTypeReference, 2228 ClassScope scope) { 2229 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 2230 l 2231 .setValue(references 2232 .getBoundedTypeReference(parameterizedSingleTypeReference.resolvedType)); 2233 context.enter(l, parameterizedSingleTypeReference); 2234 return super.visit(parameterizedSingleTypeReference, scope); 2235 } 2236 2237 @Override 2238 public boolean visit(PostfixExpression postfixExpression, BlockScope scope) { 2239 CtUnaryOperator op = factory.Core().createUnaryOperator(); 2240 if (postfixExpression.operator == OperatorIds.PLUS) 2241 op.setKind(UnaryOperatorKind.POSTINC); 2242 if (postfixExpression.operator == OperatorIds.MINUS) 2243 op.setKind(UnaryOperatorKind.POSTDEC); 2244 context.enter(op, postfixExpression); 2245 return true; 2246 } 2247 2248 @Override 2249 public boolean visit(PrefixExpression prefixExpression, BlockScope scope) { 2250 CtUnaryOperator op = factory.Core().createUnaryOperator(); 2251 if (prefixExpression.operator == OperatorIds.PLUS) 2252 op.setKind(UnaryOperatorKind.PREINC); 2253 if (prefixExpression.operator == OperatorIds.MINUS) 2254 op.setKind(UnaryOperatorKind.PREDEC); 2255 context.enter(op, prefixExpression); 2256 return true; 2257 } 2258 2259 @SuppressWarnings ("unchecked") 2260 @Override 2261 public boolean visit( 2262 QualifiedAllocationExpression qualifiedAllocationExpression, 2263 BlockScope scope) { 2264 boolean ret = visit( 2265 (AllocationExpression) qualifiedAllocationExpression, scope); 2266 if (qualifiedAllocationExpression.enclosingInstance != null) 2267 qualifiedAllocationExpression.enclosingInstance.traverse(this, 2268 scope); 2269 if (qualifiedAllocationExpression.anonymousType != null) 2270 qualifiedAllocationExpression.anonymousType.traverse(this, scope); 2271 2272 return ret; 2273 } 2274 2275 @SuppressWarnings ("unchecked") 2276 @Override 2277 public boolean visit(QualifiedNameReference qualifiedNameReference, 2278 BlockScope scope) { 2279 if (qualifiedNameReference.binding instanceof FieldBinding) { 2280 CtFieldAccess<?> fa = factory.Core().createFieldAccess(); 2281 fa 2282 .setVariable(references 2283 .getVariableReference(qualifiedNameReference 2284 .fieldBinding())); 2285 2286 if (qualifiedNameReference.otherBindings != null) 2287 for (FieldBinding b : qualifiedNameReference.otherBindings) { 2288 if (b != null) { 2289 CtFieldAccess other = factory.Core() 2290 .createFieldAccess(); 2291 other.setVariable(references.getVariableReference(b)); 2292 other.setTarget(fa); 2293 fa = other; 2294 } 2295 } 2296 context.enter(fa, qualifiedNameReference); 2297 return true; 2298 } else if (qualifiedNameReference.binding instanceof VariableBinding) { 2299 CtVariableAccess va = factory.Core().createVariableAccess(); 2300 va 2301 .setVariable(references 2302 .getVariableReference((VariableBinding) qualifiedNameReference.binding)); 2303 va.setType(va.getVariable().getType()); 2304 if (qualifiedNameReference.otherBindings != null) { 2305 for (FieldBinding b : qualifiedNameReference.otherBindings) { 2306 CtFieldAccess fa = factory.Core().createFieldAccess(); 2307 fa.setTarget(va); 2308 fa.setVariable(references.getVariableReference(b)); 2309 fa 2310 .setType(references 2311 .getTypeReference(qualifiedNameReference.resolvedType)); 2312 va = fa; 2313 } 2314 } 2315 context.enter(va, qualifiedNameReference); 2316 return false; 2317 } 2318 return false; 2319 } 2320 2321 @Override 2322 public boolean visit(QualifiedThisReference qualifiedThisReference, 2323 BlockScope scope) { 2324 return visit((ThisReference) qualifiedThisReference, scope); 2325 } 2326 2327 @Override 2328 public boolean visit(ReturnStatement returnStatement, BlockScope scope) { 2329 CtReturn ret = factory.Core().createReturn(); 2330 context.enter(ret, returnStatement); 2331 return true; 2332 } 2333 2334 @SuppressWarnings ("unchecked") 2335 @Override 2336 public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) { 2337 CtAnnotation a = factory.Core().createAnnotation(); 2338 a.setAnnotationType(references 2339 .getTypeReference(annotation.resolvedType)); 2340 context.enter(a, annotation); 2341 context.annotationValueName.push("value"); 2342 return true; 2343 } 2344 2345 @SuppressWarnings ("unchecked") 2346 @Override 2347 public boolean visit(SingleNameReference singleNameReference, 2348 BlockScope scope) { 2349 CtVariableAccess<?> va = null; 2350 if (singleNameReference.binding instanceof FieldBinding) { 2351 va = factory.Core().createFieldAccess(); 2352 va.setVariable(references.getVariableReference(singleNameReference 2353 .fieldBinding())); 2354 } else if (singleNameReference.binding instanceof VariableBinding) { 2355 va = factory.Core().createVariableAccess(); 2356 va 2357 .setVariable(references 2358 .getVariableReference((VariableBinding) singleNameReference.binding)); 2359 } 2360 if (va != null) 2361 context.enter(va, singleNameReference); 2362 return true; 2363 } 2364 2365 @Override 2366 public boolean visit(SingleTypeReference singleTypeReference, 2367 BlockScope scope) { 2368 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 2369 l.setValue(references 2370 .getTypeReference(singleTypeReference.resolvedType)); 2371 context.enter(l, singleTypeReference); 2372 return true; } 2374 2375 @Override 2376 public boolean visit(SingleTypeReference singleTypeReference, 2377 ClassScope scope) { 2378 CtLiteral<CtTypeReference> l = factory.Core().createLiteral(); 2379 l.setValue(references 2380 .getTypeReference(singleTypeReference.resolvedType)); 2381 context.enter(l, singleTypeReference); 2382 return true; } 2384 2385 @SuppressWarnings ("unchecked") 2386 @Override 2387 public boolean visit(StringLiteral stringLiteral, BlockScope scope) { 2388 CtLiteral<String > s = factory.Core().createLiteral(); 2389 s.setType(references.getTypeReference(stringLiteral.resolvedType)); 2390 s.setValue(new String (stringLiteral.source())); 2391 context.enter(s, stringLiteral); 2392 return true; 2393 } 2394 2395 @Override 2396 public boolean visit(StringLiteralConcatenation literal, BlockScope scope) { 2397 CtBinaryOperator op = factory.Core().createBinaryOperator(); 2398 op.setKind(BinaryOperatorKind.PLUS); 2399 context.enter(op, literal); 2400 return true; 2401 } 2402 2403 @SuppressWarnings ("unchecked") 2404 @Override 2405 public boolean visit(SuperReference superReference, BlockScope scope) { 2406 CtFieldReference<?> fr = factory.Core().createFieldReference(); 2407 CtTypeReference ref = references 2408 .getTypeReference(superReference.resolvedType); 2409 fr.setSimpleName("super"); 2410 fr.setDeclaringType(ref); 2411 fr.setType(ref); 2412 2413 CtFieldAccess fa = factory.Core().createFieldAccess(); 2414 fa.setVariable(fr); 2415 context.enter(fa, superReference); 2416 return super.visit(superReference, scope); 2417 } 2418 2419 @Override 2420 public boolean visit(SwitchStatement switchStatement, BlockScope scope) { 2421 CtSwitch s = factory.Core().createSwitch(); 2422 context.enter(s, switchStatement); 2423 2424 switchStatement.expression.traverse(this, switchStatement.scope); 2425 2426 if (switchStatement.statements != null) { 2427 int statementsLength = switchStatement.statements.length; 2428 for (int i = 0; i < statementsLength; i++) { 2429 if (switchStatement.statements[i] instanceof CaseStatement) { 2430 if (context.stack.peek().element instanceof CtCase) { 2431 context.exit(context.stack.peek().node); 2432 } 2433 CaseStatement cas = (CaseStatement) switchStatement.statements[i]; 2434 2435 visit(cas, switchStatement.scope); 2436 } else { 2437 switchStatement.statements[i].traverse(this, 2438 switchStatement.scope); 2439 } 2440 } 2441 if (context.stack.peek().element instanceof CtCase) { 2442 context.exit(context.stack.peek().node); 2443 } 2444 } 2445 return false; 2446 } 2447 2448 @Override 2449 public boolean visit(SynchronizedStatement synchronizedStatement, 2450 BlockScope scope) { 2451 CtSynchronized s = factory.Core().createSynchronized(); 2452 context.enter(s, synchronizedStatement); 2453 return super.visit(synchronizedStatement, scope); 2454 } 2455 2456 @SuppressWarnings ("unchecked") 2457 @Override 2458 public boolean visit(ThisReference thisReference, BlockScope scope) { 2459 CtFieldReference fr = factory.Core().createFieldReference(); 2460 CtTypeReference typeref = references 2461 .getTypeReference(thisReference.resolvedType); 2462 fr.setDeclaringType(typeref); 2463 fr.setType(typeref); 2464 fr.setSimpleName("this"); 2465 2466 CtFieldAccess fa = factory.Core().createFieldAccess(); 2467 fa.setVariable(fr); 2468 fa.setType(typeref); 2469 2470 context.enter(fa, thisReference); 2471 return true; 2472 } 2473 2474 public boolean visit(ThrowStatement throwStatement, BlockScope scope) { 2475 CtThrow t = factory.Core().createThrow(); 2476 context.enter(t, throwStatement); 2477 return true; 2478 } 2479 2480 @Override 2481 public boolean visit(TrueLiteral trueLiteral, BlockScope scope) { 2482 CtLiteral<Boolean > l = factory.Core().createLiteral(); 2483 l.setValue(true); 2484 context.enter(l, trueLiteral); 2485 return true; 2486 } 2487 2488 @SuppressWarnings ("unchecked") 2489 public boolean visit(TryStatement tryStatement, BlockScope scope) { 2490 CtTry t = factory.Core().createTry(); 2491 context.enter(t, tryStatement); 2492 tryStatement.tryBlock.traverse(this, scope); 2493 if (tryStatement.catchArguments != null) { 2494 for (int i = 0; i < tryStatement.catchArguments.length; i++) { 2495 CtCatch c = factory.Core().createCatch(); 2496 context.enter(c, tryStatement.catchBlocks[i]); 2497 CtLocalVariable var = factory.Core().createLocalVariable(); 2498 var.setSimpleName(new String ( 2499 tryStatement.catchArguments[i].name)); 2500 var 2501 .setType(references 2502 .getTypeReference(tryStatement.catchArguments[i].binding.type)); 2503 var 2504 .setModifiers(getModifier(tryStatement.catchArguments[i].modifiers)); 2505 c.setParameter(var); 2506 tryStatement.catchBlocks[i].traverse(this, scope); 2507 context.exit(tryStatement.catchBlocks[i]); 2508 } 2509 } 2510 if (tryStatement.finallyBlock != null) { 2511 context.finallyzer.push(t); 2512 tryStatement.finallyBlock.traverse(this, scope); 2513 context.finallyzer.pop(); 2514 } 2515 return false; 2516 } 2517 2518 @Override 2519 public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) { 2520 CtSimpleType t = createType(localTypeDeclaration); 2521 t.setDocComment(getJavaDoc(localTypeDeclaration.javadoc, scope 2522 .referenceCompilationUnit())); 2523 context.enter(t, localTypeDeclaration); 2524 return true; 2525 } 2526 2527 @Override 2528 public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { 2529 CtSimpleType<?> type = createType(memberTypeDeclaration); 2530 type.setDocComment(getJavaDoc(memberTypeDeclaration.javadoc, scope 2531 .referenceCompilationUnit())); 2532 context.enter(type, memberTypeDeclaration); 2533 return true; 2534 } 2535 2536 @Override 2537 public boolean visit(TypeDeclaration typeDeclaration, 2538 CompilationUnitScope scope) { 2539 2540 if (new String (typeDeclaration.name).equals("package-info")) { 2541 return false; 2545 } 2546 CtSimpleType<?> type = createType(typeDeclaration); 2547 2548 type.setDocComment(getJavaDoc(typeDeclaration.javadoc, 2549 scope.referenceContext)); 2550 2551 CtPackage pack = null; 2552 if (typeDeclaration.binding.fPackage.shortReadableName() != null 2553 && typeDeclaration.binding.fPackage.shortReadableName().length > 0) { 2554 pack = factory.Package().getOrCreate( 2555 new String (typeDeclaration.binding.fPackage 2556 .shortReadableName())); 2557 } else { 2558 pack = factory.Package().getOrCreate( 2559 CtPackage.TOP_LEVEL_PACKAGE_NAME); 2560 } 2561 context.enter(pack, typeDeclaration); 2562 context.compilationunitdeclaration = scope.referenceContext; 2563 context.enter(type, typeDeclaration); 2564 2565 if (typeDeclaration.annotations != null) 2567 for (Annotation a : typeDeclaration.annotations) { 2568 a.traverse(this, (BlockScope) null); 2569 } 2570 2571 if (typeDeclaration.memberTypes != null) { 2572 int length = typeDeclaration.memberTypes.length; 2573 for (int i = 0; i < length; i++) 2574 typeDeclaration.memberTypes[i].traverse(this, 2575 typeDeclaration.scope); 2576 } 2577 if (typeDeclaration.fields != null) { 2578 int length = typeDeclaration.fields.length; 2579 for (int i = 0; i < length; i++) { 2580 FieldDeclaration field; 2581 if ((field = typeDeclaration.fields[i]).isStatic()) { 2582 field 2583 .traverse(this, 2584 typeDeclaration.staticInitializerScope); 2585 } else { 2586 field.traverse(this, typeDeclaration.initializerScope); 2587 } 2588 } 2589 } 2590 if (typeDeclaration.methods != null) { 2591 int length = typeDeclaration.methods.length; 2592 for (int i = 0; i < length; i++) 2593 typeDeclaration.methods[i] 2594 .traverse(this, typeDeclaration.scope); 2595 } 2596 2597 return false; 2598 } 2599 2600 @Override 2601 public boolean visit(UnaryExpression unaryExpression, BlockScope scope) { 2602 CtUnaryOperator op = factory.Core().createUnaryOperator(); 2603 op 2604 .setKind(getUnaryOperator((unaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT)); 2605 context.enter(op, unaryExpression); 2606 return true; 2607 } 2608 2609 @Override 2610 public boolean visit(WhileStatement whileStatement, BlockScope scope) { 2611 CtWhile w = factory.Core().createWhile(); 2612 context.enter(w, whileStatement); 2613 return true; 2614 } 2615 2616} | Popular Tags |