Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Compagner2014-05-05 10:26:42 +0000
committerJohan Compagner2014-05-05 10:30:00 +0000
commit64540aae4a960775285a60a6951b5f3156f3ac2a (patch)
treed59bb66a2747f41abe2a929e0dac7243ac87a768
parent0221791a6e99e9d3af98ec70ebb40833d8df1cc9 (diff)
downloadorg.eclipse.dltk.javascript-64540aae4a960775285a60a6951b5f3156f3ac2a.tar.gz
org.eclipse.dltk.javascript-64540aae4a960775285a60a6951b5f3156f3ac2a.tar.xz
org.eclipse.dltk.javascript-64540aae4a960775285a60a6951b5f3156f3ac2a.zip
// if it still didn't match then the argument is maybe of union type and
matches 1 of the methods at runtime (but not a specific one at design time). just make 1 method of the matched methods. skip for now the constructors
-rw-r--r--plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java
index 8a4321b0..298b81e8 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/JavaScriptValidations.java
@@ -12,6 +12,8 @@
package org.eclipse.dltk.internal.javascript.validation;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -31,10 +33,13 @@ import org.eclipse.dltk.javascript.parser.JSProblemReporter;
import org.eclipse.dltk.javascript.parser.JavaScriptParser;
import org.eclipse.dltk.javascript.parser.Reporter;
import org.eclipse.dltk.javascript.typeinference.IValueReference;
+import org.eclipse.dltk.javascript.typeinfo.IRConstructor;
import org.eclipse.dltk.javascript.typeinfo.IRMethod;
import org.eclipse.dltk.javascript.typeinfo.IRParameter;
import org.eclipse.dltk.javascript.typeinfo.IRType;
import org.eclipse.dltk.javascript.typeinfo.JSTypeSet;
+import org.eclipse.dltk.javascript.typeinfo.RModelBuilder;
+import org.eclipse.dltk.javascript.typeinfo.RTypes;
import org.eclipse.dltk.javascript.typeinfo.TypeCompatibility;
import org.eclipse.dltk.javascript.typeinfo.model.ParameterKind;
import org.eclipse.osgi.util.NLS;
@@ -111,6 +116,7 @@ public class JavaScriptValidations {
* @param arguments
* @return
*/
+ @SuppressWarnings("unchecked")
public static <METHOD extends IRMethod> METHOD selectMethod(
List<METHOD> methods, IValueReference[] arguments, boolean fallback) {
if (methods.size() == 1) {
@@ -126,8 +132,9 @@ public class JavaScriptValidations {
}
}
if (matches != null) {
+ METHOD firstMatch = matches.get(0);
if (matches.size() == 1) {
- return matches.get(0);
+ return firstMatch;
}
OUTER: for (METHOD method : matches) {
final List<IRParameter> parameters = method.getParameters();
@@ -144,6 +151,32 @@ public class JavaScriptValidations {
}
return method;
}
+ // if it still didn't match then the argument is maybe of union type
+ // and matches 1 of the methods at runtime (but not a specific one
+ // at design time). just make 1 method of the matched methods.
+ if (!(firstMatch instanceof IRConstructor)) {
+ Collection<IRType>[] paramType = new Collection[firstMatch
+ .getParameterCount()];
+ for (METHOD method : matches) {
+ List<IRParameter> parameters = method.getParameters();
+ for (int i = 0; i < Math.min(arguments.length,
+ parameters.size()); i++) {
+ if (paramType[i] == null)
+ paramType[i] = new ArrayList<IRType>();
+ paramType[i].add(parameters.get(i).getType());
+ }
+ }
+ List<IRParameter> parameters = firstMatch.getParameters();
+ IRParameter[] params = new IRParameter[paramType.length];
+ for (int i = 0; i < parameters.size(); i++) {
+ IRParameter param = parameters.get(i);
+ params[i] = RModelBuilder.createParameter(param.getName(),
+ RTypes.union(paramType[i]), param.getKind());
+ }
+ return (METHOD) RModelBuilder.method(firstMatch.getName(),
+ firstMatch.getType(), Arrays.asList(params),
+ firstMatch.getVisibility(), firstMatch.getSource());
+ }
}
return fallback ? methods.get(0) : null;
}

Back to the top