Search in sources :

Example 11 with UnableToCompleteException

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

the class ExtensionRegistryGenerator method generate.

/** {@inheritDoc} */
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    TypeOracle typeOracle = context.getTypeOracle();
    JClassType extensionManager = typeOracle.findType(typeName);
    if (extensionManager == null) {
        logger.log(TreeLogger.ERROR, "Can't find interface type '" + typeName + "'", null);
        throw new UnableToCompleteException();
    }
    if (extensionManager.isInterface() == null) {
        logger.log(TreeLogger.ERROR, extensionManager.getQualifiedSourceName() + " is not an interface", null);
        throw new UnableToCompleteException();
    }
    List<JClassType> extensions = new ArrayList<>();
    for (JClassType type : typeOracle.getTypes()) {
        if (type.isAnnotationPresent(Extension.class)) {
            extensions.add(type);
        }
    }
    String packageName = extensionManager.getPackage().getName();
    String className = extensionManager.getSimpleSourceName() + "Impl";
    generateClass(logger, context, packageName, className, extensions);
    return packageName + "." + className;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) TypeOracle(com.google.gwt.core.ext.typeinfo.TypeOracle) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) ArrayList(java.util.ArrayList)

Example 12 with UnableToCompleteException

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

the class PhoneGapLogValueGenerator method generate.

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
    PropertyOracle propertyOracle = context.getPropertyOracle();
    ConfigurationProperty property = null;
    int value = 100;
    try {
        property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
        List<String> values = property.getValues();
        if (values.size() < 1) {
            logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
        } else {
            String stringValue = values.get(0);
            try {
                value = Integer.parseInt(stringValue);
            } catch (Exception e) {
                logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
            }
        }
    } catch (BadPropertyValueException e) {
        logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
    }
    JClassType classType = null;
    try {
        classType = context.getTypeOracle().getType(typeName);
    } catch (NotFoundException e) {
        logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
        throw new UnableToCompleteException();
    }
    String packageName = classType.getPackage().getName();
    String simpleName = classType.getSimpleSourceName() + "_" + value;
    String fullName = packageName + "." + simpleName;
    ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
    composer.addImplementedInterface(typeName);
    composer.addImport(typeName);
    PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
    if (printWriter == null) {
        return fullName;
    }
    SourceWriter writer = composer.createSourceWriter(context, printWriter);
    writer.println("public int getMaxEntries() {");
    writer.println("return " + value + ";");
    writer.println("}");
    writer.commit(logger);
    return fullName;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Example 13 with UnableToCompleteException

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

the class ImageResourceInfo method getConfigDoc.

private NodeList getConfigDoc(String xpath) throws UnableToCompleteException {
    try {
        String resourceName = bundleType_.getQualifiedSourceName().replace('.', '/') + ".cmd.xml";
        Resource resource = context_.getResourcesOracle().getResource(resourceName);
        if (resource == null)
            return null;
        Object result = XPathFactory.newInstance().newXPath().evaluate(xpath, new InputSource(resource.getLocation()), XPathConstants.NODESET);
        return (NodeList) result;
    } catch (Exception e) {
        logger_.log(TreeLogger.Type.ERROR, "Barf", e);
        throw new UnableToCompleteException();
    }
}
Also used : InputSource(org.xml.sax.InputSource) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) NodeList(org.w3c.dom.NodeList) Resource(com.google.gwt.dev.resource.Resource) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException)

Example 14 with UnableToCompleteException

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

the class ShortcutsEmitter method generate.

public void generate(SourceWriter writer) throws UnableToCompleteException {
    NodeList children = shortcutsEl_.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node childNode = children.item(i);
        if (childNode.getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element childEl = (Element) childNode;
        if (!childEl.getTagName().equals("shortcut")) {
            logger_.log(Type.ERROR, "Unexpected element: " + elementToString(childEl));
            throw new UnableToCompleteException();
        }
        String condition = childEl.getAttribute("if");
        String command = childEl.getAttribute("refid");
        String shortcutValue = childEl.getAttribute("value");
        String title = childEl.getAttribute("title");
        String disableModes = childEl.getAttribute("disableModes");
        // Use null when we don't have a command associated with the shortcut,
        // otherwise refer to the function that returns the command 
        command += command.isEmpty() ? "null" : "()";
        if (shortcutValue.length() == 0) {
            logger_.log(Type.ERROR, "Required attribute shortcut was missing\n" + elementToString(childEl));
            throw new UnableToCompleteException();
        }
        List<String> shortcuts = preprocessShortcutValue(shortcutValue);
        for (String shortcut : shortcuts) {
            printShortcut(writer, condition, shortcut, command, groupName_, title, disableModes);
        }
    }
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 15 with UnableToCompleteException

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("}");
    }
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) ArrayList(java.util.ArrayList) Pair(org.rstudio.core.client.Pair)

Aggregations

UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)17 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)7 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)4 SourceWriter (com.google.gwt.user.rebind.SourceWriter)4 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)3 PrintWriter (java.io.PrintWriter)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 GWT (com.google.gwt.core.client.GWT)2 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)2 JType (com.google.gwt.core.ext.typeinfo.JType)2 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)2 Resource (com.google.gwt.dev.resource.Resource)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Node (org.w3c.dom.Node)2 BadPropertyValueException (com.google.gwt.core.ext.BadPropertyValueException)1 ConfigurationProperty (com.google.gwt.core.ext.ConfigurationProperty)1 PropertyOracle (com.google.gwt.core.ext.PropertyOracle)1