Java: Autoformat 1.

This commit is contained in:
Anders Schack-Mulligen
2018-10-11 10:04:21 +02:00
parent 62ef811169
commit 62e942bb8b

View File

@@ -11,31 +11,96 @@
* correctness * correctness
* logic * logic
*/ */
import java import java
import semmle.code.java.Collections import semmle.code.java.Collections
predicate containerAccess(string package, string type, int p, string signature, int i) { predicate containerAccess(string package, string type, int p, string signature, int i) {
package = "java.util" and type = "Collection" and p = 0 and signature = "contains(java.lang.Object)" and i = 0 or package = "java.util" and
package = "java.util" and type = "Dictionary" and p = 0 and signature = "get(java.lang.Object)" and i = 0 or type = "Collection" and
package = "java.util" and type = "Hashtable" and p = 1 and signature = "contains(java.lang.Object)" and i = 0 or p = 0 and
package = "java.util" and type = "List" and p = 0 and signature = "indexOf(java.lang.Object)" and i = 0 or signature = "contains(java.lang.Object)" and
package = "java.util" and type = "List" and p = 0 and signature = "lastIndexOf(java.lang.Object)" and i = 0 or i = 0
package = "java.util" and type = "Map" and p = 0 and signature = "get(java.lang.Object)" and i = 0 or or
package = "java.util" and type = "Map" and p = 0 and signature = "getOrDefault(java.lang.Object,java.lang.Object)" and i = 0 or package = "java.util" and
package = "java.util" and type = "Map" and p = 0 and signature = "containsKey(java.lang.Object)" and i = 0 or type = "Dictionary" and
package = "java.util" and type = "Map" and p = 1 and signature = "containsValue(java.lang.Object)" and i = 0 or p = 0 and
package = "java.util" and type = "Stack" and p = 0 and signature = "search(java.lang.Object)" and i = 0 or signature = "get(java.lang.Object)" and
package = "java.util" and type = "Vector" and p = 0 and signature = "indexOf(java.lang.Object,int)" and i = 0 or i = 0
package = "java.util" and type = "Vector" and p = 0 and signature = "lastIndexOf(java.lang.Object,int)" and i = 0 or or
package = "java.util.concurrent" and type = "ConcurrentHashMap" and p = 1 and signature = "contains(java.lang.Object)" and i = 0 package = "java.util" and
type = "Hashtable" and
p = 1 and
signature = "contains(java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "List" and
p = 0 and
signature = "indexOf(java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "List" and
p = 0 and
signature = "lastIndexOf(java.lang.Object)" and
i = 0
or
package = "java.util" and type = "Map" and p = 0 and signature = "get(java.lang.Object)" and i = 0
or
package = "java.util" and
type = "Map" and
p = 0 and
signature = "getOrDefault(java.lang.Object,java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "Map" and
p = 0 and
signature = "containsKey(java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "Map" and
p = 1 and
signature = "containsValue(java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "Stack" and
p = 0 and
signature = "search(java.lang.Object)" and
i = 0
or
package = "java.util" and
type = "Vector" and
p = 0 and
signature = "indexOf(java.lang.Object,int)" and
i = 0
or
package = "java.util" and
type = "Vector" and
p = 0 and
signature = "lastIndexOf(java.lang.Object,int)" and
i = 0
or
package = "java.util.concurrent" and
type = "ConcurrentHashMap" and
p = 1 and
signature = "contains(java.lang.Object)" and
i = 0
} }
class MismatchedContainerAccess extends MethodAccess { class MismatchedContainerAccess extends MethodAccess {
MismatchedContainerAccess() { MismatchedContainerAccess() {
exists(string package, string type, int i | exists(string package, string type, int i |
containerAccess(package, type, _, getCallee().getSignature(), i) containerAccess(package, type, _, getCallee().getSignature(), i)
| |
getCallee().getDeclaringType().getASupertype*().getSourceDeclaration().hasQualifiedName(package, type) and getCallee()
.getDeclaringType()
.getASupertype*()
.getSourceDeclaration()
.hasQualifiedName(package, type) and
getCallee().getParameter(i).getType() instanceof TypeObject getCallee().getParameter(i).getType() instanceof TypeObject
) )
} }
@@ -47,7 +112,7 @@ class MismatchedContainerAccess extends MethodAccess {
RefType getReceiverElementType(int i) { RefType getReceiverElementType(int i) {
exists(RefType t, GenericType g, string package, string type, int p | exists(RefType t, GenericType g, string package, string type, int p |
containerAccess(package, type, p, getCallee().getSignature(), i) containerAccess(package, type, p, getCallee().getSignature(), i)
| |
t = getCallee().getDeclaringType() and t = getCallee().getDeclaringType() and
t.getASupertype*().getSourceDeclaration() = g and t.getASupertype*().getSourceDeclaration() = g and
g.hasQualifiedName(package, type) and g.hasQualifiedName(package, type) and
@@ -71,5 +136,6 @@ where
typearg = ma.getReceiverElementType(idx).getSourceDeclaration() and typearg = ma.getReceiverElementType(idx).getSourceDeclaration() and
argtype = ma.getArgumentType(idx) and argtype = ma.getArgumentType(idx) and
not haveIntersection(typearg, argtype) not haveIntersection(typearg, argtype)
select ma.getArgument(idx), "Actual argument type '" + argtype.getName() + "'" select ma.getArgument(idx),
+ " is incompatible with expected argument type '" + typearg.getName() + "'." "Actual argument type '" + argtype.getName() + "'" +
" is incompatible with expected argument type '" + typearg.getName() + "'."