Lines 20-28
Link Here
|
20 |
import org.eclipse.core.runtime.jobs.MultiRule; |
20 |
import org.eclipse.core.runtime.jobs.MultiRule; |
21 |
import org.eclipse.jdt.core.*; |
21 |
import org.eclipse.jdt.core.*; |
22 |
import org.eclipse.jdt.core.dom.AST; |
22 |
import org.eclipse.jdt.core.dom.AST; |
|
|
23 |
import org.eclipse.jdt.core.dom.ASTNode; |
23 |
import org.eclipse.jdt.core.dom.ASTParser; |
24 |
import org.eclipse.jdt.core.dom.ASTParser; |
24 |
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; |
25 |
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; |
25 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
26 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
|
27 |
import org.eclipse.jdt.core.dom.Javadoc; |
26 |
import org.eclipse.jdt.core.dom.MethodDeclaration; |
28 |
import org.eclipse.jdt.core.dom.MethodDeclaration; |
27 |
import org.eclipse.jdt.core.dom.Name; |
29 |
import org.eclipse.jdt.core.dom.Name; |
28 |
import org.eclipse.jdt.core.dom.PackageDeclaration; |
30 |
import org.eclipse.jdt.core.dom.PackageDeclaration; |
Lines 524-530
Link Here
|
524 |
CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); |
526 |
CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); |
525 |
AST ast = astCU.getAST(); |
527 |
AST ast = astCU.getAST(); |
526 |
ASTRewrite rewrite = ASTRewrite.create(ast); |
528 |
ASTRewrite rewrite = ASTRewrite.create(ast); |
527 |
updatePackageStatement(astCU, newFragName, rewrite); |
529 |
updatePackageStatement(astCU, newFragName, rewrite, cu); |
528 |
TextEdit edits = rewrite.rewriteAST(); |
530 |
TextEdit edits = rewrite.rewriteAST(); |
529 |
applyTextEdit(cu, edits); |
531 |
applyTextEdit(cu, edits); |
530 |
cu.save(null, false); |
532 |
cu.save(null, false); |
Lines 618-634
Link Here
|
618 |
AST ast = astCU.getAST(); |
620 |
AST ast = astCU.getAST(); |
619 |
ASTRewrite rewrite = ASTRewrite.create(ast); |
621 |
ASTRewrite rewrite = ASTRewrite.create(ast); |
620 |
updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); |
622 |
updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); |
621 |
updatePackageStatement(astCU, destPackageName, rewrite); |
623 |
updatePackageStatement(astCU, destPackageName, rewrite, cu); |
622 |
return rewrite.rewriteAST(); |
624 |
return rewrite.rewriteAST(); |
623 |
} |
625 |
} |
624 |
} |
626 |
} |
625 |
private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter) throws JavaModelException { |
627 |
private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { |
626 |
boolean defaultPackage = pkgName.length == 0; |
628 |
boolean defaultPackage = pkgName.length == 0; |
627 |
AST ast = astCU.getAST(); |
629 |
AST ast = astCU.getAST(); |
628 |
if (defaultPackage) { |
630 |
if (defaultPackage) { |
629 |
// remove existing package statement |
631 |
// remove existing package statement |
630 |
if (astCU.getPackage() != null) |
632 |
PackageDeclaration pkg = astCU.getPackage(); |
631 |
rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, null, null); |
633 |
if (pkg != null) { |
|
|
634 |
int pkgStart; |
635 |
Javadoc javadoc = pkg.getJavadoc(); |
636 |
if (javadoc != null) { |
637 |
pkgStart = javadoc.getStartPosition() + javadoc.getLength() + 1; |
638 |
} else { |
639 |
pkgStart = pkg.getStartPosition(); |
640 |
} |
641 |
int extendedStart = astCU.getExtendedStartPosition(pkg); |
642 |
if (pkgStart != extendedStart) { |
643 |
// keep the comments associated with package declaration |
644 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=247757 |
645 |
String commentSource = cu.getSource().substring(extendedStart, pkgStart); |
646 |
ASTNode comment = rewriter.createStringPlaceholder(commentSource, ASTNode.PACKAGE_DECLARATION); |
647 |
rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, comment, null); |
648 |
} else { |
649 |
rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, null, null); |
650 |
} |
651 |
} |
632 |
} else { |
652 |
} else { |
633 |
org.eclipse.jdt.core.dom.PackageDeclaration pkg = astCU.getPackage(); |
653 |
org.eclipse.jdt.core.dom.PackageDeclaration pkg = astCU.getPackage(); |
634 |
if (pkg != null) { |
654 |
if (pkg != null) { |