aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-11-04 23:28:04 (EST)
committerzzhongwei2012-11-04 23:32:44 (EST)
commit2952e62b0f3fd182e53c3cdea34ccb62179c415a (patch)
treedada9dbcf82973b40e193c4e275705a4dce11e31
parent8cf906e911bd911c97e2e7c1f52b6c79c5125e3f (diff)
downloadorg.eclipse.pdt-2952e62b0f3fd182e53c3cdea34ccb62179c415a.zip
org.eclipse.pdt-2952e62b0f3fd182e53c3cdea34ccb62179c415a.tar.gz
org.eclipse.pdt-2952e62b0f3fd182e53c3cdea34ccb62179c415a.tar.bz2
393253: automaticly added use statements are placed on the wrong
position https://bugs.eclipse.org/bugs/show_bug.cgi?id=393253
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteAnalyzer.java12
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java28
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteAnalyzer.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteAnalyzer.java
index f830abd..d2b6c2f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteAnalyzer.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/rewrite/ASTRewriteAnalyzer.java
@@ -464,6 +464,18 @@ public final class ASTRewriteAnalyzer extends AbstractVisitor {
}
protected int getStartOfNextNode(int nextIndex, int defaultPos) {
+ // workaround for bug 393253
+ if (nextIndex > 0
+ && this.list[nextIndex].getChangeKind() == RewriteEvent.INSERTED
+ && this.list[nextIndex - 1].getChangeKind() == RewriteEvent.UNCHANGED
+ && this.list[nextIndex].getNewValue() instanceof UseStatement
+ && this.list[nextIndex - 1].getOriginalValue() instanceof UseStatement) {
+ if (((UseStatement) this.list[nextIndex].getNewValue())
+ .getStart() > 0) {
+ return ((UseStatement) this.list[nextIndex].getNewValue())
+ .getStart();
+ }
+ }
for (int i = nextIndex; i < this.list.length; i++) {
RewriteEvent elem = this.list[i];
if (elem.getChangeKind() != RewriteEvent.INSERTED) {
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java
index 70e566b..73f4bc9 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java
@@ -330,6 +330,20 @@ public class UseStatementInjector {
int index = getLastUsestatementIndex(
currentNamespace.getBody()
.statements(), offset);
+ if (index > 0) {// workaround for bug 393253
+ try {
+ int beginLine = document
+ .getLineOfOffset(program
+ .statements()
+ .get(index - 1)
+ .getEnd()) + 1;
+ newUseStatement
+ .setSourceRange(
+ document.getLineOffset(beginLine),
+ 0);
+ } catch (Exception e) {
+ }
+ }
currentNamespace.getBody().statements()
.add(index, newUseStatement);
} else {
@@ -337,6 +351,20 @@ public class UseStatementInjector {
// document:
int index = getLastUsestatementIndex(
program.statements(), offset);
+ if (index > 0) {// workaround for bug 393253
+ try {
+ int beginLine = document
+ .getLineOfOffset(program
+ .statements()
+ .get(index - 1)
+ .getEnd()) + 1;
+ newUseStatement
+ .setSourceRange(
+ document.getLineOffset(beginLine),
+ 0);
+ } catch (Exception e) {
+ }
+ }
program.statements().add(index,
newUseStatement);
}