public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) { if (MainDataType == DataType.Complexf) { if (node.ToString() == "float") { var newNode = node.WithKeyword(SyntaxFactory.ParseToken("double")); return(newNode.WithTriviaFrom(node)); } else { return(base.VisitPredefinedType(node)); } } if (node.ToString() != mainDataTypeName) { return(base.VisitPredefinedType(node)); } if (TargetDataType == DataType.Double) { var newNode = node.WithKeyword(SyntaxFactory.ParseToken("double")); return(newNode.WithTriviaFrom(node)); } else { var newNode = SyntaxFactory.IdentifierName(targetDataTypeName); return(newNode.WithTriviaFrom(node)); } }
// "int", "string" public override void VisitPredefinedType(PredefinedTypeSyntax node) { string nodeText = node.ToString(); foreach (string item in _typeToCheck) { return; } }
private void AnalyzePredefinedType(SyntaxNodeAnalysisContext context) { if (context.IsGeneratedOrNonUserCode()) { return; } PredefinedTypeSyntax predefinedType = context.Node as PredefinedTypeSyntax; // Don't touch the void. :) if (!predefinedType.ToString().Equals("void", StringComparison.OrdinalIgnoreCase)) { String typeString = predefinedType.ToString(); String realString = TypeMap[typeString]; var diagnostic = Diagnostic.Create(Rule, predefinedType.GetLocation(), typeString, realString); context.ReportDiagnostic(diagnostic); } }
private async Task<Document> ConvertPredefinedToSpecificTypeAsync(Document document, PredefinedTypeSyntax errorToken, CancellationToken c) { String predefinedType = errorToken.ToString(); var newType = SyntaxFactory.ParseTypeName(AvoidPreDefinedTypesAnalyzer.TypeMap[predefinedType]); newType = newType.WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(c); var newRoot = root.ReplaceNode(errorToken, newType); var newDocument = document.WithSyntaxRoot(newRoot); return newDocument; }
private async Task <Document> ConvertPredefinedToSpecificTypeAsync(Document document, PredefinedTypeSyntax errorToken, CancellationToken c) { String predefinedType = errorToken.ToString(); var newType = SyntaxFactory.ParseTypeName(AvoidPreDefinedTypesAnalyzer.TypeMap[predefinedType]); newType = newType.WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(c); var newRoot = root.ReplaceNode(errorToken, newType); var newDocument = document.WithSyntaxRoot(newRoot); return(newDocument); }
/// <summary> /// 定義済みタイプの構文のTypeScript変換 /// </summary> /// <param name="condition">ExpressionSyntaxインスタンス</param> /// <param name="localDeclarationStatements">ローカル変数リスト</param> /// <returns>TypeScriptに変換した文字列</returns> private string ConvertExpression(PredefinedTypeSyntax condition, List <string> localDeclarationStatements) { return(condition.ToString()); }