// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
//   private final ImmutableList<KbaBinding> list;
// 
//   public KbaBindingList(KbaBinding... list) {
//     this(Arrays.asList(list));
//   }
//     
//   public KbaBindingList(Iterable<KbaBinding> list) {
//     this.list = ImmutableList.copyOf(list);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(list);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaBindingList)) {
//       return false;
//     }
//     KbaBindingList that = (KbaBindingList) obj;
//     return this.list.equals(that.list);
//   }
// 
//   @Override
//   public String toString() {
//     return this.list.toString();
//   }
// 
//   public ImmutableList<KbaBinding> getList() {
//     return list;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
// 
//   private final String description;
// 
//   public KbaMetaData(String description) {
//     this.description = Preconditions.checkNotNull(description);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(description);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaMetaData)) {
//       return false;
//     }
//     KbaMetaData that = (KbaMetaData)obj;
//     return
//       this.description.equals(that.description);
//   }
// 
//   @Override
//   public String toString() {
//     return String.format(
//         "description: %s",
//         this.description);
//   }
// 
//   public String getDescription() {
//     return description;
//   }
// }


import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package com.google.eclipse.mechanic.core.keybinding;



/**
 * Reads a JSON file containing the mechanic diagnostics, and returns that in
 * the internal format.
 *
 * <p>The changes will be taken from a file with a format like below:
 *
 * <pre>
 *

{
  "metadata" : {
    "description" : "",
  },
  "changeSets" : [
    {
      "scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
      "platform" : "",
      "context" : "org.eclipse.ui.contexts.window",
      "action" : "add",
      "bindings" : [
        {"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
      ]
    },
    {
      "scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
      "platform" : "",
      "context" : "org.eclipse.ui.contexts.window",
      "action" : "add",
      "bindings" : [
        {'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
      ]
    },
  ]
}

 * </pre>
 *
 * This file starts out with metadata (for mechanic's own use), then it has a
 * "changeSets" section, that being a list of what we internally call
 * {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
 * and containing a list of binding changes.
 *
 * @author zorzella@google.com
 */
class KeyBindingsParser {

  static final String METADATA_JSON_KEY = "metadata";
  static final String BINDINGS_JSON_KEY = "bindings";
  static final String CONTEXT_JSON_KEY = "context";
  static final String PLATFORM_JSON_KEY = "platform";
  static final String SCHEME_JSON_KEY = "scheme";
  static final String DESCRIPTION_JSON_KEY = "description";
  static final String CHANGE_SETS_JSON_KEY = "changeSets";
  static final String ACTION_JSON_KEY = "action";
  static final String COMMAND_JSON_KEY = "cmd";
  static final String COMMAND_PARAMETERS_JSON_KEY = "params";
  static final String KEYS_JSON_KEY = "keys";
 
  private static final Gson GSON = new GsonBuilder()
      .setPrettyPrinting()
      .registerTypeAdapter(KbaMetaData.class, new KbaMetaDataAdapter())
      .registerTypeAdapter(KeyBindingsModel.class, new KeyBindingsTaskAdapter())
      .registerTypeAdapter(KbaChangeSet.class, new KbaChangeSetAdapter())
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KbaChangeSet.java
// static final class KbaBindingList {
//   private final ImmutableList<KbaBinding> list;
// 
//   public KbaBindingList(KbaBinding... list) {
//     this(Arrays.asList(list));
//   }
//     
//   public KbaBindingList(Iterable<KbaBinding> list) {
//     this.list = ImmutableList.copyOf(list);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(list);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaBindingList)) {
//       return false;
//     }
//     KbaBindingList that = (KbaBindingList) obj;
//     return this.list.equals(that.list);
//   }
// 
//   @Override
//   public String toString() {
//     return this.list.toString();
//   }
// 
//   public ImmutableList<KbaBinding> getList() {
//     return list;
//   }
// }
// 
// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsModel.java
// public static final class KbaMetaData {
// 
//   private final String description;
// 
//   public KbaMetaData(String description) {
//     this.description = Preconditions.checkNotNull(description);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(description);
//   }
// 
//   @Override
//   public boolean equals(Object obj) {
//     if (!(obj instanceof KbaMetaData)) {
//       return false;
//     }
//     KbaMetaData that = (KbaMetaData)obj;
//     return
//       this.description.equals(that.description);
//   }
// 
//   @Override
//   public String toString() {
//     return String.format(
//         "description: %s",
//         this.description);
//   }
// 
//   public String getDescription() {
//     return description;
//   }
// }


// Path: parent/bundles/com.google.eclipse.mechanic/src/com/google/eclipse/mechanic/core/keybinding/KeyBindingsParser.java
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.eclipse.mechanic.core.keybinding.KbaChangeSet.KbaBindingList;
import com.google.eclipse.mechanic.core.keybinding.KeyBindingsModel.KbaMetaData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;

/*******************************************************************************
 * Copyright (C) 2010, Google Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package com.google.eclipse.mechanic.core.keybinding;



/**
 * Reads a JSON file containing the mechanic diagnostics, and returns that in
 * the internal format.
 *
 * <p>The changes will be taken from a file with a format like below:
 *
 * <pre>
 *

{
  "metadata" : {
    "description" : "",
  },
  "changeSets" : [
    {
      "scheme" : "org.eclipse.ui.emacsAcceleratorConfiguration",
      "platform" : "",
      "context" : "org.eclipse.ui.contexts.window",
      "action" : "add",
      "bindings" : [
        {"keys" : "Shift+Alt+Q T", "cmd" : "a.b.c.d.e"}
      ]
    },
    {
      "scheme" : "org.eclipse.ui.defaultAcceleratorConfiguration",
      "platform" : "",
      "context" : "org.eclipse.ui.contexts.window",
      "action" : "add",
      "bindings" : [
        {'keys' : 'Shift+Alt+Q I', 'cmd' : 'org.eclipse.ui.views.showView', 'params' : {'org.eclipse.ui.views.showView.viewId' : 'org.eclipse.jdt.debug.ui.DisplayView' }},
      ]
    },
  ]
}

 * </pre>
 *
 * This file starts out with metadata (for mechanic's own use), then it has a
 * "changeSets" section, that being a list of what we internally call
 * {@link KbaChangeSet}, each specific to a single scheme/platform/context/action,
 * and containing a list of binding changes.
 *
 * @author zorzella@google.com
 */
class KeyBindingsParser {

  static final String METADATA_JSON_KEY = "metadata";
  static final String BINDINGS_JSON_KEY = "bindings";
  static final String CONTEXT_JSON_KEY = "context";
  static final String PLATFORM_JSON_KEY = "platform";
  static final String SCHEME_JSON_KEY = "scheme";
  static final String DESCRIPTION_JSON_KEY = "description";
  static final String CHANGE_SETS_JSON_KEY = "changeSets";
  static final String ACTION_JSON_KEY = "action";
  static final String COMMAND_JSON_KEY = "cmd";
  static final String COMMAND_PARAMETERS_JSON_KEY = "params";
  static final String KEYS_JSON_KEY = "keys";
 
  private static final Gson GSON = new GsonBuilder()
      .setPrettyPrinting()
      .registerTypeAdapter(KbaMetaData.class, new KbaMetaDataAdapter())
      .registerTypeAdapter(KeyBindingsModel.class, new KeyBindingsTaskAdapter())
      .registerTypeAdapter(KbaChangeSet.class, new KbaChangeSetAdapter())
      .registerTypeAdapter(KbaChangeSet.KbaBindingList.class, new KbaBindingListAdapter())