aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-23 04:57:10 (EDT)
committerzzhongwei2012-08-23 04:57:10 (EDT)
commit52cd17bf64f93aa2d24368476051f1040b000a04 (patch)
tree6b50fb8e1a2ee405a186c750ab7a165d1d2a609a
parentd69c78087c9338a63c391f86f9da8a638ffa05fd (diff)
downloadorg.eclipse.pdt-52cd17bf64f93aa2d24368476051f1040b000a04.zip
org.eclipse.pdt-52cd17bf64f93aa2d24368476051f1040b000a04.tar.gz
org.eclipse.pdt-52cd17bf64f93aa2d24368476051f1040b000a04.tar.bz2
387877: Deletion of function which doesn't belong to a class from the
php explorer causes Exception. https://bugs.eclipse.org/bugs/show_bug.cgi?id=387877
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/refactor/processors/DeleteChangeCreator.java18
1 files changed, 11 insertions, 7 deletions
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/refactor/processors/DeleteChangeCreator.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/refactor/processors/DeleteChangeCreator.java
index 8f49bce..03546a0 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/refactor/processors/DeleteChangeCreator.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/refactor/processors/DeleteChangeCreator.java
@@ -111,8 +111,8 @@ class DeleteChangeCreator {
Assert.isNotNull(manager);
TextFileChange textFileChange = null;
if (cu != null && cu.getResource() instanceof IFile) {
- textFileChange = new TextFileChange(cu.getElementName(), (IFile) cu
- .getResource());
+ textFileChange = new TextFileChange(cu.getElementName(),
+ (IFile) cu.getResource());
MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
textFileChange.setEdit(fileChangeRootEdit);
@@ -129,11 +129,15 @@ class DeleteChangeCreator {
}
if (sourceRange != null) {
IStructuredDocument document = determineDocument(cu);
- int suffixLength = getSuffixLength(document, sourceRange
- .getOffset()
- + sourceRange.getLength(), ';');
+ int suffixLength = getSuffixLength(document,
+ sourceRange.getOffset() + sourceRange.getLength(),
+ ';');
+ int length = sourceRange.getLength() + suffixLength;
+ if (sourceRange.getOffset() + length > document.getLength()) {
+ length = document.getLength() - sourceRange.getOffset();
+ }
DeleteEdit edit = new DeleteEdit(sourceRange.getOffset(),
- sourceRange.getLength() + suffixLength);
+ length);
fileChangeRootEdit.addChild(edit);
if (cu.isWorkingCopy()) {
@@ -152,7 +156,7 @@ class DeleteChangeCreator {
private static int getSuffixLength(IStructuredDocument document,
int offset, char endChar) {
try {
- int length = document.getLength();
+ int length = document.getLength() - offset;
for (int rv = 0; rv < length; rv++) {
char c = document.getChar(rv + offset);
if (Character.isWhitespace(c)) {