This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
Add CodeGenerator tests and fix NREs/bugs #40838
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d928ff8
Add CodeGenerator tests and fix NREs/bugs
hughbe 4e122c1
Reverting empty collection checks
buyaa-n 5f386a3
Small typo
buyaa-n 4324a90
Skipping tests on full framework
buyaa-n ca033a2
Some more need to be skipped on framework
buyaa-n 3ed89ea
Fix test failure
buyaa-n ec382b1
Adding format for ToString
buyaa-n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -235,6 +235,11 @@ protected void GenerateNamespaces(CodeCompileUnit e) | |||||||
|
|
||||||||
| protected void GenerateTypes(CodeNamespace e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| foreach (CodeTypeDeclaration c in e.Types) | ||||||||
| { | ||||||||
| if (_options.BlankLinesBetweenMembers) | ||||||||
|
|
@@ -396,6 +401,10 @@ void ICodeGenerator.GenerateCodeFromStatement(CodeStatement e, TextWriter w, Cod | |||||||
|
|
||||||||
| public virtual void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) | ||||||||
| { | ||||||||
| if (member == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(member)); | ||||||||
| } | ||||||||
| if (_output != null) | ||||||||
| { | ||||||||
| throw new InvalidOperationException(SR.CodeGenReentrance); | ||||||||
|
|
@@ -704,6 +713,11 @@ private void GenerateSnippetMembers(CodeTypeDeclaration e) | |||||||
|
|
||||||||
| protected virtual void GenerateSnippetCompileUnit(CodeSnippetCompileUnit e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| GenerateDirectives(e.StartDirectives); | ||||||||
|
|
||||||||
| if (e.LinePragma != null) | ||||||||
|
|
@@ -789,6 +803,11 @@ protected virtual void GenerateCompileUnit(CodeCompileUnit e) | |||||||
|
|
||||||||
| protected virtual void GenerateNamespace(CodeNamespace e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| GenerateCommentStatements(e.Comments); | ||||||||
| GenerateNamespaceStart(e); | ||||||||
|
|
||||||||
|
|
@@ -801,11 +820,23 @@ protected virtual void GenerateNamespace(CodeNamespace e) | |||||||
|
|
||||||||
| protected void GenerateNamespaceImports(CodeNamespace e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| foreach (CodeNamespaceImport imp in e.Imports) | ||||||||
| { | ||||||||
| if (imp.LinePragma != null) GenerateLinePragmaStart(imp.LinePragma); | ||||||||
| if (imp.LinePragma != null) | ||||||||
| { | ||||||||
| GenerateLinePragmaStart(imp.LinePragma); | ||||||||
| } | ||||||||
|
|
||||||||
| GenerateNamespaceImport(imp); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| if (imp.LinePragma != null) GenerateLinePragmaEnd(imp.LinePragma); | ||||||||
| if (imp.LinePragma != null) | ||||||||
| { | ||||||||
| GenerateLinePragmaEnd(imp.LinePragma); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -846,6 +877,11 @@ private void GenerateProperties(CodeTypeDeclaration e) | |||||||
|
|
||||||||
| protected void GenerateStatement(CodeStatement e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (e.StartDirectives.Count > 0) | ||||||||
| { | ||||||||
| GenerateDirectives(e.StartDirectives); | ||||||||
|
|
@@ -938,6 +974,11 @@ protected void GenerateStatement(CodeStatement e) | |||||||
|
|
||||||||
| protected void GenerateStatements(CodeStatementCollection stmts) | ||||||||
| { | ||||||||
| if (stmts == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(stmts)); | ||||||||
| } | ||||||||
|
|
||||||||
| foreach (CodeStatement stmt in stmts) | ||||||||
| { | ||||||||
| ((ICodeGenerator)this).GenerateCodeFromStatement(stmt, _output.InnerWriter, _options); | ||||||||
|
|
@@ -946,7 +987,15 @@ protected void GenerateStatements(CodeStatementCollection stmts) | |||||||
|
|
||||||||
| protected virtual void OutputAttributeDeclarations(CodeAttributeDeclarationCollection attributes) | ||||||||
| { | ||||||||
| if (attributes.Count == 0) return; | ||||||||
| if (attributes == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(attributes)); | ||||||||
| } | ||||||||
| if (attributes.Count == 0) | ||||||||
| { | ||||||||
| return; | ||||||||
|
buyaa-n marked this conversation as resolved.
|
||||||||
| } | ||||||||
|
|
||||||||
| GenerateAttributeDeclarationsStart(attributes); | ||||||||
| bool first = true; | ||||||||
| foreach (CodeAttributeDeclaration current in attributes) | ||||||||
|
|
@@ -985,6 +1034,11 @@ protected virtual void OutputAttributeDeclarations(CodeAttributeDeclarationColle | |||||||
|
|
||||||||
| protected virtual void OutputAttributeArgument(CodeAttributeArgument arg) | ||||||||
| { | ||||||||
| if (arg == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(arg)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (!string.IsNullOrEmpty(arg.Name)) | ||||||||
| { | ||||||||
| OutputIdentifier(arg.Name); | ||||||||
|
|
@@ -1236,6 +1290,11 @@ protected virtual void OutputOperator(CodeBinaryOperatorType op) | |||||||
|
|
||||||||
| protected virtual void OutputParameters(CodeParameterDeclarationExpressionCollection parameters) | ||||||||
| { | ||||||||
| if (parameters == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(parameters)); | ||||||||
| } | ||||||||
|
|
||||||||
| bool first = true; | ||||||||
| bool multiline = parameters.Count > ParameterMultilineThreshold; | ||||||||
| if (multiline) | ||||||||
|
|
@@ -1269,6 +1328,11 @@ protected virtual void OutputParameters(CodeParameterDeclarationExpressionCollec | |||||||
|
|
||||||||
| protected virtual void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| bool indentedExpression = false; | ||||||||
| Output.Write('('); | ||||||||
|
|
||||||||
|
|
@@ -1320,6 +1384,11 @@ protected virtual void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpres | |||||||
|
|
||||||||
| protected virtual void GenerateParameterDeclarationExpression(CodeParameterDeclarationExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (e.CustomAttributes.Count > 0) | ||||||||
| { | ||||||||
| OutputAttributeDeclarations(e.CustomAttributes); | ||||||||
|
|
@@ -1332,12 +1401,22 @@ protected virtual void GenerateParameterDeclarationExpression(CodeParameterDecla | |||||||
|
|
||||||||
| protected virtual void GenerateDirectionExpression(CodeDirectionExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| OutputDirection(e.Direction); | ||||||||
| GenerateExpression(e.Expression); | ||||||||
| } | ||||||||
|
|
||||||||
| protected virtual void GeneratePrimitiveExpression(CodePrimitiveExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (e.Value == null) | ||||||||
| { | ||||||||
| Output.Write(NullToken); | ||||||||
|
|
@@ -1391,7 +1470,7 @@ protected virtual void GeneratePrimitiveExpression(CodePrimitiveExpression e) | |||||||
| } | ||||||||
| else | ||||||||
| { | ||||||||
| throw new ArgumentException(SR.Format(SR.InvalidPrimitiveType, e.Value.GetType())); | ||||||||
| throw new ArgumentException(SR.Format(SR.InvalidPrimitiveType, e.Value.GetType()), nameof(e)); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -1413,11 +1492,21 @@ protected virtual void GenerateDefaultValueExpression(CodeDefaultValueExpression | |||||||
|
|
||||||||
| protected virtual void GenerateTypeReferenceExpression(CodeTypeReferenceExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| OutputType(e.Type); | ||||||||
| } | ||||||||
|
|
||||||||
| protected virtual void GenerateTypeOfExpression(CodeTypeOfExpression e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| Output.Write("typeof("); | ||||||||
| OutputType(e.Type); | ||||||||
| Output.Write(')'); | ||||||||
|
|
@@ -1428,6 +1517,10 @@ protected virtual void GenerateTypeOfExpression(CodeTypeOfExpression e) | |||||||
| protected abstract void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e); | ||||||||
| protected virtual void GenerateCommentStatement(CodeCommentStatement e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
| if (e.Comment == null) | ||||||||
| { | ||||||||
| throw new ArgumentException(SR.Format(SR.Argument_NullComment, nameof(e)), nameof(e)); | ||||||||
|
|
@@ -1437,6 +1530,11 @@ protected virtual void GenerateCommentStatement(CodeCommentStatement e) | |||||||
|
|
||||||||
| protected virtual void GenerateCommentStatements(CodeCommentStatementCollection e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| foreach (CodeCommentStatement comment in e) | ||||||||
| { | ||||||||
| GenerateCommentStatement(comment); | ||||||||
|
|
@@ -1452,7 +1550,17 @@ protected virtual void GenerateCommentStatements(CodeCommentStatementCollection | |||||||
| protected abstract void GenerateRemoveEventStatement(CodeRemoveEventStatement e); | ||||||||
| protected abstract void GenerateGotoStatement(CodeGotoStatement e); | ||||||||
| protected abstract void GenerateLabeledStatement(CodeLabeledStatement e); | ||||||||
| protected virtual void GenerateSnippetStatement(CodeSnippetStatement e) => Output.WriteLine(e.Value); | ||||||||
|
|
||||||||
| protected virtual void GenerateSnippetStatement(CodeSnippetStatement e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| Output.WriteLine(e.Value); | ||||||||
| } | ||||||||
|
|
||||||||
| protected abstract void GenerateVariableDeclarationStatement(CodeVariableDeclarationStatement e); | ||||||||
| protected abstract void GenerateLinePragmaStart(CodeLinePragma e); | ||||||||
| protected abstract void GenerateLinePragmaEnd(CodeLinePragma e); | ||||||||
|
|
@@ -1469,6 +1577,11 @@ protected virtual void GenerateCommentStatements(CodeCommentStatementCollection | |||||||
|
|
||||||||
| protected virtual void GenerateCompileUnitStart(CodeCompileUnit e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (e.StartDirectives.Count > 0) | ||||||||
| { | ||||||||
| GenerateDirectives(e.StartDirectives); | ||||||||
|
|
@@ -1477,6 +1590,11 @@ protected virtual void GenerateCompileUnitStart(CodeCompileUnit e) | |||||||
|
|
||||||||
| protected virtual void GenerateCompileUnitEnd(CodeCompileUnit e) | ||||||||
| { | ||||||||
| if (e == null) | ||||||||
| { | ||||||||
| throw new ArgumentNullException(nameof(e)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (e.EndDirectives.Count > 0) | ||||||||
| { | ||||||||
| GenerateDirectives(e.EndDirectives); | ||||||||
|
|
@@ -1495,7 +1613,7 @@ protected virtual void ValidateIdentifier(string value) | |||||||
| { | ||||||||
| if (!IsValidIdentifier(value)) | ||||||||
| { | ||||||||
| throw new ArgumentException(SR.Format(SR.InvalidIdentifier, value)); | ||||||||
| throw new ArgumentException(SR.Format(SR.InvalidIdentifier, value), nameof(value)); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.