Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 16-23
Link Here
|
16 |
|
16 |
|
17 |
import org.eclipse.jdt.core.ICompilationUnit; |
17 |
import org.eclipse.jdt.core.ICompilationUnit; |
18 |
import org.eclipse.jdt.core.IPackageFragment; |
18 |
import org.eclipse.jdt.core.IPackageFragment; |
19 |
|
19 |
import org.eclipse.jdt.core.dom.AST; |
20 |
import org.eclipse.jdt.core.dom.*; |
20 |
import org.eclipse.jdt.core.dom.Block; |
|
|
21 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
22 |
import org.eclipse.jdt.core.dom.MethodDeclaration; |
23 |
import org.eclipse.jdt.core.dom.TypeDeclaration; |
21 |
|
24 |
|
22 |
public class ASTRewritingModifyingRemoveTest extends ASTRewritingModifyingTest { |
25 |
public class ASTRewritingModifyingRemoveTest extends ASTRewritingModifyingTest { |
23 |
private static final Class THIS = ASTRewritingModifyingRemoveTest.class; |
26 |
private static final Class THIS = ASTRewritingModifyingRemoveTest.class; |
Lines 407-412
Link Here
|
407 |
buf.append("package test0010;\n"); |
410 |
buf.append("package test0010;\n"); |
408 |
buf.append("\n"); |
411 |
buf.append("\n"); |
409 |
buf.append("public class X {\n"); |
412 |
buf.append("public class X {\n"); |
|
|
413 |
buf.append(" // comment1\n"); |
414 |
buf.append("\n"); |
415 |
buf.append(" \n"); |
410 |
buf.append("\n"); |
416 |
buf.append("\n"); |
411 |
buf.append(" // comment5\n"); |
417 |
buf.append(" // comment5\n"); |
412 |
buf.append("}\n"); |
418 |
buf.append("}\n"); |
Lines 458-461
Link Here
|
458 |
buf.append("}\n"); |
464 |
buf.append("}\n"); |
459 |
assertEqualString(preview, buf.toString()); |
465 |
assertEqualString(preview, buf.toString()); |
460 |
} |
466 |
} |
|
|
467 |
|
468 |
/* |
469 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=306524 |
470 |
* To test that when types are removed, only the comments in the extended source range are |
471 |
* removed, and the rest are left untouched. |
472 |
*/ |
473 |
public void test0012() throws Exception { |
474 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0012", false, null); |
475 |
StringBuffer buf= new StringBuffer(); |
476 |
buf.append("package test0012;\n"); |
477 |
buf.append("public class X {\n"); |
478 |
buf.append("\n"); |
479 |
buf.append(" // one line comment1\n"); |
480 |
buf.append("\n"); |
481 |
buf.append(" /*\n"); |
482 |
buf.append(" * comment2\n"); |
483 |
buf.append(" */\n"); |
484 |
buf.append("\n"); |
485 |
buf.append(" // one line comment3\n"); |
486 |
buf.append(" class X1{\n"); |
487 |
buf.append(" }\n"); |
488 |
buf.append(" // one line comment4\n"); |
489 |
buf.append("\n"); |
490 |
buf.append("\n"); |
491 |
buf.append(" // one line comment5\n"); |
492 |
buf.append("\n"); |
493 |
buf.append(" /*\n"); |
494 |
buf.append(" * comment6\n"); |
495 |
buf.append(" */\n"); |
496 |
buf.append("\n"); |
497 |
buf.append("\n"); |
498 |
buf.append(" /*\n"); |
499 |
buf.append(" * comment7\n"); |
500 |
buf.append(" */\n"); |
501 |
buf.append("\n"); |
502 |
buf.append(" // one line comment8\n"); |
503 |
buf.append(" // one line comment9\n"); |
504 |
buf.append(" class X2{\n"); |
505 |
buf.append(" }\n"); |
506 |
buf.append(" /*\n"); |
507 |
buf.append(" * comment10\n"); |
508 |
buf.append(" */\n"); |
509 |
buf.append("\n"); |
510 |
buf.append(" // one line comment11\n"); |
511 |
buf.append(" // one line comment12\n"); |
512 |
buf.append("}\n"); |
513 |
ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); |
514 |
|
515 |
CompilationUnit astRoot= createCU(cu, false); |
516 |
|
517 |
astRoot.recordModifications(); |
518 |
|
519 |
List types = astRoot.types(); |
520 |
TypeDeclaration typeDeclaration = (TypeDeclaration)types.get(0); |
521 |
TypeDeclaration [] members = typeDeclaration.getTypes(); |
522 |
typeDeclaration.bodyDeclarations().remove(members[0]); |
523 |
typeDeclaration.bodyDeclarations().remove(members[1]); |
524 |
|
525 |
String preview = evaluateRewrite(cu, astRoot); |
526 |
|
527 |
buf= new StringBuffer(); |
528 |
buf.append("package test0012;\n"); |
529 |
buf.append("public class X {\n"); |
530 |
buf.append("\n"); |
531 |
buf.append(" // one line comment1\n"); |
532 |
buf.append("\n"); |
533 |
buf.append(" /*\n"); |
534 |
buf.append(" * comment2\n"); |
535 |
buf.append(" */\n"); |
536 |
buf.append("\n"); |
537 |
buf.append(" \n"); |
538 |
buf.append("\n"); |
539 |
buf.append("\n"); |
540 |
buf.append(" // one line comment5\n"); |
541 |
buf.append("\n"); |
542 |
buf.append(" /*\n"); |
543 |
buf.append(" * comment6\n"); |
544 |
buf.append(" */\n"); |
545 |
buf.append("\n"); |
546 |
buf.append("\n"); |
547 |
buf.append(" /*\n"); |
548 |
buf.append(" * comment7\n"); |
549 |
buf.append(" */\n"); |
550 |
buf.append("\n"); |
551 |
buf.append(" \n"); |
552 |
buf.append("\n"); |
553 |
buf.append(" // one line comment11\n"); |
554 |
buf.append(" // one line comment12\n"); |
555 |
buf.append("}\n"); |
556 |
assertEqualString(preview, buf.toString()); |
557 |
} |
558 |
|
559 |
/* |
560 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=306524 |
561 |
* To test that when types are removed, only the comments in the extended source range are |
562 |
* removed, and the rest are left untouched. This test is for cases where type to be removed is the |
563 |
* last one in file and there are more than one leading comments that are not part of its |
564 |
* extended source range |
565 |
*/ |
566 |
public void test0013() throws Exception { |
567 |
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0013", false, null); |
568 |
StringBuffer buf= new StringBuffer(); |
569 |
buf.append("package test0013;\n"); |
570 |
buf.append("public class X {\n"); |
571 |
buf.append("\n"); |
572 |
buf.append(" // one line comment1a\n"); |
573 |
buf.append("\n"); |
574 |
buf.append(" /*\n"); |
575 |
buf.append(" * comment2\n"); |
576 |
buf.append(" */\n"); |
577 |
buf.append("\n"); |
578 |
buf.append(" // one line comment1b\n"); |
579 |
buf.append("\n"); |
580 |
buf.append(" // one line comment3\n"); |
581 |
buf.append(" class X1{\n"); |
582 |
buf.append(" }\n"); |
583 |
buf.append(" // one line comment4\n"); |
584 |
buf.append("\n"); |
585 |
buf.append("\n"); |
586 |
buf.append(" // one line comment5\n"); |
587 |
buf.append("\n"); |
588 |
buf.append(" /*\n"); |
589 |
buf.append(" * comment6\n"); |
590 |
buf.append(" */\n"); |
591 |
buf.append("\n"); |
592 |
buf.append("\n"); |
593 |
buf.append(" /*\n"); |
594 |
buf.append(" * comment7\n"); |
595 |
buf.append(" */\n"); |
596 |
buf.append("}\n"); |
597 |
ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null); |
598 |
|
599 |
CompilationUnit astRoot= createCU(cu, false); |
600 |
|
601 |
astRoot.recordModifications(); |
602 |
|
603 |
List types = astRoot.types(); |
604 |
TypeDeclaration typeDeclaration = (TypeDeclaration)types.get(0); |
605 |
TypeDeclaration [] members = typeDeclaration.getTypes(); |
606 |
typeDeclaration.bodyDeclarations().remove(members[0]); |
607 |
|
608 |
String preview = evaluateRewrite(cu, astRoot); |
609 |
buf= new StringBuffer(); |
610 |
buf.append("package test0013;\n"); |
611 |
buf.append("public class X {\n"); |
612 |
buf.append("\n"); |
613 |
buf.append(" // one line comment1a\n"); |
614 |
buf.append("\n"); |
615 |
buf.append(" /*\n"); |
616 |
buf.append(" * comment2\n"); |
617 |
buf.append(" */\n"); |
618 |
buf.append("\n"); |
619 |
buf.append(" // one line comment1b\n"); |
620 |
buf.append("\n"); |
621 |
buf.append(" \n"); |
622 |
buf.append("\n"); |
623 |
buf.append("\n"); |
624 |
buf.append(" // one line comment5\n"); |
625 |
buf.append("\n"); |
626 |
buf.append(" /*\n"); |
627 |
buf.append(" * comment6\n"); |
628 |
buf.append(" */\n"); |
629 |
buf.append("\n"); |
630 |
buf.append("\n"); |
631 |
buf.append(" /*\n"); |
632 |
buf.append(" * comment7\n"); |
633 |
buf.append(" */\n"); |
634 |
buf.append("}\n"); |
635 |
assertEqualString(preview, buf.toString()); |
636 |
} |
461 |
} |
637 |
} |