-
Notifications
You must be signed in to change notification settings - Fork 86
chore: upgrade script for next + rewriting RuleConfiguration to C# + expressions #17097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
olemartinorg
wants to merge
31
commits into
main
Choose a base branch
from
chore/removing-rulehandler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8,022
−8
Draft
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4af47e1
Adding upgrade command path for next, moving the legacy ones out of t…
720b742
Claude experiment, trying to parse out rules and generate expressions
718e120
Updates in rule config parser. All apps seems to be parsing correctly…
b09d748
Removing things we don't need
6307375
Converting to a proper JS parser
8c0ecaa
Fixing errors parsing arrow functions
937cdbf
Better parser, conditional expression matcher
cf95354
Improvements
90a84a7
Updates
cd63f7f
Minor adjustments for better stats
9bdc112
Moving files to a better named folder
49d2f3e
Attempt at implementing conversion to data processors for the legeacy…
5705614
Cleanup
7f0210b
Improvements to data processing rules conversion
36e0ca7
Better support for converting JS -> C# in data processors
b361442
Proper indentation, fixes to build, upgrading package file as well
2612d8b
Upgrading to project references instead
cf10ecc
Adding a Set() method for generating a setter for a JSON-path in a da…
8045144
Using the new Set() in generated classes
1a73600
Improvments to code generation, I hope
05ccd86
More fixes
a941305
Improvements, type detection in data models
ffbc299
Converting rules, adding them to layout JSON files
40030ad
Rename/move
5eb756d
Converting data processing rules as well
8d9a111
Minor fixes by jetbrains, removing some unused code
85942a5
Minor fixes
79fdb80
Merge branch 'refs/heads/main' into chore/removing-rulehandler
1a2a3a8
Minor fixes
7bb1031
Removing IgnoreWarnings line
797da12
Fixes. Using Roslyn for adding lines to Program.cs instead
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
147 changes: 147 additions & 0 deletions
147
src/App/backend/src/Altinn.App.Analyzers/SourceTextGenerator/SetterGenerator.cs
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| using System.Text; | ||
|
|
||
| namespace Altinn.App.Analyzers.SourceTextGenerator; | ||
|
|
||
| internal static class SetterGenerator | ||
| { | ||
| public static void Generate(StringBuilder builder, ModelPathNode rootNode) | ||
| { | ||
| if (rootNode.Properties.Count == 0) | ||
| { | ||
| builder.Append( | ||
| """ | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool Set(global::System.ReadOnlySpan<char> path, object? value) => false; | ||
|
|
||
| """ | ||
| ); | ||
| return; | ||
| } | ||
| builder.Append( | ||
| """ | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool Set(global::System.ReadOnlySpan<char> path, object? value) | ||
| { | ||
| if (path.IsEmpty) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return SetRecursive(_dataModel, path, 0, value); | ||
| } | ||
|
|
||
| """ | ||
| ); | ||
|
|
||
| GenerateRecursive(builder, rootNode, new HashSet<string>(StringComparer.Ordinal)); | ||
| } | ||
|
|
||
| private static void GenerateRecursive( | ||
| StringBuilder builder, | ||
| ModelPathNode modelPathNode, | ||
| HashSet<string> generatedTypes | ||
| ) | ||
| { | ||
| if (modelPathNode.ListType != null && generatedTypes.Add(modelPathNode.ListType)) | ||
| { | ||
| builder.Append( | ||
| $$""" | ||
|
|
||
| private static bool SetRecursive( | ||
| {{modelPathNode.ListType}}? model, | ||
| global::System.ReadOnlySpan<char> path, | ||
| int literalIndex, | ||
| int offset, | ||
| object? value | ||
| ) | ||
| { | ||
| if (model is null || literalIndex < 0 || literalIndex >= model.Count) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| {{( | ||
| modelPathNode.Properties.Count == 0 | ||
| ? GenerateListElementSet(modelPathNode) | ||
| : "return SetRecursive(model[literalIndex], path, offset, value);" | ||
| )}} | ||
| } | ||
|
|
||
| """ | ||
| ); | ||
| } | ||
| if (modelPathNode.IsJsonValueType || !generatedTypes.Add(modelPathNode.TypeName)) | ||
| { | ||
| // Do not generate recursive setters for primitive types, or types already generated | ||
| return; | ||
| } | ||
|
|
||
| builder.Append( | ||
| $$""" | ||
|
|
||
| private static bool SetRecursive( | ||
| {{modelPathNode.TypeName}}? model, | ||
| global::System.ReadOnlySpan<char> path, | ||
| int offset, | ||
| object? value | ||
| ) | ||
| { | ||
| if (model is null || offset == -1) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return ParseSegment(path, offset, out int nextOffset, out int literalIndex) switch | ||
| { | ||
|
|
||
| """ | ||
| ); | ||
| foreach (var child in modelPathNode.Properties) | ||
| { | ||
| builder.Append( | ||
| child switch | ||
| { | ||
| { ListType: not null } => | ||
| $" \"{child.JsonName}\" => SetRecursive(model.{child.CSharpName}, path, literalIndex, nextOffset, value),\r\n", | ||
| { Properties.Count: 0 } => | ||
| $" \"{child.JsonName}\" when nextOffset is -1 && literalIndex is -1 => TrySetValue(val => model.{child.CSharpName} = val, value),\r\n", | ||
| _ => | ||
| $" \"{child.JsonName}\" when literalIndex is -1 => SetRecursive(model.{child.CSharpName}, path, nextOffset, value),\r\n", | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| // Return false for unknown paths | ||
| builder.Append( | ||
| """ | ||
| _ => false, | ||
| }; | ||
| } | ||
|
|
||
| """ | ||
| ); | ||
|
|
||
| foreach (var child in modelPathNode.Properties) | ||
| { | ||
| GenerateRecursive(builder, child, generatedTypes); | ||
| } | ||
| } | ||
|
|
||
| private static string GenerateListElementSet(ModelPathNode modelPathNode) | ||
| { | ||
| // For list elements that are primitives, we need to handle the set differently | ||
| // Extract the element type from the list type (e.g., "List<int>" -> "int") | ||
| var elementType = modelPathNode.TypeName; | ||
|
|
||
| return @"if (offset == -1) | ||
| { | ||
| return TrySetValue<" | ||
| + elementType | ||
| + @">(val => model[literalIndex] = val, value); | ||
| } | ||
| return false; | ||
| "; | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Check notice
Code scanning / CodeQL
Unnecessarily complex Boolean expression Note
Copilot Autofix
AI about 19 hours ago
To fix the unnecessarily complex boolean expression on line 155, replace the ternary statement
indexedPath.IsEmpty ? false : formDataWrapper.Set(indexedPath, value)with the simplified boolean logic!indexedPath.IsEmpty && formDataWrapper.Set(indexedPath, value). This preserves the logic: the result isfalseifindexedPath.IsEmptyis true, and otherwise the result is whatever is returned byformDataWrapper.Set(indexedPath, value). Only a single line in methodSetwithin the extension classFormDataWrapperExtensionsin filesrc/App/backend/src/Altinn.App.Core/Internal/Data/IFormDataWrapper.csneeds updating.