use of com.google.gwt.core.ext.UnableToCompleteException in project rstudio by rstudio.
the class ShortcutsEmitter method printShortcut.
private void printShortcut(SourceWriter writer, String condition, String shortcut, String command, String shortcutGroup, String title, String disableModes) throws UnableToCompleteException {
List<Pair<Integer, String>> keys = new ArrayList<Pair<Integer, String>>();
for (String keyCombination : shortcut.split("\\s+")) {
String[] chunks = keyCombination.split("\\+");
// Build the shortcut modifiers integer and validate
// as we build.
int modifiers = KeyboardShortcut.NONE;
for (int i = 0; i < chunks.length - 1; i++) {
String m = chunks[i];
if (m.equals("Ctrl"))
modifiers += KeyboardShortcut.CTRL;
else if (m.equals("Alt"))
modifiers += KeyboardShortcut.ALT;
else if (m.equals("Shift"))
modifiers += KeyboardShortcut.SHIFT;
else if (m.equals("Meta"))
modifiers += KeyboardShortcut.META;
else {
logger_.log(Type.ERROR, "Invalid modifier '" + m + "'; expected one of " + "'Ctrl', 'Alt', 'Shift', 'Meta'");
throw new UnableToCompleteException();
}
}
// Validate the key name.
String key = toKey(chunks[chunks.length - 1]);
if (key == null) {
logger_.log(Type.ERROR, "Invalid shortcut '" + shortcut + "', only " + "modified alphanumeric characters, enter, " + "left, right, up, down, pageup, pagedown, " + "and tab are valid");
throw new UnableToCompleteException();
}
// Push the parsed keys to the list.
keys.add(new Pair<Integer, String>(modifiers, key));
}
// Emit the relevant code registering these shortcuts.
if (!condition.isEmpty()) {
writer.println("if (" + condition + ") {");
writer.indent();
}
if (keys.size() == 1) {
int modifiers = keys.get(0).first;
String key = keys.get(0).second;
writer.println("ShortcutManager.INSTANCE.register(" + modifiers + ", " + key + ", " + command + ", " + "\"" + shortcutGroup + "\", " + "\"" + title + "\", " + "\"" + disableModes + "\");");
} else if (keys.size() == 2) {
int m1 = keys.get(0).first;
String k1 = keys.get(0).second;
int m2 = keys.get(1).first;
String k2 = keys.get(1).second;
writer.println("ShortcutManager.INSTANCE.register(" + m1 + ", " + k1 + ", " + m2 + ", " + k2 + ", " + command + ", " + "\"" + shortcutGroup + "\", " + "\"" + title + "\", " + "\"" + disableModes + "\");");
} else {
logger_.log(Type.ERROR, "Invalid key sequence: sequences must be of length 1 or 2");
throw new UnableToCompleteException();
}
if (!condition.isEmpty()) {
writer.outdent();
writer.println("}");
}
}
use of com.google.gwt.core.ext.UnableToCompleteException in project rstudio by rstudio.
the class StaticDataResourceGenerator method createAssignment.
@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException {
URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);
if (resources.length != 1) {
logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null);
throw new UnableToCompleteException();
}
URL resource = resources[0];
String outputUrlExpression = context.deploy(resource, null, true);
SourceWriter sw = new StringSourceWriter();
// Write the expression to create the subtype.
sw.println("new " + StaticDataResource.class.getName() + "() {");
sw.indent();
// Convenience when examining the generated code.
sw.println("// " + resource.toExternalForm());
sw.println("public String getUrl() {");
sw.indent();
sw.println("return " + outputUrlExpression + ";");
sw.outdent();
sw.println("}");
sw.println("public com.google.gwt.safehtml.shared.SafeUri getSafeUri() {");
sw.indent();
sw.println("return new org.rstudio.core.client.SafeUriStringImpl(" + outputUrlExpression + ");");
sw.outdent();
sw.println("}");
sw.println("public String getName() {");
sw.indent();
sw.println("return \"" + method.getName() + "\";");
sw.outdent();
sw.println("}");
sw.outdent();
sw.println("}");
return sw.toString();
}
use of com.google.gwt.core.ext.UnableToCompleteException in project playn by threerings.
the class AutoClientBundleGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
JClassType userType;
try {
userType = typeOracle.getType(typeName);
} catch (NotFoundException e) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type: " + typeName, e);
throw new UnableToCompleteException();
}
String packageName = userType.getPackage().getName();
String className = userType.getName();
className = className.replace('.', '_');
if (userType.isInterface() == null) {
logger.log(TreeLogger.ERROR, userType.getQualifiedSourceName() + " is not an interface", null);
throw new UnableToCompleteException();
}
ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className + "Impl");
composerFactory.addImplementedInterface(userType.getQualifiedSourceName());
composerFactory.addImport(ClientBundleWithLookup.class.getName());
composerFactory.addImport(DataResource.class.getName());
composerFactory.addImport(GWT.class.getName());
composerFactory.addImport(ImageResource.class.getName());
composerFactory.addImport(ResourcePrototype.class.getName());
composerFactory.addImport(TextResource.class.getName());
File warDirectory = getWarDirectory(logger);
assert warDirectory.isDirectory();
File classesDirectory = new File(warDirectory, WEB_INF_CLASSES);
assert classesDirectory.isDirectory();
File resourcesDirectory = new File(classesDirectory, packageName.replace('.', '/'));
assert resourcesDirectory.isDirectory();
String baseClassesPath = classesDirectory.getPath();
logger.log(TreeLogger.DEBUG, "baseClassesPath: " + baseClassesPath);
Set<Resource> resources = preferMp3(getResources(context, userType, fileFilter));
Set<String> methodNames = new HashSet<String>();
PrintWriter pw = context.tryCreate(logger, packageName, className + "Impl");
if (pw != null) {
SourceWriter sw = composerFactory.createSourceWriter(context, pw);
// write out jump methods
sw.println("public ResourcePrototype[] getResources() {");
sw.indent();
sw.println("return MyBundle.INSTANCE.getResources();");
sw.outdent();
sw.println("}");
sw.println("public ResourcePrototype getResource(String name) {");
sw.indent();
sw.println("return MyBundle.INSTANCE.getResource(name);");
sw.outdent();
sw.println("}");
// write out static ClientBundle interface
sw.println("static interface MyBundle extends ClientBundleWithLookup {");
sw.indent();
sw.println("MyBundle INSTANCE = GWT.create(MyBundle.class);");
for (Resource resource : resources) {
String relativePath = resource.getPath();
String filename = resource.getPath().substring(resource.getPath().lastIndexOf('/') + 1);
String contentType = getContentType(logger, resource);
String methodName = stripExtension(filename);
if (!isValidMethodName(methodName)) {
logger.log(TreeLogger.WARN, "Skipping invalid method name (" + methodName + ") due to: " + relativePath);
continue;
}
if (!methodNames.add(methodName)) {
logger.log(TreeLogger.WARN, "Skipping duplicate method name due to: " + relativePath);
continue;
}
logger.log(TreeLogger.DEBUG, "Generating method for: " + relativePath);
Class<? extends ResourcePrototype> returnType = getResourcePrototype(contentType);
// generate method
sw.println();
if (returnType == DataResource.class) {
if (contentType.startsWith("audio/")) {
// Prevent the use of data URLs, which Flash won't play
sw.println("@DataResource.DoNotEmbed");
} else {
// Specify an explicit MIME type, for use in the data URL
sw.println("@DataResource.MimeType(\"" + contentType + "\")");
}
}
sw.println("@Source(\"" + relativePath + "\")");
sw.println(returnType.getName() + " " + methodName + "();");
}
sw.outdent();
sw.println("}");
sw.commit(logger);
}
return composerFactory.getCreatedClassName();
}
use of com.google.gwt.core.ext.UnableToCompleteException in project gwt-cs by iSergio.
the class CesiumLinkerUtils method getContents.
static String getContents(EmittedArtifact emittedArtifact, TreeLogger logger) throws UnableToCompleteException {
InputStream in = emittedArtifact.getContents(logger);
BufferedInputStream bis = new BufferedInputStream(in);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
try {
// Fix for SmartGWT. Thanks for Mark Erikson (https://groups.google.com/forum/#!msg/cesium-dev/ZfyW0CNRsSU/lP6KTaUpEQAJ)
buf.write("if (window.buildInDataView === undefined) {window.buildInDataView = window.DataView;}\n".getBytes());
int result = bis.read();
while (result != -1) {
byte b = (byte) result;
buf.write(b);
result = bis.read();
}
} catch (IOException e) {
logger.log(TreeLogger.ERROR, "Unable to read resource", e);
throw new UnableToCompleteException();
}
return buf.toString();
}
use of com.google.gwt.core.ext.UnableToCompleteException in project mvp4g by mvp4g.
the class Mvp4gRunAsyncGenerator method generateIncrementally.
@Override
public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext generatorContext, String typeName) throws UnableToCompleteException {
TypeOracle typeOracle = generatorContext.getTypeOracle();
assert (typeOracle != null);
JClassType originalType = typeOracle.findType(typeName);
if (originalType == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'");
throw new UnableToCompleteException();
}
if (originalType.isInterface() == null) {
logger.log(TreeLogger.ERROR, "'" + typeName + "' is not a interface");
throw new UnableToCompleteException();
}
TreeLogger moduleLogger = logger.branch(TreeLogger.DEBUG, "Generating client proxy for remote service interface '" + originalType.getQualifiedSourceName() + "'", null);
return create(originalType, moduleLogger, generatorContext, typeName);
}
Aggregations