/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
@Override public ReturnStmt doMerge(ReturnStmt first, ReturnStmt second) { ReturnStmt rs = new ReturnStmt(); rs.setExpr(mergeSingle(first.getExpr(),second.getExpr())); return rs; }
private MethodDeclaration getterDeclaration(EntityField field) { MethodDeclaration decl = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.createReferenceType(field.getType().getSimpleName(), 0), "get" + CaseConverter.pascalCase(field.getName())); BlockStmt body = new BlockStmt(); body.setStmts( Collections.singletonList( new ReturnStmt( new FieldAccessExpr(new ThisExpr(), field.getName())))); decl.setBody(body); return decl; }
getElements.getBody().get().getStatements().add(new ReturnStmt( new NameExpr("elements")));