// Ext.dom.Element.CLIP protected bool tryToGetTypeExistenceAsClassStaticProperty(string typeFullName) { ExtClass extClass; List <string> typeFullNameExploded = typeFullName.Split('.').ToList(); int lastExplodedIndex = typeFullNameExploded.Count - 1; string statPropName = typeFullNameExploded[lastExplodedIndex]; typeFullNameExploded.RemoveAt(lastExplodedIndex); string typeFullNameStatProp = String.Join(".", typeFullNameExploded); if (this.processor.Store.ExtClassesMap.ContainsKey(typeFullNameStatProp)) { extClass = this.processor.Store.GetByFullName(typeFullNameStatProp); if ( extClass != null && extClass.Members.PropertiesStatic.ContainsKey(statPropName) ) { // there is static property - check if it has only single type and create interface for it Property staticProp = extClass.Members.PropertiesStatic[statPropName] as Property; if (staticProp.Types.Count == 1) { string altClassName = extClass.Name.FullName + "." + statPropName; string[] propTypes = staticProp.Types.Keys.ToArray <string>(); string propType = propTypes[0]; string propTypeUc; if (JavascriptInternals.IsJsPrimitiveWithTypescriptInterface(propType.ToLower())) { propTypeUc = propType.Substring(0, 1).ToUpper() + propType.Substring(1); } else { propTypeUc = propType; } // declare namespace Ext.dom.Element { interface CLIP extends Number {} } ExtClass alternativeAliasClass = new ExtClass( altClassName, propTypeUc, new string[] { } ); alternativeAliasClass.Package = extClass.Package; //alternativeAliasClass.SrcJson = extClass.SrcJson; alternativeAliasClass.Name.PackagedNamespace = this.processor.Reader.GetPackagedNamespaceFromFullClassName( extClass.Name.FullName ); alternativeAliasClass.ClassType = ExtTypes.Enums.ClassType.CLASS_CONSTANT_ALIAS; this.processor.Store.AddExtClass(alternativeAliasClass); // add into method, where is type defined also the base type if (!this.processor.Store.StaticPropsTypes.ContainsKey(altClassName)) { this.processor.Store.StaticPropsTypes.Add(altClassName, new List <string>()); } List <string> staticPropTypes = this.processor.Store.StaticPropsTypes[altClassName]; if (!staticPropTypes.Contains(propType)) { staticPropTypes.Add(propType); } } return(true); } } return(false); }
protected SpecialParamTypes matchSpecStructParamInParamTypesCollection( List <string> paramAllTypesCollection, bool standardParamsCollection ) { // Process params collection - clone and remove all primitive types, then decide: SpecialParamTypes result = new SpecialParamTypes() { Matches = SpecialParamMatch.NONE, MethodOrEventAllParamTypes = new List <string>(), }; List <string> nonPrimitiveTypes = new List <string>(); foreach (string paramType in paramAllTypesCollection) { if (!JavascriptInternals.IsJsPrimitive(paramType.ToLower())) { nonPrimitiveTypes.Add(paramType); } } if (nonPrimitiveTypes.Count > 0) { // Callback function: if (nonPrimitiveTypes.Contains("Function")) { result.Matches |= standardParamsCollection ? SpecialParamMatch.STANDARD_COLLECTION_FUNC : SpecialParamMatch.SPREAD_COLLECTION_FUNC; nonPrimitiveTypes.Remove("Function"); } if (standardParamsCollection && nonPrimitiveTypes.Contains("Function[]")) { result.Matches |= SpecialParamMatch.STANDARD_COLLECTION_FUNC_ARR; nonPrimitiveTypes.Remove("Function[]"); } // Configuration object: if (nonPrimitiveTypes.Contains("Object")) { result.Matches |= standardParamsCollection ? SpecialParamMatch.STANDARD_COLLECTION_OBJECT : SpecialParamMatch.SPREAD_COLLECTION_OBJECT; nonPrimitiveTypes.Remove("Object"); } if (nonPrimitiveTypes.Contains("object")) { result.Matches |= standardParamsCollection ? SpecialParamMatch.STANDARD_COLLECTION_OBJECT : SpecialParamMatch.SPREAD_COLLECTION_OBJECT; nonPrimitiveTypes.Remove("object"); } if (standardParamsCollection && nonPrimitiveTypes.Contains("Object[]")) { result.Matches |= SpecialParamMatch.STANDARD_COLLECTION_OBJECT_ARR; nonPrimitiveTypes.Remove("Object[]"); } if (standardParamsCollection && nonPrimitiveTypes.Contains("object[]")) { result.Matches |= SpecialParamMatch.STANDARD_COLLECTION_OBJECT_ARR; nonPrimitiveTypes.Remove("object[]"); } // Any other like: Ext.event.Event: if (nonPrimitiveTypes.Count > 0) { bool arrayMatch = false; bool nonArrayMatch = false; foreach (string nonPrimitiveType in nonPrimitiveTypes) { if (nonPrimitiveType.EndsWith("[]")) { arrayMatch = true; } else { nonArrayMatch = true; } result.MethodOrEventAllParamTypes.Add(nonPrimitiveType); } if (standardParamsCollection && arrayMatch) { result.Matches |= SpecialParamMatch.STANDARD_COLLECTION_INTERFACE_ARR; } if (nonArrayMatch) { result.Matches |= standardParamsCollection ? SpecialParamMatch.STANDARD_COLLECTION_INTERFACE : SpecialParamMatch.SPREAD_COLLECTION_INTERFACE; } } } return(result); }
/** * Complete result types collection(s): */ protected void completeResultList( ref ParsedTypes result, List <string> rawTypesList, TypeDefinitionPlace typeDefinitionPlace, bool methodParamDefinition, string definitionFullPath, string memberOrParamName ) { string typeItem = ""; string typeItemLower = ""; int arrBracketsPos = 0; string arrayBrackets = ""; bool functionParamSpreadSyntax; bool anyMatchedNormal = false; bool anyMatchedSpreadSyntax = false; for (int i = 0; i < rawTypesList.Count; i++) { // Trim type definition string: typeItem = rawTypesList[i].Trim( new char[] { ' ', '\t', '\v', '\r', '\n' } ); // Check and correct the type if there is function param spread syntax detected functionParamSpreadSyntax = methodParamDefinition && typeItem.Contains("..."); if (functionParamSpreadSyntax) { typeItem = typeItem.Replace("...", ""); } // Take off temporary array brackets at the end if there are any: arrBracketsPos = typeItem.IndexOf("[]"); if (arrBracketsPos > -1) { arrayBrackets = typeItem.Substring(arrBracketsPos); typeItem = typeItem.Substring(0, arrBracketsPos); } else { arrayBrackets = ""; } // Create lowercase type definition variant to determinate primitive JS types and define correct typescript type form: if (this.processor.Store.ClassesFixes.ContainsKey(typeItem)) { typeItem = this.processor.Store.ClassesFixes[typeItem]; } typeItemLower = typeItem.ToLower(); // Check internal JS priitives, internal js types, special wildcard definitions, // function arguments type or any other type to register and chack later if (JavascriptInternals.IsJsPrimitiveTypescriptLower(typeItemLower)) { // Primitive JS types has to be lowercased for TypeScript: // https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html typeItem = typeItemLower; } else if (typeItemLower == "arguments") { // If type is defined as function arguments object, // correct it to TypeScript `IArguments` interface defined in `lib.es5.d.ts`: typeItem = "IArguments"; } else if (InheritanceResolvers.Types.IsBrowserInternalType(typeItem)) { /*if (JavascriptInternals.JsGlobalsAlsoInExtNamespace.Contains(typeItem)) { * typeItem = SpecialsGenerator.GLOBAL_CLASS_BASE * .Replace("<browserGlobalClassName>", typeItem); * } else*/if (typeItemLower == "array") { // If type is internal JS type or internal EcmaScript DOM type, // correct only `array` to `any[]` and do not register anything for later chacking: typeItem = "any[]"; } } else if (typeItemLower == "mixed" || typeItemLower == "*" || typeItemLower == "type" /* always in private classes */ || typeItemLower == "[type]") { // If type is any special JS Docs wildcard - corect it to TypeScript `any` type: typeItem = "any"; } else { // If type is anything other - register this type for later checking process: if ( !typeItem.StartsWith("'") && // if it is not start with "'" !typeItem.EndsWith("'") && // if it is not end with "'" !Regex.Match(typeItem, @"^([0-9\+\-\.]+)$").Success&& // if it is not numeric !Regex.Match(typeItem, @"^\{(.*)\}$").Success // if it is not direct object: { x:: Number, y: Number, ...} ) { this.processor.Store.AddTypePlace( typeDefinitionPlace, definitionFullPath, memberOrParamName, typeItem ); } } // Add array brackets back at the end if there were any: if (arrayBrackets.Length > 0) { typeItem += arrayBrackets; } // If there is `any` TypeScript type matched - store this information later and ad this type at the result list end if (typeItem == "any") { if (functionParamSpreadSyntax) { anyMatchedSpreadSyntax = true; } else { anyMatchedNormal = true; }; } else { this.addTypeToResult( ref result, typeDefinitionPlace, functionParamSpreadSyntax, typeItem ); } } // add `any` TypeScript type always at the end: if (anyMatchedNormal) // add any always as last { this.addTypeToResult( ref result, typeDefinitionPlace, false, "any" ); } if (anyMatchedSpreadSyntax) // add any always as last { this.addTypeToResult( ref result, typeDefinitionPlace, true, "any" ); } }