@Override public JavaClassSource extendSuperType(final Class<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
@Override public JavaClassSource extendSuperType(JavaClass<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
@Override public JavaClassSource extendSuperType(JavaClass<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
@Override public JavaClassSource extendSuperType(final Class<?> type) { setSuperType(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.addAnnotation(Override.class); } return this; }
/** * Create a <i>hashCode</i> and <i>equals</i> implementation for the given class and fields * * @deprecated Use {@link Refactory#createHashCodeAndEquals(JavaClass, Field<O>...)} instead, since this method * relies on the existence of the id field */ @Deprecated public static void createHashCodeAndEquals(final JavaClassSource clazz) { clazz.addMethod( "public boolean equals(Object that) { " + "if (this == that) { return true; } " + "if (that == null) { return false; } " + "if (getClass() != that.getClass()) { return false; } " + "if (id != null) { return id.equals(((" + clazz.getName() + ") that).id); } " + "return super.equals(that); " + "}") .addAnnotation(Override.class); clazz.addMethod( "public int hashCode() { " + "if (id != null) { return id.hashCode(); } " + "return super.hashCode(); }") .addAnnotation(Override.class); }
/** * Create a <i>hashCode</i> and <i>equals</i> implementation for the given class and fields * * @deprecated Use {@link Refactory#createHashCodeAndEquals(JavaClass, Field<O>...)} instead, since this method * relies on the existence of the id field */ @Deprecated public static void createHashCodeAndEquals(final JavaClassSource clazz) { clazz.addMethod( "public boolean equals(Object that) { " + "if (this == that) { return true; } " + "if (that == null) { return false; } " + "if (getClass() != that.getClass()) { return false; } " + "if (id != null) { return id.equals(((" + clazz.getName() + ") that).id); } " + "return super.equals(that); " + "}") .addAnnotation(Override.class); clazz.addMethod( "public int hashCode() { " + "if (id != null) { return id.hashCode(); } " + "return super.hashCode(); }") .addAnnotation(Override.class); }
/** * Create a <i>hashCode</i> and <i>equals</i> implementation for the given class and fields * * @deprecated Use {@link Refactory#createHashCodeAndEquals(JavaClass, Field<O>...)} instead, since this method relies * on the existence of the id field */ @Deprecated public static void createHashCodeAndEquals(final JavaClassSource clazz) { clazz.addMethod( "public boolean equals(Object that) { " + "if (this == that) { return true; } " + "if (that == null) { return false; } " + "if (getClass() != that.getClass()) { return false; } " + "if (id != null) { return id.equals(((" + clazz.getName() + ") that).id); } " + "return super.equals(that); " + "}") .addAnnotation(Override.class); clazz.addMethod( "public int hashCode() { " + "if (id != null) { return id.hashCode(); } " + "return super.hashCode(); }") .addAnnotation(Override.class); }
private void addGetMetdataMethod(JavaClassSource command) { MethodSource<JavaClassSource> method = command.addMethod() .setPublic() .setName("getMetadata").setReturnType(UICommandMetadata.class) .setParameters("UIContext context"); method.addAnnotation(Override.class); StringBuilder body = new StringBuilder() .append("return Metadata.forCommand(") .append(command.getName()).append(".class)").append('\n') .append("\t.name(\"").append(commandName.getValue()) .append("\")"); Iterator<String> iterator = categories.getValue().iterator(); if (iterator.hasNext()) { body.append("\t.category(Categories.create("); while (iterator.hasNext()) { body.append('"').append(iterator.next()).append('"'); if (iterator.hasNext()) body.append(", "); } body.append("))"); } body.append(';'); method.setBody(body.toString()); }
@Override public O implementInterface(Class<?> type) { O obj = addInterface(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.setPublic().addAnnotation(Override.class); } return obj; }
@Override public O implementInterface(Class<?> type) { O obj = addInterface(type); for (MethodSource<?> methodSource : Methods.implementAbstractMethods(type, this)) { methodSource.setPublic().addAnnotation(Override.class); } return obj; }
private JavaClassSource createCommand(JavaClassSource command, String commandName, Iterable<String> categories) { MethodSource<JavaClassSource> commandMethod = command.addMethod().setName(toMethodName(command, commandName)) .setReturnType(String.class) .setBody(String.format("return \"Command %s executed\";", commandName)).setPublic(); AnnotationSource<JavaClassSource> commandAnn = commandMethod.addAnnotation(Command.class); List<String> categoryList = new ArrayList<>(Lists.toList(categories)); commandAnn.setStringValue("value", commandName); if (!categoryList.isEmpty()) { commandAnn.setStringArrayValue("categories", categoryList.toArray(new String[categoryList.size()])); } // build the thing return command; }
method.addAnnotation(Override.class);
private void addTestMethod(JavaClassSource test) { test.addImport("org.junit.Test"); MethodSource<JavaClassSource> testMethod = test.addMethod() .setPublic() .setReturnTypeVoid() .setName("should_start_service") .setBody(""); testMethod.addAnnotation("Test"); }
private void addInitializeUIMethod(JavaClassSource command) { command.addMethod() .setPublic() .setName("initializeUI") .setReturnTypeVoid() .setBody("// not implemented") .setParameters("UIBuilder builder") .addThrows(Exception.class) .addAnnotation(Override.class); }
private void addNextMethod(JavaClassSource command) { MethodSource<JavaClassSource> method = command.addMethod().setPublic() .setName("next") .setReturnType(NavigationResult.class) .setParameters("UINavigationContext context"); method.addThrows(Exception.class).addAnnotation(Override.class); try { final String bodyTemplate = loadTextResource( Boolean.TRUE.equals(requireProject.getValue()) ? "nextMethodBodyP.txt" : "nextMethodBody.txt"); method.setBody(String.format(bodyTemplate, command.getName(), script.getValue().getName())); } catch (IOException e) { method.setBody("// ERROR READING BODY TEMPLATE"); } }
private void addExecuteMethod(JavaClassSource command) { command.addMethod() .setPublic() .setName("execute") .setReturnType(Result.class) .setParameters("UIExecutionContext context") .setBody( "return Results.success(\"Command '" + commandName.getValue() + "' successfully executed!\");") .addThrows(Exception.class) .addAnnotation(Override.class); }
private String addJavaVerticle(Project project, String packageName, String className, boolean isMain) { JavaSourceFacet source = project.getFacet(JavaSourceFacet.class); String topLevelPackage; if (packageName == null) { topLevelPackage = source.getBasePackage(); } else { topLevelPackage = packageName; } if (className.endsWith(".java")) { className = className.substring(0, className.length() - ".java".length()); } JavaClassSource mainVerticle = Roaster.create(JavaClassSource.class) .setPackage(topLevelPackage) .setAbstract(false) .setName(className) .setSuperType("io.vertx.core.AbstractVerticle"); mainVerticle .addImport("io.vertx.core.*"); mainVerticle.addMethod().setName("start").setBody( "vertx.createHttpServer().requestHandler(req -> req.response().end(\"Hello World!\")).listen(8080);") .setPublic() .addAnnotation(Override.class); JavaResource resource = source.saveJavaSource(mainVerticle.getEnclosingType()); if (isMain) { ForgeUtils.addPropertyToProject(project, "vertx.verticle", topLevelPackage + "." + className); } addJavaVerticleTest(project,packageName,className); return resource.toString(); }
methodSource.setPublic().addAnnotation(Override.class);
methodSource.setPublic().addAnnotation(Override.class);
"\t\treturn new JacksonJsonProvider();\n" + "\t}"); method.addAnnotation("org.springframework.context.annotation.Bean");