diff --git a/java/ql/src/semmle/code/java/deadcode/DeadCode.qll b/java/ql/src/semmle/code/java/deadcode/DeadCode.qll index 95d3ceb2a4f..19f6764b799 100644 --- a/java/ql/src/semmle/code/java/deadcode/DeadCode.qll +++ b/java/ql/src/semmle/code/java/deadcode/DeadCode.qll @@ -97,29 +97,20 @@ class SuppressedConstructor extends Constructor { getNumberOfParameters() = 0 and // Not the compiler-generated constructor itself. not isDefaultConstructor() and - /* - * Verify that there is only one statement, which is the `super()` call. This exists - * even for empty constructors. - */ - + // Verify that there is only one statement, which is the `super()` call. This exists + // even for empty constructors. getBody().(Block).getNumStmt() = 1 and getBody().(Block).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and - /* - * A constructor that is called is not acting to suppress the default constructor. We permit - * calls from suppressed and default constructors - in both cases, they can only come from - * sub-class constructors. - */ - + // A constructor that is called is not acting to suppress the default constructor. We permit + // calls from suppressed and default constructors - in both cases, they can only come from + // sub-class constructors. not exists(Call c | c.getCallee().getSourceDeclaration() = this and not c.getCaller() instanceof SuppressedConstructor and not c.getCaller().(Constructor).isDefaultConstructor() ) and - /* - * If other constructors are declared, then no compiler-generated constructor is added, so - * this constructor is not acting to suppress the default compiler-generated constructor. - */ - + // If other constructors are declared, then no compiler-generated constructor is added, so + // this constructor is not acting to suppress the default compiler-generated constructor. not exists(Constructor other | other = getDeclaringType().getAConstructor() and other != this) } } @@ -130,11 +121,8 @@ class SuppressedConstructor extends Constructor { class NamespaceClass extends RefType { NamespaceClass() { fromSource() and - /* - * All members, apart from the default constructor and, if present, a "suppressed" constructor - * must be static. There must be at least one member apart from the permitted constructors. - */ - + // All members, apart from the default constructor and, if present, a "suppressed" constructor + // must be static. There must be at least one member apart from the permitted constructors. forex(Member m | m.getDeclaringType() = this and not m.(Constructor).isDefaultConstructor() and @@ -174,29 +162,20 @@ class LiveClass extends SourceClassOrInterface { ) or exists(LiveField f | f.getDeclaringType() = this | - /* - * A `serialVersionUID` field is considered to be a live field, but is - * not be enough to be make this class live. - */ - + // A `serialVersionUID` field is considered to be a live field, but is + // not be enough to be make this class live. not f instanceof SerialVersionUIDField ) or ( - /* - * If this is a namespace class, it is live if there is at least one live nested class. - * The definition of `NamespaceClass` is such, that the nested classes must all be static. - * Static methods are handled above. - */ - + // If this is a namespace class, it is live if there is at least one live nested class. + // The definition of `NamespaceClass` is such, that the nested classes must all be static. + // Static methods are handled above. this instanceof NamespaceClass and exists(NestedType r | r.getEnclosingType() = this | r instanceof LiveClass) ) or - /* - * An annotation on the class is reflectively accessed. - */ - + // An annotation on the class is reflectively accessed. exists(ReflectiveAnnotationAccess reflectiveAnnotationAccess | this = reflectiveAnnotationAccess.getInferredClassType() and isLive(reflectiveAnnotationAccess.getEnclosingCallable()) @@ -232,11 +211,8 @@ class DeadClass extends SourceClassOrInterface { * Holds if this dead class is only used within the class itself. */ predicate isUnusedOutsideClass() { - /* - * Accessed externally if any callable in the class has a possible liveness cause outside the - * class. Only one step is required. - */ - + // Accessed externally if any callable in the class has a possible liveness cause outside the + // class. Only one step is required. not exists(Callable c | c = possibleLivenessCause(getACallable()) and not c = getACallable() @@ -264,11 +240,8 @@ class DeadMethod extends Callable { fromSource() and not isLive(this) and not this.(Constructor).isDefaultConstructor() and - /* - * Ignore `SuppressedConstructor`s in `NamespaceClass`es. There is no reason to use a suppressed - * constructor in other cases. - */ - + // Ignore `SuppressedConstructor`s in `NamespaceClass`es. There is no reason to use a suppressed + // constructor in other cases. not ( this instanceof SuppressedConstructor and this.getDeclaringType() instanceof NamespaceClass ) and @@ -276,14 +249,11 @@ class DeadMethod extends Callable { this.(Method).isAbstract() and exists(Method m | m.overridesOrInstantiates+(this.(Method)) | isLive(m)) ) and - /* - * A getter or setter associated with a live JPA field. - * - * These getters and setters are often generated in an ad-hoc way by the developer, which leads to - * methods that are theoretically dead, but uninteresting. We therefore ignore them, so long as - * they are "simple". - */ - + // A getter or setter associated with a live JPA field. + // + // These getters and setters are often generated in an ad-hoc way by the developer, which leads to + // methods that are theoretically dead, but uninteresting. We therefore ignore them, so long as + // they are "simple". not exists(JPAReadField readField | this.getDeclaringType() = readField.getDeclaringType() | this.(GetterMethod).getField() = readField or this.(SetterMethod).getField() = readField @@ -294,11 +264,8 @@ class DeadMethod extends Callable { * Holds if this dead method is already within the scope of a dead class. */ predicate isInDeadScope() { - /* - * We do not need to consider whitelisting because whitelisted classes should not have dead - * methods reported. - */ - + // We do not need to consider whitelisting because whitelisted classes should not have dead + // methods reported. this.getDeclaringType() instanceof DeadClass } diff --git a/java/ql/src/semmle/code/java/deadcode/DeadEnumConstant.qll b/java/ql/src/semmle/code/java/deadcode/DeadEnumConstant.qll index e631eb278ad..1c19a9e20cf 100644 --- a/java/ql/src/semmle/code/java/deadcode/DeadEnumConstant.qll +++ b/java/ql/src/semmle/code/java/deadcode/DeadEnumConstant.qll @@ -58,11 +58,8 @@ predicate exception(EnumConstant e) { values.getParent().(MethodAccess).getMethod().hasName("findThisIn") ) or - /* - * The `valueOf` method is called, meaning that depending on the string any constant - * could be retrieved. - */ - + // The `valueOf` method is called, meaning that depending on the string any constant + // could be retrieved. exists(MethodAccess valueOf | valueOf.getMethod().getDeclaringType() = t | valueOf.getMethod().hasName("valueOf") ) diff --git a/java/ql/src/semmle/code/java/deadcode/DeadField.qll b/java/ql/src/semmle/code/java/deadcode/DeadField.qll index 0ba55c11411..2ea94907718 100644 --- a/java/ql/src/semmle/code/java/deadcode/DeadField.qll +++ b/java/ql/src/semmle/code/java/deadcode/DeadField.qll @@ -39,10 +39,7 @@ class LiveField extends SourceField { isLive(access.getEnclosingCallable()) or exists(Annotation a | - /* - * This is an access used in an annotation, either directly, or within the expression. - */ - + // This is an access used in an annotation, either directly, or within the expression. a.getValue(_) = access.getParent*() | // The annotated element is a live callable. @@ -51,13 +48,9 @@ class LiveField extends SourceField { isLive(a.getAnnotatedElement().(LocalVariableDecl).getEnclosingCallable()) or // The annotated element is a live field. a.getAnnotatedElement() instanceof LiveField or - /* - * The annotated element is a live source class or interface. - * - * Note: We ignore annotation values on library classes, because they should only refer to - * fields in library classes, not `fromSource()` fields. - */ - + // The annotated element is a live source class or interface. + // Note: We ignore annotation values on library classes, because they should only refer to + // fields in library classes, not `fromSource()` fields. a.getAnnotatedElement() instanceof LiveClass ) ) diff --git a/java/ql/src/semmle/code/java/deadcode/EntryPoints.qll b/java/ql/src/semmle/code/java/deadcode/EntryPoints.qll index 94d54e5610c..aef97efd309 100644 --- a/java/ql/src/semmle/code/java/deadcode/EntryPoints.qll +++ b/java/ql/src/semmle/code/java/deadcode/EntryPoints.qll @@ -72,12 +72,9 @@ class LibOverrideMethodEntry extends CallableEntryPoint { LibOverrideMethodEntry() { this.fromSource() and exists(Method libraryMethod | this.(Method).overrides*(libraryMethod) | - /* - * The library method must not come from source, either directly, or added automatically. - * For example, `values()` and `valueOf(...)` methods are not `fromSource()`, but are added - * automatically to source types. - */ - + // The library method must not come from source, either directly, or added automatically. + // For example, `values()` and `valueOf(...)` methods are not `fromSource()`, but are added + // automatically to source types. not libraryMethod.getDeclaringType().getSourceDeclaration().fromSource() ) } @@ -103,11 +100,8 @@ library class JacksonReflectivelyConstructedClass extends ReflectivelyConstructe JacksonReflectivelyConstructedClass() { this instanceof JacksonDeserializableType } override Callable getALiveCallable() { - /* - * Constructors may be called by Jackson, if they are a no-arg, they have a suitable annotation, - * or inherit a suitable annotation through a mixin. - */ - + // Constructors may be called by Jackson, if they are a no-arg, they have a suitable annotation, + // or inherit a suitable annotation through a mixin. result = getAConstructor() and ( result.getNumberOfParameters() = 0 or @@ -265,11 +259,8 @@ class JaxRsBeanParamConstructorEntryPoint extends JaxRsBeanParamConstructor, Cal */ class ManagedBeanImplEntryPoint extends EntryPoint, RegisteredManagedBeanImpl { override Method getALiveCallable() { - /* - * Find the method that will be called for each method on each managed bean that this class - * implements. - */ - + // Find the method that will be called for each method on each managed bean that this class + // implements. this.inherits(result) and result.(Method).overrides(getAnImplementedManagedBean().getAMethod()) } diff --git a/java/ql/src/semmle/code/java/deadcode/TestEntryPoints.qll b/java/ql/src/semmle/code/java/deadcode/TestEntryPoints.qll index d879f65339e..6ccd7502b4a 100644 --- a/java/ql/src/semmle/code/java/deadcode/TestEntryPoints.qll +++ b/java/ql/src/semmle/code/java/deadcode/TestEntryPoints.qll @@ -82,12 +82,9 @@ class JUnitCategory extends WhitelistedLiveClass { */ class TestNGReflectivelyConstructedListener extends ReflectivelyConstructedClass { TestNGReflectivelyConstructedListener() { - /* - * Consider any class that implements a TestNG listener interface to be live. Listeners can be - * specified on the command line, in `testng.xml` files and in Ant build files, so it is safest - * to assume that all such listeners are live. - */ - + // Consider any class that implements a TestNG listener interface to be live. Listeners can be + // specified on the command line, in `testng.xml` files and in Ant build files, so it is safest + // to assume that all such listeners are live. this instanceof TestNGListenerImpl } } @@ -154,12 +151,9 @@ class CucumberConstructedClass extends ReflectivelyConstructedClass { } override Callable getALiveCallable() { - /* - * Consider any constructor to be live - Cucumber calls a runtime-specified dependency - * injection framework (possibly an in-built one) to construct these instances, so any - * constructor could be called. - */ - + // Consider any constructor to be live - Cucumber calls a runtime-specified dependency + // injection framework (possibly an in-built one) to construct these instances, so any + // constructor could be called. result = getAConstructor() } } diff --git a/java/ql/src/semmle/code/java/deadcode/WebEntryPoints.qll b/java/ql/src/semmle/code/java/deadcode/WebEntryPoints.qll index 15f6808743c..b31a04e11be 100644 --- a/java/ql/src/semmle/code/java/deadcode/WebEntryPoints.qll +++ b/java/ql/src/semmle/code/java/deadcode/WebEntryPoints.qll @@ -10,12 +10,9 @@ import semmle.code.java.frameworks.Servlets class ServletConstructedClass extends ReflectivelyConstructedClass { ServletConstructedClass() { this instanceof ServletClass and - /* - * If we have seen any `web.xml` files, this servlet will be considered to be live only if it is - * referred to as a servlet-class in at least one. If no `web.xml` files are found, we assume - * that XML extraction was not enabled, and therefore consider all `Servlet` classes as live. - */ - + // If we have seen any `web.xml` files, this servlet will be considered to be live only if it is + // referred to as a servlet-class in at least one. If no `web.xml` files are found, we assume + // that XML extraction was not enabled, and therefore consider all `Servlet` classes as live. ( isWebXMLIncluded() implies @@ -33,12 +30,9 @@ class ServletConstructedClass extends ReflectivelyConstructedClass { class ServletListenerClass extends ReflectivelyConstructedClass { ServletListenerClass() { getAnAncestor() instanceof ServletWebXMLListenerType and - /* - * If we have seen any `web.xml` files, this listener will be considered to be live only if it is - * referred to as a listener-class in at least one. If no `web.xml` files are found, we assume - * that XML extraction was not enabled, and therefore consider all listener classes as live. - */ - + // If we have seen any `web.xml` files, this listener will be considered to be live only if it is + // referred to as a listener-class in at least one. If no `web.xml` files are found, we assume + // that XML extraction was not enabled, and therefore consider all listener classes as live. ( isWebXMLIncluded() implies @@ -54,12 +48,9 @@ class ServletListenerClass extends ReflectivelyConstructedClass { class ServletFilterClass extends ReflectivelyConstructedClass { ServletFilterClass() { getASupertype*().hasQualifiedName("javax.servlet", "Filter") and - /* - * If we have seen any `web.xml` files, this filter will be considered to be live only if it is - * referred to as a filter-class in at least one. If no `web.xml` files are found, we assume - * that XML extraction was not enabled, and therefore consider all filter classes as live. - */ - + // If we have seen any `web.xml` files, this filter will be considered to be live only if it is + // referred to as a filter-class in at least one. If no `web.xml` files are found, we assume + // that XML extraction was not enabled, and therefore consider all filter classes as live. (isWebXMLIncluded() implies exists(WebFilterClass filterClass | this = filterClass.getClass())) } } @@ -77,11 +68,8 @@ class GWTEntryPointConstructedClass extends ReflectivelyConstructedClass { class GWTServletClass extends ReflectivelyConstructedClass { GWTServletClass() { this instanceof ServletClass and - /* - * There must be evidence that GWT is being used, otherwise missing `*.gwt.xml` files could cause - * all `Servlet`s to be live. - */ - + // There must be evidence that GWT is being used, otherwise missing `*.gwt.xml` files could cause + // all `Servlet`s to be live. exists(Package p | p.getName().matches("com.google.gwt%")) and ( isGwtXmlIncluded() @@ -102,12 +90,9 @@ class GwtUiBinderEntryPoint extends CallableEntryPoint { or this instanceof GwtUiHandler or - /* - * The UiBinder framework constructs instances of classes specified in the template files. If a - * no-arg constructor is present, that may be called automatically. Or, if there is a - * constructor marked as a `UiConstructor`, then that may be called instead. - */ - + // The UiBinder framework constructs instances of classes specified in the template files. If a + // no-arg constructor is present, that may be called automatically. Or, if there is a + // constructor marked as a `UiConstructor`, then that may be called instead. this instanceof GwtUiConstructor or exists(GwtComponentTemplateElement componentElement |