Search in sources :

Example 1 with LayerBuilder

use of org.openide.filesystems.annotations.LayerBuilder in project netbeans-rcp-lite by outersky.

the class OpenUriHandlerProcessor method registerHandler.

private void registerHandler(Element e, IntentHandlerRegistration r) throws LayerGenerationException {
    TypeElement intentTypeElement = getTypeElement(Intent.class);
    TypeElement objectTypeElement = getTypeElement(Object.class);
    TypeElement resultTypeElement = getTypeElement(Result.class);
    if (!ElementKind.METHOD.equals(e.getKind())) {
        throw error(e, // NOI18N
        "The annotation can be applied only to" + // NOI18N
        " a method.");
    }
    if (!e.getModifiers().contains(Modifier.STATIC)) {
        // NOI18N
        throw error(e, "The annotated method must be static.");
    }
    ExecutableElement ee;
    if (e instanceof ExecutableElement) {
        ee = (ExecutableElement) e;
    } else {
        throw error(e, // NOI18N
        "Annotated element must be an " + // NOI18N
        "ExecutableElement");
    }
    String type;
    if (ee.getParameters().size() == 1 && hasParameter(ee, 0, intentTypeElement) && hasResultType(ee, objectTypeElement)) {
        type = "RETURN";
    } else if (ee.getParameters().size() == 2 && hasParameter(ee, 0, intentTypeElement) && hasParameter(ee, 1, resultTypeElement) && hasVoidResultType(ee)) {
        type = "SETBACK";
    } else {
        throw error(e, // NOI18N
        "The handler method must take a " + // NOI18N
        "single argument of type " + // NOI18N
        "org.netbeans.api.intent.Intent and return Object" + // NOI18N
        "; or take two arguments of types" + // NOI18N
        "org.netbeans.api.intent.Intent" + // NOI18N
        "and org.netbeans.spi.intent.Result" + // NOI18N
        " and return void.");
    }
    boolean takeAll = false;
    boolean empty = true;
    StringBuilder sb = new StringBuilder();
    for (String action : r.actions()) {
        if ("*".equals(action)) {
            takeAll = true;
            break;
        } else {
            if (!empty) {
                sb.append(',');
            }
            sb.append(action);
            empty = false;
        }
    }
    String actions = takeAll ? "*" : sb.toString();
    final LayerBuilder b = layer(e);
    File f = b.file(// NOI18N
    "Services/Intent/Handlers/" + getName(e).replace('.', '-') + SUFFIX);
    f.position(r.position());
    // NOI18N
    f.stringvalue(// NOI18N
    "instanceClass", IntentHandler.class.getCanonicalName());
    f.methodvalue("instanceCreate", IntentHandler.class.getCanonicalName(), // NOI18N
    "create");
    // NOI18N
    f.bundlevalue("displayName", r.displayName());
    // NOI18N
    f.stringvalue("uriPattern", r.uriPattern());
    // NOI18N
    f.stringvalue("icon", r.icon());
    // NOI18N
    f.stringvalue("type", type);
    // NOI18N
    f.stringvalue("actions", actions);
    f.write();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) LayerBuilder(org.openide.filesystems.annotations.LayerBuilder) File(org.openide.filesystems.annotations.LayerBuilder.File)

Example 2 with LayerBuilder

use of org.openide.filesystems.annotations.LayerBuilder 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;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) MultiViewElement(org.netbeans.core.spi.multiview.MultiViewElement) LayerGenerationException(org.openide.filesystems.annotations.LayerGenerationException) MultiViewElement(org.netbeans.core.spi.multiview.MultiViewElement) TypeMirror(javax.lang.model.type.TypeMirror) LayerBuilder(org.openide.filesystems.annotations.LayerBuilder) MultiViewFactory(org.netbeans.core.spi.multiview.MultiViewFactory)

Example 3 with LayerBuilder

use of org.openide.filesystems.annotations.LayerBuilder in project netbeans-rcp-lite by outersky.

the class TemplateProcessor method process.

private void process(Element e, TemplateRegistration t) throws LayerGenerationException {
    LayerBuilder builder = layer(e);
    String basename;
    if (!t.id().isEmpty()) {
        if (t.content().length > 0) {
            throw new LayerGenerationException("Cannot specify both id and content", e, processingEnv, t);
        }
        basename = t.id();
    } else if (t.content().length > 0) {
        basename = basename(t.content()[0]);
    } else {
        if (e.getKind() == ElementKind.CLASS) {
            basename = ((TypeElement) e).getQualifiedName().toString().replace('.', '-');
        } else if (e.getKind() == ElementKind.METHOD) {
            basename = ((TypeElement) e.getEnclosingElement()).getQualifiedName().toString().replace('.', '-') + '-' + e.getSimpleName();
        } else {
            throw new LayerGenerationException("cannot use @Template on a package without specifying content", e, processingEnv, t);
        }
    }
    String folder = "Templates/" + t.folder() + '/';
    LayerBuilder.File f = builder.file(folder + basename);
    f.boolvalue("template", true);
    f.position(t.position());
    if (!t.displayName().isEmpty()) {
        f.bundlevalue("displayName", t.displayName());
    }
    if (!t.iconBase().isEmpty()) {
        builder.validateResource(t.iconBase(), e, t, "iconBase", true);
        f.stringvalue("iconBase", t.iconBase());
    } else if (t.content().length == 0) {
        throw new LayerGenerationException("Must specify iconBase if content is not specified", e, processingEnv, t);
    }
    if (!t.description().isEmpty()) {
        f.urlvalue("instantiatingWizardURL", contentURI(e, t.description(), builder, t, "description"));
    }
    if (e.getKind() != ElementKind.PACKAGE) {
        if (t.page().isEmpty()) {
            try {
                // NOI18N
                Class<?> iterClazz = Class.forName("org.openide.WizardDescriptor$InstantiatingIterator");
                f.instanceAttribute("instantiatingIterator", iterClazz);
            } catch (ClassNotFoundException ex) {
                Messager msg = processingEnv.getMessager();
                msg.printMessage(Diagnostic.Kind.ERROR, // NOI18N
                "Either specify 'page' value or implement or return WizardDescriptor.InstantiatingIterator", e);
            }
        } else {
            registerHTMLWizard(e, builder, f, t);
        }
    }
    if (t.content().length > 0) {
        f.url(contentURI(e, t.content()[0], builder, t, "content").toString());
        for (int i = 1; i < t.content().length; i++) {
            builder.file(folder + basename(t.content()[i])).url(contentURI(e, t.content()[i], builder, t, "content").toString()).position(0).write();
        }
    }
    if (!t.scriptEngine().isEmpty()) {
        f.stringvalue(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, t.scriptEngine());
    }
    if (t.category().length > 0) {
        StringBuilder sb = new StringBuilder();
        for (String c : t.category()) {
            if (sb.length() > 0) {
                sb.append(',');
            }
            sb.append(c);
        }
        f.stringvalue("templateCategory", sb.toString());
    }
    f.boolvalue("requireProject", t.requireProject());
    if (!t.targetName().trim().isEmpty()) {
        // NOI18N
        f.bundlevalue("targetName", t.targetName());
    }
    String[] techIds = t.techIds();
    for (int i = 0; i < techIds.length; i++) {
        String id = techIds[i];
        // NOI18N
        f.stringvalue("techId." + i, id);
    }
    f.write();
}
Also used : Messager(javax.annotation.processing.Messager) TypeElement(javax.lang.model.element.TypeElement) LayerBuilder(org.openide.filesystems.annotations.LayerBuilder) LayerGenerationException(org.openide.filesystems.annotations.LayerGenerationException)

Example 4 with LayerBuilder

use of org.openide.filesystems.annotations.LayerBuilder in project netbeans-rcp-lite by outersky.

the class MIMEResolverProcessor method registerNamespace.

private void registerNamespace(Element e, NamespaceRegistration r) throws LayerGenerationException {
    final LayerBuilder b = layer(e);
    // NOI18N
    File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Namespace" + SUFFIX);
    // NOI18N
    f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create");
    // NOI18N
    f.stringvalue("instanceClass", MIMEResolver.class.getName());
    // NOI18N
    f.stringvalue("mimeType", r.mimeType());
    int cnt = 0;
    for (String ext : r.doctypePublicId()) {
        // NOI18N
        f.stringvalue("doctype." + (cnt++), ext);
    }
    cnt = 0;
    for (String ext : r.checkedExtension()) {
        // NOI18N
        f.stringvalue("ext." + (cnt++), ext);
    }
    cnt = 0;
    for (String ext : r.acceptedExtension()) {
        // NOI18N
        f.stringvalue("accept." + (cnt++), ext);
    }
    cnt = 0;
    // NOI18N
    f.stringvalue("element", r.elementName());
    for (String ext : r.elementNS()) {
        // NOI18N
        f.stringvalue("ns." + (cnt++), ext);
    }
    f.position(r.position());
    // NOI18N
    f.bundlevalue("displayName", r.displayName());
    f.write();
}
Also used : LayerBuilder(org.openide.filesystems.annotations.LayerBuilder) MIMEResolver(org.openide.filesystems.MIMEResolver) File(org.openide.filesystems.annotations.LayerBuilder.File)

Example 5 with LayerBuilder

use of org.openide.filesystems.annotations.LayerBuilder in project netbeans-rcp-lite by outersky.

the class MIMEResolverProcessor method registerDefinition.

private void registerDefinition(Element e, String relRes, Registration r) throws LayerGenerationException {
    String absRes = LayerBuilder.absolutizeResource(e, relRes);
    final LayerBuilder b = layer(e);
    FileObject fo = b.validateResource(absRes, e, r, null, false);
    // NOI18N
    File f = b.file("Services/MIMEResolver/" + getName(e).replace('.', '-') + "-Registration" + SUFFIX);
    // NOI18N
    f.methodvalue("instanceCreate", MIMEResolver.class.getName(), "create");
    // NOI18N
    f.stringvalue("instanceClass", MIMEResolver.class.getName());
    // NOI18N
    f.serialvalue("bytes", generateInstanceResolver(fo, e, f, r));
    f.position(r.position());
    int ccnt = 0;
    for (String chooser : r.showInFileChooser()) {
        f.bundlevalue("fileChooser." + (ccnt++), chooser);
    }
    // NOI18N
    f.bundlevalue("displayName", r.displayName());
    f.write();
}
Also used : LayerBuilder(org.openide.filesystems.annotations.LayerBuilder) MIMEResolver(org.openide.filesystems.MIMEResolver) FileObject(javax.tools.FileObject) File(org.openide.filesystems.annotations.LayerBuilder.File)

Aggregations

LayerBuilder (org.openide.filesystems.annotations.LayerBuilder)10 TypeElement (javax.lang.model.element.TypeElement)7 File (org.openide.filesystems.annotations.LayerBuilder.File)6 Element (javax.lang.model.element.Element)5 ExecutableElement (javax.lang.model.element.ExecutableElement)5 LayerGenerationException (org.openide.filesystems.annotations.LayerGenerationException)5 TypeMirror (javax.lang.model.type.TypeMirror)4 MIMEResolver (org.openide.filesystems.MIMEResolver)3 Messager (javax.annotation.processing.Messager)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 PackageElement (javax.lang.model.element.PackageElement)2 VariableElement (javax.lang.model.element.VariableElement)2 ActionListener (java.awt.event.ActionListener)1 Map (java.util.Map)1 AnnotationValue (javax.lang.model.element.AnnotationValue)1 FileObject (javax.tools.FileObject)1 MultiViewElement (org.netbeans.core.spi.multiview.MultiViewElement)1 MultiViewFactory (org.netbeans.core.spi.multiview.MultiViewFactory)1 ContainerRegistration (org.netbeans.spi.options.OptionsPanelController.ContainerRegistration)1 Keywords (org.netbeans.spi.options.OptionsPanelController.Keywords)1