protected abstract Class<? extends JavaSource<?>> getSourceType();
@Override
public Result execute(UIExecutionContext context) throws Exception
{
UIContext uiContext = context.getUIContext();
Project project = getSelectedProject(uiContext);
JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
JavaSource<?> source = JavaParser.create(getSourceType()).setName(named.getValue());
JavaResource javaResource;
if (targetPackage.hasValue() || targetPackage.hasDefaultValue())
{
source.setPackage(targetPackage.getValue());
}
else
{
source.setPackage(javaSourceFacet.getBasePackage());
}
if (source.hasSyntaxErrors())
{
UIOutput output = uiContext.getProvider().getOutput();
PrintStream err = output.err();
err.println("Syntax Errors:");
for (SyntaxError error : source.getSyntaxErrors())
{
err.println(error);
}
err.println();
return Results.fail("Syntax Errors found. See above");
}
else
{
javaResource = javaSourceFacet.saveJavaSource(source);
}
uiContext.setSelection(javaResource);
return Results.success(getType() + " " + source.getQualifiedName() + " was created");
}