aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-11-01 06:08:42 (EDT)
committerzzhongwei2012-11-01 06:08:42 (EDT)
commit2d185fe6dc5ffb77ec2781c79b985f72ae5a9e98 (patch)
tree9c34e785c3eea47d03adbf787ff84a8226dc181f
parent0458f555ff43d88cebb779f4f93368342bf88080 (diff)
downloadorg.eclipse.pdt-2d185fe6dc5ffb77ec2781c79b985f72ae5a9e98.zip
org.eclipse.pdt-2d185fe6dc5ffb77ec2781c79b985f72ae5a9e98.tar.gz
org.eclipse.pdt-2d185fe6dc5ffb77ec2781c79b985f72ae5a9e98.tar.bz2
Bug 393253 - automaticly added use statements are placed on the wrong
position
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/UseStatementInjector.java23
1 files changed, 20 insertions, 3 deletions
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 47b3615..70e566b 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
@@ -327,13 +327,18 @@ public class UseStatementInjector {
// insert in the beginning of the
// current
// namespace:
+ int index = getLastUsestatementIndex(
+ currentNamespace.getBody()
+ .statements(), offset);
currentNamespace.getBody().statements()
- .add(0, newUseStatement);
+ .add(index, newUseStatement);
} else {
// insert in the beginning of the
// document:
- program.statements()
- .add(0, newUseStatement);
+ int index = getLastUsestatementIndex(
+ program.statements(), offset);
+ program.statements().add(index,
+ newUseStatement);
}
Map options = new HashMap(
PHPCorePlugin.getOptions());
@@ -430,6 +435,18 @@ public class UseStatementInjector {
return offset;
}
+ private int getLastUsestatementIndex(List<Statement> statements, int offset) {
+ int result = 0;
+ for (int i = 0; i < statements.size(); i++) {
+ Statement statement = statements.get(i);
+ if (statement.getEnd() <= offset
+ && statement instanceof UseStatement) {
+ result = i + 1;
+ }
+ }
+ return result;
+ }
+
/**
* Get all the class / namespace names which have been imported by use
* statement