Java: add isParameterless predicate to Constructor class

This commit is contained in:
Jami Cogswell
2022-12-09 15:51:40 -05:00
parent 083b8d1de6
commit cde93a39cd
2 changed files with 7 additions and 6 deletions

View File

@@ -638,6 +638,9 @@ class Constructor extends Callable, @constructor {
/** Holds if this is a default constructor, not explicitly declared in source code. */
predicate isDefaultConstructor() { isDefConstr(this) }
/** Holds if this is a constructor without parameters. */
predicate isParameterless() { this.getNumberOfParameters() = 0 }
override Constructor getSourceDeclaration() { constrs(this, _, _, _, _, result) }
override string getSignature() { constrs(this, _, result, _, _, _) }

View File

@@ -31,16 +31,14 @@ private string containerAsJar(Container container) {
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
}
/** Holds if the given callable is a constructor without parameters. */
private predicate isParameterlessConstructor(Callable c) {
c instanceof Constructor and c.getNumberOfParameters() = 0
}
/** Holds if the given callable is part of a common testing library or framework. */
private predicate isTestLibrary(Callable c) { c.getDeclaringType() instanceof TestLibrary }
/** Holds if the given callable is not worth supporting. */
private predicate isUninteresting(Callable c) { isTestLibrary(c) or isParameterlessConstructor(c) }
private predicate isUninteresting(Callable c) {
isTestLibrary(c) or
c.(Constructor).isParameterless()
}
/**
* An external API from either the Standard Library or a 3rd party library.