summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKaloyan Raev2013-09-20 07:03:50 (EDT)
committer Kaloyan Raev2013-10-24 04:36:02 (EDT)
commit75934c174061f7901335425ebc13778ade23ce82 (patch)
tree483c5e32e2afa46b3cf2a6a34d26a4d1013bc16c
parentb7cf7c63817184022936a7a94a177113261fc040 (diff)
downloadorg.eclipse.pdt-75934c174061f7901335425ebc13778ade23ce82.zip
org.eclipse.pdt-75934c174061f7901335425ebc13778ade23ce82.tar.gz
org.eclipse.pdt-75934c174061f7901335425ebc13778ade23ce82.tar.bz2
Bug 420243 - improvements in ASTUtils methods for use statementsrefs/changes/21/17721/1
The following three utility methods are improved in performance and functional correctness: - findUseStatementByAlias() - findUseStatementByNamespace() - getUseStatements() The AST visitors used in the above methods are reworked to traverse only the nodes where use statements can be legally found and not go deeper in the AST tree. More details in the JavaDoc. Tests added to the suite. Bug: 420243 Change-Id: Ia235fca7bc973c8f0a4dc8b7fee3c51cb46a8a7a Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/ASTUtils.java109
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/AbstractUseStatementASTVisitor.java159
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByAliasASTVisitor.java80
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByNamespaceASTVisitor.java73
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/GetUseStatementsASTVisitor.java66
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java6
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByAliasTests.java113
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByNamespaceTests.java113
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/GetUseStatementsByTests.java113
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testClassScope.pdtt20
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeAfterOffset.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNewAlias.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNonExisting.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeSameName.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testNamespaceScope.pdtt15
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testClassScope.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeAfterOffset.pdtt16
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNewAlias.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNonExisting.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeSameName.pdtt14
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testNamespaceScope.pdtt13
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testClassScope.pdtt18
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScope.pdtt35
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeAfterOffset.pdtt26
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeTwoInOne.pdtt30
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNamespaceScope.pdtt23
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNoneDeclared.pdtt10
27 files changed, 1068 insertions, 86 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/ASTUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/ASTUtils.java
index d481e08..992405d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/ASTUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/ASTUtils.java
@@ -27,7 +27,6 @@ import org.eclipse.dltk.ast.references.ConstantReference;
import org.eclipse.dltk.ast.references.TypeReference;
import org.eclipse.dltk.ast.references.VariableReference;
import org.eclipse.dltk.ast.statements.Block;
-import org.eclipse.dltk.ast.statements.Statement;
import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.ISourceModule;
import org.eclipse.dltk.ti.IContext;
@@ -103,8 +102,7 @@ public class ASTUtils {
int len = name.length();
if (len > 1
&& (name.charAt(0) == '\'' && name.charAt(len - 1) == '\'' || name
- .charAt(0) == '"'
- && name.charAt(len - 1) == '"')) {
+ .charAt(0) == '"' && name.charAt(len - 1) == '"')) {
name = name.substring(1, len - 1);
}
return name;
@@ -412,8 +410,8 @@ public class ASTUtils {
String constant = ASTUtils.stripQuotes(((Scalar) argument)
.getValue());
FieldDeclaration fieldDeclaration = new FieldDeclaration(
- constant, argument.sourceStart(), argument
- .sourceEnd(), callExpression.sourceStart(),
+ constant, argument.sourceStart(),
+ argument.sourceEnd(), callExpression.sourceStart(),
callExpression.sourceEnd());
fieldDeclaration.setModifier(Modifiers.AccGlobal
| Modifiers.AccConstant | Modifiers.AccFinal);
@@ -439,47 +437,18 @@ public class ASTUtils {
* statement couldn't be found
*/
public static UsePart findUseStatementByAlias(
- ModuleDeclaration moduleDeclaration, final String aliasName,
- final int offset) {
- final UsePart[] result = new UsePart[1];
- try {
- moduleDeclaration.traverse(new ASTVisitor() {
- boolean found;
-
- public boolean visit(Statement s) throws Exception {
- if (s instanceof UseStatement) {
- UseStatement useStatement = (UseStatement) s;
- for (UsePart usePart : useStatement.getParts()) {
- String alias;
- if (usePart.getAlias() != null) {
- alias = usePart.getAlias().getName();
- } else {
- // In case there's no alias - the alias is the
- // last segment of the namespace name:
- alias = usePart.getNamespace().getName();
- }
- if (aliasName.equalsIgnoreCase(alias)) {
- found = true;
- result[0] = usePart;
- break;
- }
- }
- }
- return visitGeneral(s);
- }
+ ModuleDeclaration moduleDeclaration, String aliasName, int offset) {
- public boolean visitGeneral(ASTNode node) throws Exception {
- if (found || node.sourceStart() > offset) {
- return false;
- }
- return super.visitGeneral(node);
- }
- });
+ FindUseStatementByAliasASTVisitor visitor = new FindUseStatementByAliasASTVisitor(
+ aliasName, offset);
+
+ try {
+ moduleDeclaration.traverse(visitor);
} catch (Exception e) {
Logger.logException(e);
}
- return result[0];
+ return visitor.getResult();
}
/**
@@ -499,39 +468,17 @@ public class ASTUtils {
public static UsePart findUseStatementByNamespace(
ModuleDeclaration moduleDeclaration, final String namespace,
final int offset) {
- final UsePart[] result = new UsePart[1];
- try {
- moduleDeclaration.traverse(new ASTVisitor() {
- boolean found;
-
- public boolean visit(Statement s) throws Exception {
- if (s instanceof UseStatement) {
- UseStatement useStatement = (UseStatement) s;
- for (UsePart usePart : useStatement.getParts()) {
- String ns = usePart.getNamespace()
- .getFullyQualifiedName();
- if (namespace.equalsIgnoreCase(ns)) {
- found = true;
- result[0] = usePart;
- break;
- }
- }
- }
- return visitGeneral(s);
- }
- public boolean visitGeneral(ASTNode node) throws Exception {
- if (found || node.sourceStart() > offset) {
- return false;
- }
- return super.visitGeneral(node);
- }
- });
+ FindUseStatementByNamespaceASTVisitor visitor = new FindUseStatementByNamespaceASTVisitor(
+ namespace, offset);
+
+ try {
+ moduleDeclaration.traverse(visitor);
} catch (Exception e) {
Logger.logException(e);
}
- return result[0];
+ return visitor.getResult();
}
/**
@@ -547,26 +494,16 @@ public class ASTUtils {
*/
public static UseStatement[] getUseStatements(
ModuleDeclaration moduleDeclaration, final int offset) {
- final List<UseStatement> result = new LinkedList<UseStatement>();
- try {
- moduleDeclaration.traverse(new ASTVisitor() {
- public boolean visit(Statement s) throws Exception {
- if (s instanceof UseStatement) {
- result.add((UseStatement) s);
- }
- return visitGeneral(s);
- }
- public boolean visitGeneral(ASTNode node) throws Exception {
- if (node.sourceStart() > offset) {
- return false;
- }
- return super.visitGeneral(node);
- }
- });
+ GetUseStatementsASTVisitor visitor = new GetUseStatementsASTVisitor(
+ offset);
+
+ try {
+ moduleDeclaration.traverse(visitor);
} catch (Exception e) {
Logger.logException(e);
}
- return (UseStatement[]) result.toArray(new UseStatement[result.size()]);
+
+ return visitor.getResult();
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/AbstractUseStatementASTVisitor.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/AbstractUseStatementASTVisitor.java
new file mode 100644
index 0000000..dbc7d03
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/AbstractUseStatementASTVisitor.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.compiler.ast.parser;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.php.internal.core.compiler.ast.nodes.NamespaceDeclaration;
+import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
+import org.eclipse.php.internal.core.compiler.ast.nodes.UseStatement;
+
+/**
+ * Base AST visitor for finding use statements in PHP source modules.
+ *
+ * <p>
+ * This visitor is optimized for performance to look not deeper than the
+ * necessary level in the AST tree. As described in the <a
+ * href="http://php.net/manual/en/language.namespaces.importing.php">PHP
+ * Manual</a> use statements can be legally placed only in the global scope of a
+ * file or inside namespace declarations.
+ * </p>
+ *
+ * <p>
+ * This visitor also accepts an <code>offset</code> parameter. Searching is not
+ * performed after the <code>offset</code>.
+ * </p>
+ *
+ * @author Kaloyan Raev
+ *
+ */
+public abstract class AbstractUseStatementASTVisitor extends ASTVisitor {
+
+ /**
+ * The position in the AST tree after which the search stops.
+ */
+ protected int offset;
+
+ /**
+ * Constructor of the visitor
+ *
+ * @param offset
+ * the position in the AST tree after which the search stops
+ */
+ protected AbstractUseStatementASTVisitor(int offset) {
+ this.offset = offset;
+ }
+
+ /**
+ * The visitor must always look inside {@link ModuleDeclaration}s.
+ */
+ @Override
+ public boolean visit(ModuleDeclaration s) throws Exception {
+ return isBeforeOffset(s);
+ }
+
+ /**
+ * The visitor must check if a {@link Statement} is an {@link UseStatement}.
+ * If yes then call {@link #visit(UseStatement)}. Otherwise the visitor must
+ * not look deeper in the AST tree.
+ */
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (s instanceof UseStatement && isBeforeOffset(s)) {
+ UseStatement useStatement = (UseStatement) s;
+ visit(useStatement);
+ }
+ return false;
+ }
+
+ /**
+ * The visitor must look into an {@link Expression} only if it is a
+ * {@link Block} (because it can be a block of namespace declaration).
+ */
+ @Override
+ public boolean visit(Expression s) throws Exception {
+ return s instanceof Block && isBeforeOffset(s);
+ }
+
+ /**
+ * The visitor must look into a {@link TypeDeclaration} only if it a
+ * {@link NamespaceDeclaration}.
+ */
+ @Override
+ public boolean visit(TypeDeclaration s) throws Exception {
+ return s instanceof NamespaceDeclaration && isBeforeOffset(s);
+ }
+
+ /**
+ * In all other cases the visitor must not look deeper into the AST tree -
+ * there is no chance to find an {@link UseStatement} there.
+ */
+ @Override
+ public boolean visitGeneral(ASTNode node) throws Exception {
+ return false;
+ }
+
+ /**
+ * Visits a {@link UseStatement} node.
+ *
+ * <p>
+ * This is a default implementation that calls {@link #visit(UsePart)} for
+ * each <code>UsePart<code> in the <code>UseStatement</code>. It can be
+ * overridden by subclasses.
+ * </p>
+ *
+ * @param UseStatement
+ * the <code>UseStatement</code> node that is being visited
+ */
+ protected void visit(UseStatement s) throws Exception {
+ for (UsePart usePart : s.getParts()) {
+ if (!visit(usePart)) {
+ // do not visit the rest of the use parts
+ break;
+ }
+ }
+ }
+
+ /**
+ * Visits a {@link UsePart} node.
+ *
+ * <p>
+ * This is a default implementation that can be overridden by subclasses.
+ * </p>
+ *
+ * @param usePart
+ * the <code>UsePart</code> node that is being visited
+ * @return <code>true</code> if the next <code>UsePart</code> in a
+ * <code>UseStatament</code> should be visited, <code>false</code> -
+ * otherwise.
+ */
+ protected boolean visit(UsePart usePart) {
+ return false;
+ }
+
+ /**
+ * Checks if the specified node position is before the offset.
+ *
+ * @param node
+ * the <code>ASTNode<code> to check
+ * @return <code>true</code> if the node's start position is before the
+ * offset, <code>false</code> - otherwise.
+ */
+ protected boolean isBeforeOffset(ASTNode node) {
+ return node.sourceStart() < offset;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByAliasASTVisitor.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByAliasASTVisitor.java
new file mode 100644
index 0000000..ca84184
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByAliasASTVisitor.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.compiler.ast.parser;
+
+import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
+
+/**
+ * AST visitor for finding use statements by alias.
+ *
+ * @author Kaloyan Raev
+ */
+public class FindUseStatementByAliasASTVisitor extends
+ AbstractUseStatementASTVisitor {
+
+ /**
+ * The alias to look for.
+ */
+ private String aliasName;
+
+ /**
+ * The found {@link UsePart} node to return as result.
+ */
+ private UsePart result;
+
+ /**
+ * Constructor of the visitor.
+ *
+ * @param aliasName
+ * the alias to look for
+ * @param offset
+ * the position in the AST tree after which the search stops
+ */
+ public FindUseStatementByAliasASTVisitor(String aliasName, int offset) {
+ super(offset);
+ this.aliasName = aliasName;
+ }
+
+ /**
+ * Returns the found {@link UsePart} node that corresponds to the specified
+ * alias name.
+ *
+ * @return a <code>UsePart</code> node, or
+ * <code>null<code> if there is not use statement for the specified alias name.
+ */
+ public UsePart getResult() {
+ return result;
+ }
+
+ /**
+ * Compares the alias of the {@link UsePart} node being visited with the
+ * alias name that the visitor is looking for.
+ */
+ @Override
+ protected boolean visit(UsePart usePart) {
+ String alias;
+ if (usePart.getAlias() != null) {
+ alias = usePart.getAlias().getName();
+ } else {
+ // In case there's no alias - the alias is the
+ // last segment of the namespace name:
+ alias = usePart.getNamespace().getName();
+ }
+
+ if (aliasName.equalsIgnoreCase(alias)) {
+ result = usePart;
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByNamespaceASTVisitor.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByNamespaceASTVisitor.java
new file mode 100644
index 0000000..6a4f25c
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/FindUseStatementByNamespaceASTVisitor.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.compiler.ast.parser;
+
+import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
+
+/**
+ * AST visitor for finding use statements by namespace.
+ *
+ * @author Kaloyan Raev
+ */
+public class FindUseStatementByNamespaceASTVisitor extends
+ AbstractUseStatementASTVisitor {
+
+ /**
+ * The namespace to look for.
+ */
+ private String namespace;
+
+ /**
+ * The found {@link UsePart} node to return as result.
+ */
+ private UsePart result;
+
+ /**
+ * Constructor of the visitor.
+ *
+ * @param namespace
+ * the namespace to look for
+ * @param offset
+ * the position in the AST tree after which the search stops
+ */
+ public FindUseStatementByNamespaceASTVisitor(String namespace, int offset) {
+ super(offset);
+ this.namespace = namespace;
+ }
+
+ /**
+ * Returns the found {@link UsePart} node that corresponds to the specified
+ * namespace.
+ *
+ * @return a <code>UsePart</code> node, or
+ * <code>null<code> if there is not use statement for the specified namespace.
+ */
+ public UsePart getResult() {
+ return result;
+ }
+
+ /**
+ * Compares the namespace of the {@link UsePart} node being visited with the
+ * namespace that the visitor is looking for.
+ */
+ @Override
+ protected boolean visit(UsePart usePart) {
+ String ns = usePart.getNamespace().getFullyQualifiedName();
+
+ if (namespace.equalsIgnoreCase(ns)) {
+ result = usePart;
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/GetUseStatementsASTVisitor.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/GetUseStatementsASTVisitor.java
new file mode 100644
index 0000000..41d5b3c
--- /dev/null
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/compiler/ast/parser/GetUseStatementsASTVisitor.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.internal.core.compiler.ast.parser;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.php.internal.core.compiler.ast.nodes.UseStatement;
+
+/**
+ * AST visitor for finding all use statements in a PHP source module.
+ *
+ * @author Kaloyan Raev
+ */
+public class GetUseStatementsASTVisitor extends AbstractUseStatementASTVisitor {
+
+ /**
+ * The result list of all found {@link UseStatement}s.
+ */
+ private List<UseStatement> result = new LinkedList<UseStatement>();
+
+ /**
+ * Constructor of the visitor.
+ *
+ * @param offset
+ * the position in the AST tree after which the search stops
+ */
+ public GetUseStatementsASTVisitor(int offset) {
+ super(offset);
+ }
+
+ /**
+ * Returns all found {@link UseStatement}s.
+ *
+ * <p>
+ * This method never returns <code>null</code>.
+ * </p>
+ *
+ * @return an array of {@link UseStatement} nodes.
+ */
+ public UseStatement[] getResult() {
+ return (UseStatement[]) result.toArray(new UseStatement[result.size()]);
+ }
+
+ /**
+ * Just add every {@link UseStatement} node visited to the result.
+ *
+ * <p>
+ * The base AST visitor ensures that only nodes before the
+ * <code>offset</code> are visited.
+ * </p>
+ */
+ @Override
+ protected void visit(UseStatement s) {
+ result.add(s);
+ }
+
+}
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
index 2d2c8fc..2e21e6c 100644
--- a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/AllTests.java
@@ -16,6 +16,9 @@ import junit.framework.TestSuite;
import org.eclipse.php.core.tests.codeassist.CodeAssistTests;
import org.eclipse.php.core.tests.compiler_ast.parser.CompilerParserTests;
+import org.eclipse.php.core.tests.compiler_ast.parser.FindUseStatementByAliasTests;
+import org.eclipse.php.core.tests.compiler_ast.parser.FindUseStatementByNamespaceTests;
+import org.eclipse.php.core.tests.compiler_ast.parser.GetUseStatementsByTests;
import org.eclipse.php.core.tests.compiler_ast.phpdoc.PHPDocAwareDeclarationTests;
import org.eclipse.php.core.tests.compiler_ast.phpdoc.PHPDocParserTests;
import org.eclipse.php.core.tests.document.lexer.DocumentLexerTests;
@@ -46,6 +49,9 @@ public class AllTests {
// Model tests:
suite.addTest(DomParserTests.suite());
suite.addTest(CompilerParserTests.suite());
+ suite.addTest(FindUseStatementByAliasTests.suite());
+ suite.addTest(FindUseStatementByNamespaceTests.suite());
+ suite.addTest(GetUseStatementsByTests.suite());
suite.addTest(ErrorReportingTests.suite());
suite.addTest(ASTRewriteTests.suite());
suite.addTest(ASTMatcherTests.suite());
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByAliasTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByAliasTests.java
new file mode 100644
index 0000000..4cc0e33
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByAliasTests.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.core.tests.compiler_ast.parser;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.php.core.tests.AbstractPDTTTest;
+import org.eclipse.php.core.tests.PdttFile;
+import org.eclipse.php.internal.core.PHPVersion;
+import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
+import org.eclipse.php.internal.core.compiler.ast.parser.ASTUtils;
+import org.eclipse.php.internal.core.compiler.ast.parser.AbstractPHPSourceParser;
+import org.eclipse.php.internal.core.compiler.ast.parser.PHPSourceParserFactory;
+import org.eclipse.php.internal.core.project.ProjectOptions;
+
+public class FindUseStatementByAliasTests extends AbstractPDTTTest {
+
+ protected static final Map<PHPVersion, String[]> TESTS = new LinkedHashMap<PHPVersion, String[]>();
+ static {
+ TESTS.put(
+ PHPVersion.PHP5_3,
+ new String[] { "/workspace/astutils/find_use_statement_by_alias/php53" });
+ };
+
+ public FindUseStatementByAliasTests(String description) {
+ super(description);
+ }
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("Find Use Statement By Alias Tests");
+
+ for (final PHPVersion phpVersion : TESTS.keySet()) {
+ TestSuite phpVerSuite = new TestSuite(phpVersion.getAlias());
+ final AbstractPHPSourceParser parser = PHPSourceParserFactory
+ .createParser(phpVersion);
+
+ for (String testsDirectory : TESTS.get(phpVersion)) {
+
+ for (final String fileName : getPDTTFiles(testsDirectory)) {
+ try {
+ final PdttFile pdttFile = new PdttFile(fileName);
+ phpVerSuite.addTest(new CompilerParserTests(phpVersion
+ .getAlias() + " - /" + fileName) {
+
+ protected void runTest() throws Throwable {
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(
+ pdttFile.getFile().trim().getBytes());
+ ModuleDeclaration moduleDeclaration = (ModuleDeclaration) parser
+ .parse(new InputStreamReader(
+ inputStream),
+ null,
+ ProjectOptions
+ .useShortTags((IProject) null));
+
+ String alias = pdttFile.getConfig()
+ .get("alias");
+ int offset = Integer.parseInt(pdttFile
+ .getConfig().get("offset"));
+
+ UsePart usePart = ASTUtils
+ .findUseStatementByAlias(
+ moduleDeclaration, alias,
+ offset);
+
+ String actual = (usePart == null) ? "null"
+ : usePart.toString();
+ assertContents(pdttFile.getExpected(), actual);
+ }
+ });
+ } catch (final Exception e) {
+ // dummy test indicating PDTT file parsing failure
+ phpVerSuite.addTest(new TestCase(fileName) {
+ protected void runTest() throws Throwable {
+ throw e;
+ }
+ });
+ }
+ }
+ }
+ suite.addTest(phpVerSuite);
+ }
+
+ // Create a setup wrapper
+ TestSetup setup = new TestSetup(suite) {
+ protected void setUp() throws Exception {
+ }
+
+ protected void tearDown() throws Exception {
+ }
+ };
+ return setup;
+ }
+}
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByNamespaceTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByNamespaceTests.java
new file mode 100644
index 0000000..e122c73
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/FindUseStatementByNamespaceTests.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.core.tests.compiler_ast.parser;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.php.core.tests.AbstractPDTTTest;
+import org.eclipse.php.core.tests.PdttFile;
+import org.eclipse.php.internal.core.PHPVersion;
+import org.eclipse.php.internal.core.compiler.ast.nodes.UsePart;
+import org.eclipse.php.internal.core.compiler.ast.parser.ASTUtils;
+import org.eclipse.php.internal.core.compiler.ast.parser.AbstractPHPSourceParser;
+import org.eclipse.php.internal.core.compiler.ast.parser.PHPSourceParserFactory;
+import org.eclipse.php.internal.core.project.ProjectOptions;
+
+public class FindUseStatementByNamespaceTests extends AbstractPDTTTest {
+
+ protected static final Map<PHPVersion, String[]> TESTS = new LinkedHashMap<PHPVersion, String[]>();
+ static {
+ TESTS.put(
+ PHPVersion.PHP5_3,
+ new String[] { "/workspace/astutils/find_use_statement_by_namespace/php53" });
+ };
+
+ public FindUseStatementByNamespaceTests(String description) {
+ super(description);
+ }
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("Find Use Statement By Namespace Tests");
+
+ for (final PHPVersion phpVersion : TESTS.keySet()) {
+ TestSuite phpVerSuite = new TestSuite(phpVersion.getAlias());
+ final AbstractPHPSourceParser parser = PHPSourceParserFactory
+ .createParser(phpVersion);
+
+ for (String testsDirectory : TESTS.get(phpVersion)) {
+
+ for (final String fileName : getPDTTFiles(testsDirectory)) {
+ try {
+ final PdttFile pdttFile = new PdttFile(fileName);
+ phpVerSuite.addTest(new CompilerParserTests(phpVersion
+ .getAlias() + " - /" + fileName) {
+
+ protected void runTest() throws Throwable {
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(
+ pdttFile.getFile().trim().getBytes());
+ ModuleDeclaration moduleDeclaration = (ModuleDeclaration) parser
+ .parse(new InputStreamReader(
+ inputStream),
+ null,
+ ProjectOptions
+ .useShortTags((IProject) null));
+
+ String namespace = pdttFile.getConfig().get(
+ "namespace");
+ int offset = Integer.parseInt(pdttFile
+ .getConfig().get("offset"));
+
+ UsePart usePart = ASTUtils
+ .findUseStatementByNamespace(
+ moduleDeclaration, namespace,
+ offset);
+
+ String actual = (usePart == null) ? "null"
+ : usePart.toString();
+ assertContents(pdttFile.getExpected(), actual);
+ }
+ });
+ } catch (final Exception e) {
+ // dummy test indicating PDTT file parsing failure
+ phpVerSuite.addTest(new TestCase(fileName) {
+ protected void runTest() throws Throwable {
+ throw e;
+ }
+ });
+ }
+ }
+ }
+ suite.addTest(phpVerSuite);
+ }
+
+ // Create a setup wrapper
+ TestSetup setup = new TestSetup(suite) {
+ protected void setUp() throws Exception {
+ }
+
+ protected void tearDown() throws Exception {
+ }
+ };
+ return setup;
+ }
+}
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/GetUseStatementsByTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/GetUseStatementsByTests.java
new file mode 100644
index 0000000..e3c6d9e
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/compiler_ast/parser/GetUseStatementsByTests.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Zend Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zend Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.php.core.tests.compiler_ast.parser;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.php.core.tests.AbstractPDTTTest;
+import org.eclipse.php.core.tests.PdttFile;
+import org.eclipse.php.internal.core.PHPVersion;
+import org.eclipse.php.internal.core.compiler.ast.nodes.UseStatement;
+import org.eclipse.php.internal.core.compiler.ast.parser.ASTUtils;
+import org.eclipse.php.internal.core.compiler.ast.parser.AbstractPHPSourceParser;
+import org.eclipse.php.internal.core.compiler.ast.parser.PHPSourceParserFactory;
+import org.eclipse.php.internal.core.project.ProjectOptions;
+
+public class GetUseStatementsByTests extends AbstractPDTTTest {
+
+ protected static final Map<PHPVersion, String[]> TESTS = new LinkedHashMap<PHPVersion, String[]>();
+ static {
+ TESTS.put(PHPVersion.PHP5_3,
+ new String[] { "/workspace/astutils/get_use_statements/php53" });
+ };
+
+ public GetUseStatementsByTests(String description) {
+ super(description);
+ }
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("Get Use Statements Tests");
+
+ for (final PHPVersion phpVersion : TESTS.keySet()) {
+ TestSuite phpVerSuite = new TestSuite(phpVersion.getAlias());
+ final AbstractPHPSourceParser parser = PHPSourceParserFactory
+ .createParser(phpVersion);
+
+ for (String testsDirectory : TESTS.get(phpVersion)) {
+
+ for (final String fileName : getPDTTFiles(testsDirectory)) {
+ try {
+ final PdttFile pdttFile = new PdttFile(fileName);
+ phpVerSuite.addTest(new CompilerParserTests(phpVersion
+ .getAlias() + " - /" + fileName) {
+
+ protected void runTest() throws Throwable {
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(
+ pdttFile.getFile().trim().getBytes());
+ ModuleDeclaration moduleDeclaration = (ModuleDeclaration) parser
+ .parse(new InputStreamReader(
+ inputStream),
+ null,
+ ProjectOptions
+ .useShortTags((IProject) null));
+
+ int offset = Integer.parseInt(pdttFile
+ .getConfig().get("offset"));
+
+ UseStatement[] useStatements = ASTUtils
+ .getUseStatements(moduleDeclaration,
+ offset);
+
+ StringBuilder builder = new StringBuilder();
+ for (UseStatement s : useStatements) {
+ builder.append(s);
+ }
+ String actual = builder.toString();
+
+ assertContents(pdttFile.getExpected(), actual);
+ }
+ });
+ } catch (final Exception e) {
+ // dummy test indicating PDTT file parsing failure
+ phpVerSuite.addTest(new TestCase(fileName) {
+ protected void runTest() throws Throwable {
+ throw e;
+ }
+ });
+ }
+ }
+ }
+ suite.addTest(phpVerSuite);
+ }
+
+ // Create a setup wrapper
+ TestSetup setup = new TestSetup(suite) {
+ protected void setUp() throws Exception {
+ }
+
+ protected void tearDown() throws Exception {
+ }
+ };
+ return setup;
+ }
+}
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testClassScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testClassScope.pdtt
new file mode 100644
index 0000000..d3a84bd
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testClassScope.pdtt
@@ -0,0 +1,20 @@
+--TEST--
+Find use statement in class scope (illegal)
+--CONFIG--
+alias: Danish
+offset: 114
+--FILE--
+<?php
+namespace Languages;
+
+class Greenlandic
+{
+ use Languages\Danish;
+
+ function func() {
+ $obj = new Danish;
+ }
+}
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeAfterOffset.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeAfterOffset.pdtt
new file mode 100644
index 0000000..4b6c8f6
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeAfterOffset.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+Find use statement in global scope after the offset
+--CONFIG--
+alias: NSname
+offset: 111
+--FILE--
+<?php
+use My\Full\Classname as Another;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+
+use My\Full\NSname;
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNewAlias.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNewAlias.pdtt
new file mode 100644
index 0000000..eb8b421
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNewAlias.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope importing a class as new alias
+--CONFIG--
+alias: Another
+offset: 68
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+[USE: My\Full\Classname AS Another] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNonExisting.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNonExisting.pdtt
new file mode 100644
index 0000000..e1ff9b8
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeNonExisting.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope for non-existing alias
+--CONFIG--
+alias: Classname
+offset: 195
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeSameName.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeSameName.pdtt
new file mode 100644
index 0000000..9a39aa1
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testGlobalScopeSameName.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope importing a class with same name
+--CONFIG--
+alias: NSname
+offset: 127
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+[USE: My\Full\NSname] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testNamespaceScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testNamespaceScope.pdtt
new file mode 100644
index 0000000..165b950
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_alias/php53/testNamespaceScope.pdtt
@@ -0,0 +1,15 @@
+--TEST--
+Find use statement in namespace scope
+--CONFIG--
+alias: Danish
+offset: 65
+--FILE--
+<?php
+namespace MyProject {
+ use Languages\Danish;
+
+ $obj = new Danish;
+}
+?>
+--EXPECT--
+[USE: Languages\Danish] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testClassScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testClassScope.pdtt
new file mode 100644
index 0000000..447a4cb
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testClassScope.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+Find use statement in class scope (illegal)
+--CONFIG--
+namespace: Languages\Danish
+offset: 114
+--FILE--
+<?php
+namespace Languages;
+
+class Greenlandic
+{
+ use Languages\Danish;
+}
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeAfterOffset.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeAfterOffset.pdtt
new file mode 100644
index 0000000..8936daf
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeAfterOffset.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+Find use statement in global scope after the offset
+--CONFIG--
+namespace: My\Full\NSname
+offset: 111
+--FILE--
+<?php
+use My\Full\Classname as Another;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+
+use My\Full\NSname;
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNewAlias.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNewAlias.pdtt
new file mode 100644
index 0000000..ab7d957
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNewAlias.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope importing a class as new alias
+--CONFIG--
+namespace: My\Full\Classname
+offset: 68
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+[USE: My\Full\Classname AS Another] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNonExisting.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNonExisting.pdtt
new file mode 100644
index 0000000..9e5234a
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeNonExisting.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope for non-existing alias
+--CONFIG--
+namespace: Another
+offset: 195
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+null \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeSameName.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeSameName.pdtt
new file mode 100644
index 0000000..48b3688
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testGlobalScopeSameName.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Find use statement in global scope importing a class with same name
+--CONFIG--
+namespace: My\Full\NSname
+offset: 127
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+[USE: My\Full\NSname] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testNamespaceScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testNamespaceScope.pdtt
new file mode 100644
index 0000000..956b841
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/find_use_statement_by_namespace/php53/testNamespaceScope.pdtt
@@ -0,0 +1,13 @@
+--TEST--
+Find use statement in namespace scope
+--CONFIG--
+namespace: Languages\Danish
+offset: 65
+--FILE--
+<?php
+namespace MyProject {
+ use Languages\Danish;
+}
+?>
+--EXPECT--
+[USE: Languages\Danish] \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testClassScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testClassScope.pdtt
new file mode 100644
index 0000000..753bd14
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testClassScope.pdtt
@@ -0,0 +1,18 @@
+--TEST--
+Get use statements in class scope (illegal)
+--CONFIG--
+offset: 114
+--FILE--
+<?php
+namespace Languages;
+
+class Greenlandic
+{
+ use Languages\Danish;
+
+ function func() {
+ $obj = new Danish;
+ }
+}
+?>
+--EXPECT--
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScope.pdtt
new file mode 100644
index 0000000..bc5c6be
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScope.pdtt
@@ -0,0 +1,35 @@
+--TEST--
+Get use statement in global scope
+--CONFIG--
+offset: 131
+--FILE--
+<?php
+use My\Full\Classname as Another;
+use My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+<UseStatement start="6" end="39">
+ <Parts>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="10" end="27" name="My\Full\Classname">
+ <NamespaceReference start="10" end="17" name="My\Full" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ <SimpleReference start="31" end="38" name="Another">
+ </SimpleReference>
+ </UsePart>
+ </Parts>
+</UseStatement>
+<UseStatement start="40" end="59">
+ <Parts>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="44" end="58" name="My\Full\NSname">
+ <NamespaceReference start="44" end="51" name="My\Full" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ </UsePart>
+ </Parts>
+</UseStatement> \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeAfterOffset.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeAfterOffset.pdtt
new file mode 100644
index 0000000..7ad722e
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeAfterOffset.pdtt
@@ -0,0 +1,26 @@
+--TEST--
+Get use statements in global scope as there use statements after the offset
+--CONFIG--
+offset: 111
+--FILE--
+<?php
+use My\Full\Classname as Another;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+
+use My\Full\NSname;
+?>
+--EXPECT--
+<UseStatement start="6" end="39">
+ <Parts>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="10" end="27" name="My\Full\Classname">
+ <NamespaceReference start="10" end="17" name="My\Full" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ <SimpleReference start="31" end="38" name="Another">
+ </SimpleReference>
+ </UsePart>
+ </Parts>
+</UseStatement> \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeTwoInOne.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeTwoInOne.pdtt
new file mode 100644
index 0000000..e155863
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testGlobalScopeTwoInOne.pdtt
@@ -0,0 +1,30 @@
+--TEST--
+Get use statements in global scope - two parts in one statement
+--CONFIG--
+offset: 68
+--FILE--
+<?php
+use My\Full\Classname as Another, My\Full\NSname;
+
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--
+<UseStatement start="6" end="55">
+ <Parts>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="10" end="27" name="My\Full\Classname">
+ <NamespaceReference start="10" end="17" name="My\Full" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ <SimpleReference start="31" end="38" name="Another">
+ </SimpleReference>
+ </UsePart>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="40" end="54" name="My\Full\NSname">
+ <NamespaceReference start="40" end="47" name="My\Full" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ </UsePart>
+ </Parts>
+</UseStatement> \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNamespaceScope.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNamespaceScope.pdtt
new file mode 100644
index 0000000..f7e153d
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNamespaceScope.pdtt
@@ -0,0 +1,23 @@
+--TEST--
+Get use statements in namespace scope
+--CONFIG--
+offset: 65
+--FILE--
+<?php
+namespace MyProject {
+ use Languages\Danish;
+
+ $obj = new Danish;
+}
+?>
+--EXPECT--
+<UseStatement start="29" end="50">
+ <Parts>
+ <UsePart start="0" end="0">
+ <FullyQualifiedReference start="33" end="49" name="Languages\Danish">
+ <NamespaceReference start="33" end="42" name="Languages" global="false" local="false">
+ </NamespaceReference>
+ </FullyQualifiedReference>
+ </UsePart>
+ </Parts>
+</UseStatement> \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNoneDeclared.pdtt b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNoneDeclared.pdtt
new file mode 100644
index 0000000..fb5d270
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/astutils/get_use_statements/php53/testNoneDeclared.pdtt
@@ -0,0 +1,10 @@
+--TEST--
+Get use statements - none declared
+--CONFIG--
+offset: 100
+--FILE--
+<?php
+$obj = new Another; // instantiates object of class My\Full\Classname
+NSname\subns\func(); // calls function My\Full\NSname\subns\func
+?>
+--EXPECT--