diff --git a/src/intellij_plugin/ohosgen/src/main/java/antlr/typescript/TypeScriptCustomListener.java b/src/intellij_plugin/ohosgen/src/main/java/antlr/typescript/TypeScriptCustomListener.java index 2e9ba4867d362837766fa14bdf90d7d3361bbfdb..a9c2d2bd05b634f028e7b3cda722e61d1317d370 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/antlr/typescript/TypeScriptCustomListener.java +++ b/src/intellij_plugin/ohosgen/src/main/java/antlr/typescript/TypeScriptCustomListener.java @@ -294,6 +294,41 @@ public class TypeScriptCustomListener extends TypeScriptParserBaseListener imple System.out.println("enterVariableStatement: " + ctx.getText()); } + @Override + public void enterFormalParameterList(TypeScriptParser.FormalParameterListContext ctx) { + super.enterFormalParameterList(ctx); + System.out.println("enterParameterList: " + ctx.getText()); + if (this.currentObject instanceof FuncObj fo) { + if (!fo.getParamList().isEmpty()) { + return; + } + TypeScriptParser.FormalParameterListContext fpl = ctx.formalParameterList(); + List fpacl = ctx.formalParameterArg(); + for (TypeScriptParser.FormalParameterArgContext fpac : fpacl) { + String name = fpac.assignable().getText(); + String type = fpac.typeAnnotation().type_().getText(); + ParamObj po = new ParamObj(); + po.setName(name); + po.setType(type); + fo.addParam(po); + } + } + } + + @Override + public void enterParameterList(TypeScriptParser.ParameterListContext ctx) { + super.enterParameterList(ctx); + System.out.println("enterParameterList: " + ctx.getText()); + if (this.currentObject instanceof FuncObj fo) { + List pcl = ctx.parameter(); + int cnt = pcl.size(); + for (int i = 0; i < cnt; i++) { + TypeScriptParser.ParameterContext pcItem = pcl.get(i); + + } + } + } + @Override public void enterVariableDeclaration(TypeScriptParser.VariableDeclarationContext ctx) { String varName = ctx.identifierOrKeyWord().getText(); @@ -303,24 +338,8 @@ public class TypeScriptCustomListener extends TypeScriptParserBaseListener imple System.out.println("type : " + typeAnno); if (varName.equals(TsToken.TS_TOKEN_TYPE)) { TypeObj to = new TypeObj(); - List secList = ctx.singleExpression(); - for (TypeScriptParser.SingleExpressionContext sec : secList) { - String value = sec.getText(); - System.out.println("single : " + value); - int cnt = sec.getChildCount(); - System.out.println("single child cnt: " + cnt); - if (cnt == 3) { - ParseTree pt = sec.getChild(0); - to.setName(pt.getText()); - - ParseTree pt2 = sec.getChild(2); - to.addTypeValue(pt2.getText()); - } - for (int i = 0; i < cnt; i++) { - ParseTree pt = sec.getChild(i); - System.out.println("single child pt: " + pt.getText()); - } - } + setVariableType(ctx, to); + this.typeObjList.add(to); System.out.println("type: " + to.toJsonString()); @@ -330,9 +349,10 @@ public class TypeScriptCustomListener extends TypeScriptParserBaseListener imple ParseTree item = ctx.children.get(i); System.out.println("item: " + item.getText()); } - } - + } else if (ctx.singleExpression() != null) { + setVariableSingleExpression(ctx, varName); + } System.out.println("------------------------------"); } @@ -443,21 +463,14 @@ public class TypeScriptCustomListener extends TypeScriptParserBaseListener imple String callSign = ctx.callSignature().getText(); System.out.println("Function callSign: " + callSign); - String typeAnno = ctx.callSignature().typeAnnotation().stop.getText(); + String typeAnno = getFuncType(ctx); System.out.println("Function typeAnno: " + typeAnno); + FuncObj fo = new FuncObj(); fo.setName(funcName); fo.setRetValue(typeAnno); if (ctx.callSignature().parameterList() != null) { - List plc = ctx.callSignature().parameterList().parameter(); - for (TypeScriptParser.ParameterContext pc : plc) { - System.out.println("Function param: " + pc.getText()); - TypeScriptParser. RequiredParameterContext rpc = pc.requiredParameter(); - String type = rpc.typeAnnotation().stop.getText(); - String name = rpc.identifierOrPattern().getText(); - System.out.println("Function type: " + type + " name: " + name); - fo.addParam(name, type); - } + setFuncParam(ctx, fo); } System.out.println("--------------------" + fo.toJsonString()); this.funcObjList.add(fo); @@ -897,6 +910,126 @@ public class TypeScriptCustomListener extends TypeScriptParserBaseListener imple return false; } + private String checkFuncType(TypeScriptParser.Type_Context tc) { + int typeCnt = tc.unionOrIntersectionOrPrimaryType().getChildCount(); + for (int j = 0; j < typeCnt; j++) { + int rotCnt = tc.unionOrIntersectionOrPrimaryType().getChild(j).getChildCount(); + for (int k = 0; k < rotCnt; k++) { + String typeStr = tc.unionOrIntersectionOrPrimaryType().getChild(j).getChild(k).getText(); + if (typeStr.equals(TsToken.TS_TOKEN_IS)) { + return TsToken.TS_TOKEN_BOOLEAN; + } + } + } + return tc.getText(); + } + + private String getFuncType(TypeScriptParser.FunctionDeclarationContext ctx) { + String typeAnno = TsToken.TS_TOKEN_VOID; + if (ctx.callSignature().typeAnnotation() != null) { + TypeScriptParser.Type_Context tc = ctx.callSignature().typeAnnotation().type_(); + typeAnno = checkFuncType(tc); + } + return typeAnno; + } + + private void setVariableType(TypeScriptParser.VariableDeclarationContext ctx, TypeObj to) { + List secList = ctx.singleExpression(); + for (TypeScriptParser.SingleExpressionContext sec : secList) { + String value = sec.getText(); + System.out.println("single : " + value); + int cnt = sec.getChildCount(); + System.out.println("single child cnt: " + cnt); + if (cnt == 3) { + ParseTree pt = sec.getChild(0); + to.setName(pt.getText()); + + ParseTree pt2 = sec.getChild(2); + to.addTypeValue(pt2.getText()); + } + for (int i = 0; i < cnt; i++) { + ParseTree pt = sec.getChild(i); + System.out.println("single child pt: " + pt.getText()); + } + } + } + + private void setFuncExpressionParam(TypeScriptParser.ArrowFunctionDeclarationContext afdc, FuncObj fo) { + if (afdc.arrowFunctionParameters().formalParameterList() != null) { + List fpacl = + afdc.arrowFunctionParameters().formalParameterList().formalParameterArg(); + + for (TypeScriptParser.FormalParameterArgContext fpac : fpacl) { + String name = fpac.assignable().getText(); + String type = fpac.typeAnnotation().type_().getText(); + fo.addParam(name, type); + System.out.println("addparam: " + fo.toJsonString()); + } + } + } + + private void setVariableSingleExpression(TypeScriptParser.VariableDeclarationContext ctx, String varName) { + List sel = ctx.singleExpression(); + for (TypeScriptParser.SingleExpressionContext sec : sel) { + String varType = sec.start.getText(); + if (varType.equals(TsToken.TS_TOKEN_FUNCTION)) { + this.currentIdentifier = varName; + FuncObj fo = new FuncObj(); + fo.setAlias(varName); + this.currentObject = fo; + this.funcObjList.add(fo); + break; + } else if ((sec instanceof TypeScriptParser.FunctionExpressionContext fec) && + fec.anonymousFunction() != null) { + TypeScriptParser.AnonymousFunctionContext afc = fec.anonymousFunction(); + TypeScriptParser.ArrowFunctionDeclarationContext afdc = afc.arrowFunctionDeclaration(); + FuncObj fo = new FuncObj(); + fo.setAlias(varName); + this.currentObject = fo; + this.funcObjList.add(fo); + setFuncExpressionParam(afdc, fo); + } else if (sec instanceof TypeScriptParser.ParenthesizedExpressionContext pec) { + FuncObj fo = new FuncObj(); + fo.setAlias(varName); + this.currentObject = fo; + this.funcObjList.add(fo); + List secl = pec.expressionSequence().singleExpression(); + + for (TypeScriptParser.SingleExpressionContext secItem : secl) { + String name = secItem.getText(); + fo.addParam(name, ""); + } + } + } + } + + private void setFuncParam(TypeScriptParser.FunctionDeclarationContext ctx, FuncObj fo) { + TypeScriptParser.ParameterListContext plc = ctx.callSignature().parameterList(); + List plcl = plc.parameter(); + for (TypeScriptParser.ParameterContext pc : plcl) { + System.out.println("Function param: " + pc.getText()); + TypeScriptParser.OptionalParameterContext opc = pc.optionalParameter(); + if (opc != null) { + String type = opc.typeAnnotation().type_().getText(); + String name = opc.identifierOrPattern().getText(); + System.out.println("OptionalParameter type: " + type + " name: " + name); + fo.addParam(name, type, TsToken.TS_TOKEN_OPTIONAL); + } + TypeScriptParser.RequiredParameterContext rpc = pc.requiredParameter(); + if (rpc != null) { + String type = rpc.typeAnnotation().type_().getText(); + String name = rpc.identifierOrPattern().getText(); + System.out.println("RequiredParameter type: " + type + " name: " + name); + fo.addParam(name, type, TsToken.TS_TOKEN_REQUIRED); + } + } + if (plc.restParameter() != null) { + String name = plc.restParameter().singleExpression().getText(); + String type = plc.restParameter().typeAnnotation().type_().getText(); + fo.addParam(name, type, TsToken.TS_TOKEN_REST_PARAM); + } + } + private void setFuncAccessor(TypeScriptParser.GetterSetterDeclarationExpressionContext gsdec) { if (gsdec.getAccessor() != null && gsdec.getAccessor().getter() != null) { String type = gsdec.getAccessor().getter().identifier().getText(); diff --git a/src/intellij_plugin/ohosgen/src/main/java/grammar/FuncObj.java b/src/intellij_plugin/ohosgen/src/main/java/grammar/FuncObj.java index e5af7f8adce0d6e7f1e2534d6cf01b342b0f4f0b..3df6dc52df82b2961d36ddabd5a484cdf32b3682 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/grammar/FuncObj.java +++ b/src/intellij_plugin/ohosgen/src/main/java/grammar/FuncObj.java @@ -30,10 +30,34 @@ import java.util.concurrent.CopyOnWriteArrayList; * @since 2025-02-28 */ public class FuncObj extends GBaseObject { + /** + * 访问方式: public, protected, private + */ private String accessor; + + /** + * 访问类型:async,get,set + */ private String type; + + /** + * 方法名称 + */ private String name; + + /** + * 方法别名:可以是函数指针 + */ + private String alias; + + /** + * 方法返回值 + */ private String retValue; + + /** + * 方法参数 + */ private List paramList; /** @@ -41,7 +65,9 @@ public class FuncObj extends GBaseObject { */ public FuncObj() { this.token = TsToken.TS_TOKEN_FUNCTION; - + this.accessor = TsToken.TS_TOKEN_PUBLIC; + this.type = ""; + this.retValue = TsToken.TS_TOKEN_VOID; this.paramList = new CopyOnWriteArrayList<>(); } @@ -80,6 +106,24 @@ public class FuncObj extends GBaseObject { return type; } + /** + * 设置alias + * + * @param alias 函数别名 + */ + public void setAlias(String alias) { + this.alias = alias; + } + + /** + * 获取alias + * + * @return 返回函数别名 + */ + public String getAlias() { + return this.alias; + } + /** * 设置访问属性 * @@ -173,4 +217,19 @@ public class FuncObj extends GBaseObject { po.setType(type); this.paramList.add(po); } + + /** + * 添加参数 + * + * @param name 名字 + * @param type 类型 + * @param decorator 修饰 + */ + public void addParam(String name, String type, String decorator) { + ParamObj po = new ParamObj(); + po.setName(name); + po.setType(type); + po.setDecorator(decorator); + this.paramList.add(po); + } } diff --git a/src/intellij_plugin/ohosgen/src/main/java/grammar/ParamObj.java b/src/intellij_plugin/ohosgen/src/main/java/grammar/ParamObj.java index aad5514037d2a601a8c5451b8fd9815324320cad..2a07a5392c0f3965badd0281bc456b3f526785a9 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/grammar/ParamObj.java +++ b/src/intellij_plugin/ohosgen/src/main/java/grammar/ParamObj.java @@ -15,6 +15,8 @@ package grammar; +import utils.TsToken; + /** *

类名:该类用于xxx

* description param grammar @@ -25,16 +27,42 @@ package grammar; * @since 2025-02-28 */ public class ParamObj extends GBaseObject { + /** + * 参数约束:constant,abstract + */ private String qualifier; + + /** + * 参数修饰:可选(optional),必选(required) + */ + private String decorator; + + /** + * 参数类型 + */ private String type; + + /** + * 参数名称 + */ private String name; + + /** + * 参数数组数量 + */ private int arraySize; + + /** + * 参数赋值 + */ private int[] asList; /** * 构造函数 */ - public ParamObj() {} + public ParamObj() { + this.decorator = TsToken.TS_TOKEN_REQUIRED; + } /** * 构造函数 @@ -45,6 +73,7 @@ public class ParamObj extends GBaseObject { * @param asl 数组下标数组 */ public ParamObj(String tv, String nv, int as, int[] asl) { + this(); this.type = tv; this.name = nv; this.arraySize = as; @@ -69,6 +98,24 @@ public class ParamObj extends GBaseObject { this.qualifier = qualifier; } + /** + * 获取修饰 + * + * @return 修饰 + */ + public String getDecorator() { + return decorator; + } + + /** + * 设置 修饰 + * + * @param decorator 修饰 + */ + public void setDecorator(String decorator) { + this.decorator = decorator; + } + /** * 获取名字 * diff --git a/src/intellij_plugin/ohosgen/src/main/java/utils/TsToken.java b/src/intellij_plugin/ohosgen/src/main/java/utils/TsToken.java index 19907897d40ed05ab92cd349e7d9341b1166ed8f..f8530c2afb725c79541448cf236b6d8885017467 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/utils/TsToken.java +++ b/src/intellij_plugin/ohosgen/src/main/java/utils/TsToken.java @@ -26,6 +26,21 @@ package utils; */ public class TsToken { + /** + * optional token + */ + public static final String TS_TOKEN_OPTIONAL = "optional"; + + /** + * required token + */ + public static final String TS_TOKEN_REQUIRED = "required"; + + /** + * rest parameter token + */ + public static final String TS_TOKEN_REST_PARAM = "rest_param"; + /** * enum token */ diff --git a/src/intellij_plugin/ohosgen/src/test/java/parse/ParseTsTest.java b/src/intellij_plugin/ohosgen/src/test/java/parse/ParseTsTest.java index 74fd4b3f81d8151c7ce85447426d809f6674947f..a7289daad4826debd914e481fcbe374cc038132d 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/parse/ParseTsTest.java +++ b/src/intellij_plugin/ohosgen/src/test/java/parse/ParseTsTest.java @@ -19,6 +19,7 @@ import grammar.*; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CodePointCharStream; import org.junit.jupiter.api.Test; +import utils.TsToken; import java.util.List; @@ -172,6 +173,90 @@ class ParseTsTest { " }\n" + "}"; + String testFunc2 = "namespace StringUtility\n" + + "{\n" + + " function ToCapital(str: string): string {\n" + + " return str.toUpperCase();\n" + + " }\n" + + "\n" + + " function Nemw(str: string, length: number = 0): string {\n" + + " return str.toUpperCase();\n" + + " }\n" + + " export function Eported(from: string, length: number = 0): string {\n" + + " return from.toUpperCase();\n" + + " }\n" + + "\n" + + " export function Eported2(str: string, length: number = 0): string {\n" + + " return str.toUpperCase();\n" + + " }\n" + + "}"; + + String testFunc3 = "function Sum(x: number, y: number) : void {\n" + + " console.log('processNumKeyPairs: key = ' + key + ', value = ' + value)\n" + + " return x + y;\n" + + "}"; + + String testFunc4 = "let greeting = function() {\n" + + " console.log(\"Hello TypeScript!\");\n" + + "};"; + + String testFunc5 = "let SumAnon = function(x: number, y: number) : number\n" + + "{\n" + + " return x + y;\n" + + "}"; + + String testFunc6 = "function Greet(greeting: string, name?: string ) : string {\n" + + " return greeting + ' ' + name + '!';\n" + + "}"; + + String testFunc7 = "function terminateJob(jobId: string) {\n" + + " return this.http.delete>();\n" + + "}"; + + String testFunc8 = "function Greet2(name: string, greeting: string = \"Hello\") : string {\n" + + " return greeting + ' ' + name + '!';\n" + + "}"; + + String testFunc9 = "Greet(undefined, 'Steve');"; + + String testFunc10 = "let sumArrow = (x: number, y: number): number => {\n" + + " return x + y\n" + + "}"; + + String testFunc11 = "let Print = () => console.log(\"Hello TypeScript\");"; + + String testFunc12 = "let sumShortArrow = (x: number, y: number) => x + y;"; + + String testFunc13 = "function Greet(greeting: string, ...names: string[]) {\n" + + " return greeting + \" \" + names.join(\", \") + \"!\";\n" + + "}"; + + String testFunc14 = "function Test(value: TestClass | TestClass2): value is TestClass {\n" + + " return (value).someFunction !== undefined;\n" + + "}"; + + String testFunc15 = "function buildName(firstName: string, lastName?: string) {\n" + + " if (lastName) return firstName + \" \" + lastName;\n" + + " else return firstName;\n" + + " }"; + + String testFunc16 = "// Try passing a nested type to the function. " + + " This tests we don't match \">>\" and \">>>\" operators\n" + + "// when closing nested types.\n" + + "function nestedType(map: Map>>) {\n" + + " // Check that we can parse these too.\n" + + " let a = 12;\n" + + " let b = a >> 5;\n" + + " let c = b >>> 5;\n" + + "}"; + + String testFunc17 = "// Function parameter lists can have a trailing comma.\n" + + "// See https://github.com/Microsoft/TypeScript/issues/16152\n" + + "function TrailingComma(arg1: string, arg2: number,) {}"; + + String testFunc18 = "var myFunction = function(arg1: string, arg2: number,) {};"; + + @Test void parseFile() { } @@ -644,7 +729,7 @@ class ParseTsTest { } @Test - void parseCStreamFunc() { + void parseCStreamFunc_1() { ParseBase parser = ParseFactory.getParser("ts"); String testFunc = "export function transform2D(\n" + "\tdirection: number,\n" + @@ -670,6 +755,338 @@ class ParseTsTest { assertEquals("Calculate", poItem.getType()); } + @Test + void parseCStreamFunc_2() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc2; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(4, fol.size()); + FuncObj fo = fol.get(0); + assertEquals("ToCapital", fo.getName()); + assertEquals("string", fo.getRetValue()); + List pol = fo.getParamList(); + assertEquals(1, pol.size()); + ParamObj poItem = pol.get(0); + assertEquals("str", poItem.getName()); + assertEquals("string", poItem.getType()); + + fo = fol.get(1); + assertEquals("Nemw", fo.getName()); + assertEquals("string", fo.getRetValue()); + pol = fo.getParamList(); + assertEquals(2, pol.size()); + poItem = pol.get(0); + assertEquals("str", poItem.getName()); + assertEquals("string", poItem.getType()); + poItem = pol.get(1); + assertEquals("length", poItem.getName()); + assertEquals("number", poItem.getType()); + + fo = fol.get(2); + assertEquals("Eported", fo.getName()); + assertEquals("string", fo.getRetValue()); + pol = fo.getParamList(); + assertEquals(2, pol.size()); + poItem = pol.get(0); + assertEquals("from", poItem.getName()); + assertEquals("string", poItem.getType()); + poItem = pol.get(1); + assertEquals("length", poItem.getName()); + assertEquals("number", poItem.getType()); + + fo = fol.get(3); + assertEquals("Eported2", fo.getName()); + assertEquals("string", fo.getRetValue()); + pol = fo.getParamList(); + assertEquals(2, pol.size()); + poItem = pol.get(0); + assertEquals("str", poItem.getName()); + assertEquals("string", poItem.getType()); + poItem = pol.get(1); + assertEquals("length", poItem.getName()); + assertEquals("number", poItem.getType()); + } + + @Test + void parseCStreamFunc_3() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc3; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Sum", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("x", pol.get(0).getName()); + assertEquals("number", pol.get(0).getType()); + assertEquals("y", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_4() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc4; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("greeting", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(0, pol.size()); + } + + @Test + void parseCStreamFunc_5() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc5; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("SumAnon", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("x", pol.get(0).getName()); + assertEquals("number", pol.get(0).getType()); + assertEquals("y", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_6() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc6; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Greet", fol.get(0).getName()); + assertEquals("string", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("greeting", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals("name", pol.get(1).getName()); + assertEquals("string", pol.get(1).getType()); + assertEquals(TsToken.TS_TOKEN_OPTIONAL, pol.get(1).getDecorator()); + } + + @Test + void parseCStreamFunc_7() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc7; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("terminateJob", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(1, pol.size()); + assertEquals("jobId", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + + } + + @Test + void parseCStreamFunc_8() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc8; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Greet2", fol.get(0).getName()); + assertEquals("string", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("name", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals("greeting", pol.get(1).getName()); + assertEquals("string", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_9() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc9; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Greet", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("undefined", pol.get(0).getName()); + assertEquals("", pol.get(0).getType()); + assertEquals("'Steve'", pol.get(1).getName()); + assertEquals("", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_10() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc10; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("sumArrow", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("x", pol.get(0).getName()); + assertEquals("number", pol.get(0).getType()); + assertEquals("y", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_11() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc11; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + List pol = fol.get(0).getParamList(); + assertEquals(0, pol.size()); + } + + @Test + void parseCStreamFunc_12() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc12; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("sumShortArrow", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("x", pol.get(0).getName()); + assertEquals("number", pol.get(0).getType()); + assertEquals("y", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_13() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc13; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Greet", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("greeting", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals("names", pol.get(1).getName()); + assertEquals("string[]", pol.get(1).getType()); + assertEquals(TsToken.TS_TOKEN_REST_PARAM, pol.get(1).getDecorator()); + } + + @Test + void parseCStreamFunc_14() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc14; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("Test", fol.get(0).getName()); + assertEquals("boolean", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(1, pol.size()); + assertEquals("value", pol.get(0).getName()); + assertEquals("TestClass|TestClass2", pol.get(0).getType()); + + } + + @Test + void parseCStreamFunc_15() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc15; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("buildName", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("firstName", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals(TsToken.TS_TOKEN_REQUIRED, pol.get(0).getDecorator()); + assertEquals("lastName", pol.get(1).getName()); + assertEquals("string", pol.get(1).getType()); + assertEquals(TsToken.TS_TOKEN_OPTIONAL, pol.get(1).getDecorator()); + } + + @Test + void parseCStreamFunc_16() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc16; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("nestedType", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(1, pol.size()); + assertEquals("map", pol.get(0).getName()); + assertEquals("Map>>", pol.get(0).getType()); + } + + @Test + void parseCStreamFunc_17() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc17; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("TrailingComma", fol.get(0).getName()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("arg1", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals("arg2", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + + @Test + void parseCStreamFunc_18() { + ParseBase parser = ParseFactory.getParser("ts"); + String testFunc = testFunc18; + CodePointCharStream cStream = CharStreams.fromString(testFunc); + ParseObj po = parser.parseCStream(cStream); + List fol = po.getFuncList(); + assertEquals(1, fol.size()); + assertEquals("myFunction", fol.get(0).getAlias()); + assertEquals("void", fol.get(0).getRetValue()); + List pol = fol.get(0).getParamList(); + assertEquals(2, pol.size()); + assertEquals("arg1", pol.get(0).getName()); + assertEquals("string", pol.get(0).getType()); + assertEquals("arg2", pol.get(1).getName()); + assertEquals("number", pol.get(1).getType()); + } + @Test void parseCStreamInterface() { ParseBase parser = ParseFactory.getParser("ts");