Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.php.core/Resources/parserTools/parser/php7/php_compiler_ast_parser.cup2
-rw-r--r--plugins/org.eclipse.php.core/Resources/parserTools/parser/php71/php_compiler_ast_parser.cup2
-rw-r--r--plugins/org.eclipse.php.core/Resources/parserTools/parser/php72/php_compiler_ast_parser.cup2
-rw-r--r--plugins/org.eclipse.php.core/Resources/parserTools/parser/php73/php_compiler_ast_parser.cup2
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/NamespaceReference.java14
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java10
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java54
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java22
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/TypeReferenceEvaluator.java4
-rw-r--r--tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/errors/AbstractErrorReportingTests.java3
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal7.pdtt37
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal8.pdtt37
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError3.pdtt34
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError4.pdtt34
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError5.pdtt32
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError6.pdtt32
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement1.pdtt34
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement2.pdtt34
18 files changed, 357 insertions, 32 deletions
diff --git a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php7/php_compiler_ast_parser.cup b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php7/php_compiler_ast_parser.cup
index 446ec2dd0..2524b7cb8 100644
--- a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php7/php_compiler_ast_parser.cup
+++ b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php7/php_compiler_ast_parser.cup
@@ -3294,7 +3294,7 @@ namespace_name:name
| T_NAMESPACE:s T_NS_SEPARATOR namespace_name:name
{:
if (name.getNamespace() == null) {
- name.setNamespace(new NamespaceReference(nameleft, nameleft, null));
+ name.setNamespace(new NamespaceReference(nameleft, nameleft, ""));
}
name.getNamespace().setLocal(true);
diff --git a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php71/php_compiler_ast_parser.cup b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php71/php_compiler_ast_parser.cup
index b8b69ecfe..850173944 100644
--- a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php71/php_compiler_ast_parser.cup
+++ b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php71/php_compiler_ast_parser.cup
@@ -3289,7 +3289,7 @@ namespace_name:name
| T_NAMESPACE:s T_NS_SEPARATOR namespace_name:name
{:
if (name.getNamespace() == null) {
- name.setNamespace(new NamespaceReference(nameleft, nameleft, null));
+ name.setNamespace(new NamespaceReference(nameleft, nameleft, ""));
}
name.getNamespace().setLocal(true);
diff --git a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php72/php_compiler_ast_parser.cup b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php72/php_compiler_ast_parser.cup
index 04f6d2cab..8f3f3f05b 100644
--- a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php72/php_compiler_ast_parser.cup
+++ b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php72/php_compiler_ast_parser.cup
@@ -3290,7 +3290,7 @@ namespace_name:name
| T_NAMESPACE:s T_NS_SEPARATOR namespace_name:name
{:
if (name.getNamespace() == null) {
- name.setNamespace(new NamespaceReference(nameleft, nameleft, null));
+ name.setNamespace(new NamespaceReference(nameleft, nameleft, ""));
}
name.getNamespace().setLocal(true);
diff --git a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php73/php_compiler_ast_parser.cup b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php73/php_compiler_ast_parser.cup
index dfdc767d5..31a148e7e 100644
--- a/plugins/org.eclipse.php.core/Resources/parserTools/parser/php73/php_compiler_ast_parser.cup
+++ b/plugins/org.eclipse.php.core/Resources/parserTools/parser/php73/php_compiler_ast_parser.cup
@@ -3290,7 +3290,7 @@ namespace_name:name
| T_NAMESPACE:s T_NS_SEPARATOR namespace_name:name
{:
if (name.getNamespace() == null) {
- name.setNamespace(new NamespaceReference(nameleft, nameleft, null));
+ name.setNamespace(new NamespaceReference(nameleft, nameleft, ""));
}
name.getNamespace().setLocal(true);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/NamespaceReference.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/NamespaceReference.java
index 3799fd99f..3ab3e084c 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/NamespaceReference.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/core/compiler/ast/nodes/NamespaceReference.java
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.php.core.compiler.ast.nodes;
+import org.eclipse.dltk.annotations.NonNull;
import org.eclipse.dltk.ast.references.TypeReference;
/**
@@ -82,7 +83,14 @@ public class NamespaceReference extends TypeReference {
this.local = local;
}
+ /**
+ * Returns namespace name, prefixed by "\" for global namespaces or
+ * "namespace\" for local namespaces. The returned value is never null and
+ * never empty.
+ */
+ @SuppressWarnings("null")
@Override
+ @NonNull
public String getName() {
StringBuilder buf = new StringBuilder();
if (global) {
@@ -92,6 +100,10 @@ public class NamespaceReference extends TypeReference {
buf.append("namespace\\"); //$NON-NLS-1$
}
buf.append(super.getName());
- return buf.toString();
+ String name = buf.toString();
+
+ assert name.length() > 0;
+
+ return name;
}
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
index 95bf126b3..988d60a8f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPClassType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2019 IBM Corporation and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -139,10 +139,10 @@ public class PHPClassType extends ClassType implements IClassType {
public static PHPClassType fromTypeName(String typeName, ISourceModule sourceModule, int offset) {
String namespace = PHPModelUtils.extractNamespaceName(typeName, sourceModule, offset);
String elementName = PHPModelUtils.extractElementName(typeName);
- if (namespace != null) {
+ if (namespace != null && typeName != null && sourceModule != null && elementName != null) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=515844
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=527153
- elementName = PHPModelUtils.getRealName(typeName, sourceModule, offset, elementName);
+ elementName = PHPModelUtils.getRealName(namespace, typeName, sourceModule, offset, elementName);
}
final ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
if (PHPModelUtils.isInUseTraitStatement(moduleDeclaration, offset)) {
@@ -166,10 +166,10 @@ public class PHPClassType extends ClassType implements IClassType {
public static PHPClassType fromTraitName(String typeName, ISourceModule sourceModule, int offset) {
String namespace = PHPModelUtils.extractNamespaceName(typeName, sourceModule, offset);
String elementName = PHPModelUtils.extractElementName(typeName);
- if (namespace != null) {
+ if (namespace != null && typeName != null && sourceModule != null && elementName != null) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=515844
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=527153
- elementName = PHPModelUtils.getRealName(typeName, sourceModule, offset, elementName);
+ elementName = PHPModelUtils.getRealName(namespace, typeName, sourceModule, offset, elementName);
}
if (namespace != null) {
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
index f29f0bfd5..533e5ed0f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/PHPModelUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2016, 2017, 2018 IBM Corporation and others.
+ * Copyright (c) 2009, 2016-2019 IBM Corporation and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -191,28 +191,43 @@ public class PHPModelUtils {
}
/**
- * if the elementName is a class alias for a namespace class, we get its
- * original name from its alias
+ * If the elementName is a class alias for a namespace class "elementName"
+ * (and for a specific namespace "namespace"), we get its original name from
+ * its alias.
*
+ * @param fqNamespaceName
+ * fully qualified namespace name (<b>without any leading
+ * '\'</b>), empty name "" means global namespace, leading
+ * "namespace\" is allowed. The resulting name <b>must</b> have
+ * fqNamespaceName as its fully qualified namespace or it will be
+ * rejected.
* @param elementName
+ * namespace class
* @param sourceModule
* @param offset
* @param defaultClassName
- * @return
+ * return this value when elementName couldn't be resolved
+ * against fqNamespaceName, or when no alias was found
+ * @return original name from its alias (if available and applicable),
+ * defaultClassName otherwise
*/
- public static String getRealName(String elementName, ISourceModule sourceModule, final int offset,
- String defaultClassName) {
-
+ public static String getRealName(@NonNull String fqNamespaceName, @NonNull String elementName,
+ @NonNull ISourceModule sourceModule, final int offset, String defaultClassName) {
// Check class name aliasing:
ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
UsePart usePart = ASTUtils.findUseStatementByAlias(moduleDeclaration, elementName, offset);
if (usePart != null) {
- elementName = usePart.getFullUseStatementName();
- int nsIndex = elementName.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR);
- if (nsIndex != -1) {
- defaultClassName = elementName.substring(nsIndex + 1);
- } else {
- defaultClassName = elementName;
+ String fullName = usePart.getFullUseStatementName();
+ String newElementName = PHPModelUtils.extractElementName(fullName);
+ String newNamespace = PHPModelUtils.extractNameSpaceName(fullName);
+ if (newNamespace == null) {
+ // No namespace prefix found, translate it as global namespace
+ newNamespace = ""; //$NON-NLS-1$
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=549197
+ // Avoid namespace mismatches
+ if (fqNamespaceName.equalsIgnoreCase(newNamespace)) {
+ return newElementName;
}
}
return defaultClassName;
@@ -1879,8 +1894,8 @@ public class PHPModelUtils {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=515844
// only look for aliases when there is no namespace
// separator in the type name
- if (typeNameSpaceName == null) {
- typeName = getRealName(typeName, sourceModule, offset, typeName);
+ if (typeNameSpaceName == null && typeName != null) {
+ typeName = getRealName(namespace, typeName, sourceModule, offset, typeName);
}
IType[] types = getNamespaceType(namespace, typeName, true, sourceModule, cache, monitor, isType);
@@ -2348,11 +2363,16 @@ public class PHPModelUtils {
}
@NonNull
- public static String getFullName(@NonNull String typeName, ISourceModule sourceModule, final int offset) {
+ public static String getFullName(@NonNull String typeName, @NonNull ISourceModule sourceModule, final int offset) {
String namespace = extractNamespaceName(typeName, sourceModule, offset);
String elementName = extractElementName(typeName);
+ // XXX: cannot be null here, but we need to silence null type mismatch
+ // error:
+ if (elementName == null) {
+ return ""; //$NON-NLS-1$
+ }
if (namespace != null) {
- elementName = getRealName(elementName, sourceModule, offset, elementName);
+ elementName = getRealName(namespace, elementName, sourceModule, offset, elementName);
if (namespace.length() > 0) {
elementName = namespace + NamespaceReference.NAMESPACE_SEPARATOR + elementName;
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
index a9378e45e..2eb2c7f5c 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2019 IBM Corporation and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -74,8 +74,24 @@ public class TraitUtils {
String name = typeReference.getName();
if (typeReference instanceof FullyQualifiedReference) {
FullyQualifiedReference reference = (FullyQualifiedReference) typeReference;
- if (reference.getNamespace() != null) {
- name = reference.getNamespace().getName() + NamespaceReference.NAMESPACE_SEPARATOR + name;
+ NamespaceReference namespace = reference.getNamespace();
+ if (namespace != null) {
+ String namespaceName = namespace.getName();
+ if (namespaceName.length() > 0 // Just to be safe...
+ && namespaceName.charAt(0) == NamespaceReference.NAMESPACE_SEPARATOR) {
+ // NB: namespaceName can be "\"
+ namespaceName = namespaceName.substring(1);
+ }
+ if (namespaceName.length() > 0) {
+ name = namespaceName + NamespaceReference.NAMESPACE_SEPARATOR + name;
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=549197
+ // Do not do alias resolution when the namespace name is
+ // already fully qualified.
+ if (namespace.isGlobal()) {
+ useTrait.getTraits().add(name);
+ continue;
+ }
}
}
useTrait.getTraits().add(PHPModelUtils.getFullName(name, sourceModule, offset));
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/TypeReferenceEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/TypeReferenceEvaluator.java
index 5603d1994..4c4bd9be4 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/TypeReferenceEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/TypeReferenceEvaluator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2016, 2017 IBM Corporation and others.
+ * Copyright (c) 2009, 2016, 2017, 2019 IBM Corporation and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
@@ -239,7 +239,7 @@ public class TypeReferenceEvaluator extends GoalEvaluator {
parentNamespace = extractedNamespace;
// See also code from PHPClassType.fromTypeName(...) and
// PHPClassType.fromTraitName(...)
- elementName = PHPModelUtils.getRealName(fullyQualifiedName, sourceModule, offset, elementName);
+ elementName = PHPModelUtils.getRealName(extractedNamespace, fullyQualifiedName, sourceModule, offset, elementName);
}
if (PHPModelUtils.isInUseTraitStatement(((ISourceModuleContext) context).getRootNode(),
typeReference.sourceStart())) {
diff --git a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/errors/AbstractErrorReportingTests.java b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/errors/AbstractErrorReportingTests.java
index b27a6ddde..eeed6b039 100644
--- a/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/errors/AbstractErrorReportingTests.java
+++ b/tests/org.eclipse.php.core.tests/src/org/eclipse/php/core/tests/errors/AbstractErrorReportingTests.java
@@ -83,6 +83,9 @@ abstract public class AbstractErrorReportingTests {
PdttFile pdttFile = new PdttFile(fileName);
pdttFiles.put(fileName, pdttFile);
files.put(fileName, createFile(pdttFile.getFile().trim()));
+ for (String otherFile : pdttFile.getOtherFiles()) {
+ createFile(otherFile.trim());
+ }
}
TestUtils.setProjectPHPVersion(project, getPHPVersion());
// Perform full build to trigger errors check
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal7.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal7.pdtt
new file mode 100644
index 000000000..8dece51c4
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal7.pdtt
@@ -0,0 +1,37 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+namespace Traits
+{
+
+ trait StuffMaker
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker;
+
+ interface IStuffMaker
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker implements IStuffMaker
+ {
+ use Traits\|;
+ }
+}
+?>
+--EXPECT--
+type(StuffMaker) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal8.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal8.pdtt
new file mode 100644
index 000000000..9f4d5c72c
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal8.pdtt
@@ -0,0 +1,37 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+namespace Traits2
+{
+
+ trait StuffMaker2
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker2;
+
+ interface IStuffMaker2
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker2 implements IStuffMaker2
+ {
+ use \Traits2\|;
+ }
+}
+?>
+--EXPECT--
+type(StuffMaker2) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError3.pdtt b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError3.pdtt
new file mode 100644
index 000000000..23e5d305b
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError3.pdtt
@@ -0,0 +1,34 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+namespace Traits
+{
+
+ trait StuffMaker
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker;
+
+ interface IStuffMaker
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker implements IStuffMaker
+ {
+ use Traits\StuffMaker;
+ }
+}
+--EXPECT--
+[line=17, start=158, end=166] The import stdClass is never used \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError4.pdtt b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError4.pdtt
new file mode 100644
index 000000000..49aa21757
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError4.pdtt
@@ -0,0 +1,34 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+namespace Traits2
+{
+
+ trait StuffMaker2
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker2;
+
+ interface IStuffMaker2
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker2 implements IStuffMaker2
+ {
+ use \Traits2\StuffMaker2;
+ }
+}
+--EXPECT--
+[line=17, start=160, end=168] The import stdClass is never used \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError5.pdtt b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError5.pdtt
new file mode 100644
index 000000000..798980b8b
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError5.pdtt
@@ -0,0 +1,32 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+use stdClass as StuffMaker3;
+
+class AStuffMaker3 implements IStuffMaker3
+{
+ use Traits3\StuffMaker3;
+}
+?>
+--FILE0--
+<?php
+interface IStuffMaker3
+{
+ public function makeStuff();
+}
+?>
+--FILE1--
+<?php
+namespace Traits3;
+
+trait StuffMaker3
+{
+ public function makeStuff()
+ {
+ //code
+ }
+}
+?>
+--EXPECT--
+[line=2, start=10, end=18] The import stdClass is never used \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError6.pdtt b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError6.pdtt
new file mode 100644
index 000000000..a26df52f9
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/errors/php54/testTypeReferenceError6.pdtt
@@ -0,0 +1,32 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+use stdClass as StuffMaker4;
+
+class AStuffMaker4 implements IStuffMaker4
+{
+ use \Traits4\StuffMaker4;
+}
+?>
+--FILE0--
+<?php
+interface IStuffMaker4
+{
+ public function makeStuff();
+}
+?>
+--FILE1--
+<?php
+namespace Traits4;
+
+trait StuffMaker4
+{
+ public function makeStuff()
+ {
+ //code
+ }
+}
+?>
+--EXPECT--
+[line=2, start=10, end=18] The import stdClass is never used \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement1.pdtt b/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement1.pdtt
new file mode 100644
index 000000000..854eaec94
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement1.pdtt
@@ -0,0 +1,34 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+namespace Traits
+{
+
+ trait StuffMaker
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker;
+
+ interface IStuffMaker
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker implements IStuffMaker
+ {
+ use Traits\|StuffMaker|;
+ }
+}
+--EXPECT--
+type(StuffMaker) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement2.pdtt b/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement2.pdtt
new file mode 100644
index 000000000..e3612a49c
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/selection/php54/testUseTraitStatement2.pdtt
@@ -0,0 +1,34 @@
+--TEST--
+Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
+--FILE--
+<?php
+namespace Traits2
+{
+
+ trait StuffMaker2
+ {
+
+ public function makeStuff()
+ {
+ //code
+ }
+ }
+}
+namespace
+{
+
+ use stdClass as StuffMaker2;
+
+ interface IStuffMaker2
+ {
+
+ public function makeStuff();
+ }
+
+ class AStuffMaker2 implements IStuffMaker2
+ {
+ use \Traits2\|StuffMaker2|;
+ }
+}
+--EXPECT--
+type(StuffMaker2) \ No newline at end of file

Back to the top