Repository: flex-falcon Updated Branches: refs/heads/develop b0963ce5d -> 44eaace85
Refactored JSTypeUtils. Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/44eaace8 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/44eaace8 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/44eaace8 Branch: refs/heads/develop Commit: 44eaace85753ab55190381439ff3187faef2fe12 Parents: b0963ce Author: Michael Schmalle <[email protected]> Authored: Fri Jun 26 08:45:31 2015 -0400 Committer: Michael Schmalle <[email protected]> Committed: Fri Jun 26 08:45:31 2015 -0400 ---------------------------------------------------------------------- .../externals/reference/ClassReference.java | 3 +- .../codegen/externals/utils/JSTypeUtils.java | 283 +++++++------------ 2 files changed, 104 insertions(+), 182 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/44eaace8/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 dd8e49e..692d759 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 @@ -693,8 +693,7 @@ public class ClassReference extends BaseReference private void emitSuperClass(StringBuilder sb) { sb.append("extends "); - String value = JSTypeUtils.toTypeJsType(getModel(), - getComment().getBaseType()).toString(); + String value = JSTypeUtils.toClassTypeString(this); sb.append(value); } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/44eaace8/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 be0154e..e351870 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 @@ -22,6 +22,7 @@ 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.ClassReference; import org.apache.flex.compiler.internal.codegen.externals.reference.ConstantReference; import org.apache.flex.compiler.internal.codegen.externals.reference.ReferenceModel; @@ -31,207 +32,81 @@ import com.google.javascript.rhino.jstype.UnionType; public class JSTypeUtils { - public static String toParamTypeString(BaseReference reference, - String paramName) + public static String toClassTypeString(ClassReference reference) { - String type = "Object"; - - JSTypeExpression paramType = reference.getComment().getParameterType( - paramName); - - if (paramType != null) - { - JSType jsType = JSTypeUtils.toParamJsType(reference.getModel(), - paramType); - //System.err.println(jsType); - - if (jsType != null) - { - type = jsType.toString(); - - if (jsType.isFunctionType()) - { - return "Function /* " + type + " */"; - } - else if (jsType.isRecordType()) - { - return "Object /* " + type + " */"; - } - else - { - if (type.indexOf("Array<") == 0) - { - return "Array"; - } - else if (type.indexOf("Object<") == 0) - { - return "Object"; - } - } - - } - else - { - return "Object"; // TemplateType - } - } - - type = transformParamType(type); - + String type = getJsType(reference.getModel(), + reference.getComment().getBaseType()).toString(); return type; } - private static JSType toParamJsType(ReferenceModel model, - JSTypeExpression typeExpression) + public static String toParamTypeString(BaseReference reference, + String paramName) { - JSType jsType = model.evaluate(typeExpression); - - if (jsType.isUnionType()) - { - UnionType ut = (UnionType) jsType; - JSType jsType2 = ut.restrictByNotNullOrUndefined(); - - //System.err.println(jsType2); - - if (!jsType2.isUnionType()) - jsType = jsType2; - } - - return jsType; - } + JSTypeExpression expression = reference.getComment().getParameterType( + paramName); + if (expression == null) + return "Object"; - public static String toConstantTypeString(ConstantReference reference) - { - JSTypeExpression typeExpression = reference.getComment().getType(); - JSType jsType = reference.getModel().evaluate(typeExpression); - String type = jsType.toString(); + String type = toTypeExpressionString(reference, expression); type = transformParamType(type); + return type; } public static String toReturnTypeString(BaseReference reference) { - String type = "void"; - - JSTypeExpression returnType = reference.getComment().getReturnType(); - if (returnType != null) - { - - JSType jsType = JSTypeUtils.toReturnJsType(reference.getModel(), - returnType); - //System.err.println(jsType); - - if (jsType != null) - { - if (jsType.isRecordType()) - return "Object"; - - type = jsType.toString(); - - if (type.indexOf("Array<") == 0) - { - return "Array"; - } - else if (type.indexOf("Object<") == 0) - { - return "Object"; - } - } - else - { - return "Object"; // TemplateType - } - } + JSTypeExpression expression = reference.getComment().getReturnType(); + if (expression == null) + return "void"; + String type = toTypeExpressionString(reference, expression); type = transformReturnType(type); return type; } - private static JSType toReturnJsType(ReferenceModel model, - JSTypeExpression typeExpression) + public static String toFieldString(BaseReference reference) { - JSType jsType = model.evaluate(typeExpression); - - if (jsType.isUnionType()) - { - UnionType ut = (UnionType) jsType; - JSType jsType2 = ut.restrictByNotNullOrUndefined(); + JSTypeExpression expression = reference.getComment().getType(); + if (expression == null) + return "Object"; - if (!jsType2.isUnionType()) - jsType = jsType2; - } + String type = toTypeExpressionString(reference, expression); + type = transformType(type); - return jsType; + return type; } - public static String toFieldString(BaseReference reference) + public static String toConstantTypeString(ConstantReference reference) { - String type = "Object"; - - JSTypeExpression ttype = reference.getComment().getType(); - - if (ttype != null) - { - JSType jsType = JSTypeUtils.toTypeJsType(reference.getModel(), - ttype); - //System.err.println(jsType); - - if (jsType != null) - { - if (jsType.isUnionType()) - { - UnionType ut = (UnionType) jsType; - JSType jsType2 = ut.restrictByNotNullOrUndefined(); - - if (!jsType2.isUnionType()) - jsType = jsType2; - } - - type = jsType.toString(); - - if (jsType.isFunctionType()) - { - return "Function /* " + type + " */"; - } - else - { - if (type.indexOf("Array<") == 0) - { - return "Array"; - } - else if (type.indexOf("Object<") == 0) - { - return "Object"; - } - } - } - else - { - return "Object"; // TemplateType - } - } + JSTypeExpression expression = reference.getComment().getType(); + if (expression == null) + return "Object"; + String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; } - public static JSType toTypeJsType(ReferenceModel model, - JSTypeExpression typeExpression) - { - JSType jsType = model.evaluate(typeExpression); + //-------------------------------------------------------------------------- - if (jsType.isUnionType()) - { - UnionType ut = (UnionType) jsType; - JSType jsType2 = ut.restrictByNotNullOrUndefined(); + // 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 (!jsType2.isUnionType()) - jsType = jsType2; - } + if (map.containsKey(type)) + return map.get(type); - return jsType; + return type; } // XXX These are NOT for returned types @@ -275,22 +150,70 @@ public class JSTypeUtils return type; } - // XXX shouldn't be public - public static String transformType(String type) + private static String toTypeExpressionString(BaseReference reference, + JSTypeExpression expression) { - 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 */"); + String type = null; - if (map.containsKey(type)) - return map.get(type); + if (expression != null) + { + JSType jsType = getJsType(reference.getModel(), expression); + + if (jsType != null) + { + type = one(jsType); + } + else + { + return "Object"; // TemplateType + } + } return type; } + private static String one(JSType jsType) + { + String type = jsType.toString(); + + if (jsType.isFunctionType()) + { + return "Function /* " + type + " */"; + } + else if (jsType.isRecordType()) + { + return "Object /* " + type + " */"; + } + else + { + if (type.indexOf("Array<") == 0) + { + return "Array"; + } + else if (type.indexOf("Object<") == 0) + { + return "Object"; + } + } + + return type; + } + + private static JSType getJsType(ReferenceModel model, + JSTypeExpression typeExpression) + { + JSType jsType = model.evaluate(typeExpression); + + if (jsType.isUnionType()) + { + UnionType ut = (UnionType) jsType; + JSType jsType2 = ut.restrictByNotNullOrUndefined(); + + if (!jsType2.isUnionType()) + jsType = jsType2; + } + + return jsType; + } + }
