aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-08 03:00:46 (EDT)
committerzzhongwei2012-08-08 03:00:46 (EDT)
commitf59d3c03f99519286cb8b03dae704e791688db70 (patch)
treed70815583121ceb027c20227c48947ed1d263cac
parent68922bd1d68311f920cf2049873b37f78f1202f8 (diff)
downloadorg.eclipse.pdt-f59d3c03f99519286cb8b03dae704e791688db70.zip
org.eclipse.pdt-f59d3c03f99519286cb8b03dae704e791688db70.tar.gz
org.eclipse.pdt-f59d3c03f99519286cb8b03dae704e791688db70.tar.bz2
386799: if a trait method has a alias,this method does not show in CA
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386799
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/TraitUtils.java200
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/UseTrait.java4
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityChangeName.pdtt3
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPro3.pdtt3
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPub3.pdtt3
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPri3.pdtt5
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPub3.pdtt3
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri3.pdtt5
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri4.pdtt1
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro3.pdtt5
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro4.pdtt1
11 files changed, 141 insertions, 92 deletions
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 7626b80..b79ed53 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
@@ -81,7 +81,15 @@ public class TraitUtils {
.getName();
}
useTrait.getTraitAliases().add(ta);
- useTrait.getAliasMap().put(ta.traitMethodName, ta);
+ List<TraitAliasObject> traitAliases = useTrait
+ .getAliasMap().get(ta.traitMethodName);
+ if (traitAliases == null) {
+ traitAliases = new ArrayList<TraitAliasObject>();
+ useTrait.getAliasMap().put(ta.traitMethodName,
+ traitAliases);
+ }
+ traitAliases.add(ta);
+ // useTrait.getAliasMap().put(ta.traitMethodName, ta);
} else if (traitMethod instanceof FullyQualifiedTraitMethodReference) {
FullyQualifiedTraitMethodReference simpleReference = (FullyQualifiedTraitMethodReference) traitMethod;
@@ -95,7 +103,15 @@ public class TraitUtils {
.getName();
}
useTrait.getTraitAliases().add(ta);
- useTrait.getAliasMap().put(ta.traitMethodName, ta);
+ List<TraitAliasObject> traitAliases = useTrait
+ .getAliasMap().get(ta.traitMethodName);
+ if (traitAliases == null) {
+ traitAliases = new ArrayList<TraitAliasObject>();
+ useTrait.getAliasMap().put(ta.traitMethodName,
+ traitAliases);
+ }
+ traitAliases.add(ta);
+ // useTrait.getAliasMap().put(ta.traitMethodName, ta);
}
} else if (traitStatement instanceof TraitPrecedenceStatement) {
@@ -140,16 +156,19 @@ public class TraitUtils {
fields = PHPModelUtils.getTypeField(traitType, "", false);
// fields = traitType.getFields();
for (IField field : fields) {
- field = getFieldWrapper(useTrait, field, type);
- if (field == null) {
- continue;
- }
- String elementName = field.getElementName();
- if (elementName.startsWith("$")) {
- elementName = elementName.substring(1);
- }
- if (!nameSet.contains(elementName)) {
- fieldList.add(field);
+ List<IField> aliasList = getFieldWrapper(useTrait,
+ field, type);
+ for (IField alias : aliasList) {
+ if (alias == null) {
+ continue;
+ }
+ String elementName = alias.getElementName();
+ if (elementName.startsWith("$")) {
+ elementName = elementName.substring(1);
+ }
+ if (!nameSet.contains(elementName)) {
+ fieldList.add(alias);
+ }
}
}
} catch (ModelException e) {
@@ -159,54 +178,52 @@ public class TraitUtils {
return fieldList.toArray(new IField[fieldList.size()]);
}
- private static IField getFieldWrapper(UseTrait useTrait, IField field,
- IType type) {
- // TraitAliasObject tao = useTrait.getAliasMap().get(
- // field.getElementName());
- // TraitPrecedenceObject tpo = useTrait.getPrecedenceMap().get(
- // field.getElementName());
- // if (tpo != null) {
- // String fullName = PHPModelUtils.getFullName(field
- // .getDeclaringType());
- // if (!fullName.equals(tpo.traitName) || tao == null
- // || tao.newMethodName == null) {
- // return null;
- // }
- // } else {
- //
- // }
- // if (tao != null) {
- // field = new FieldWrapper(field, tao.newMethodVisibility,
- // tao.newMethodName);
- // }
- // return field;
+ private static List<IField> getFieldWrapper(UseTrait useTrait,
+ IField field, IType type) {
+ List<IField> result = new ArrayList<IField>();
String fieldName = field.getElementName();
if (fieldName.startsWith("$")) {
fieldName = fieldName.substring(1);
}
- TraitAliasObject tao = useTrait.getAliasMap().get(fieldName);
TraitPrecedenceObject tpo = useTrait.getPrecedenceMap().get(fieldName);
- String fullName = PHPModelUtils.getFullName(field.getDeclaringType());
- if (tao != null
- && (tao.traitName == null || fullName.equals(tao.traitName))) {
- field = new FieldWrapper(field, tao.newMethodVisibility,
- tao.newMethodName, type);
- return field;
- }
+ boolean shouldAddSelf = true;
+ boolean changeVisibility = false;
if (tpo != null) {
- if (!fullName.equals(tpo.traitName)) {
- return null;
+ shouldAddSelf = false;
+ }
+ List<TraitAliasObject> aliasList = useTrait.getAliasMap()
+ .get(fieldName);
+ String fullName = PHPModelUtils.getFullName(field.getDeclaringType());
+ if (aliasList != null) {
+ for (TraitAliasObject tao : aliasList) {
+ if ((tao.traitName == null || fullName.equals(tao.traitName))) {
+ IField alias = new FieldWrapper(field,
+ tao.newMethodVisibility, tao.newMethodName, type);
+ result.add(alias);
+ if (fieldName.equals(tao.newMethodName)
+ || tao.newMethodName == null) {
+ changeVisibility = true;
+ }
+ }
+ if (tpo != null) {
+ if (!fullName.equals(tpo.traitName)) {
+ continue;
+ } else {
+ shouldAddSelf = true;
+ }
+ }
}
- // if (!fullName.equals(tpo.traitName)
- // && (tao == null || (fullName.equals(tao.traitName)
- // && tao.newMethodName != null && !fullName
- // .equals(tao.newMethodName)))) {
- // return null;
- // }
} else {
+ if (tpo != null && fullName.equals(tpo.traitName)) {
+ shouldAddSelf = true;
+ }
+ }
+ if (shouldAddSelf && !changeVisibility) {
+ result.add(field);
}
- return field;
+ // TraitAliasObject tao = useTrait.getAliasMap().get(fieldName);
+ return result;
}
public static IMethod[] getTraitMethods(IType type, Set<String> nameSet) {
@@ -231,13 +248,17 @@ public class TraitUtils {
methods = PHPModelUtils.getTypeMethod(traitType, "", false);
// methods = traitType.getMethods();
for (IMethod method : methods) {
- method = getMethodWrapper(useTrait, method, type);
- if (method == null) {
- continue;
- }
- String elementName = method.getElementName();
- if (!nameSet.contains(elementName)) {
- fieldList.add(method);
+
+ List<IMethod> aliasList = getMethodWrapper(useTrait,
+ method, type);
+ for (IMethod alias : aliasList) {
+ if (alias == null) {
+ continue;
+ }
+ String elementName = alias.getElementName();
+ if (!nameSet.contains(elementName)) {
+ fieldList.add(alias);
+ }
}
}
} catch (ModelException e) {
@@ -247,33 +268,52 @@ public class TraitUtils {
return fieldList.toArray(new IMethod[fieldList.size()]);
}
- private static IMethod getMethodWrapper(UseTrait useTrait, IMethod method,
- IType type) {
- TraitAliasObject tao = useTrait.getAliasMap().get(
- method.getElementName());
- TraitPrecedenceObject tpo = useTrait.getPrecedenceMap().get(
- method.getElementName());
- String fullName = PHPModelUtils.getFullName(method.getDeclaringType());
- if (tao != null
- && (tao.traitName == null || fullName.equals(tao.traitName))) {
- method = new MethodWrapper(method, tao.newMethodVisibility,
- tao.newMethodName, type);
- return method;
- }
+ private static List<IMethod> getMethodWrapper(UseTrait useTrait,
+ IMethod method, IType type) {
+
+ List<IMethod> result = new ArrayList<IMethod>();
+ String methodName = method.getElementName();
+ TraitPrecedenceObject tpo = useTrait.getPrecedenceMap().get(methodName);
+ boolean shouldAddSelf = true;
+ boolean changeVisibility = false;
if (tpo != null) {
- if (!fullName.equals(tpo.traitName)) {
- return null;
+ shouldAddSelf = false;
+ }
+ List<TraitAliasObject> aliasList = useTrait.getAliasMap().get(
+ methodName);
+ String fullName = PHPModelUtils.getFullName(method.getDeclaringType());
+ if (aliasList != null) {
+ for (TraitAliasObject tao : aliasList) {
+ if ((tao.traitName == null || fullName.equals(tao.traitName))) {
+ IMethod alias = new MethodWrapper(method,
+ tao.newMethodVisibility, tao.newMethodName, type);
+ result.add(alias);
+ if (methodName.equals(tao.newMethodName)
+ || tao.newMethodName == null) {
+ changeVisibility = true;
+ }
+ }
+ if (tpo != null) {
+ if (!fullName.equals(tpo.traitName)) {
+ continue;
+ } else {
+ shouldAddSelf = true;
+ }
+ }
}
- // if (!fullName.equals(tpo.traitName)
- // && (tao == null || (fullName.equals(tao.traitName)
- // && tao.newMethodName != null && !fullName
- // .equals(tao.newMethodName)))) {
- // return null;
- // }
} else {
-
+ if (tpo != null) {
+ if (fullName.equals(tpo.traitName)) {
+ shouldAddSelf = true;
+ }
+ }
+ }
+ if (shouldAddSelf && !changeVisibility) {
+ result.add(method);
}
- return method;
+ // TraitAliasObject tao = useTrait.getAliasMap().get(fieldName);
+ return result;
+
}
/**
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/UseTrait.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/UseTrait.java
index 0a9d0b8..ed7b312 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/UseTrait.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/UseTrait.java
@@ -11,7 +11,7 @@ public class UseTrait {
private List<TraitPrecedenceObject> traitPrecedences = new ArrayList<TraitPrecedenceObject>();
private List<TraitAliasObject> traitAliases = new ArrayList<TraitAliasObject>();
private Map<String, TraitPrecedenceObject> precedenceMap = new HashMap<String, TraitPrecedenceObject>();
- private Map<String, TraitAliasObject> aliasMap = new HashMap<String, TraitAliasObject>();
+ private Map<String, List<TraitAliasObject>> aliasMap = new HashMap<String, List<TraitAliasObject>>();
public List<String> getTraits() {
return traits;
@@ -25,7 +25,7 @@ public class UseTrait {
return traitAliases;
}
- public Map<String, TraitAliasObject> getAliasMap() {
+ public Map<String, List<TraitAliasObject>> getAliasMap() {
return aliasMap;
}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityChangeName.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityChangeName.pdtt
index 9423ffb..c660c35 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityChangeName.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityChangeName.pdtt
@@ -16,4 +16,5 @@ $o= new MyClass();
$o->|
?>
--EXPECT--
-method(say) \ No newline at end of file
+method(say)
+method(sayHello) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPro3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPro3.pdtt
index e79bba5..20944c2 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPro3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPro3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
+method(foo)
method(say)
-method(foo) \ No newline at end of file
+method(sayHello) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPub3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPub3.pdtt
index 1b697f1..aa24b4e 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPub3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPriToPub3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
+method(foo)
method(say)
-method(foo) \ No newline at end of file
+method(sayHello) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPri3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPri3.pdtt
index 33fe79b..610430a 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPri3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPri3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
-method(say)
-method(foo) \ No newline at end of file
+method(foo)
+method(sayHello)
+method(say) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPub3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPub3.pdtt
index 7f08af1..d94c16d 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPub3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityProToPub3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
+method(foo)
method(say)
-method(foo) \ No newline at end of file
+method(sayHello) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri3.pdtt
index b0cc9e9..48e0340 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
-method(say)
-method(foo) \ No newline at end of file
+method(foo)
+method(sayHello)
+method(say) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri4.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri4.pdtt
index 1aff699..aaf0c45 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri4.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPri4.pdtt
@@ -16,3 +16,4 @@ $o= new MyClass();
$o->|
?>
--EXPECT--
+method(sayHello)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro3.pdtt
index 509dfad..e736f1f 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro3.pdtt
@@ -17,5 +17,6 @@ class MyClass {
}
?>
--EXPECT--
-method(say)
-method(foo) \ No newline at end of file
+method(foo)
+method(sayHello)
+method(say) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro4.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro4.pdtt
index 4420829..ed96ff4 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro4.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitVisibilityPubToPro4.pdtt
@@ -16,3 +16,4 @@ $o= new MyClass();
$o->|
?>
--EXPECT--
+method(sayHello)