File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
main/java/au/com/integradev/delphi/checks
test/java/au/com/integradev/delphi/checks Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
### Changed
15
15
16
16
- Exclude common non-ref-counted interface implementations by default in ` ObjectPassedAsInterface ` .
17
+ - Handle property references in ` ObjectPassedAsInterface ` (in addition to variables/fields).
17
18
18
19
### Fixed
19
20
Original file line number Diff line number Diff line change 32
32
import org .sonar .plugins .communitydelphi .api .ast .PrimaryExpressionNode ;
33
33
import org .sonar .plugins .communitydelphi .api .check .DelphiCheck ;
34
34
import org .sonar .plugins .communitydelphi .api .check .DelphiCheckContext ;
35
+ import org .sonar .plugins .communitydelphi .api .symbol .declaration .PropertyNameDeclaration ;
35
36
import org .sonar .plugins .communitydelphi .api .symbol .declaration .RoutineNameDeclaration ;
36
37
import org .sonar .plugins .communitydelphi .api .symbol .declaration .VariableNameDeclaration ;
37
38
import org .sonar .plugins .communitydelphi .api .type .Type ;
39
+ import org .sonar .plugins .communitydelphi .api .type .Typed ;
38
40
39
41
@ Rule (key = "ObjectPassedAsInterface" )
40
42
public class ObjectPassedAsInterfaceCheck extends DelphiCheck {
@@ -91,11 +93,12 @@ private boolean isObjectReferenceExpression(ExpressionNode expression) {
91
93
}
92
94
93
95
var declaration = ((NameReferenceNode ) maybeName ).getLastName ().getNameDeclaration ();
94
- if (!(declaration instanceof VariableNameDeclaration )) {
96
+ if (!(declaration instanceof VariableNameDeclaration
97
+ || declaration instanceof PropertyNameDeclaration )) {
95
98
return false ;
96
99
}
97
100
98
- Type type = ((VariableNameDeclaration ) declaration ).getType ();
101
+ Type type = ((Typed ) declaration ).getType ();
99
102
100
103
return type .isClass ()
101
104
&& excludedTypesList .stream ().noneMatch (e -> type .is (e ) || type .isDescendantOf (e ));
Original file line number Diff line number Diff line change @@ -67,6 +67,31 @@ void testObjectPassedAsInterfaceShouldAddIssue() {
67
67
.verifyIssues ();
68
68
}
69
69
70
+ @ Test
71
+ void testQualifiedObjectPassedAsInterfaceShouldAddIssue () {
72
+ CheckVerifier .newVerifier ()
73
+ .withCheck (new ObjectPassedAsInterfaceCheck ())
74
+ .onFile (
75
+ new DelphiTestUnitBuilder ()
76
+ .appendDecl ("type" )
77
+ .appendDecl (" TFoo = class(TInterfacedObject, IInterface)" )
78
+ .appendDecl (" end;" )
79
+ .appendDecl (" IBar = interface" )
80
+ .appendDecl (" property Foo: TFoo;" )
81
+ .appendDecl (" end;" )
82
+ .appendDecl (" TBar = class(TInterfacedObject, IBar)" )
83
+ .appendDecl (" end;" )
84
+ .appendDecl ("procedure DoThing(Obj: IInterface);" )
85
+ .appendImpl ("procedure Test;" )
86
+ .appendImpl ("var" )
87
+ .appendImpl (" Intf: IBar;" )
88
+ .appendImpl ("begin" )
89
+ .appendImpl (" Intf := TBar.Create;" )
90
+ .appendImpl (" DoThing(Intf.Foo); // Noncompliant" )
91
+ .appendImpl ("end;" ))
92
+ .verifyIssues ();
93
+ }
94
+
70
95
@ Test
71
96
void testInterfacePassedAsInterfaceShouldNotAddIssue () {
72
97
CheckVerifier .newVerifier ()
You can’t perform that action at this time.
0 commit comments