Skip to content

Commit 9ebee60

Browse files
committed
fixes
1 parent 8a473f6 commit 9ebee60

2 files changed

Lines changed: 51 additions & 42 deletions

File tree

src/CustomCode-Analyzer/Analyzer.cs

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,21 @@ Location GetMemberLocation()
461461
if (osStructureField.NamedArguments.Any(na => na.Key == "DataType"))
462462
{
463463
var dataType = osStructureField.NamedArguments.First(na => na.Key == "DataType").Value;
464-
var type = member is IFieldSymbol fieldSymbol ? fieldSymbol.Type :
465-
(member is IPropertySymbol propertySymbol ? propertySymbol.Type : null);
464+
465+
// Determine the type based on member kind
466+
ITypeSymbol type;
467+
if (member is IFieldSymbol fieldSymbol)
468+
{
469+
type = fieldSymbol.Type;
470+
}
471+
else if (member is IPropertySymbol propertySymbol)
472+
{
473+
type = propertySymbol.Type;
474+
}
475+
else
476+
{
477+
type = null;
478+
}
466479

467480
// Check if the DataType mapping is incompatible
468481
if (HasIncompatibleDataTypeMapping(type, dataType))
@@ -664,55 +677,48 @@ Location GetMemberLocation()
664677
.Any(attr => attr.AttributeClass?.Name is "OSInterfaceAttribute" or "OSInterface"));
665678
}
666679

667-
if (hasOSInterfaceAttribute || implementsOSInterface)
680+
if ((hasOSInterfaceAttribute || implementsOSInterface) &&
681+
methodSymbol.Name.StartsWith("_"))
668682
{
669-
// Enforce naming conventions: methods should not start with an underscore
670-
if (methodSymbol.Name.StartsWith("_"))
671-
{
672-
// Report diagnostic if method name starts with an underscore
673-
context.ReportDiagnostic(
674-
Diagnostic.Create(
675-
NameBeginsWithUnderscoresRule,
676-
methodSyntax.GetLocation(),
677-
"Method",
678-
methodSymbol.Name));
679-
}
683+
// Report diagnostic if method name starts with an underscore
684+
context.ReportDiagnostic(
685+
Diagnostic.Create(
686+
NameBeginsWithUnderscoresRule,
687+
methodSyntax.GetLocation(),
688+
"Method",
689+
methodSymbol.Name));
680690
}
681691

682692
// Reference parameter check only for OSInterface methods (not implementations)
683693
if (hasOSInterfaceAttribute)
684694
{
685695
foreach (var parameter in methodSymbol.Parameters)
686696
{
687-
// Check each parameter for ref/out/in modifiers
688-
if (parameter.RefKind is RefKind.Ref or RefKind.Out or RefKind.In)
697+
// Check for reference parameters
698+
if (parameter.RefKind is RefKind.Ref or RefKind.Out or RefKind.In &&
699+
parameter.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is ParameterSyntax refParameterSyntax)
689700
{
690-
if (parameter.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is ParameterSyntax parameterSyntax)
691-
{
692-
// Report diagnostic if parameter is passed by reference
693-
context.ReportDiagnostic(
694-
Diagnostic.Create(
695-
ParameterByReferenceRule,
696-
parameterSyntax.GetLocation(),
697-
parameter.Name,
698-
methodSymbol.Name));
699-
}
701+
// Report diagnostic if parameter is passed by reference
702+
context.ReportDiagnostic(
703+
Diagnostic.Create(
704+
ParameterByReferenceRule,
705+
refParameterSyntax.GetLocation(),
706+
parameter.Name,
707+
methodSymbol.Name));
700708
}
701709

702710
// Check for default values
703-
if (parameter.HasExplicitDefaultValue && !IsValidParameterDefaultValue(parameter))
711+
if (parameter.HasExplicitDefaultValue &&
712+
!IsValidParameterDefaultValue(parameter) &&
713+
parameter.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is ParameterSyntax defaultParameterSyntax &&
714+
defaultParameterSyntax.Default?.Value != null)
704715
{
705-
// Retrieve parameter syntax to locate the default value expression
706-
if (parameter.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is ParameterSyntax parameterSyntax &&
707-
parameterSyntax.Default?.Value != null)
708-
{
709-
// Report diagnostic if default value is unsupported
710-
context.ReportDiagnostic(
711-
Diagnostic.Create(
712-
UnsupportedDefaultValueRule,
713-
parameterSyntax.Default.Value.GetLocation(),
714-
parameter.Name));
715-
}
716+
// Report diagnostic if default value is unsupported
717+
context.ReportDiagnostic(
718+
Diagnostic.Create(
719+
UnsupportedDefaultValueRule,
720+
defaultParameterSyntax.Default.Value.GetLocation(),
721+
parameter.Name));
716722
}
717723

718724
// Check if the parameter type requires OSStructure decoration
@@ -807,7 +813,7 @@ Location GetMemberLocation()
807813
t.TypeKind == TypeKind.Interface).ToList();
808814

809815
if (interfaces.Any() &&
810-
interfaces.First().DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is InterfaceDeclarationSyntax interfaceDeclaration)
816+
interfaces[0].DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is InterfaceDeclarationSyntax interfaceDeclaration)
811817
{
812818
// Report diagnostic if no interface is decorated with OSInterface
813819
context.ReportDiagnostic(
@@ -820,17 +826,18 @@ Location GetMemberLocation()
820826
{
821827
// If multiple OSInterfaces are found, report diagnostic
822828
// Get the first interface by source location for error reporting
823-
var (Syntax, Symbol) = osInterfaces.Values
829+
var firstSyntax = osInterfaces.Values
824830
.OrderBy(i => i.Syntax.GetLocation().GetLineSpan().StartLinePosition)
825-
.First();
831+
.First()
832+
.Syntax;
826833

827834
// Create a comma-separated list of interface names
828835
var interfaceNames = string.Join(", ",
829836
osInterfaces.Keys.OrderBy(name => name));
830837

831838
// Report diagnostic indicating multiple OSInterfaces
832839
context.ReportDiagnostic(
833-
Diagnostic.Create(ManyInterfacesRule, Syntax.GetLocation(), interfaceNames));
840+
Diagnostic.Create(ManyInterfacesRule, firstSyntax.GetLocation(), interfaceNames));
834841
}
835842
else
836843
{

src/CustomCode-Analyzer/CustomCode-Analyzer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<RootNamespace>CustomCode_Analyzer</RootNamespace>
1010
<PackageId>CustomCode.Analyzer</PackageId>
1111
<Version>0.1.1</Version>
12+
<AssemblyVersion>0.1.1</AssemblyVersion>
13+
<FileVersion>0.1.1</FileVersion>
1214
<Authors>Jonathan Algar</Authors>
1315
<Product>OutSystems Developer Cloud (ODC) Custom Code Analyzer</Product>
1416
<Description>Get feedback on your OutSytems Developer Cloud (ODC) custom C# code as you code.</Description>

0 commit comments

Comments
 (0)