diff --git a/java/ql/src/Violations of Best Practice/Boxed Types/BoxedVariable.ql b/java/ql/src/Violations of Best Practice/Boxed Types/BoxedVariable.ql index 4f8ed49e010c..a5523845c243 100644 --- a/java/ql/src/Violations of Best Practice/Boxed Types/BoxedVariable.ql +++ b/java/ql/src/Violations of Best Practice/Boxed Types/BoxedVariable.ql @@ -39,6 +39,9 @@ predicate notDeliberatelyBoxed(LocalBoxedVar v) { ) } +pragma[nomagic] +int callableGetNumberOfParameters(Callable c) { result = c.getNumberOfParameters() } + /** * Replacing the type of a boxed variable with the corresponding primitive type may affect * overload resolution. If this is the case then the boxing is most likely intentional and @@ -52,7 +55,7 @@ predicate affectsOverload(LocalBoxedVar v) { c1.getParameterType(i) instanceof RefType and c2.getParameterType(i) instanceof PrimitiveType and c1.getName() = c2.getName() and - c1.getNumberOfParameters() = c2.getNumberOfParameters() + callableGetNumberOfParameters(c1) = callableGetNumberOfParameters(c2) ) } diff --git a/java/ql/src/semmle/code/Location.qll b/java/ql/src/semmle/code/Location.qll index 92b92fc69edb..a34bba9ddc7c 100755 --- a/java/ql/src/semmle/code/Location.qll +++ b/java/ql/src/semmle/code/Location.qll @@ -84,6 +84,7 @@ class Top extends @top { int getNumberOfCommentLines() { numlines(this, _, _, result) } /** Gets a textual representation of this element. */ + cached string toString() { hasName(this, result) } } diff --git a/java/ql/src/semmle/code/java/deadcode/DeadCode.qll b/java/ql/src/semmle/code/java/deadcode/DeadCode.qll index 9c7d7ba4a533..9749413a23c4 100644 --- a/java/ql/src/semmle/code/java/deadcode/DeadCode.qll +++ b/java/ql/src/semmle/code/java/deadcode/DeadCode.qll @@ -301,7 +301,7 @@ class RootdefCallable extends Callable { } } -pragma[noinline] +pragma[nomagic] private predicate overrideAccess(Callable c, int i) { exists(Method m | m.overridesOrInstantiates+(c) | exists(m.getParameter(i).getAnAccess())) } diff --git a/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll b/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll index ed68cd395fbc..c704320657f6 100644 --- a/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll +++ b/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll @@ -61,19 +61,29 @@ class ClientSideGwtCompilationUnit extends GwtCompilationUnit { } } -/** Auxiliary predicate: `jsni` is a JSNI comment associated with method `m`. */ -private predicate jsniComment(Javadoc jsni, Method m) { +private predicate jsni(Javadoc jsni, File file, int startline) { // The comment must start with `-{` ... jsni.getChild(0).getText().matches("-{%") and // ... and it must end with `}-`. jsni.getChild(jsni.getNumChild() - 1).getText().matches("%}-") and - // The associated callable must be marked as `native` ... + file = jsni.getFile() and + startline = jsni.getLocation().getStartLine() +} + +private predicate nativeMethodLines(Method m, File file, int line) { m.isNative() and - // ... and the comment has to be contained in `m`. - jsni.getFile() = m.getFile() and - jsni.getLocation().getStartLine() in [m.getLocation().getStartLine() .. m - .getLocation() - .getEndLine()] + file = m.getFile() and + line in [m.getLocation().getStartLine() .. m.getLocation().getEndLine()] +} + +/** Auxiliary predicate: `jsni` is a JSNI comment associated with method `m`. */ +private predicate jsniComment(Javadoc jsni, Method m) { + exists(File file, int line | + jsni(jsni, file, line) and + // The associated callable must be marked as `native` + // and the comment has to be contained in `m`. + nativeMethodLines(m, file, line) + ) } /**