Java: Autoformat most queries.

This commit is contained in:
Anders Schack-Mulligen
2018-10-10 17:49:12 +02:00
parent 85cca69721
commit dd5a8f0c14
443 changed files with 2548 additions and 2043 deletions

View File

@@ -8,16 +8,13 @@
* @id java/missing-override-annotation
* @tags maintainability
*/
import java
class OverridingMethod extends Method {
OverridingMethod() {
exists(Method m | this.overrides(m))
}
OverridingMethod() { exists(Method m | this.overrides(m)) }
predicate isOverrideAnnotated() {
this.getAnAnnotation() instanceof OverrideAnnotation
}
predicate isOverrideAnnotated() { this.getAnAnnotation() instanceof OverrideAnnotation }
}
from OverridingMethod m, Method overridden
@@ -26,5 +23,5 @@ where
m.overrides(overridden) and
not m.isOverrideAnnotated() and
not exists(FunctionalExpr mref | mref.asMethod() = m)
select m, "This method overrides $@; it is advisable to add an Override annotation.",
overridden, overridden.getDeclaringType() + "." + overridden.getName()
select m, "This method overrides $@; it is advisable to add an Override annotation.", overridden,
overridden.getDeclaringType() + "." + overridden.getName()

View File

@@ -9,6 +9,7 @@
* @id java/non-final-immutable-field
* @tags reliability
*/
import java
class Initialization extends Callable {
@@ -41,7 +42,8 @@ class ImmutableField extends Field {
forall(FieldAccess fw, AnyAssignment ae |
fw.getField().getSourceDeclaration() = this and
fw = ae.getDest()
| ae.getEnclosingCallable().getDeclaringType() = this.getDeclaringType() and
|
ae.getEnclosingCallable().getDeclaringType() = this.getDeclaringType() and
ae.getEnclosingCallable() instanceof Initialization
)
}
@@ -49,4 +51,5 @@ class ImmutableField extends Field {
from ImmutableField f
where not f.isFinal()
select f, "This immutable field is not declared final but is only assigned to during initialization."
select f,
"This immutable field is not declared final but is only assigned to during initialization."

View File

@@ -8,6 +8,7 @@
* @id java/non-private-field
* @tags maintainability
*/
import java
import semmle.code.java.JDKAnnotations

View File

@@ -10,10 +10,10 @@
* non-attributable
* external/cwe/cwe-477
*/
import java
private
predicate isDeprecatedCallable(Callable c) {
private predicate isDeprecatedCallable(Callable c) {
c.getAnAnnotation() instanceof DeprecatedAnnotation or
exists(c.getDoc().getJavadoc().getATag("@deprecated"))
}
@@ -24,5 +24,5 @@ where
isDeprecatedCallable(c) and
// Exclude deprecated calls from within deprecated code.
not isDeprecatedCallable(ca.getCaller())
select ca, "Invoking $@ should be avoided because it has been deprecated.",
c, c.getDeclaringType() + "." + c.getName()
select ca, "Invoking $@ should be avoided because it has been deprecated.", c,
c.getDeclaringType() + "." + c.getName()

View File

@@ -19,9 +19,10 @@ RefType getTaggedType(ThrowsTag tag) {
predicate canThrow(Callable callable, RefType exception) {
exists(string uncheckedException |
uncheckedException = "RuntimeException" or uncheckedException = "Error"
|
|
exception.getASupertype*().hasQualifiedName("java.lang", uncheckedException)
) or
)
or
callable.getAnException().getType().getASubtype*() = exception
}
@@ -31,4 +32,5 @@ where
docMethod.getDoc().getJavadoc().getAChild*() = throwsTag and
not canThrow(docMethod, thrownType)
select throwsTag,
"Javadoc for " + docMethod + " claims to throw " + thrownType.getName() + " but this is impossible."
"Javadoc for " + docMethod + " claims to throw " + thrownType.getName() +
" but this is impossible."

View File

@@ -8,9 +8,11 @@
* @id java/undocumented-function
* @tags maintainability
*/
import java
import JavadocCommon
from DocuCallable c
where not c.hasAcceptableDocText()
select c, "This " + c.toMethodOrConstructorString() + " does not have a non-trivial Javadoc comment."
select c,
"This " + c.toMethodOrConstructorString() + " does not have a non-trivial Javadoc comment."

View File

@@ -8,6 +8,7 @@
* @id java/undocumented-parameter
* @tags maintainability
*/
import java
import JavadocCommon

View File

@@ -8,6 +8,7 @@
* @id java/undocumented-return-value
* @tags maintainability
*/
import java
import JavadocCommon

View File

@@ -8,6 +8,7 @@
* @id java/undocumented-exception
* @tags maintainability
*/
import java
import JavadocCommon
@@ -18,5 +19,6 @@ where
e.getType() = t and
not c.hasAcceptableThrowsTag(e)
)
select c, "This " + c.toMethodOrConstructorString() + " throws $@ but does not have a corresponding Javadoc tag.",
t, t.getName()
select c,
"This " + c.toMethodOrConstructorString() +
" throws $@ but does not have a corresponding Javadoc tag.", t, t.getName()

View File

@@ -8,6 +8,7 @@
* @id java/undocumented-type
* @tags maintainability
*/
import java
import JavadocCommon

View File

@@ -13,20 +13,17 @@ import java
from Callable callable, ParamTag paramTag, string what, string msg
where
callable.(Documentable).getJavadoc().getAChild() = paramTag and
( if callable instanceof Constructor
then what = "constructor"
else what = "method"
) and
if exists(paramTag.getParamName()) then (
(if callable instanceof Constructor then what = "constructor" else what = "method") and
if exists(paramTag.getParamName())
then (
// The tag's value is neither matched by a callable parameter name ...
not callable.getAParameter().getName() = paramTag.getParamName() and
// ... nor by a type parameter name.
not exists(TypeVariable tv | tv.getGenericCallable() = callable |
"<" + tv.getName() + ">" = paramTag.getParamName()
) and
msg = "@param tag \"" + paramTag.getParamName()
+ "\" does not match any actual parameter of " + what + " \""
+ callable.getName() + "()\"."
msg = "@param tag \"" + paramTag.getParamName() + "\" does not match any actual parameter of " +
what + " \"" + callable.getName() + "()\"."
) else
// The tag has no value at all.
msg = "This @param tag does not have a value."

View File

@@ -8,6 +8,7 @@
* @id java/use-of-clone-method
* @tags reliability
*/
import java
class ObjectCloneMethod extends Method {

View File

@@ -8,6 +8,7 @@
* @id java/override-of-clone-method
* @tags reliability
*/
import java
class ObjectCloneMethod extends Method {

View File

@@ -8,6 +8,7 @@
* @id java/use-of-cloneable-interface
* @tags reliability
*/
import java
from RefType t

View File

@@ -7,6 +7,7 @@
* @id java/override-of-finalize-method
* @tags reliability
*/
import java
class ObjectFinalizeMethod extends Method {

View File

@@ -7,6 +7,7 @@
* @id java/misnamed-constant
* @tags maintainability
*/
import java
import NamingConventionsCommon

View File

@@ -7,6 +7,7 @@
* @id java/misnamed-function
* @tags maintainability
*/
import java
from Method m

View File

@@ -7,6 +7,7 @@
* @id java/misnamed-package
* @tags maintainability
*/
import java
from RefType t, Package p
@@ -14,4 +15,6 @@ where
p = t.getPackage() and
t.fromSource() and
not p.getName().toLowerCase() = p.getName()
select t, "This type belongs to the package " + p.getName() + ", which should not include uppercase letters."
select t,
"This type belongs to the package " + p.getName() +
", which should not include uppercase letters."

View File

@@ -7,6 +7,7 @@
* @id java/misnamed-type
* @tags maintainability
*/
import java
from RefType t

View File

@@ -7,6 +7,7 @@
* @id java/misnamed-variable
* @tags maintainability
*/
import java
import NamingConventionsCommon

View File

@@ -7,12 +7,14 @@
* @id java/multiple-statements-on-same-line
* @tags maintainability
*/
import java
predicate lineDefinesEnum(File f, int line) {
exists(Location l |
exists(EnumType e | e.getLocation() = l) or
exists(EnumConstant e | e.getLocation() = l) |
exists(EnumConstant e | e.getLocation() = l)
|
f = l.getFile() and line = l.getStartLine()
)
}

View File

@@ -8,6 +8,7 @@
* @id java/raw-constructor-invocation
* @tags maintainability
*/
import java
from ClassInstanceExpr cie

View File

@@ -8,6 +8,7 @@
* @id java/raw-return-type
* @tags maintainability
*/
import java
from Method m

View File

@@ -8,6 +8,7 @@
* @id java/raw-variable
* @tags maintainability
*/
import java
from Variable v