public static string GetSignature(TypeScriptCompiler compiler, MethodDeclaration methodDeclaration, string methodNameSuffix = "") { var modifiers = GetModifiers(compiler, methodDeclaration); var methodName = methodDeclaration.Name.Data; var methodArguments = GetArguments(compiler, methodDeclaration); var returnType = GetReturnType(compiler, methodDeclaration); var arrayDepth = GetArrayDepth(methodDeclaration); return string.Format("{0}{1}{2}({3}): {4}{5}", modifiers, methodName, methodNameSuffix, methodArguments, returnType, arrayDepth); }
public static bool SkipCompile(ICompiler compiler, MethodDeclaration methodDeclaration) { var classInheritanceStack = compiler.GetClassInheritanceStack(GetClassName(compiler)); return GetMethodDetail(compiler, methodDeclaration).NeedsExclusion(classInheritanceStack); }
public MethodDeclarationCompiler(ICompiler compiler, MethodDeclaration methodDeclaration) { _compiler = (TypeScriptCompiler)compiler; _methodDeclaration = methodDeclaration; }
private static string GetModifiers(TypeScriptCompiler compiler, MethodDeclaration methodDeclaration) { var modifiers = new List<string>(); var methodDetail = GetMethodDetail(compiler, methodDeclaration); modifiers.Add( methodDetail.NeedsExtending() || methodDetail.GetDependantMethods().Any() || (methodDeclaration.Modifiers != null && methodDeclaration.Modifiers.All(x => x.Data != Keywords.Private)) ? Keywords.Public : Keywords.Private); if (methodDeclaration.Modifiers != null && methodDeclaration.Modifiers.Any(x => x.Data == Keywords.Static)) { modifiers.Add(Keywords.Static); } return modifiers.Aggregate((x, y) => x + " " + y) + " "; }
private static string GetReturnType(TypeScriptCompiler compiler, MethodDeclaration methodDeclaration) { return methodDeclaration.ReturnType == null ? string.Empty : compiler.GetTypeString(methodDeclaration.ReturnType, "MethodDeclarationCompiler -> GetReturnType"); }
private static MethodDetail GetMethodDetail(ICompiler compiler, MethodDeclaration methodDeclaration) { return JavaClassMetadata.GetClass(GetClassName(compiler)).GetMethod(methodDeclaration.Name.Data); }
private static string GetArrayDepth(MethodDeclaration methodDeclaration) { var arrayString = string.Empty; for (var i = 0; i < methodDeclaration.ReturnArrayDepth; i++) { arrayString += "[]"; } return arrayString; }
private static string GetArguments(TypeScriptCompiler compiler, MethodDeclaration methodDeclaration) { return methodDeclaration.Arguments == null || methodDeclaration.Arguments.Count == 0 ? string.Empty : methodDeclaration.Arguments .Select(x => compiler.GetMethodArgumentString(x)) .Aggregate((x, y) => x + ", " + y); }
private static string GetParametersAreOfRightType(MethodDeclaration constructor, string argumentPrefix) { var isOfRightTypeNumber = 0; return constructor.Arguments.Count == 0 ? string.Empty : constructor.Arguments .Select(x => GetTypeCheck(x, isOfRightTypeNumber++, argumentPrefix)) .Aggregate((x, y) => x + " && " + y); }
private static string GetParametersAreDefined(IList<MethodDeclaration> methodDeclarations, MethodDeclaration constructor, string argumentPrefix) { var isDefinedNumber = 0; return methodDeclarations .First(x => x.Arguments.Count == methodDeclarations.Max(y => y.Arguments.Count)) .Arguments .Select(x => string.Format(@"(typeof {0}{1} {2} ""undefined"")", argumentPrefix, isDefinedNumber, isDefinedNumber++ < constructor.Arguments.Count ? "!=" : "==")) .Aggregate((x, y) => x + " && " + y); }