use of org.openide.filesystems.annotations.LayerGenerationException in project netbeans-rcp-lite by outersky.
the class TopComponentProcessor method findInfo.
private Description findInfo(Element e) throws LayerGenerationException {
Element type;
switch(e.asType().getKind()) {
case DECLARED:
type = e;
break;
case EXECUTABLE:
type = ((DeclaredType) ((ExecutableType) e.asType()).getReturnType()).asElement();
break;
default:
throw new LayerGenerationException("" + e.asType().getKind(), e);
}
TopComponent.Description info = type.getAnnotation(TopComponent.Description.class);
return info;
}
use of org.openide.filesystems.annotations.LayerGenerationException in project netbeans-rcp-lite by outersky.
the class TopComponentProcessor method handleProcess.
@Override
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
for (Element e : roundEnv.getElementsAnnotatedWith(TopComponent.Registration.class)) {
TopComponent.Registration reg = e.getAnnotation(TopComponent.Registration.class);
if (reg == null) {
continue;
}
Description info = findInfo(e);
if (info == null) {
throw new LayerGenerationException("Cannot find TopComponent.Description for this element", e, processingEnv, reg);
}
String id = info.preferredID();
checkValidId(id, e, processingEnv, info);
String rootFolder;
String[] roles = reg.roles();
if (roles.length == 0) {
rootFolder = "Windows2";
generateSettingsAndWstcref(e, rootFolder, id, reg, info);
} else {
Set<String> uniqueRoles = new HashSet<String>();
for (String role : roles) {
if (!uniqueRoles.add(role)) {
throw new LayerGenerationException("Duplicate role name found", e, processingEnv, reg);
}
if (role.isEmpty()) {
throw new LayerGenerationException("Unnamed role found", e, processingEnv, reg);
}
rootFolder = "Windows2/Roles/" + role;
generateSettingsAndWstcref(e, rootFolder, id, reg, info);
}
}
}
for (Element e : roundEnv.getElementsAnnotatedWith(TopComponent.OpenActionRegistration.class)) {
TopComponent.OpenActionRegistration reg = e.getAnnotation(TopComponent.OpenActionRegistration.class);
assert reg != null;
Description info = findInfo(e);
ActionID aid = e.getAnnotation(ActionID.class);
if (aid != null) {
File actionFile = layer(e).file("Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance").methodvalue("instanceCreate", "org.openide.windows.TopComponent", "openAction");
actionFile.instanceAttribute("component", TopComponent.class, reg, null);
if (reg.preferredID().length() > 0) {
actionFile.stringvalue("preferredID", reg.preferredID());
}
actionFile.bundlevalue("displayName", reg.displayName(), reg, "displayName");
if (info != null && info.iconBase().length() > 0) {
actionFile.stringvalue("iconBase", info.iconBase());
}
actionFile.write();
}
}
return true;
}
use of org.openide.filesystems.annotations.LayerGenerationException in project netbeans-rcp-lite by outersky.
the class MultiViewProcessor method handleProcess.
@Override
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
if (roundEnv.processingOver()) {
return false;
}
TypeMirror pane = null;
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(CloneableEditorSupport.Pane.class.getCanonicalName());
if (typeElement != null) {
pane = typeElement.asType();
}
for (Element e : roundEnv.getElementsAnnotatedWith(MultiViewElement.Registration.class)) {
MultiViewElement.Registration mvr = e.getAnnotation(MultiViewElement.Registration.class);
if (mvr.mimeType().length == 0) {
throw new LayerGenerationException("You must specify mimeType", e, processingEnv, mvr, "mimeType");
}
TypeMirror[] exprType = new TypeMirror[1];
String[] binAndMethodNames = findDefinition(e, exprType, mvr);
String fileBaseName = binAndMethodNames[0].replace('.', '-');
if (binAndMethodNames[1] != null) {
fileBaseName += "-" + binAndMethodNames[1];
}
for (String type : mvr.mimeType()) {
final LayerBuilder builder = layer(e);
LayerBuilder.File f = builder.file("Editors/" + (type.equals("") ? "" : type + '/') + "MultiView/" + fileBaseName + ".instance");
f.methodvalue("instanceCreate", MultiViewFactory.class.getName(), "createMultiViewDescription");
f.stringvalue("instanceClass", ContextAwareDescription.class.getName());
f.stringvalue("class", binAndMethodNames[0]);
f.bundlevalue("displayName", mvr.displayName(), mvr, "displayName");
if (!mvr.iconBase().isEmpty()) {
builder.validateResource(mvr.iconBase(), e, mvr, "iconBase", true);
f.stringvalue("iconBase", mvr.iconBase());
}
f.stringvalue("preferredID", mvr.preferredID());
f.intvalue("persistenceType", mvr.persistenceType());
f.position(mvr.position());
if (binAndMethodNames[1] != null) {
f.stringvalue("method", binAndMethodNames[1]);
}
if (pane != null && processingEnv.getTypeUtils().isAssignable(exprType[0], pane)) {
f.boolvalue("sourceview", true);
}
f.write();
}
}
return true;
}
use of org.openide.filesystems.annotations.LayerGenerationException in project netbeans-rcp-lite by outersky.
the class OptionAnnotationProcessorImpl method handleProcess.
@Override
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
PrimitiveType boolType = processingEnv.getTypeUtils().getPrimitiveType(TypeKind.BOOLEAN);
TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
ArrayType stringArray = processingEnv.getTypeUtils().getArrayType(stringType);
Set<TypeElement> processors = new HashSet<TypeElement>();
for (Element e : roundEnv.getElementsAnnotatedWith(Arg.class)) {
if (e.getModifiers().contains(Modifier.STATIC)) {
throw new LayerGenerationException("@Arg can be applied only to non-static fields", e);
}
if (!e.getModifiers().contains(Modifier.PUBLIC)) {
throw new LayerGenerationException("@Arg can be applied only to public fields", e);
}
if (e.getModifiers().contains(Modifier.FINAL)) {
throw new LayerGenerationException("@Arg can be applied only to non-final fields", e);
}
Arg arg = e.getAnnotation(Arg.class);
if (arg.longName().isEmpty() && arg.shortName() == Option.NO_SHORT_NAME) {
throw new LayerGenerationException("At least one of longName or shortName attributes needs to be non-empty", e);
}
if (arg.implicit() && !e.asType().equals(stringArray)) {
throw new LayerGenerationException("implicit @Arg can only be applied to String[] fields", e);
}
processors.add(TypeElement.class.cast(e.getEnclosingElement()));
}
for (TypeElement te : processors) {
int cnt = 1;
final String typeName = processingEnv.getElementUtils().getBinaryName(te).toString().replace('.', '-');
File f = layer(te).file("Services/OptionProcessors/" + typeName + ".instance");
f.methodvalue("instanceCreate", DefaultProcessor.class.getName(), "create");
f.stringvalue("instanceOf", OptionProcessor.class.getName());
f.stringvalue("class", processingEnv.getElementUtils().getBinaryName(te).toString());
for (Element e : te.getEnclosedElements()) {
Arg o = e.getAnnotation(Arg.class);
if (o == null) {
continue;
}
Description d = e.getAnnotation(Description.class);
if (o.shortName() != Option.NO_SHORT_NAME) {
f.charvalue(cnt + ".shortName", o.shortName());
}
if (!o.longName().isEmpty()) {
f.stringvalue(cnt + ".longName", o.longName());
}
if (boolType == e.asType()) {
f.stringvalue(cnt + ".type", "withoutArgument");
} else if (stringType == e.asType()) {
if (o.defaultValue().equals("\u0000")) {
f.stringvalue(cnt + ".type", "requiredArgument");
} else {
f.stringvalue(cnt + ".type", "optionalArgument");
}
} else {
if (!stringArray.equals(e.asType())) {
throw new LayerGenerationException("Field type has to be either boolean, String or String[]!", e);
}
f.stringvalue(cnt + ".type", "additionalArguments");
}
if (o.implicit()) {
f.boolvalue(cnt + ".implicit", true);
}
if (d != null) {
writeBundle(f, cnt + ".displayName", d.displayName(), e);
writeBundle(f, cnt + ".shortDescription", d.shortDescription(), e);
}
cnt++;
}
f.write();
}
return true;
}
use of org.openide.filesystems.annotations.LayerGenerationException in project netbeans-rcp-lite by outersky.
the class TemplateProcessor method contentURI.
private URI contentURI(Element e, String relativePath, LayerBuilder builder, TemplateRegistration t, String annotationMethod) throws LayerGenerationException {
String path = LayerBuilder.absolutizeResource(e, relativePath);
builder.validateResource(path, e, t, annotationMethod, false);
try {
return new URI("nbresloc", "/" + path, null).normalize();
} catch (URISyntaxException x) {
throw new LayerGenerationException("could not translate " + path, e, processingEnv, t);
}
}
Aggregations