Skip to content

Commit cde93a3

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add isParameterless predicate to Constructor class
1 parent 083b8d1 commit cde93a3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ class Constructor extends Callable, @constructor {
638638
/** Holds if this is a default constructor, not explicitly declared in source code. */
639639
predicate isDefaultConstructor() { isDefConstr(this) }
640640

641+
/** Holds if this is a constructor without parameters. */
642+
predicate isParameterless() { this.getNumberOfParameters() = 0 }
643+
641644
override Constructor getSourceDeclaration() { constrs(this, _, _, _, _, result) }
642645

643646
override string getSignature() { constrs(this, _, result, _, _, _) }

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ private string containerAsJar(Container container) {
3131
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
3232
}
3333

34-
/** Holds if the given callable is a constructor without parameters. */
35-
private predicate isParameterlessConstructor(Callable c) {
36-
c instanceof Constructor and c.getNumberOfParameters() = 0
37-
}
38-
3934
/** Holds if the given callable is part of a common testing library or framework. */
4035
private predicate isTestLibrary(Callable c) { c.getDeclaringType() instanceof TestLibrary }
4136

4237
/** Holds if the given callable is not worth supporting. */
43-
private predicate isUninteresting(Callable c) { isTestLibrary(c) or isParameterlessConstructor(c) }
38+
private predicate isUninteresting(Callable c) {
39+
isTestLibrary(c) or
40+
c.(Constructor).isParameterless()
41+
}
4442

4543
/**
4644
* An external API from either the Standard Library or a 3rd party library.

0 commit comments

Comments
 (0)