@Override public Result execute(UIExecutionContext context) throws Exception { Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap(); Project project = (Project) attributeMap.get(Project.class); if (project.hasFacet(JavaSourceFacet.class)) { JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); MetadataFacet metadata = project.getFacet(MetadataFacet.class); if (createMain.getValue()) { JavaClassSource javaClass = Roaster .create(JavaClassSource.class) .setPackage(facet.getBasePackage()) .setName("Main") .addMethod("public static void main(String[] args) {}") .setBody("System.out.println(\"Hi there! I was forged as part of the project you call " + metadata.getProjectName() + ".\");") .getOrigin(); facet.saveJavaSource(javaClass); } } return null; } }
/** * Adds a default method implementation to the given {@link MethodSource}. This method will call * {@link MethodSource#setAbstract(false)} before setting the body if the origin is not an interface * * @param source */ public static void implementMethod(MethodSource<?> source) { if (source.getOrigin().isInterface()) { source.setBody(null); } else { if (source.isNative()) { source.setNative(false); } source.setAbstract(false); if (source.isReturnTypeVoid()) { source.setBody(""); } else { source.setBody("return " + Types.getDefaultValue(source.getReturnType().getName()) + ";"); } } }
/** * Adds a default method implementation to the given {@link MethodSource}. This method will call * {@link MethodSource#setAbstract(false)} before setting the body if the origin is not an interface * * @param source */ public static void implementMethod(MethodSource<?> source) { if (source.getOrigin().isInterface()) { source.setBody(null); } else { if (source.isNative()) { source.setNative(false); } source.setAbstract(false); if (source.isReturnTypeVoid()) { source.setBody(""); } else { source.setBody("return " + Types.getDefaultValue(source.getReturnType().getName()) + ";"); } } }
.setPublic() .setBody("super(\"camel.dataformat\", \"camel.dataformat." + dataformatName + "\");") .getOrigin() );
.setPublic() .setBody("super(\"camel.component\", \"camel.component." + componentName + "\");") .getOrigin() );
.setPublic() .setBody("super(\"camel.component\", \"camel.component." + languageName + "\");") .getOrigin() );