{
throw new RuntimeException("Type already exists [" + resource.getFullyQualifiedName()
+ "] Re-run with '--overwrite' to continue.");
}
JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
JavaAnnotation stereotype = JavaParser.create(JavaAnnotation.class);
stereotype.setName(java.calculateName(resource));
stereotype.setPackage(java.calculatePackage(resource));
stereotype.addAnnotation(Stereotype.class);
if (inherited)
{
stereotype.addAnnotation(Inherited.class);
}
if (named)
{
stereotype.addAnnotation(Named.class);
}
if (alternative)
{
stereotype.addAnnotation(Alternative.class);
}
stereotype.addAnnotation(Retention.class).setEnumValue(RUNTIME);
final Set<ElementType> targetTypes;
if (allTargets)
{
targetTypes = STEREOTYPE_TARGETS;
}
else
{
Set<ElementType> input;
while (true)
{
input = shell.promptMultiSelect("Select target element types", STEREOTYPE_TARGETS);
if (input.isEmpty())
{
ShellMessages.error(shell, "No target element types selected");
continue;
}
if (input.contains(TYPE) && input.size() == 2)
{
ShellMessages.error(shell, "Invalid combination of target element types: " + input);
continue;
}
break;
}
targetTypes = input;
}
stereotype.addAnnotation(Target.class).setEnumValue(targetTypes.toArray(new ElementType[targetTypes.size()]));
stereotype.addAnnotation(Documented.class);
java.saveJavaSource(stereotype);
pickup.fire(new PickupResource(java.getJavaResource(stereotype)));
}