You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ms...@apache.org on 2015/06/26 14:05:37 UTC
git commit: [flex-falcon] [refs/heads/develop] - Fixed @template var
arg bug.
Repository: flex-falcon
Updated Branches:
refs/heads/develop b32643380 -> b0963ce5d
Fixed @template var arg bug.
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/b0963ce5
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/b0963ce5
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/b0963ce5
Branch: refs/heads/develop
Commit: b0963ce5d81db7d495825178d6ea587ebef20272
Parents: b326433
Author: Michael Schmalle <ms...@apache.org>
Authored: Fri Jun 26 08:05:19 2015 -0400
Committer: Michael Schmalle <ms...@apache.org>
Committed: Fri Jun 26 08:05:19 2015 -0400
----------------------------------------------------------------------
.../codegen/externals/TestConstructor.java | 2 +-
.../codegen/externals/TestExternES3.java | 21 +
.../externals/reference/ClassReference.java | 4 +-
.../externals/reference/FunctionReference.java | 2 +-
.../externals/reference/MethodReference.java | 11 +-
.../codegen/externals/utils/FunctionUtils.java | 104 ++---
.../codegen/externals/utils/JSTypeUtils.java | 70 ++-
.../codegen/externals/utils/TypeUtils.java | 421 -------------------
8 files changed, 140 insertions(+), 495 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
index 8b95585..e2c7001 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestConstructor.java
@@ -107,7 +107,7 @@ public class TestConstructor extends ExternalsTestBase
+ "that is wrapped by another line in the comment.\n * @param var_args "
+ "[*] A var agr param.\n * @see http://foo.bar.com \n * @see "
+ "[constructor_params]\n * @returns {(FooVarArgs|null)} Another instance.\n"
- + " */\n public function FooOptVarArgs(arg1:Number, opt_arg2:* = null, ...rest) "
+ + " */\n public function FooOptVarArgs(arg1:Number, opt_arg2:* = null, ...var_args) "
+ "{\n super();\n }\n", string);
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
index 5dee9b5..937b38b 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/externals/TestExternES3.java
@@ -20,11 +20,14 @@
package org.apache.flex.compiler.internal.codegen.externals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.apache.flex.compiler.clients.ExternCConfiguration;
+import org.apache.flex.compiler.internal.codegen.externals.reference.ClassReference;
+import org.apache.flex.compiler.internal.codegen.externals.reference.MethodReference;
import org.junit.Test;
import com.google.javascript.jscomp.Result;
@@ -63,6 +66,24 @@ public class TestExternES3 extends ExternalsTestBase
}
}
+ @Test
+ public void test_Array() throws IOException
+ {
+ Result result = compile();
+ assertTrue(result.success);
+
+ ClassReference Array = model.getClassReference("Array");
+ assertNotNull(Array);
+
+ MethodReference constructor = Array.getConstructor();
+ StringBuilder sb = new StringBuilder();
+ constructor.emitCode(sb);
+ String emit = sb.toString();
+ assertEquals(
+ " public function Array(...var_args):Object { return null; }\n",
+ emit);
+ }
+
@Override
protected void configure(ExternCConfiguration config) throws IOException
{
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
index 696b2d0..dd8e49e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/ClassReference.java
@@ -29,7 +29,6 @@ import java.util.Map.Entry;
import org.apache.flex.compiler.internal.codegen.externals.utils.DebugLogUtils;
import org.apache.flex.compiler.internal.codegen.externals.utils.JSTypeUtils;
-import org.apache.flex.compiler.internal.codegen.externals.utils.TypeUtils;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSDocInfoBuilder;
@@ -160,7 +159,8 @@ public class ClassReference extends BaseReference
*/
JSTypeExpression enumParameterType = comment.getEnumParameterType();
- String overrideStringType = TypeUtils.transformType(getModel().evaluate(
+ // XXX Fix this, encapulate toType()
+ String overrideStringType = JSTypeUtils.transformType(getModel().evaluate(
enumParameterType).toAnnotationString());
Node objLit = null;
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
index 01c3c9e..83ad795 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/FunctionReference.java
@@ -125,7 +125,7 @@ public class FunctionReference extends BaseReference
private String transformReturnString()
{
- return FunctionUtils.transformReturnString(getContext(), getComment());
+ return FunctionUtils.toReturnString(getContext(), getComment());
}
private String toPrameterString()
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
index fa5dda2..7f88ffe 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/reference/MethodReference.java
@@ -102,6 +102,13 @@ public class MethodReference extends MemberReference
excluded.print(sb);
}
+ emitCode(sb);
+
+ override = null;
+ }
+
+ public void emitCode(StringBuilder sb)
+ {
String staticValue = (isStatic) ? "static " : "";
if (getClassReference().isInterface())
staticValue = "";
@@ -144,8 +151,6 @@ public class MethodReference extends MemberReference
sb.append(transformReturnString());
sb.append(braces);
sb.append("\n");
-
- override = null;
}
private void emitConstructor(StringBuilder sb)
@@ -202,7 +207,7 @@ public class MethodReference extends MemberReference
private String transformReturnString()
{
- return FunctionUtils.transformReturnString(getContext(),
+ return FunctionUtils.toReturnString(getContext(),
getContext().getComment());
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
index 95b27f0..8c2d99a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/FunctionUtils.java
@@ -21,53 +21,54 @@ package org.apache.flex.compiler.internal.codegen.externals.utils;
import org.apache.flex.compiler.internal.codegen.externals.reference.BaseReference;
-import com.google.common.collect.ImmutableList;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSTypeExpression;
import com.google.javascript.rhino.Node;
public class FunctionUtils
{
- public static String transformReturnString(BaseReference reference,
+ public static String toReturnString(BaseReference reference,
JSDocInfo comment)
{
- StringBuilder sb = new StringBuilder();
- ImmutableList<String> names = comment.getTemplateTypeNames();
- if (names.size() > 0)
+ final StringBuilder sb = new StringBuilder();
+
+ String returnType = null;
+
+ if (hasTemplate(reference))
{
- sb.append("Object");
+ returnType = "Object";
}
else
{
- String type = JSTypeUtils.toReturnTypeString(reference);
- if (type.indexOf("|") != -1 || type.indexOf('?') != -1)
- type = "*";
-
- if (type.indexOf("|") != -1)
- type = "Object /* TODO " + type + "*/";
-
- sb.append(type);
- return sb.toString();
+ returnType = JSTypeUtils.toReturnTypeString(reference);
+ // if (returnType.indexOf("|") != -1 || returnType.indexOf('?') != -1)
+ // returnType = "*";
+ //
+ // if (returnType.indexOf("|") != -1)
+ // returnType = "Object /* TODO " + returnType + "*/";
}
+ sb.append(returnType);
+
return sb.toString();
}
public static String toPrameterString(BaseReference reference,
JSDocInfo comment, Node paramNode)
{
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
+
sb.append("(");
if (paramNode != null)
{
int index = 0;
int len = comment.getParameterCount();
- //int childCount = paramNode.getChildCount();
if (len == 0)
{
+ // Missing JSDocInf @param tags, so instead of using the @param tags
+ // we use the actual Node list from the AST
len = paramNode.getChildCount();
- // Missing JSDocInf @param tags
if (len > 0)
{
for (Node param : paramNode.children())
@@ -79,20 +80,6 @@ public class FunctionUtils
}
}
}
- // else if (len != childCount)
- // {
- // // XXX Match up existing @param tags with parameters
- // if (childCount > 0)
- // {
- // for (Node param : paramNode.children())
- // {
- // sb.append(param.getString() + ":Object");
- // if (index < childCount - 1)
- // sb.append(", ");
- // index++;
- // }
- // }
- // }
else
{
for (String paramName : comment.getParameterNames())
@@ -102,6 +89,7 @@ public class FunctionUtils
if (index < len - 1)
sb.append(", ");
+
index++;
}
}
@@ -112,51 +100,36 @@ public class FunctionUtils
return sb.toString();
}
- public static String toParameter(BaseReference reference,
+ private static String toParameter(BaseReference reference,
JSDocInfo comment, String paramName, JSTypeExpression parameterType)
{
- StringBuilder sb = new StringBuilder();
-
- if (parameterType == null)
- {
- sb.append(paramName);
- sb.append(":");
- sb.append("Object /* TODO is this correct? */");
- return sb.toString();
- }
+ final StringBuilder sb = new StringBuilder();
- //JSTypeExpression parameterType = comment.getParameterType(paramName);
+ String paramType = null;
- ImmutableList<String> names = comment.getTemplateTypeNames();
- if (names.size() > 0)
+ if (parameterType.isVarArgs())
{
- sb.append(paramName);
- sb.append(":");
- sb.append("Object");
+ sb.append("..." + paramName);
}
else
{
- if (parameterType.isVarArgs())
+ if (hasTemplate(reference))
{
- sb.append("...rest");
+ paramType = "Object";
}
else
{
- String paramType = JSTypeUtils.toParamTypeString(reference,
- paramName);
-
- sb.append(paramName);
- sb.append(":");
- sb.append(paramType);
+ paramType = JSTypeUtils.toParamTypeString(reference, paramName);
+ }
- if (paramType.indexOf("|") != -1)
- paramType = "Object /* TODO " + paramType + "*/";
+ sb.append(paramName);
+ sb.append(":");
+ sb.append(paramType);
- if (parameterType.isOptionalArg())
- {
- sb.append(" = ");
- sb.append(toDefaultParameterValue(paramType));
- }
+ if (parameterType.isOptionalArg())
+ {
+ sb.append(" = ");
+ sb.append(toDefaultParameterValue(paramType));
}
}
@@ -176,4 +149,9 @@ public class FunctionUtils
return "null";
}
+ private static boolean hasTemplate(BaseReference reference)
+ {
+ return reference.getComment().getTemplateTypeNames().size() > 0;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
index 70ee50d..be0154e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/JSTypeUtils.java
@@ -19,6 +19,8 @@
package org.apache.flex.compiler.internal.codegen.externals.utils;
+import java.util.HashMap;
+
import org.apache.flex.compiler.internal.codegen.externals.reference.BaseReference;
import org.apache.flex.compiler.internal.codegen.externals.reference.ConstantReference;
import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel;
@@ -74,7 +76,7 @@ public class JSTypeUtils
}
}
- type = TypeUtils.transformParamType(type);
+ type = transformParamType(type);
return type;
}
@@ -103,7 +105,7 @@ public class JSTypeUtils
JSTypeExpression typeExpression = reference.getComment().getType();
JSType jsType = reference.getModel().evaluate(typeExpression);
String type = jsType.toString();
- type = TypeUtils.transformParamType(type);
+ type = transformParamType(type);
return type;
}
@@ -141,7 +143,7 @@ public class JSTypeUtils
}
}
- type = TypeUtils.transformReturnType(type);
+ type = transformReturnType(type);
return type;
}
@@ -210,7 +212,7 @@ public class JSTypeUtils
}
}
- type = TypeUtils.transformType(type);
+ type = transformType(type);
return type;
}
@@ -231,4 +233,64 @@ public class JSTypeUtils
return jsType;
}
+
+ // XXX These are NOT for returned types
+ private static String transformParamType(String type)
+ {
+ if (type.indexOf("|") != -1)
+ return "Object";
+
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put("?", "Object /* ? */");
+ map.put("*", "*");
+ map.put("string", "String");
+ map.put("number", "Number");
+ map.put("boolean", "Boolean");
+ map.put("undefined", "Object /* undefined */");
+ map.put("null", "Object /* null */");
+
+ if (map.containsKey(type))
+ return map.get(type);
+
+ return type;
+ }
+
+ private static String transformReturnType(String type)
+ {
+ if (type.indexOf("|") != -1)
+ return "Object";
+
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put("?", "Object /* ? */");
+ map.put("*", "*");
+ map.put("string", "String");
+ map.put("number", "Number");
+ map.put("boolean", "Boolean");
+ map.put("undefined", "Object /* undefined */");
+ map.put("null", "void /* null */");
+
+ if (map.containsKey(type))
+ return map.get(type);
+
+ return type;
+ }
+
+ // XXX shouldn't be public
+ public static String transformType(String type)
+ {
+ HashMap<String, String> map = new HashMap<String, String>();
+ map.put("?", "Object /* ? */");
+ map.put("*", "*");
+ map.put("string", "String");
+ map.put("number", "Number");
+ map.put("boolean", "Boolean");
+ map.put("undefined", "Object /* undefined */");
+ map.put("null", "Object /* null */");
+
+ if (map.containsKey(type))
+ return map.get(type);
+
+ return type;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b0963ce5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/TypeUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/TypeUtils.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/TypeUtils.java
deleted file mode 100644
index 2e7aa20..0000000
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/externals/utils/TypeUtils.java
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.flex.compiler.internal.codegen.externals.utils;
-
-import java.util.HashMap;
-
-import com.google.javascript.jscomp.parsing.Config.LanguageMode;
-import com.google.javascript.rhino.ErrorReporter;
-
-public final class TypeUtils
-{
-
- @SuppressWarnings("unused")
- private static boolean isIdeMode = true;
- @SuppressWarnings("unused")
- private static LanguageMode mode = LanguageMode.ECMASCRIPT5;
-
- // private static Node parseWarning(String string, String... warnings)
- // {
- // TestErrorReporter testErrorReporter = new TestErrorReporter(null,
- // warnings);
- // StaticSourceFile file = new SimpleSourceFile("input", false);
- // Node script = ParserRunner.parse(file, string,
- // ParserRunner.createConfig(isIdeMode, mode, false, null),
- // testErrorReporter).ast;
- //
- // // verifying that all warnings were seen
- // testErrorReporter.assertHasEncounteredAllErrors();
- // testErrorReporter.assertHasEncounteredAllWarnings();
- // //
- // // JSDocInfo j = script.getChildAtIndex(0).getJSDocInfo();
- // // JSTypeExpression baseType = j.getType();
- // // boolean functionDeclaration = j.containsFunctionDeclaration();
- // //
- // // String stringTree = script.toStringTree();
- //
- // return script;
- // }
-
- // public static String getType(String value)
- // {
- //
- // String type = getTypeRaw(value);
- //
- // String comment = "/** @type " + type + " */ var foo;";
- //
- // Node node = parseWarning(comment);
- // JSDocInfo j = node.getChildAtIndex(0).getJSDocInfo();
- // JSTypeExpression baseType = j.getType();
- // boolean functionDeclaration = j.containsFunctionDeclaration();
- // boolean varArgs = baseType.isVarArgs();
- // boolean optionalArg = baseType.isOptionalArg();
- //
- // // XXX Warnings
- // if (type == null)
- // return "Object";
- // if (type.indexOf("{?function (") != -1
- // || type.equals("{?function (Event)}")
- // || type.equals("{?function (Event=)}"))
- // return "Function";
- //
- // int start = -1;
- // int end = -1;
- //
- // // XXX {?function(this:S, T, number, !Array.<T>): ?} callback
- // if (type.indexOf("<") != -1 && type.indexOf(">") != -1)
- // return "Object";
- //
- // // {*} [The ALL type]
- // start = type.indexOf("{*}");
- // if (start != -1)
- // {
- // return "*";
- // }
- //
- // // {?} [The UNKNOWN type]
- // start = type.indexOf("{?}");
- // if (start != -1)
- // {
- // return "Object /* ? */";
- // }
- //
- // // {Array<string>}
- // start = type.indexOf("{Array<");
- // if (start != -1)
- // {
- // end = type.indexOf(">}", start);
- // String innerType = type.substring(start + 7, end);
- // innerType = transformParamType(innerType);
- // return "Vector.<" + innerType + ">";
- // }
- //
- // // {Object<string, number>}
- // start = type.indexOf("{Object<");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String orignal = type.substring(1, end);
- // return "Object" + " /* " + orignal + " */";
- // }
- //
- // // @param {...number} var_args [Variable parameters (in @param annotations) ]
- // start = type.indexOf("{...");
- // if (start != -1)
- // {
- // // Function /* (string, boolean) */
- // end = type.indexOf("}", start);
- // //String orignal = type.substring(start + 12, end).trim();
- // return "...rest";// + " /* " + orignal + " */";
- // }
- //
- // // XXX ADDD
- // // ?=}
- // end = type.indexOf("?=}");
- // if (end != -1)
- // {
- // start = type.indexOf("{");
- // String innerType = type.substring(start + 1, end);
- // String asType = transformParamType(innerType);
- // return asType + " = " + transformOptionNull(asType);
- // }
- //
- // // @param {number=} opt_argument [Optional parameter in a @param annotation ]
- // end = type.indexOf("=}");
- // if (end != -1)
- // {
- // start = type.indexOf("{");
- // //end = type.indexOf("}", start);
- // String innerType = type.substring(start + 1, end);
- // String asType = transformParamType(innerType);
- // return asType + " = " + transformOptionNull(asType);
- // }
- //
- // // {{myNum: number, myObject}}
- // start = type.indexOf("{{");
- // if (start != -1)
- // {
- // return "Object";
- // }
- //
- // // XXX ADDED {?string=}
- // start = type.indexOf("{?");
- // if (start != -1 && type.indexOf("=}") != -1)
- // {
- // end = type.indexOf("?}", start);
- // String innerType = type.substring(start + 2, end);
- // return transformParamType(innerType);
- // }
- //
- // // {?number} or {?null}
- // start = type.indexOf("{?");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String innerType = type.substring(start + 2, end);
- // return transformParamType(innerType);
- // }
- //
- // // {!Object}
- // start = type.indexOf("{!");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String innerType = type.substring(start + 2, end);
- // return transformParamType(innerType);
- // }
- //
- // // {function(): number} [return type]
- // start = type.indexOf("{function():");
- // if (start != -1)
- // {
- // // Function /* (string, boolean) */
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 12, end).trim();
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // {function(this:goog.ui.Menu, string)} [Function this Type]
- // start = type.indexOf("{function(this:");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 9, end).trim();
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // {function(new:goog.ui.Menu, string)} [Function new Type]
- // start = type.indexOf("{function(new:");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 9, end).trim();
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // {function(string, ...number): number} [Variable parameters]
- // start = type.indexOf("{function(");
- // if (start != -1 && type.indexOf("...") != -1)
- // {
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 9, end).trim();
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // {function(?string=, number=)} [Optional argument in a function type]
- // start = type.indexOf("{function(?");
- // if (start != -1)
- // {
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 9, end).trim();
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // {function(string, boolean)} [function type]
- // start = type.indexOf("{function(");
- // if (start != -1)
- // {
- // // Function /* (string, boolean) */
- // end = type.indexOf("}", start);
- // String orignal = type.substring(start + 9, end);
- // return "Function" + " /* " + orignal + " */";
- // }
- //
- // // XXX multiple functions
- // start = type.indexOf("{(function");
- // if (start != -1)
- // {
- // return "Object";
- // }
- //
- // // {(, {(foo|bar)}
- // start = type.indexOf("{(");
- // if (start != -1)
- // {
- // end = type.indexOf(")}", start);
- // String orignal = type.substring(1, end + 1);
- // return "Object" + " /* " + orignal + " */";
- // }
- //
- // // {boolean}
- // return transformParamType(type.substring(1, type.length() - 1));
- // }
-
- @SuppressWarnings("unused")
- private static String transformOptionNull(String asType)
- {
- if (asType.indexOf("|") != -1)
- return "*";
-
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("*", "null");
- map.put("String", "null");
- map.put("Number", "null");
- map.put("Boolean", "null");
- map.put("Object", "null");
- map.put("Function", "null");
-
- if (map.containsKey(asType))
- return map.get(asType);
-
- return asType;
- }
-
- public static String transformReturnType(String type)
- {
- if (type.indexOf("|") != -1)
- return "Object";
-
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("*", "*");
- map.put("string", "String");
- map.put("number", "Number");
- map.put("boolean", "Boolean");
- map.put("undefined", "Object /* undefined */");
- map.put("null", "void /* null */");
-
- if (map.containsKey(type))
- return map.get(type);
-
- return type;
- }
-
- // XXX These are NOT for returned types
- public static String transformParamType(String type)
- {
- if (type.indexOf("|") != -1)
- return "Object";
-
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("?", "Object /* ? */");
- map.put("*", "*");
- map.put("string", "String");
- map.put("number", "Number");
- map.put("boolean", "Boolean");
- map.put("undefined", "Object /* undefined */");
- map.put("null", "Object /* null */");
-
- if (map.containsKey(type))
- return map.get(type);
-
- return type;
- }
-
- public static String transformType(String type)
- {
- HashMap<String, String> map = new HashMap<String, String>();
- map.put("?", "Object /* ? */");
- map.put("*", "*");
- map.put("string", "String");
- map.put("number", "Number");
- map.put("boolean", "Boolean");
- map.put("undefined", "Object /* undefined */");
- map.put("null", "Object /* null */");
-
- if (map.containsKey(type))
- return map.get(type);
-
- return type;
- }
-
- public final static class TestErrorReporter implements ErrorReporter
- {
- private String[] errors;
- private String[] warnings;
- private int errorsIndex = 0;
- private int warningsIndex = 0;
-
- public TestErrorReporter(String[] errors, String[] warnings)
- {
- this.errors = errors;
- this.warnings = warnings;
- }
-
- public static TestErrorReporter forNoExpectedReports()
- {
- return new TestErrorReporter(null, null);
- }
-
- public void setErrors(String[] errors)
- {
- this.errors = errors;
- errorsIndex = 0;
- }
-
- public void setWarnings(String[] warnings)
- {
- this.warnings = warnings;
- warningsIndex = 0;
- }
-
- @Override
- public void error(String message, String sourceName, int line,
- int lineOffset)
- {
- if (errors != null && errorsIndex < errors.length)
- {
- //assertThat(message).isEqualTo(errors[errorsIndex++]);
- }
- else
- {
- //Assert.fail("extra error: " + message);
- }
- }
-
- @Override
- public void warning(String message, String sourceName, int line,
- int lineOffset)
- {
- if (warnings != null && warningsIndex < warnings.length)
- {
- //assertThat(message).isEqualTo(warnings[warningsIndex++]);
- }
- else
- {
- //Assert.fail("extra warning: " + message);
- }
- }
-
- public void assertHasEncounteredAllWarnings()
- {
- if (warnings == null)
- {
- //assertThat(warningsIndex).isEqualTo(0);
- }
- else
- {
- //assertThat(warnings).hasLength(warningsIndex);
- }
- }
-
- public void assertHasEncounteredAllErrors()
- {
- if (errors == null)
- {
- //assertThat(errorsIndex).isEqualTo(0);
- }
- else
- {
- //assertThat(errors).hasLength(errorsIndex);
- }
- }
-
- }
-}