コード例 #1
0
 private static ProgramState closeResource(
     ProgramState programState, @Nullable final SymbolicValue target) {
   if (target != null) {
     ObjectConstraint oConstraint = openedConstraint(programState, target);
     if (oConstraint != null) {
       return programState.addConstraint(
           target.wrappedValue(), oConstraint.withStatus(Status.CLOSED));
     }
   }
   return programState;
 }
コード例 #2
0
 private static ObjectConstraint openedConstraint(
     ProgramState programState, SymbolicValue value) {
   final Object constraint = programState.getConstraint(value.wrappedValue());
   if (constraint instanceof ObjectConstraint) {
     ObjectConstraint oConstraint = (ObjectConstraint) constraint;
     if (oConstraint.hasStatus(Status.OPENED)) {
       return oConstraint;
     }
   }
   return null;
 }
コード例 #3
0
 @Override
 public void checkEndOfExecutionPath(CheckerContext context, ConstraintManager constraintManager) {
   final List<ObjectConstraint> constraints =
       context.getState().getFieldConstraints(Status.OPENED);
   for (ObjectConstraint constraint : constraints) {
     Tree syntaxNode = constraint.syntaxNode();
     String name = null;
     if (syntaxNode.is(Tree.Kind.NEW_CLASS)) {
       name = ((NewClassTree) syntaxNode).identifier().symbolType().name();
     } else if (syntaxNode.is(Tree.Kind.METHOD_INVOCATION)) {
       name = ((MethodInvocationTree) syntaxNode).symbolType().name();
     }
     if (name != null) {
       context.reportIssue(syntaxNode, this, "Close this \"" + name + "\".");
     }
   }
 }