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";
}
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();
}
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();
}
}
}
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();
}
}
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("}");
}
}
Aggregations