@Override public void visit(ReturnStmt n, Void arg) { out.println("ReturnStmt: " + (extended ? n : n.getExpression())); super.visit(n, arg); }
/** * Generates something like <code>return field</code> * * @param fieldName * @return */ private static BlockStmt returnField(String fieldName) { BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt(fieldName)); return body; }
@Override public ReturnStmt doMerge(ReturnStmt first, ReturnStmt second) { ReturnStmt rs = new ReturnStmt(); rs.setExpr(mergeSingle(first.getExpr(),second.getExpr())); return rs; }
private void addCastExpr(Statement stmt, Type castType) { ReturnStmt rstmt = (ReturnStmt) stmt; Optional<Expression> o_expr = rstmt.getExpression(); Expression expr = o_expr.isPresent() ? o_expr.get() : null; CastExpr ce = new CastExpr(castType, expr); rstmt.setExpression(ce); // removes the parent link from expr if (expr != null) { expr.setParentNode(ce); // restore it } }
((CastExpr)parent).setExpression(v); } else if (parent instanceof ReturnStmt) { ((ReturnStmt)parent).setExpression(v); } else if (parent instanceof AssignExpr) { ((AssignExpr)parent).setValue(v);
@Override public void visit(final ReturnStmt n, final Context ctx) { this.type = type(n.getExpr(), ctx); }
private List<Expression> getAllReturnExpressions(BlockStmt blockStmt) { return Navigator.findAllNodesOfGivenClass(blockStmt, ReturnStmt.class).stream() .filter(r -> r.getExpression().isPresent()) .map(r -> r.getExpression().get()) .collect(Collectors.toList()); }
/** * Generates something like <code>return field</code> * * @param fieldName * @return */ private static BlockStmt returnField(String fieldName) { BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt(fieldName)); return body; }
Expression expr = ( ( ReturnStmt ) lastStatement ).getExpr(); if ( expr instanceof ClassExpr )
private List<Expression> getAllReturnExpressions(BlockStmt blockStmt) { return blockStmt.findAll(ReturnStmt.class).stream() .filter(r -> r.getExpression().isPresent()) .map(r -> r.getExpression().get()) .collect(toList()); }
/** * Generates something like * <code>return P_INDEX_UPDATER.getAndSet(this, newValue)</code> * * @param fieldUpdaterFieldName * @param newValueName * @return */ private static BlockStmt fieldUpdaterGetAndSet(String fieldUpdaterFieldName, String newValueName) { BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt( methodCallExpr(fieldUpdaterFieldName, "getAndSet", new ThisExpr(), new NameExpr(newValueName)))); return body; }
continue; Expression returnStmtExpr = ((ReturnStmt) stmt).getExpr(); if (!(returnStmtExpr instanceof MethodCallExpr)) { continue;
private List<Expression> getAllReturnExpressions(BlockStmt blockStmt) { return Navigator.findAllNodesOfGivenClass(blockStmt, ReturnStmt.class).stream() .filter(r -> r.getExpression().isPresent()) .map(r -> r.getExpression().get()) .collect(Collectors.toList()); }
/** * Generates something like * <code>return P_INDEX_UPDATER.compareAndSet(this, expectedValue, newValue)</code> * * @param fieldUpdaterFieldName * @param expectedValueName * @param newValueName * @return */ private static BlockStmt fieldUpdaterCompareAndSet(String fieldUpdaterFieldName, String expectedValueName, String newValueName) { BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt(methodCallExpr(fieldUpdaterFieldName, "compareAndSet", new ThisExpr(), new NameExpr(expectedValueName), new NameExpr(newValueName)))); return body; }
continue; Expression returnStmtExpr = ((ReturnStmt) stmt).getExpr(); if (!(returnStmtExpr instanceof MethodCallExpr)) { continue;
private boolean isValueCompatibleBlock(Statement statement) { // A block lambda body is value-compatible if it cannot complete normally (ยง14.21) and every return statement // in the block has the form return Expression;. if (statement instanceof BlockStmt) { if (!ControlFlowLogic.getInstance().canCompleteNormally(statement)) { return true; } List<ReturnStmt> returnStmts = statement.findAll(ReturnStmt.class); return returnStmts.stream().allMatch(r -> r.getExpression().isPresent()); } return false; }
/** * Generates something like * <code>return P_INDEX_UPDATER.compareAndSet(this, expectedValue, newValue)</code> * * @param fieldUpdaterFieldName * @param expectedValueName * @param newValueName * @return */ private static BlockStmt fieldUpdaterCompareAndSet(String fieldUpdaterFieldName, String expectedValueName, String newValueName) { BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt(methodCallExpr(fieldUpdaterFieldName, "compareAndSet", new ThisExpr(), new NameExpr(expectedValueName), new NameExpr(newValueName)))); return body; }
protected void prepareReturnStmt(MethodDeclaration methodDeclaration, ReturnStmt returnStmt) { returnStmt.getExpression().ifPresent(expression -> { String returnStmtStr = expression.toString(); Matcher matcher = RETURN_STMT_PATTERN.matcher(returnStmtStr); if (!returnMap.containsKey(methodDeclaration.getNameAsString())) { returnMap.put(methodDeclaration.getNameAsString(), DfCollectionUtil.newArrayList()); } returnMap.get(methodDeclaration.getNameAsString()).add(matcher.find() ? matcher.group(0) : "##unanalyzable##"); }); } }
/** * Given a method declaration node this method will replace it's code and * signature with code to redirect all calls to it to the * <code>newMethodName</code>. Method signatures of both methods must match * exactly. * * @param methodToPatch * @param toMethodName * @param returnType * @param parameters */ private static void patchMethodAsDepreciatedRedirector(MethodDeclaration methodToPatch, String toMethodName, Type returnType, Parameter... parameters) { methodToPatch.setType(returnType); for (Parameter parameter : parameters) { methodToPatch.addParameter(parameter); } methodToPatch.addAnnotation(new MarkerAnnotationExpr("Deprecated")); methodToPatch.setJavadocComment( formatMultilineJavadoc(1, "@deprecated This was renamed to " + toMethodName + " please migrate")); MethodCallExpr methodCall = methodCallExpr("this", toMethodName); for (Parameter parameter : parameters) { methodCall.addArgument(new NameExpr(parameter.getName())); } BlockStmt body = new BlockStmt(); body.addStatement(new ReturnStmt(methodCall)); methodToPatch.setBody(body); }