Merge pull request #11624 from jcogs33/jcogs33/exclude-paramless-constructors-from-dataflowtargetapi

Java/C#: exclude parameterless constructors from `DataFlowTargetApi`
This commit is contained in:
Jami
2022-12-13 10:05:57 -05:00
committed by GitHub
6 changed files with 22 additions and 20 deletions

View File

@@ -358,6 +358,9 @@ class Constructor extends DotNet::Constructor, Callable, Member, Attributable, @
if this.isStatic() then result = this.getParameter(i) else result = this.getParameter(i - 1)
}
/** Holds if this is a constructor without parameters. */
predicate isParameterless() { this.getNumberOfParameters() = 0 }
override string getUndecoratedName() { result = ".ctor" }
}

View File

@@ -38,7 +38,8 @@ private predicate isRelevantForModels(CS::Callable api) {
api.getDeclaringType().getNamespace().getFullName() != "" and
not api instanceof CS::ConversionOperator and
not api instanceof Util::MainMethod and
not api instanceof CS::Destructor
not api instanceof CS::Destructor and
not api.(CS::Constructor).isParameterless()
}
/**

View File

@@ -131,4 +131,15 @@ public class CollectionFlow
{
return a;
}
}
}
// A neutral model should not be created for a parameterless constructor.
public class ParameterlessConstructor
{
public bool IsInitialized;
public ParameterlessConstructor()
{
IsInitialized = true;
}
}