Skip to content
Snippets Groups Projects
Commit 81d41c23 authored by Johannes Mey's avatar Johannes Mey
Browse files

extract java-specific part from analysis (not all parts, though)

parent 2aa86825
No related branches found
No related tags found
No related merge requests found
...@@ -40,16 +40,8 @@ aspect AlreadyClosedAnalysis { ...@@ -40,16 +40,8 @@ aspect AlreadyClosedAnalysis {
/** Check if the reciever of this method access was already closed. */ /** Check if the reciever of this method access was already closed. */
syn boolean MethodAccess.alreadyClosedStream() { syn boolean MethodAccess.alreadyClosedStream() {
// The receiver must be an effectively final local variable (or parameter). if (!isCloseableAccess()) return false;
if (name().equals("close") // Don't check for repeated close() calls.
|| name().equals("toString") || name().equals("toByteArray")
|| !hasPrevExpr() // Does not have a variable or parameter receiver.
|| prevExpr().varDecl() == null // Receiver is not a variable/parameter.
|| !(prevExpr().varDecl().isFinal()
|| prevExpr().varDecl().isEffectivelyFinal()) // Receiver might have changed.
|| !prevExpr().type().isCloseable()) { // Receiver is not instance of java.io.Closeable.
return false;
}
final Variable receiver = prevExpr().varDecl(); final Variable receiver = prevExpr().varDecl();
return null != call().reverseBfs(new CfgVisitor() { return null != call().reverseBfs(new CfgVisitor() {
@Override @Override
...@@ -75,6 +67,18 @@ aspect AlreadyClosedAnalysis { ...@@ -75,6 +67,18 @@ aspect AlreadyClosedAnalysis {
}); });
} }
/**
* Determines if a MethodAccess is an access of a Closable and its expression is an effectively final local variable (or parameter).
*/
syn boolean MethodAccess.isCloseableAccess() = !(
name().equals("close") // Don't check for repeated close() calls.
|| name().equals("toString") || name().equals("toByteArray")
|| !hasPrevExpr() // Does not have a variable or parameter receiver.
|| prevExpr().varDecl() == null // Receiver is not a variable/parameter.
|| !(prevExpr().varDecl().isFinal()
|| prevExpr().varDecl().isEffectivelyFinal()) // Receiver might have changed.
|| !prevExpr().type().isCloseable());
/** Test if the CFG node is a call node with the given variable as receiver. */ /** Test if the CFG node is a call node with the given variable as receiver. */
syn boolean CfgNode.isCall(Variable receiver) = false; syn boolean CfgNode.isCall(Variable receiver) = false;
eq CfgMethodCall.isCall(Variable receiver) = methodAccess().hasReceiver(receiver); eq CfgMethodCall.isCall(Variable receiver) = methodAccess().hasReceiver(receiver);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment