help = "the annotation definition: surround with quotes",
description = "annotation definition") final String... def) throws FileNotFoundException
{
JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
JavaAnnotation type = null;
if (def != null)
{
String classDef = Strings.join(Arrays.asList(def), " ");
type = JavaParser.parse(JavaAnnotation.class, classDef);
}
else if (in != null)
{
type = JavaParser.parse(JavaAnnotation.class, in);
}
else if (annotationName != null)
{
type = JavaParser.create(JavaAnnotation.class).setName(annotationName);
}
else
{
throw new RuntimeException("arguments required");
}
if (pckg != null)
{
type.setPackage(pckg);
}
if (documented)
{
type.addAnnotation(Documented.class);
}
if (retentionPolicy != null)
{
type.addAnnotation(Retention.class).setEnumValue(retentionPolicy);
}
final Set<ElementType> targetTypes;
if (noTarget)
{
targetTypes = Collections.emptySet();
}
else
{
targetTypes = shell.promptMultiSelectWithWildcard("*",
"Select target element types", ElementType.values());
}
if (targetTypes.isEmpty())
{
shell.printlnVerbose("Skipping @Target annotation");
}
else
{
type.addAnnotation(Target.class).setEnumValue(targetTypes.toArray(new ElementType[targetTypes.size()]));
}
if (!type.hasSyntaxErrors())
{
java.saveJavaSource(type);
}
else
{
writer.println(ShellColor.RED, "Syntax Errors:");
for (SyntaxError error : type.getSyntaxErrors())
{
writer.println(error.toString());
}
writer.println();