/** * 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>P_INDEX_UPDATER.lazySet(this, newValue)</code> * * @param fieldUpdaterFieldName * @param newValueName * @return */ private static BlockStmt fieldUpdaterLazySet(String fieldUpdaterFieldName, String newValueName) { BlockStmt body = new BlockStmt(); body.addStatement(new ExpressionStmt( methodCallExpr(fieldUpdaterFieldName, "lazySet", new ThisExpr(), new NameExpr(newValueName)))); 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>P_INDEX_UPDATER.lazySet(this, newValue)</code> * * @param fieldUpdaterFieldName * @param newValueName * @return */ private static BlockStmt fieldUpdaterLazySet(String fieldUpdaterFieldName, String newValueName) { BlockStmt body = new BlockStmt(); body.addStatement(new ExpressionStmt( methodCallExpr(fieldUpdaterFieldName, "lazySet", 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>field = newValue</code> * * @param fieldName * @param valueName * @return */ private static BlockStmt fieldAssignment(String fieldName, String valueName) { BlockStmt body = new BlockStmt(); body.addStatement( new ExpressionStmt(new AssignExpr(new NameExpr(fieldName), new NameExpr(valueName), Operator.ASSIGN))); 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>field = newValue</code> * * @param fieldName * @param valueName * @return */ private static BlockStmt fieldAssignment(String fieldName, String valueName) { BlockStmt body = new BlockStmt(); body.addStatement( new ExpressionStmt(new AssignExpr(new NameExpr(fieldName), new NameExpr(valueName), Operator.ASSIGN))); 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 BlockStmt doMerge(BlockStmt first, BlockStmt second) { BlockStmt bs = new BlockStmt(); bs.setStmts(mergeCollectionsInOrder(first.getStmts(),second.getStmts())); return bs; }
/** * creates the compilation unit */ private static CompilationUnit createCU() { CompilationUnit cu = new CompilationUnit(); // set the package cu.setPakage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test"))); // create the type declaration ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass"); ASTHelper.addTypeDeclaration(cu, type); // create a method MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main"); method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC)); ASTHelper.addMember(type, method); // add a parameter to the method Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args"); param.setVarArgs(true); ASTHelper.addParameter(method, param); // add a body to the method BlockStmt block = new BlockStmt(); method.setBody(block); // add a statement do the method body NameExpr clazz = new NameExpr("System"); FieldAccessExpr field = new FieldAccessExpr(clazz, "out"); MethodCallExpr call = new MethodCallExpr(field, "println"); ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!")); ASTHelper.addStmt(block, call); return cu; }
Expression compare = null; List<Expression> update = null; BlockStmt methodBody = new BlockStmt(); ForStmt forStmt = new ForStmt(beginLine, beginColumn, endLine, endColumn, init, compare, update, methodBody);
private BlockStmt createStatementExecuteBlock() { BlockStmt block = new BlockStmt(); MethodCallExpr stmtExecute = new MethodCallExpr(ASTHelper.createNameExpr("stmt"), "execute"); ASTHelper.addArgument(stmtExecute, new StringLiteralExpr(createTableStatement)); ASTHelper.addStmt(block, stmtExecute); return block; }
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; }
migrateMethod.setAnnotations(annotations); BlockStmt block = new BlockStmt(); migrateMethod.setBody(block);
public static BlockStmt mergeBlock(BlockStmt one, BlockStmt two) { if (isAllNull(one, two)) return null; BlockStmt blockStmt = null; if (isAllNotNull(one, two)) { blockStmt = new BlockStmt(); blockStmt.setComment(mergeSelective(one.getComment(), two.getComment())); blockStmt.setStmts(mergeListInOrder(one.getStmts(), two.getStmts())); } else { blockStmt = findFirstNotNull(one, two); } return blockStmt; }
private MethodDeclaration setterDeclaration(EntityField field) { MethodDeclaration decl = new MethodDeclaration(ModifierSet.PUBLIC, new VoidType(), "set" + CaseConverter.pascalCase(field.getName()), Collections.singletonList(new Parameter( ASTHelper.createReferenceType(field.getType().getSimpleName(), 0), new VariableDeclaratorId(field.getName())))); BlockStmt body = new BlockStmt(); body.setStmts( Collections.singletonList( new ExpressionStmt( new AssignExpr( new FieldAccessExpr(new ThisExpr(), field.getName()), ASTHelper.createNameExpr(field.getName()), AssignExpr.Operator.assign )))); decl.setBody(body); return decl; }