How to fix this problem got when compiling my component

YaClientApp:
[mkdir] Created dir: C:\xampp\htdocs\hyride\hydride\appinventor\appengine\build\extra
[java] Compiling module com.google.appinventor.YaClient
[java] Ignored 3 units with compilation errors in first pass.
[java] Compile with -strict or with -logLevel set to DEBUG or WARN to see all errors.
[java] Ignored 3 units with compilation errors in first pass.
[java] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[java] Computing all possible rebind results for ‘com.google.appinventor.client.editor.youngandroid.BlocklyPanel.BlocklySource’
[java] Rebinding com.google.appinventor.client.editor.youngandroid.BlocklyPanel.BlocklySource
[java] Invoking generator com.google.gwt.query.rebind.JsniBundleGenerator
[java] JsniBundleGenerator - importing external javascript: com/google/appinventor/client/editor/youngandroid/blockly.js
[java] [ERROR] Errors in ‘file:/C:/xampp/htdocs/hyride/hydride/appinventor/build/components/ComponentTranslation/src/com/google/appinventor/client/ComponentsTranslation.java’
[java] [ERROR] Line 58: The code of method map() is exceeding the 65535 bytes limit
[java] Tracing compile failure path for type ‘com.google.appinventor.client.ComponentsTranslation’
[java] [ERROR] Errors in ‘file:/C:/xampp/htdocs/hyride/hydride/appinventor/build/components/ComponentTranslation/src/com/google/appinventor/client/ComponentsTranslation.java’
[java] [ERROR] Line 58: The code of method map() is exceeding the 65535 bytes limit
[java] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

Please help me to fix this issue !

1 Like

@ewpatton Would it be worthwhile to bring this up as an issue? It seems that by making an extension, the ComponentsTranslation map method was overflown with more methods than Java can handle. It might be worthwhile to rewrite the generator code to split it up in multiple methods to resolve future extensions.

To reply to the thread, it seems that the functionality you added that also affects Component Translation entries has surpassed the limit of the map() method in Component Translations. Unfortunately I am not aware of a simple fix (maybe there is one that I am not aware of and someone else could direct to it), but the underlying idea is that the Component Translation Generator code most likely has to be modified to fix the issue by creating new methods instead of putting all the code into a single method body.

1 Like

This technically doesn’t affect extensions because building extensions (ant extensions) doesn’t invoke the compilation of ComponentsTranslation. That’s done as part of the appengine build. We have some other work we’re doing around translations and so we can work on addressing this issue as part of that. My goal is that ideally ComponentsTranslation will go away entirely.

1 Like

During Compilation of ComponentsTranslation, the code too large comes up:

ComponentsTranslation.java:61: error: code too large
[javac] public static HashMap<String, String> map() {

What might be causing this issue and is there any solution? Thanks

2 Likes

Simply Dividing won't solve the issue

1 Like

I know, currently i just quickly solved it for the time being but i hope AppInventor patches it with something stable

2 Likes

Is there any solution available to this?

No, but if you're building an extension you can always switch to using the extension template.

Hi @ewpatton
But I am creating an app inventor.
I asked some users and they said to change something in Components Translation Generator but no one told me what I have to change.
Kindly suggest any workaround.

Can anyone help? :thinking:

You need to modify the ComponentTranslationsGenerator code to break out the output into smaller chunks. You could probably do it per type of translation (property, method, event) and have each method invoked separately so that the length of each method is below the limit.

1 Like

Hi @ewpatton
Sorry for disturbing you again.
But I failed to do that. :disappointed_relieved:
Here is the current file:

package com.google.appinventor.components.scripts;
import java.io.IOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;

public final class ComponentTranslationGenerator extends ComponentProcessor {
  // Where to write results.
  private static final String OUTPUT_FILE_NAME = "ComponentsTranslation.java";
  private static final String AUTOGEN_OUTPUT_FILE_NAME = "AutogeneratedOdeMessages.java";

  private Map<String, String> tooltips = new TreeMap<>();
  private Map<String, Set<String>> tooltipComponent = new TreeMap<>();
  private Set<String> collisionKeys = new HashSet<>();
  private Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
  public String componentString(ComponentInfo component){
    return "\n\n/* Component: " + component.getName() + " */\n\n" +
            "    map.put(\"COMPONENT-" + component.getName() + "\", MESSAGES."
            + Character.toLowerCase(component.getName().charAt(0)) + component.getName().substring(1)
            + "ComponentPallette());\n\n" +
            "    map.put(\"" + component.getName() + "-helpString\", MESSAGES."
            + component.getName() + "HelpStringComponentPallette());\n\n";
  }
  public String propertyString(ComponentInfo component,Set<String> outProperties){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Properties */\n\n");
    for (Property prop : component.properties.values()) {
      String propertyName = prop.name;
      if (prop.isUserVisible()
              || component.designerProperties.containsKey(propertyName)
              || prop.isDeprecated() // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    map.put(\"PROPERTY-").append(propertyName).append("\", MESSAGES.").append(propertyName).append("Properties());\n");
        outProperties.add(propertyName);
      }
    }
    return sb.toString();
  }
  public String eventString(ComponentInfo component,Set<String> outEvents){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Events */\n\n");
    for (Event event : component.events.values()) {
      String propertyName = event.name;
      if (event.userVisible
              || event.deprecated // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    map.put(\"EVENT-" + propertyName + "\", MESSAGES." + propertyName + "Events());\n");
        for (Parameter parameter : event.parameters) {
          parameters.put(parameter.name, parameter);
        }
        outEvents.add(propertyName);
      }
    }
    return sb.toString();
  }
  public String methodString(ComponentInfo component,Set<String> outMethods){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Methods */\n\n");
    for (Method method : component.methods.values()) {
      String propertyName = method.name;
      if (method.userVisible
              || method.deprecated // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    map.put(\"METHOD-" + propertyName + "\", MESSAGES." + propertyName + "Methods());\n");
        for (Parameter parameter : method.parameters) {
          parameters.put(parameter.name, parameter);
        }
        outMethods.add(propertyName);
      }
    }
    return sb.toString();
  }
  private void outputComponent(ComponentInfo component, Set<String> outProperties,
                               Set<String> outMethods, Set<String> outEvents, StringBuilder sb) {
    if (component.getExternal()) { // Avoid adding entries for external components
      return;
    }
    sb.append(componentString(component));
    sb.append(propertyString(component,outProperties));
    sb.append(eventString(component,outEvents));
    sb.append(methodString(component,outMethods));
    // This special case adds the notAlreadyHandled parameter, which is the second parameter for the generic event
    // handlers. Since it's not explicitly declared in any event handler, we add it here for internationalization.
    parameters.put("notAlreadyHandled", new Parameter("notAlreadyHandled", "boolean"));
    sb.append("\n\n/* Parameters */\n\n");
    for (Parameter parameter : parameters.values()) {
      sb.append("    map.put(\"PARAM-" + parameter.name + "\", MESSAGES." +
              Character.toLowerCase(parameter.name.charAt(0)) + parameter.name.substring(1) +
              "Params());\n");
    }
  }

  private void outputCategory(String category, StringBuilder sb) {
    // santize the category name
    String[] parts = category.split(" ");
    sb.append("    map.put(\"CATEGORY-").append(category).append("\", MESSAGES.").append(parts[0].replaceAll("[^A-Za-z0-9]", "").toLowerCase());
    for (int i = 1; i < parts.length; i++) {
      String lower = parts[i].replaceAll("[^A-Za-z0-9]", "").toLowerCase();
      sb.append(Character.toUpperCase(lower.charAt(0)));
      sb.append(lower.substring(1));
    }
    sb.append("ComponentPallette());\n");
  }

  private void outputPropertyCategory(String category, StringBuilder sb) {
    sb.append("    map.put(\"CATEGORY-");
    sb.append(category);
    sb.append("\", MESSAGES.");
    sb.append(category);
    sb.append("PropertyCategory());\n");
  }

  private void outputComponentAutogen(ComponentInfo component,
                                      Map<String, Property> outProperties, Map<String, Method> outMethods,
                                      Map<String, Event> outEvents, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(component.getName());
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(Character.toLowerCase(component.getName().charAt(0)));
    sb.append(component.getName().substring(1));
    sb.append("ComponentPallette();\n\n");
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(component.description));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(component.getName());
    sb.append("HelpStringComponentPallette();\n\n");
    for (Property property : component.properties.values()) {
      if (property.isUserVisible() || component.designerProperties.containsKey(property.name) ||
              property.isDeprecated()) {
        outProperties.put(property.name, property);
      }
    }
    for (Method method : component.methods.values()) {
      if (method.userVisible || method.deprecated) {
        outMethods.put(method.name, method);
      }
    }
    for (Event event : component.events.values()) {
      if (event.userVisible || event.deprecated) {
        outEvents.put(event.name, event);
      }
    }
  }

  private void outputPropertyAutogen(Property property, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(property.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(property.name);
    sb.append("Properties();\n\n");
  }

  private void outputMethodAutogen(Method method, Map<String, Parameter> outParameters, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(method.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(method.name);
    sb.append("Methods();\n\n");
    for (Parameter param : method.parameters) {
      outParameters.put(param.name, param);
    }
  }

  private void outputEventAutogen(Event event, Map<String, Parameter> outParameters, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(event.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(event.name);
    sb.append("Events();\n\n");
    for (Parameter param : event.parameters) {
      outParameters.put(param.name, param);
    }
  }

  private void outputParameterAutogen(Parameter parameter, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(parameter.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(parameter.name);
    sb.append("Params();\n\n");
  }

  private void outputCategoryAutogen(String category, StringBuilder sb) {
    String[] parts = category.split(" ");
    sb.append("  @DefaultMessage(\"");
    sb.append(category);
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(parts[0].replaceAll("[^A-Za-z0-9]", "").toLowerCase());
    for (int i = 1; i < parts.length; i++) {
      String lower = parts[i].replaceAll("[^A-Za-z0-9]", "").toLowerCase();
      sb.append(Character.toUpperCase(lower.charAt(0)));
      sb.append(lower.substring(1));
    }
    sb.append("ComponentPallette();\n\n");
  }

  private void outputPropertyCategoryAutogen(String category, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(category);
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(category);
    sb.append("PropertyCategory();\n\n");
  }

  private String sanitize(String input) {
    return input.replaceAll("\r", "").replaceAll("\n", "").replaceAll("\\\\", "\\\\\\\\")
            .replaceAll("\"", "\\\\\"").replaceAll("'", "''").replaceAll("[ \t]+", " ").trim();
  }

  private void storeTooltip(ComponentInfo component, String name, String suffix,
                            String description) {
    String key = name + suffix;
    String value = tooltips.get(key);
    if (collisionKeys.contains(key)) {
      // Already detected a collision
      key = component.getName() + "__" + key;
      tooltips.put(key, description);
    } else if (value == null) {
      // This is the first observation of this key
      tooltips.put(key, description);
      Set<String> components = new HashSet<>();
      components.add(component.getName());
      tooltipComponent.put(key, components);
    } else if (!value.equals(description)) {
      // Descriptions don't match == collision!
      collisionKeys.add(key);
      for (String componentName : tooltipComponent.get(key)) {
        tooltips.put(componentName + "__" + key, value);
      }
      key = component.getName() + "__" + key;
      tooltips.put(key, description);
    } else {
      // Two (or more) components have the exact same description. Technically not a collision, but
      // we need to do some bookkeeping in case a collision is detected with another component.
      tooltipComponent.get(key).add(component.getName());
    }
  }

  private void computeTooltipMap(ComponentInfo component) {
    for (Property property : component.properties.values()) {
      storeTooltip(component, property.name, "PropertyDescriptions", property.getDescription());
    }
    for (Method method : component.methods.values()) {
      storeTooltip(component, method.name, "MethodDescriptions", method.description);
    }
    for (Event event : component.events.values()) {
      storeTooltip(component, event.name, "EventDescriptions", event.description);
    }
  }

  protected void outputAutogenOdeMessages() throws IOException {
    Set<String> categories = new TreeSet<>();
    Map<String, Property> properties = new TreeMap<>();
    Map<String, Method> methods = new TreeMap<>();
    Map<String, Event> events = new TreeMap<>();
    Map<String, Parameter> parameters = new TreeMap<>();
    StringBuilder sb = new StringBuilder();
    sb.append("// THIS FILE IS AUTOMATICALLY GENERATED DURING COMPILATION.\n");
    sb.append("// DO NOT EDIT THIS FILE. ANY CHANGES WILL BE OVERWRITTEN.\n\n");
    sb.append("package com.google.appinventor.client;\n\n");
    sb.append("import com.google.gwt.i18n.client.Messages;\n\n");
    sb.append("public interface AutogeneratedOdeMessages extends Messages {\n");
    sb.append("\n  /* Components */\n");
    for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
      ComponentInfo component = entry.getValue();
      outputComponentAutogen(component, properties, methods, events, sb);
      computeTooltipMap(component);
      categories.add(component.getCategory());
    }
    for (String key : collisionKeys) {
      tooltips.remove(key);
    }
    sb.append("\n  /* Properties */\n");
    for (Map.Entry<String, Property> entry : properties.entrySet()) {
      outputPropertyAutogen(entry.getValue(), sb);
    }
    sb.append("\n  /* Methods */\n");
    for (Map.Entry<String, Method> entry : methods.entrySet()) {
      outputMethodAutogen(entry.getValue(), parameters, sb);
    }
    sb.append("\n  /* Events */\n");
    for (Map.Entry<String, Event> entry : events.entrySet()) {
      outputEventAutogen(entry.getValue(), parameters, sb);
    }
    for (Map.Entry<String, String> entry : tooltips.entrySet()) {
      sb.append("  @DefaultMessage(\"");
      sb.append(sanitize(entry.getValue()));
      sb.append("\")\n");
      sb.append("  @Description(\"\")\n");
      sb.append("  String ");
      sb.append(entry.getKey());
      sb.append("();\n\n");
    }
    sb.append("\n  /* Parameters */\n");
    for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
      outputParameterAutogen(entry.getValue(), sb);
    }
    sb.append("\n  /* Component Categories */\n");
    for (String category : categories) {
      outputCategoryAutogen(category, sb);
    }
    sb.append("\n  /* Property Categories */\n");
    outputPropertyCategoryAutogen("Appearance", sb);
    outputPropertyCategoryAutogen("Behavior", sb);
    outputPropertyCategoryAutogen("Unspecified", sb);
    sb.append("}\n");
    FileObject src = createOutputFileObject(AUTOGEN_OUTPUT_FILE_NAME);
    Writer writer = src.openWriter();
    writer.write(sb.toString());
    writer.flush();
    writer.close();
    messager.printMessage(Kind.NOTE, "Wrote file " + src.toUri());
  }
  public String oR(){
    return "package com.google.appinventor.client;\n" +
            "\n" +
            "import java.util.HashMap;\n" +
            "import java.util.Map;\n" +
            "\n" +
            "import static com.google.appinventor.client.Ode.MESSAGES;\n" +
            "\n" +
            "public class ComponentsTranslation {\n" +
            "  public static Map<String, String> myMap = map();\n\n" +
            "  private static String getName(String key) {\n" +
            "    String value = myMap.get(key);\n" +
            "    if (key == null) {\n" +
            "      return \"**Missing key in ComponentsTranslations**\";\n" +
            "    } else {\n" +
            "      return value;\n" +
            "    }\n" +
            "  }\n\n" +
            "  public static String getPropertyName(String key) {\n" +
            "    String value = getName(\"PROPERTY-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n\n" +
            "  public static String getPropertyDescription(String key) {\n" +
            "    String value = getName(\"PROPDESC-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n\n" +
            "  public static String getMethodName(String key) {\n" +
            "    String value = getName(\"METHOD-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n" +
            "\n" +
            "  public static String getEventName(String key) {\n" +
            "    String value = getName(\"EVENT-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n" +
            "\n" +
            "  public static String getComponentName(String key) {\n" +
            "    String value = getName(\"COMPONENT-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n" +
            "\n" +
            "  public static String getCategoryName(String key) {\n" +
            "    String value = getName(\"CATEGORY-\" + key);\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n" +
            "\n" +
            "  public static String getComponentHelpString(String key) {\n" +
            "    String value = getName(key + \"-helpString\");\n" +
            "    if(value == null) return key;\n" +
            "    return value;\n" +
            "  }\n" +
            "  public static HashMap<String, String> map() {\n" +
            "    HashMap<String, String> map = new HashMap<String, String>();\n";
  }
  @Override
  protected void outputResults() throws IOException {
    outputAutogenOdeMessages();
    StringBuilder sb = new StringBuilder();
    sb.append(oR());
    // Components are already sorted.
    Set<String> categories = new TreeSet<>();
    Set<String> properties = new TreeSet<>();
    Set<String> methods = new TreeSet<>();
    Set<String> events = new TreeSet<>();
    for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
      ComponentInfo component = entry.getValue();
      outputComponent(component, properties, methods, events, sb);
      categories.add(component.getCategory());
    }
    sb.append("\n\n    /* Descriptions */\n\n");
    for (String key : tooltips.keySet()) {
      if (key.endsWith("PropertyDescriptions")) {
        sb.append("    map.put(\"PROPDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      } else if (key.endsWith("MethodDescriptions")) {
        sb.append("    map.put(\"METHODDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      } else if (key.endsWith("EventDescriptions")) {
        sb.append("    map.put(\"EVENTDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      }
    }
    sb.append("\n\n    /* Categories */\n\n");
    for (String category : categories) {
      outputCategory(category, sb);
    }
    sb.append("  return map;\n");
    sb.append("  }\n");
    sb.append("}\n");
    FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
    Writer writer = src.openWriter();
    writer.write(sb.toString());
    writer.flush();
    writer.close();
    messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
  }
}

Kindly provide an example.

Thank you Sir.
Here is the working code:

package com.google.appinventor.components.scripts;

import java.io.IOException;
import java.io.Writer;
import java.util.*;

import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;

public final class ComponentTranslationGenerator extends ComponentProcessor {
  // Where to write results.
  private static final String OUTPUT_FILE_NAME = "ComponentsTranslation.java";
  private static final String AUTOGEN_OUTPUT_FILE_NAME = "AutogeneratedOdeMessages.java";

  private Map<String, String> tooltips = new TreeMap<>();
  private Map<String, Set<String>> tooltipComponent = new TreeMap<>();
  private Set<String> collisionKeys = new HashSet<>();
  private Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
  public String componentString(ComponentInfo component){
    return "\n\n/* Component: " + component.getName() + " */\n\n" +
            "    map.put(\"COMPONENT-" + component.getName() + "\", MESSAGES."
            + Character.toLowerCase(component.getName().charAt(0)) + component.getName().substring(1)
            + "ComponentPallette());\n\n" +
            "    map.put(\"" + component.getName() + "-helpString\", MESSAGES."
            + component.getName() + "HelpStringComponentPallette());\n\n";
  }
  public String propertyString(ComponentInfo component,Set<String> outProperties){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Properties */\n\n");
    for (Property prop : component.properties.values()) {
      String propertyName = prop.name;
      if (prop.isUserVisible()
              || component.designerProperties.containsKey(propertyName)
              || prop.isDeprecated() // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    propertyStringMap.put(\"PROPERTY-").append(propertyName).append("\", MESSAGES.").append(propertyName).append("Properties());\n");
        outProperties.add(propertyName);
      }
    }
    return sb.toString();
  }
  public String eventString(ComponentInfo component,Set<String> outEvents){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Events */\n\n");
    for (Event event : component.events.values()) {
      String propertyName = event.name;
      if (event.userVisible
              || event.deprecated // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    eventStringMap.put(\"EVENT-").append(propertyName).append("\", MESSAGES.").append(propertyName).append("Events());\n");
        for (Parameter parameter : event.parameters) {
          parameters.put(parameter.name, parameter);
        }
        outEvents.add(propertyName);
      }
    }
    return sb.toString();
  }
  public String methodString(ComponentInfo component,Set<String> outMethods){
    StringBuilder sb = new StringBuilder();
    sb.append("\n\n/* Methods */\n\n");
    for (Method method : component.methods.values()) {
      String propertyName = method.name;
      if (method.userVisible
              || method.deprecated // [lyn, 2015/12/30] For deprecated AI2 blocks (but not AI1 blocks)
        // must translate property names so they can be displayed in bad blocks.
      ) {
        sb.append("    methodStringMap.put(\"METHOD-").append(propertyName).append("\", MESSAGES.").append(propertyName).append("Methods());\n");
        for (Parameter parameter : method.parameters) {
          parameters.put(parameter.name, parameter);
        }
        outMethods.add(propertyName);
      }
    }
    return sb.toString();
  }
  private void outputEventString(ComponentInfo component,Set<String> outEvents, StringBuilder sb){
      if (component.getExternal()) { // Avoid adding entries for external components
          return;
      }
      sb.append(eventString(component,outEvents));
  }
    private void outputMethodString(ComponentInfo component,Set<String> outMethods, StringBuilder sb){
        if (component.getExternal()) { // Avoid adding entries for external components
            return;
        }
        sb.append(methodString(component,outMethods));
    }
    private void outputPropertyString(ComponentInfo component,Set<String> outProperties, StringBuilder sb){
        if (component.getExternal()) { // Avoid adding entries for external components
            return;
        }
        sb.append(propertyString(component,outProperties));
    }

  private void outputComponent(ComponentInfo component, Set<String> outProperties,
                               Set<String> outMethods, Set<String> outEvents, StringBuilder sb) {
    if (component.getExternal()) { // Avoid adding entries for external components
      return;
    }
    /*sb.append("public static HashMap<String,String> component(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");*/
    sb.append(componentString(component));
    /*sb.append(propertyString(component,outProperties));
    sb.append(methodString(component,outMethods));*/
    // This special case adds the notAlreadyHandled parameter, which is the second parameter for the generic event
    // handlers. Since it's not explicitly declared in any event handler, we add it here for internationalization.
    parameters.put("notAlreadyHandled", new Parameter("notAlreadyHandled", "boolean"));
    sb.append("\n\n/* Parameters */\n\n");
    for (Parameter parameter : parameters.values()) {
      sb.append("    map.put(\"PARAM-").append(parameter.name).append("\", MESSAGES.").append(Character.toLowerCase(parameter.name.charAt(0))).append(parameter.name.substring(1)).append("Params());\n");
    }
    /*sb.append("return map;\n" +
            "    }");*/
  }

  private void outputCategory(String category, StringBuilder sb) {
    // sanitize the category name
    String[] parts = category.split(" ");
    sb.append("    map.put(\"CATEGORY-").append(category).append("\", MESSAGES.").append(parts[0].replaceAll("[^A-Za-z0-9]", "").toLowerCase());
    for (int i = 1; i < parts.length; i++) {
      String lower = parts[i].replaceAll("[^A-Za-z0-9]", "").toLowerCase();
      sb.append(Character.toUpperCase(lower.charAt(0)));
      sb.append(lower.substring(1));
    }
    sb.append("ComponentPallette());\n");
  }

  private void outputPropertyCategory(String category, StringBuilder sb) {
    sb.append("    map.put(\"CATEGORY-");
    sb.append(category);
    sb.append("\", MESSAGES.");
    sb.append(category);
    sb.append("PropertyCategory());\n");
  }

  private void outputComponentAutogen(ComponentInfo component,
                                      Map<String, Property> outProperties, Map<String, Method> outMethods,
                                      Map<String, Event> outEvents, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(component.getName());
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(Character.toLowerCase(component.getName().charAt(0)));
    sb.append(component.getName().substring(1));
    sb.append("ComponentPallette();\n\n");
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(component.description));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(component.getName());
    sb.append("HelpStringComponentPallette();\n\n");
    for (Property property : component.properties.values()) {
      if (property.isUserVisible() || component.designerProperties.containsKey(property.name) ||
              property.isDeprecated()) {
        outProperties.put(property.name, property);
      }
    }
    for (Method method : component.methods.values()) {
      if (method.userVisible || method.deprecated) {
        outMethods.put(method.name, method);
      }
    }
    for (Event event : component.events.values()) {
      if (event.userVisible || event.deprecated) {
        outEvents.put(event.name, event);
      }
    }
  }

  private void outputPropertyAutogen(Property property, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(property.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(property.name);
    sb.append("Properties();\n\n");
  }

  private void outputMethodAutogen(Method method, Map<String, Parameter> outParameters, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(method.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(method.name);
    sb.append("Methods();\n\n");
    for (Parameter param : method.parameters) {
      outParameters.put(param.name, param);
    }
  }

  private void outputEventAutogen(Event event, Map<String, Parameter> outParameters, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(event.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(event.name);
    sb.append("Events();\n\n");
    for (Parameter param : event.parameters) {
      outParameters.put(param.name, param);
    }
  }

  private void outputParameterAutogen(Parameter parameter, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(sanitize(parameter.name));
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(parameter.name);
    sb.append("Params();\n\n");
  }

  private void outputCategoryAutogen(String category, StringBuilder sb) {
    String[] parts = category.split(" ");
    sb.append("  @DefaultMessage(\"");
    sb.append(category);
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(parts[0].replaceAll("[^A-Za-z0-9]", "").toLowerCase());
    for (int i = 1; i < parts.length; i++) {
      String lower = parts[i].replaceAll("[^A-Za-z0-9]", "").toLowerCase();
      sb.append(Character.toUpperCase(lower.charAt(0)));
      sb.append(lower.substring(1));
    }
    sb.append("ComponentPallette();\n\n");
  }

  private void outputPropertyCategoryAutogen(String category, StringBuilder sb) {
    sb.append("  @DefaultMessage(\"");
    sb.append(category);
    sb.append("\")\n");
    sb.append("  @Description(\"\")\n");
    sb.append("  String ");
    sb.append(category);
    sb.append("PropertyCategory();\n\n");
  }

  private String sanitize(String input) {
    return input.replaceAll("\r", "").replaceAll("\n", "").replaceAll("\\\\", "\\\\\\\\")
            .replaceAll("\"", "\\\\\"").replaceAll("'", "''").replaceAll("[ \t]+", " ").trim();
  }

  private void storeTooltip(ComponentInfo component, String name, String suffix,
                            String description) {
    String key = name + suffix;
    String value = tooltips.get(key);
    if (collisionKeys.contains(key)) {
      // Already detected a collision
      key = component.getName() + "__" + key;
      tooltips.put(key, description);
    } else if (value == null) {
      // This is the first observation of this key
      tooltips.put(key, description);
      Set<String> components = new HashSet<>();
      components.add(component.getName());
      tooltipComponent.put(key, components);
    } else if (!value.equals(description)) {
      // Descriptions don't match == collision!
      collisionKeys.add(key);
      for (String componentName : tooltipComponent.get(key)) {
        tooltips.put(componentName + "__" + key, value);
      }
      key = component.getName() + "__" + key;
      tooltips.put(key, description);
    } else {
      // Two (or more) components have the exact same description. Technically not a collision, but
      // we need to do some bookkeeping in case a collision is detected with another component.
      tooltipComponent.get(key).add(component.getName());
    }
  }

  private void computeTooltipMap(ComponentInfo component) {
    for (Property property : component.properties.values()) {
      storeTooltip(component, property.name, "PropertyDescriptions", property.getDescription());
    }
    for (Method method : component.methods.values()) {
      storeTooltip(component, method.name, "MethodDescriptions", method.description);
    }
    for (Event event : component.events.values()) {
      storeTooltip(component, event.name, "EventDescriptions", event.description);
    }
  }

  protected void outputAutogenOdeMessages() throws IOException {
    Set<String> categories = new TreeSet<>();
    Map<String, Property> properties = new TreeMap<>();
    Map<String, Method> methods = new TreeMap<>();
    Map<String, Event> events = new TreeMap<>();
    Map<String, Parameter> parameters = new TreeMap<>();
    StringBuilder sb = new StringBuilder();
    sb.append("// THIS FILE IS AUTOMATICALLY GENERATED DURING COMPILATION.\n");
    sb.append("// DO NOT EDIT THIS FILE. ANY CHANGES WILL BE OVERWRITTEN.\n\n");
    sb.append("package com.google.appinventor.client;\n\n");
    sb.append("import com.google.gwt.i18n.client.Messages;\n\n");
    sb.append("public interface AutogeneratedOdeMessages extends Messages {\n");
    sb.append("\n  /* Components */\n");
    for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
      ComponentInfo component = entry.getValue();
      outputComponentAutogen(component, properties, methods, events, sb);
      computeTooltipMap(component);
      categories.add(component.getCategory());
    }
    for (String key : collisionKeys) {
      tooltips.remove(key);
    }
    sb.append("\n  /* Properties */\n");
    for (Map.Entry<String, Property> entry : properties.entrySet()) {
      outputPropertyAutogen(entry.getValue(), sb);
    }
    sb.append("\n  /* Methods */\n");
    for (Map.Entry<String, Method> entry : methods.entrySet()) {
      outputMethodAutogen(entry.getValue(), parameters, sb);
    }
    sb.append("\n  /* Events */\n");
    for (Map.Entry<String, Event> entry : events.entrySet()) {
      outputEventAutogen(entry.getValue(), parameters, sb);
    }
    for (Map.Entry<String, String> entry : tooltips.entrySet()) {
      sb.append("  @DefaultMessage(\"");
      sb.append(sanitize(entry.getValue()));
      sb.append("\")\n");
      sb.append("  @Description(\"\")\n");
      sb.append("  String ");
      sb.append(entry.getKey());
      sb.append("();\n\n");
    }
    sb.append("\n  /* Parameters */\n");
    for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
      outputParameterAutogen(entry.getValue(), sb);
    }
    sb.append("\n  /* Component Categories */\n");
    for (String category : categories) {
      outputCategoryAutogen(category, sb);
    }
    sb.append("\n  /* Property Categories */\n");
    outputPropertyCategoryAutogen("Appearance", sb);
    outputPropertyCategoryAutogen("Behavior", sb);
    outputPropertyCategoryAutogen("Unspecified", sb);
    sb.append("}\n");
    FileObject src = createOutputFileObject(AUTOGEN_OUTPUT_FILE_NAME);
    Writer writer = src.openWriter();
    writer.write(sb.toString());
    writer.flush();
    writer.close();
    messager.printMessage(Kind.NOTE, "Wrote file " + src.toUri());
  }
  public String oR(){
    return "package com.google.appinventor.client;\n" +
            "\n" +
            "import java.util.HashMap;\n" +
            "import java.util.Map;\n" +
            "\n" +
            "import static com.google.appinventor.client.Ode.MESSAGES;\n" +
            "\n" +
            "public class ComponentsTranslation {\n" +
            "  public static Map<String, String> myMap = map();\n" +
            "    public static Map<String,String> propertyMap = property();\n" +
            "    public static Map<String,String> eventMap = event();\n" +
            "    public static Map<String,String> methodMap = method();\n" +
            "     public static Map<String,String> componentMap = component();\n" +
            "public static Map<String,String> propertyStringMap = propertyString();\n" +
            "    public static Map<String,String> methodStringMap = methodString();\n" +
            "    public static Map<String,String> eventStringMap = eventString();\n" +
            "  private static String getName(String key,int type) {\n" +
            "        String value = \"\";\n" +
            "        if (type == 1){\n" +
            "            value = propertyMap.get(key);\n" +
            "        }else if(type == 2){\n" +
            "            value = methodMap.get(key);\n" +
            "        }else if(type == 3){\n" +
            "            value = eventMap.get(key);\n" +
            "        }else if(type == 4){\n" +
            "            value = componentMap.get(key);\n" +
            "        }else if(type == 5){\n" +
            "            value = eventStringMap.get(key);\n" +
            "        }else if(type == 6){\n" +
            "            value = methodStringMap.get(key);\n" +
            "        }else if(type == 7){\n" +
            "            value = propertyStringMap.get(key);\n" +
            "        }else {\n" +
            "            value = myMap.get(key);\n" +
            "        }\n" +
            "        if (key == null) {\n" +
            "            return \"\";\n" +
            "        } else {\n" +
            "            return value;\n" +
            "        }\n" +
            "    }" +
            "  public static String getPropertyName(String key) {\n" +
            "        String value = getName(\"PROPERTY-\" + key,1);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getPropertyDescription(String key) {\n" +
            "        String value = getName(\"PROPDESC-\" + key,1);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getMethodName(String key) {\n" +
            "        String value = getName(\"METHOD-\" + key,2);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getEventName(String key) {\n" +
            "        String value = getName(\"EVENT-\" + key,3);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getComponentName(String key) {\n" +
            "        String value = getName(\"COMPONENT-\" + key,4);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getCategoryName(String key) {\n" +
            "        String value = getName(\"CATEGORY-\" + key,0);\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "    public static String getComponentHelpString(String key) {\n" +
            "        String value = \"\";\n" +
            "        if (key.contains(\"EVENT-\")) {\n" +
            "            value = getName(key + \"-helpString\", 5);\n" +
            "        }else if(key.contains(\"METHOD-\")){\n" +
            "            value = getName(key + \"-helpString\", 6);\n" +
            "        }else if (key.contains(\"PROPERTY-\")){\n" +
            "            value = getName(key + \"-helpString\", 7);\n" +
            "        }\n" +
            "        if(value == null) return key;\n" +
            "        return value;\n" +
            "    }\n" +
            "  public static HashMap<String, String> map() {\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();\n" +
            "        /*map.putAll(component());\n" +
            "        map.putAll(event());\n" +
            "        map.putAll(method());\n" +
            "        map.putAll(property());*/\n" +
            "        map.putAll(category());\n";
  }
  @Override
  protected void outputResults() throws IOException {
    outputAutogenOdeMessages();
    StringBuilder sb = new StringBuilder();
    sb.append(oR());
    Set<String> categories = new TreeSet<>();
    for (String category : categories) {
      outputCategory(category, sb);
    }
    sb.append("return map;\n" +
            "     }\n");
    sb.append("public static HashMap<String,String> component(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
    // Components are already sorted.
    Set<String> properties = new TreeSet<>();
    Set<String> methods = new TreeSet<>();
    Set<String> events = new TreeSet<>();
    for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
      ComponentInfo component = entry.getValue();
      outputComponent(component, properties, methods, events, sb);
      categories.add(component.getCategory());
    }
    sb.append("return map;\n" +
            "     }");
    sb.append("public static HashMap<String,String> eventString(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
      for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
          ComponentInfo component = entry.getValue();
          outputEventString(component,events,sb);
          categories.add(component.getCategory());
      }
    sb.append("return map;\n" +
              "     }");
      sb.append("public static HashMap<String,String> methodString(){\n" +
              "        HashMap<String, String> map = new HashMap<String, String>();");
      for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
          ComponentInfo component = entry.getValue();
          outputMethodString(component,methods,sb);
          categories.add(component.getCategory());
      }
      sb.append("return map;\n" +
              "     }");
      sb.append("public static HashMap<String,String> propertyString(){\n" +
              "        HashMap<String, String> map = new HashMap<String, String>();");
      for (Map.Entry<String, ComponentInfo> entry : components.entrySet()) {
          ComponentInfo component = entry.getValue();
          outputPropertyString(component,properties,sb);
          categories.add(component.getCategory());
      }
      sb.append("return map;\n" +
              "     }");
    sb.append("\n\n    /* Categories */\n\n");
    sb.append("public static HashMap<String,String> category(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
    sb.append("return map;\n" +
            "     }");
    sb.append("\n\n    /* Descriptions */\n\n");
    sb.append("public static HashMap<String,String> property(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
    for (String key : tooltips.keySet()) {
      if (key.endsWith("PropertyDescriptions")) {
        sb.append("    map.put(\"PROPDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      }
    }
    sb.append("return map;\n" +
            "    }");
    sb.append("public static HashMap<String,String> method(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
    for (String key : tooltips.keySet()) {
      if (key.endsWith("MethodDescriptions")) {
        sb.append("    map.put(\"METHODDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      }
    }
      sb.append("return map;\n" +
            "    }");
    sb.append("public static HashMap<String,String> event(){\n" +
            "        HashMap<String, String> map = new HashMap<String, String>();");
    for (String key : tooltips.keySet()) {
      if (key.endsWith("EventDescriptions")) {
        sb.append("    map.put(\"EVENTDESC-");
        sb.append(key.replaceAll("__", "."));
        sb.append("\", MESSAGES.");
        sb.append(key);
        sb.append("());\n");
      }
    }
    sb.append("return map;\n" +
            "    }");
    sb.append("}\n");
    FileObject src = createOutputFileObject(OUTPUT_FILE_NAME);
    Writer writer = src.openWriter();
    writer.write(sb.toString());
    writer.flush();
    writer.close();
    messager.printMessage(Diagnostic.Kind.NOTE, "Wrote file " + src.toUri());
  }
}

Kindly check and let me know if there is anything wrong.
Thanks once again.