Search in sources :

Example 1 with JMethod

use of com.google.gwt.core.ext.typeinfo.JMethod in project rstudio by rstudio.

the class ImageResourceInfo method emitConstructor.

private void emitConstructor(SourceWriter writer, ImageResourceInfo images) throws UnableToCompleteException {
    writer.println("public " + simpleName_ + "() {");
    // Get additional properties from XML resource file, if exists
    Map<String, Element> props = getCommandProperties();
    // Implement the methods for the commands
    for (JMethod method : commandMethods_) emitCommandInitializers(writer, props, method, images);
    writer.println();
    writer.indentln("__registerShortcuts();");
    writer.println("}");
}
Also used : Element(org.w3c.dom.Element) JMethod(com.google.gwt.core.ext.typeinfo.JMethod)

Example 2 with JMethod

use of com.google.gwt.core.ext.typeinfo.JMethod in project rstudio by rstudio.

the class ImageResourceInfo method emitMenus.

private void emitMenus(SourceWriter writer) throws UnableToCompleteException {
    for (JMethod method : menuMethods_) {
        String name = method.getName();
        NodeList nodes = getConfigDoc("/commands/menu[@id='" + name + "']");
        if (nodes.getLength() == 0) {
            logger_.log(TreeLogger.Type.ERROR, "Unable to find config info for menu " + name);
            throw new UnableToCompleteException();
        } else if (nodes.getLength() > 1) {
            logger_.log(TreeLogger.Type.ERROR, "Duplicate menu entries for menu " + name);
        }
        String menuClass = new MenuEmitter(logger_, context_, bundleType_, (Element) nodes.item(0)).generate();
        writer.println("public void " + name + "(MenuCallback callback) {");
        writer.indentln("new " + menuClass + "(this).createMenu(callback);");
        writer.println("}");
    }
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) JMethod(com.google.gwt.core.ext.typeinfo.JMethod)

Example 3 with JMethod

use of com.google.gwt.core.ext.typeinfo.JMethod in project GwtMobile by dennisjzh.

the class GenUtils method inspectType.

public void inspectType(String typeName, List<JMethod> getters, List<JMethod> hasManyRels, List<JMethod> hasOneRels) throws UnableToCompleteException {
    JClassType classType = getClassType(typeName);
    for (JMethod method : classType.getOverridableMethods()) {
        if (!method.isAbstract()) {
            continue;
        }
        String methodName = method.getName();
        if (methodName.startsWith("get")) {
            // getId() is reserved. 
            String propertyName = methodName.substring(3);
            if (propertyName.equals("Id")) {
                continue;
            }
            JType returnType = method.getReturnType();
            String returnTypeName = returnType.getSimpleSourceName();
            if (returnType.isPrimitive() != null && !returnTypeName.equals("long") || returnTypeName.equals("String") || returnTypeName.equals("Date") || isSubclassOf(returnType, "JSONValue")) {
                getters.add(method);
                continue;
            }
            if (returnTypeName.equals("long")) {
                logger.log(TreeLogger.ERROR, "GWT JSNI does not support 'long' as return type on getter '" + methodName + "'. Use 'double' instead.");
                throw new UnableToCompleteException();
            }
            if (returnTypeName.startsWith("Collection")) {
                hasManyRels.add(method);
                continue;
            }
            if (isSubclassOf(returnType, "Persistable")) {
                hasOneRels.add(method);
                continue;
            }
            logger.log(TreeLogger.ERROR, "Unsupported return type '" + returnTypeName + "' on getter '" + methodName + "'.");
            throw new UnableToCompleteException();
        } else {
        // TODO: check if method is a setter. ignore if so, error if not.
        }
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) JMethod(com.google.gwt.core.ext.typeinfo.JMethod) JType(com.google.gwt.core.ext.typeinfo.JType)

Example 4 with JMethod

use of com.google.gwt.core.ext.typeinfo.JMethod in project rstudio by rstudio.

the class ImageResourceInfo method getMethods.

private JMethod[] getMethods(boolean includeCommands, boolean includeMenus, boolean includeShortcuts) throws UnableToCompleteException {
    ArrayList<JMethod> methods = new ArrayList<JMethod>();
    for (JMethod method : bundleType_.getMethods()) {
        if (!method.isAbstract())
            continue;
        validateMethod(method);
        if (!includeCommands && isCommandMethod(method))
            continue;
        if (!includeMenus && isMenuMethod(method))
            continue;
        if (!includeShortcuts && isShortcutsMethod(method))
            continue;
        methods.add(method);
    }
    return methods.toArray(new JMethod[methods.size()]);
}
Also used : ArrayList(java.util.ArrayList) JMethod(com.google.gwt.core.ext.typeinfo.JMethod)

Example 5 with JMethod

use of com.google.gwt.core.ext.typeinfo.JMethod in project rstudio by rstudio.

the class ImageResourceInfo method emitCommandAccessors.

private void emitCommandAccessors(SourceWriter writer) {
    for (JMethod method : commandMethods_) {
        String name = method.getName();
        writer.println("public AppCommand " + name + "() {");
        writer.indent();
        writer.println("return " + name + "_;");
        writer.outdent();
        writer.println("}");
    }
}
Also used : JMethod(com.google.gwt.core.ext.typeinfo.JMethod)

Aggregations

JMethod (com.google.gwt.core.ext.typeinfo.JMethod)9 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)2 Element (org.w3c.dom.Element)2 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 JType (com.google.gwt.core.ext.typeinfo.JType)1 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)1 SourceWriter (com.google.gwt.user.rebind.SourceWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 NodeList (org.w3c.dom.NodeList)1