Search in sources :

Example 1 with UnableToCompleteException

use of com.google.gwt.core.ext.UnableToCompleteException in project gerrit by GerritCodeReview.

the class CssLinker method name.

private String name(final TreeLogger logger, final PublicResource r) throws UnableToCompleteException {
    byte[] out;
    try (ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        InputStream in = r.getContents(logger)) {
        final byte[] buf = new byte[2048];
        int n;
        while ((n = in.read(buf)) >= 0) {
            tmp.write(buf, 0, n);
        }
        out = tmp.toByteArray();
    } catch (IOException e) {
        final UnableToCompleteException ute = new UnableToCompleteException();
        ute.initCause(e);
        throw ute;
    }
    String base = r.getPartialPath();
    final int s = base.lastIndexOf('/');
    if (0 < s) {
        base = base.substring(0, s + 1);
    } else {
        base = "";
    }
    return base + Util.computeStrongName(out) + ".cache.css";
}
Also used : InputStream(java.io.InputStream) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with UnableToCompleteException

use of com.google.gwt.core.ext.UnableToCompleteException in project gerrit by GerritCodeReview.

the class PluginGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();
    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);
    // Ensure that the requested type exists
    if (sourceType == null) {
        logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
        throw new UnableToCompleteException();
    }
    // Make sure the Gadget type is correctly defined
    validateType(logger, sourceType);
    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "PluginImpl";
    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(), generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.setSuperclass(typeName);
    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);
    // If an implementation already exists, we don't need to do any work
    if (out != null) {
        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);
        sw.commit(logger);
    }
    return f.getCreatedClassName();
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) GWT(com.google.gwt.core.client.GWT) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) PrintWriter(java.io.PrintWriter)

Example 3 with UnableToCompleteException

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

the class MenuEmitter method emitMenu.

private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException {
    for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) {
        if (n.getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element child = (Element) n;
        if (child.getTagName().equals("cmd")) {
            String cmdId = child.getAttribute("refid");
            writer.print("callback.addCommand(");
            writer.print("\"" + Generator.escape(cmdId) + "\", ");
            writer.println("this.cmds." + cmdId + "());");
        } else if (child.getTagName().equals("separator")) {
            writer.println("callback.addSeparator();");
        } else if (child.getTagName().equals("menu")) {
            String label = child.getAttribute("label");
            writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");");
            emitMenu(writer, child);
            writer.println("callback.endMenu();");
        } else if (child.getTagName().equals("dynamic")) {
            String dynamicClass = child.getAttribute("class");
            writer.println("new " + dynamicClass + "().execute(callback);");
        } else {
            logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu");
            throw new UnableToCompleteException();
        }
    }
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 4 with UnableToCompleteException

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

the class ShortcutsEmitter method elementToString.

private String elementToString(Element el) throws UnableToCompleteException {
    try {
        javax.xml.transform.TransformerFactory tfactory = TransformerFactory.newInstance();
        javax.xml.transform.Transformer xform = tfactory.newTransformer();
        javax.xml.transform.Source src = new DOMSource(el);
        java.io.StringWriter writer = new StringWriter();
        Result result = new javax.xml.transform.stream.StreamResult(writer);
        xform.transform(src, result);
        return writer.toString();
    } catch (Exception e) {
        logger_.log(Type.ERROR, "Error attempting to stringify some XML", e);
        throw new UnableToCompleteException();
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) StringWriter(java.io.StringWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) Result(javax.xml.transform.Result) StringWriter(java.io.StringWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) TransformerFactory(javax.xml.transform.TransformerFactory)

Example 5 with UnableToCompleteException

use of com.google.gwt.core.ext.UnableToCompleteException 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)

Aggregations

UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)29 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)14 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)8 SourceWriter (com.google.gwt.user.rebind.SourceWriter)6 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)4 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)4 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 GWT (com.google.gwt.core.client.GWT)2 TreeLogger (com.google.gwt.core.ext.TreeLogger)2 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)2 JType (com.google.gwt.core.ext.typeinfo.JType)2 Resource (com.google.gwt.dev.resource.Resource)2 GinModule (com.google.gwt.inject.client.GinModule)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2