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);
}
}