json.editor.plugin_1.0.0.201311011708

16:38:13.136 INFO  jd.cli.Main - Decompiling json.editor.plugin_1.0.0.201311011708.jar
package json;

import json.text.JsonScanner;
import json.util.JsonColorProvider;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.swt.graphics.Color;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class JsonEditorPlugin
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "Json";
  private static JsonEditorPlugin fgInstance;
  private JsonScanner fJsonScanner;
  private JsonColorProvider fColorProvider;
  public static final String SPACES_FOR_TABS = "spaces_for_tabs";
  public static final String NUM_SPACES = "num_spaces";
  public static final String EDITOR_MATCHING_BRACKETS = "matchingBrackets";
  public static final String EDITOR_MATCHING_BRACKETS_COLOR = "matchingBracketsColor";
  
  public JsonEditorPlugin()
  {
    fgInstance = this;
  }
  
  public static JsonEditorPlugin getDefault()
  {
    return fgInstance;
  }
  
  public RuleBasedScanner getJsonScanner()
  {
    if (fJsonScanner == null) {
      fJsonScanner = new JsonScanner(getColorProvider());
    }
    return fJsonScanner;
  }
  
  public JsonColorProvider getColorProvider()
  {
    if (fColorProvider == null) {
      fColorProvider = new JsonColorProvider();
    }
    return fColorProvider;
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    fgInstance = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    fgInstance = null;
    super.stop(context);
  }
  
  public static ImageDescriptor getImageDescriptor(String path)
  {
    return imageDescriptorFromPlugin("Json", path);
  }
  
  public static IPreferenceStore getJsonPreferenceStore()
  {
    IPreferenceStore store = 
      getDefault().getPreferenceStore();
    JsonColorProvider provider = getDefault().getColorProvider();
    store.setDefault("spaces_for_tabs", true);
    store.setDefault("num_spaces", 4);
    store.setDefault("matchingBrackets", true);
    store.setDefault("matchingBracketsColor", provider.getColor(JsonColorProvider.STRING).toString());
    return store;
  }
}

/* Location:
 * Qualified Name:     json.JsonEditorPlugin
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

public class JsonLog
{
  public static void logInfo(String message)
  {
    log(1, 0, message, null);
  }
  
  public static void logError(Throwable exception)
  {
    logError("Unexpected Exception", exception);
  }
  
  public static void logError(String message, Throwable exception)
  {
    log(4, 0, message, exception);
  }
  
  public static void log(int severity, int code, String message, Throwable exception)
  {
    log(createStatus(severity, code, message, exception));
  }
  
  public static IStatus createStatus(int severity, int code, String message, Throwable exception)
  {
    return new Status(severity, "Json", code, message, exception);
  }
  
  public static void log(IStatus status)
  {
    JsonEditorPlugin.getDefault().getLog().log(status);
  }
}

/* Location:
 * Qualified Name:     json.JsonLog
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.part.FileEditorInput;

class JsonPageEditor$1
  implements Runnable
{
  JsonPageEditor$1(JsonPageEditor paramJsonPageEditor, IResourceChangeEvent paramIResourceChangeEvent) {}
  
  public void run()
  {
    IWorkbenchPage[] pages = this$0.getSite().getWorkbenchWindow().getPages();
    for (int i = 0; i < pages.length; i++) {
      if (((FileEditorInput)JsonPageEditor.access$0(this$0).getEditorInput()).getFile().getProject().equals(val$event.getResource()))
      {
        IEditorPart editorPart = pages[i].findEditor(JsonPageEditor.access$0(this$0).getEditorInput());
        pages[i].closeEditor(editorPart, true);
      }
    }
  }
}

/* Location:
 * Qualified Name:     json.editors.JsonPageEditor.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.MultiPageEditorPart;

public class JsonPageEditor
  extends MultiPageEditorPart
  implements IResourceChangeListener
{
  private TextEditor editor;
  
  public JsonPageEditor()
  {
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
  }
  
  void createPage0()
  {
    try
    {
      editor = new JsonTextEditor();
      int index = addPage(editor, getEditorInput());
      setPageText(index, editor.getTitle());
    }
    catch (PartInitException e)
    {
      ErrorDialog.openError(
        getSite().getShell(), 
        Messages.JsonPageEditor_0, 
        null, 
        e.getStatus());
    }
  }
  
  protected void createPages()
  {
    createPage0();
    setPartName(editor.getTitle());
  }
  
  public void dispose()
  {
    ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
    super.dispose();
  }
  
  public void doSave(IProgressMonitor monitor)
  {
    getEditor(0).doSave(monitor);
  }
  
  public void doSaveAs()
  {
    IEditorPart editor = getEditor(0);
    editor.doSaveAs();
    setPageText(0, editor.getTitle());
    setPartName(editor.getTitle());
    setInput(editor.getEditorInput());
  }
  
  public void gotoMarker(IMarker marker)
  {
    setActivePage(0);
    IDE.gotoMarker(getEditor(0), marker);
  }
  
  public void init(IEditorSite site, IEditorInput editorInput)
    throws PartInitException
  {
    super.init(site, editorInput);
  }
  
  public boolean isSaveAsAllowed()
  {
    return true;
  }
  
  public void resourceChanged(final IResourceChangeEvent event)
  {
    if (event.getType() == 2) {
      Display.getDefault().asyncExec(new Runnable()
      {
        public void run()
        {
          IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
          for (int i = 0; i < pages.length; i++) {
            if (((FileEditorInput)editor.getEditorInput()).getFile().getProject().equals(event.getResource()))
            {
              IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
              pages[i].closeEditor(editorPart, true);
            }
          }
        }
      });
    }
  }
  
  public TextEditor getEditor()
  {
    return editor;
  }
}

/* Location:
 * Qualified Name:     json.editors.JsonPageEditor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;

public class JsonPageEditorContributor
  extends MultiPageEditorActionBarContributor
{
  private IEditorPart activeEditorPart;
  
  protected IAction getAction(ITextEditor editor, String actionID)
  {
    return editor == null ? null : editor.getAction(actionID);
  }
  
  public void setActivePage(IEditorPart part)
  {
    if (activeEditorPart == part) {
      return;
    }
    activeEditorPart = part;
  }
}

/* Location:
 * Qualified Name:     json.editors.JsonPageEditorContributor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import json.JsonEditorPlugin;
import json.model.JsonReconcilingStrategy;
import json.text.JsonIndentLineAutoEditStrategy;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

public class JsonSourceViewerConfiguration
  extends SourceViewerConfiguration
{
  private JsonTextEditor textEditor;
  
  public JsonSourceViewerConfiguration(JsonTextEditor textEditor)
  {
    this.textEditor = textEditor;
  }
  
  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer)
  {
    PresentationReconciler reconciler = new PresentationReconciler();
    
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(JsonEditorPlugin.getDefault().getJsonScanner());
    reconciler.setDamager(dr, "__dftl_partition_content_type");
    reconciler.setRepairer(dr, "__dftl_partition_content_type");
    
    return reconciler;
  }
  
  public IReconciler getReconciler(ISourceViewer sourceViewer)
  {
    JsonReconcilingStrategy strategy = new JsonReconcilingStrategy();
    strategy.setTextEditor(textEditor);
    
    MonoReconciler reconciler = new MonoReconciler(strategy, false);
    
    return reconciler;
  }
  
  public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
  {
    return new IAutoEditStrategy[] { new JsonIndentLineAutoEditStrategy() };
  }
}

/* Location:
 * Qualified Name:     json.editors.JsonSourceViewerConfiguration
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import java.util.HashMap;
import java.util.List;
import json.JsonEditorPlugin;
import json.model.jsonnode.JsonNode;
import json.outline.JsonContentOutlinePage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

public class JsonTextEditor
  extends TextEditor
{
  private JsonSourceViewerConfiguration viewerConfiguration;
  protected static final char[] PAIRS = { '{', '}', '[', ']' };
  private DefaultCharacterPairMatcher pairsMatcher = new DefaultCharacterPairMatcher(PAIRS);
  private JsonContentOutlinePage fOutlinePage;
  private ProjectionAnnotationModel annotationModel;
  private ProjectionSupport projectionSupport;
  private Annotation[] oldAnnotations;
  
  protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support)
  {
    support.setCharacterPairMatcher(pairsMatcher);
    
    support.setMatchingCharacterPainterPreferenceKeys("matchingBrackets", "matchingBracketsColor");
    super.configureSourceViewerDecorationSupport(support);
  }
  
  protected void initializeEditor()
  {
    super.initializeEditor();
    setEditorContextMenuId("#JsonTextEditorContext");
    setRulerContextMenuId("#JsonTextRulerContext");
    viewerConfiguration = new JsonSourceViewerConfiguration(this);
    setSourceViewerConfiguration(viewerConfiguration);
  }
  
  public void dispose()
  {
    if (fOutlinePage != null) {
      fOutlinePage.setInput(null);
    }
    if (pairsMatcher != null)
    {
      pairsMatcher.dispose();
      pairsMatcher = null;
    }
    super.dispose();
  }
  
  public void doRevertToSaved()
  {
    super.doRevertToSaved();
    if (fOutlinePage != null) {
      fOutlinePage.update();
    }
  }
  
  public void doSave(IProgressMonitor monitor)
  {
    super.doSave(monitor);
    if (fOutlinePage != null) {
      fOutlinePage.update();
    }
  }
  
  public void doSaveAs()
  {
    super.doSaveAs();
    if (fOutlinePage != null) {
      fOutlinePage.update();
    }
  }
  
  public void doSetInput(IEditorInput input)
    throws CoreException
  {
    super.doSetInput(input);
    if (fOutlinePage != null) {
      fOutlinePage.setInput(input);
    }
  }
  
  public Object getAdapter(Class required)
  {
    if (IContentOutlinePage.class.equals(required))
    {
      if (fOutlinePage == null)
      {
        fOutlinePage = new JsonContentOutlinePage(getDocumentProvider(), this);
        if (getEditorInput() != null) {
          fOutlinePage.setInput(getEditorInput());
        }
      }
      return fOutlinePage;
    }
    return super.getAdapter(required);
  }
  
  public void createPartControl(Composite parent)
  {
    super.createPartControl(parent);
    ProjectionViewer viewer = (ProjectionViewer)getSourceViewer();
    
    projectionSupport = new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
    projectionSupport.install();
    
    viewer.doOperation(19);
    
    annotationModel = viewer.getProjectionAnnotationModel();
    
    SourceViewerDecorationSupport support = getSourceViewerDecorationSupport(viewer);
    support.install(JsonEditorPlugin.getJsonPreferenceStore());
  }
  
  protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles)
  {
    ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
    
    getSourceViewerDecorationSupport(viewer);
    return viewer;
  }
  
  public void updateFoldingStructure(List<Position> positions)
  {
    Annotation[] annotations = new Annotation[positions.size()];
    
    HashMap<ProjectionAnnotation, Position> newAnnotations = new HashMap();
    for (int i = 0; i < positions.size(); i++)
    {
      ProjectionAnnotation annotation = new ProjectionAnnotation();
      newAnnotations.put(annotation, (Position)positions.get(i));
      annotations[i] = annotation;
    }
    annotationModel.modifyAnnotations(oldAnnotations, newAnnotations, null);
    
    oldAnnotations = annotations;
  }
  
  public JsonContentOutlinePage getFOutlinePage()
  {
    return fOutlinePage;
  }
  
  public void updateContentOutlinePage(List<JsonNode> jsonNodes)
  {
    if (fOutlinePage != null) {
      fOutlinePage.setJsonNodes(jsonNodes);
    }
  }
}

/* Location:
 * Qualified Name:     json.editors.JsonTextEditor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.editors;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "json.editors.messages";
  public static String JsonPageEditor_0;
  
  static
  {
    NLS.initializeMessages("json.editors.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     json.editors.Messages
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.handlers;

import json.editors.JsonPageEditor;
import json.editors.JsonTextEditor;
import json.outline.JsonContentOutlinePage;
import json.text.JsonTextFormatter;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.IDocumentProvider;

public class FormatTextHandler
  implements IHandler
{
  public void addHandlerListener(IHandlerListener handlerListener) {}
  
  public void dispose() {}
  
  public Object execute(ExecutionEvent event)
    throws ExecutionException
  {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof JsonPageEditor)) {
      return null;
    }
    JsonTextEditor textEditor = (JsonTextEditor)((JsonPageEditor)editor).getEditor();
    String text = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
    
    JsonTextFormatter textFormatter = new JsonTextFormatter(text);
    
    textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()).set(textFormatter.formatText());
    textEditor.getFOutlinePage().update();
    
    return null;
  }
  
  public boolean isEnabled()
  {
    return true;
  }
  
  public boolean isHandled()
  {
    return true;
  }
  
  public void removeHandlerListener(IHandlerListener handlerListener) {}
}

/* Location:
 * Qualified Name:     json.handlers.FormatTextHandler
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.model;

import json.editors.JsonTextEditor;

class JsonReconcilingStrategy$1
  implements Runnable
{
  JsonReconcilingStrategy$1(JsonReconcilingStrategy paramJsonReconcilingStrategy) {}
  
  public void run()
  {
    JsonReconcilingStrategy.access$0(this$0).updateFoldingStructure(this$0.fPositions);
    JsonReconcilingStrategy.access$0(this$0).updateContentOutlinePage(this$0.jsonNodes);
  }
}

/* Location:
 * Qualified Name:     json.model.JsonReconcilingStrategy.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.model;

import java.util.ArrayList;
import java.util.List;
import json.editors.JsonTextEditor;
import json.model.folding.JsonFoldingPositionsBuilder;
import json.model.jsonnode.JsonNode;
import json.model.jsonnode.JsonNodeBuilder;
import json.model.node.Node;
import json.model.node.NodeBuilder;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
import org.eclipse.swt.widgets.Display;

public class JsonReconcilingStrategy
  implements IReconcilingStrategy, IReconcilingStrategyExtension
{
  private JsonTextEditor textEditor;
  private IDocument fDocument;
  List<Node> nodes;
  List<JsonNode> jsonNodes;
  protected final List<Position> fPositions = new ArrayList();
  
  public void reconcile(IRegion partition)
  {
    initialReconcile();
  }
  
  public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion)
  {
    initialReconcile();
  }
  
  public void setDocument(IDocument document)
  {
    fDocument = document;
  }
  
  public void initialReconcile()
  {
    parse();
  }
  
  public void setProgressMonitor(IProgressMonitor monitor) {}
  
  private void parse()
  {
    nodes = new NodeBuilder(fDocument).buildNodes();
    jsonNodes = new JsonNodeBuilder(fDocument, nodes).buildJsonNodes();
    fPositions.clear();
    fPositions.addAll(new JsonFoldingPositionsBuilder(jsonNodes).buildFoldingPositions());
    if (textEditor != null) {
      Display.getDefault().asyncExec(new Runnable()
      {
        public void run()
        {
          textEditor.updateFoldingStructure(fPositions);
          textEditor.updateContentOutlinePage(jsonNodes);
        }
      });
    }
  }
  
  public JsonTextEditor getTextEditor()
  {
    return textEditor;
  }
  
  public void setTextEditor(JsonTextEditor textEditor)
  {
    this.textEditor = textEditor;
  }
}

/* Location:
 * Qualified Name:     json.model.JsonReconcilingStrategy
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.model.folding;

import java.util.LinkedList;
import java.util.List;
import json.model.jsonnode.JsonNode;
import json.model.jsonnode.JsonType;
import json.model.node.Node;
import org.eclipse.jface.text.Position;

public class JsonFoldingPositionsBuilder
{
  private List<JsonNode> jsonNodes;
  
  public JsonFoldingPositionsBuilder(List<JsonNode> jsonNodes)
  {
    this.jsonNodes = jsonNodes;
  }
  
  public List<Position> buildFoldingPositions()
  {
    List<Position> positions = new LinkedList();
    List<Position> positionsStack = new LinkedList();
    if (jsonNodes != null) {
      for (JsonNode jsonNode : jsonNodes)
      {
        if (isJsonNodeType(jsonNode, new JsonType[] { JsonType.Array, JsonType.Object }))
        {
          Position position = new Position(getStart(jsonNode));
          positionsStack.add(0, position);
          positions.add(position);
        }
        if ((isJsonNodeType(jsonNode, new JsonType[] { JsonType.End })) && 
          (positionsStack.size() > 0))
        {
          Position position = (Position)positionsStack.remove(0);
          position.setLength(getEnd(jsonNode) - position.getOffset());
        }
      }
    }
    return positions;
  }
  
  private boolean isJsonNodeType(JsonNode jsonNode, JsonType... jsonTypes)
  {
    JsonType[] arrayOfJsonType;
    int j = (arrayOfJsonType = jsonTypes).length;
    for (int i = 0; i < j; i++)
    {
      JsonType jsonType = arrayOfJsonType[i];
      if (jsonNode.getJsonType() == jsonType) {
        return true;
      }
    }
    return false;
  }
  
  public int getStart(JsonNode jsonNode)
  {
    Node startNode = jsonNode.getKey();
    if (startNode == null) {
      startNode = jsonNode.getValue();
    }
    return startNode.getStart();
  }
  
  public int getEnd(JsonNode jsonNode)
  {
    Node endNode = jsonNode.getValue();
    if (endNode == null) {
      endNode = jsonNode.getKey();
    }
    if (endNode == null) {
      return 0;
    }
    return endNode.getEnd();
  }
}

/* Location:
 * Qualified Name:     json.model.folding.JsonFoldingPositionsBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.model.jsonnode;

import json.model.node.Node;

public class JsonNode
{
  private Node key;
  private Node value;
  private JsonType jsonType;
  
  public JsonNode(Node key, Node value, JsonType jsonType)
  {
    this.key = key;
    this.value = value;
    this.jsonType = jsonType;
  }
  
  public Node getKey()
  {
    return key;
  }
  
  public void setKey(Node key)
  {
    this.key = key;
  }
  
  public Node getValue()
  {
    return value;
  }
  
  public void setValue(Node value)
  {
    this.value = value;
  }
  
  public JsonType getJsonType()
  {
    return jsonType;
  }
  
  public void setJsonType(JsonType jsonType)
  {
    this.jsonType = jsonType;
  }
  
  public String toString()
  {
    String toString = jsonType.toString();
    String keyString = key != null ? key.getValue() + "," : "";
    
    toString = toString + ", " + keyString + ", " + (value != null ? value.getValue() : "");
    return toString;
  }
  
  public int hashCode()
  {
    int result = 1;
    result = 31 * result + (
      jsonType == null ? 0 : jsonType.hashCode());
    result = 31 * result + (key == null ? 0 : key.hashCode());
    result = 31 * result + (value == null ? 0 : value.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    JsonNode other = (JsonNode)obj;
    if (jsonType == null)
    {
      if (jsonType != null) {
        return false;
      }
    }
    else if (!jsonType.equals(jsonType)) {
      return false;
    }
    if (key == null)
    {
      if (key != null) {
        return false;
      }
    }
    else if (!key.equals(key)) {
      return false;
    }
    if (value == null)
    {
      if (value != null) {
        return false;
      }
    }
    else if (!value.equals(value)) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     json.model.jsonnode.JsonNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package json.model.jsonnode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import json.model.node.Node;
import json.model.node.Type;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;

public class JsonNodeBuilder
{
  private IDocument fDocument;
  private List<Node> nodes;
  private List<JsonNode> jsonNodes;
  private List<JsonNode> objectArrayStack;
  
  public JsonNodeBuilder(IDocument document, List<Node> nodes)
  {
    fDocument = document;
    this.nodes = nodes;
  }
  
  public List<JsonNode> buildJsonNodes()
  {
    try
    {
      return privateBuildJsonNodes();
    }
    catch (Exception localException) {}
    return null;
  }
  
  private List<JsonNode> privateBuildJsonNodes()
  {
    int index = 0;
    jsonNodes = new ArrayList();
    objectArrayStack = new ArrayList();
    boolean parseMatched = false;
    
    List<Node> errorNodes = new ArrayList();
    while (index < nodes.size())
    {
      if (parseMatched) {
        if (errorNodes.size() > 0)
        {
          int oldLength = nodes.size();
          List<JsonNode> reparsedNodes = reparseErrorNodes(errorNodes);
          int stepBack = ((JsonNode)jsonNodes.get(jsonNodes.size() - 1)).getJsonType() == JsonType.End ? 2 : 1;
          jsonNodes.addAll(jsonNodes.size() - stepBack, reparsedNodes);
          errorNodes.clear();
          int newLength = nodes.size();
          index += newLength - oldLength;
        }
      }
      parseMatched = true;
      if (isStringNode(index))
      {
        if (isNodeType(index + 3, nodes, new Type[] { Type.Colon }))
        {
          int retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Value, new Type[] { Type.Number, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Null, new Type[] { Type.Null, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.True, new Type[] { Type.True, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.False, new Type[] { Type.False, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 5, JsonType.String, new Type[] { Type.Quote, Type.String, Type.Quote, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Value, new Type[] { Type.Number, Type.CloseObject, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Null, new Type[] { Type.Null, Type.CloseObject, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.True, new Type[] { Type.True, Type.CloseObject, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.False, new Type[] { Type.False, Type.CloseObject, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 5, JsonType.String, new Type[] { Type.Quote, Type.String, Type.Quote, Type.CloseObject, Type.Comma });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Value, new Type[] { Type.Number, Type.CloseObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Null, new Type[] { Type.Null, Type.CloseObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.True, new Type[] { Type.True, Type.CloseObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.False, new Type[] { Type.False, Type.CloseObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 5, JsonType.String, new Type[] { Type.Quote, Type.String, Type.Quote, Type.CloseObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Object, new Type[] { Type.OpenObject });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
          retIndex = doCompare(index, index + 4, index + 1, index + 4, JsonType.Array, new Type[] { Type.OpenArray });
          if (retIndex != -1)
          {
            index = retIndex; continue;
          }
        }
        int retIndex = doCompare(index, index + 3, -1, index + 1, JsonType.String, new Type[] { Type.CloseArray, Type.Comma });
        if (retIndex != -1)
        {
          index = retIndex; continue;
        }
        retIndex = doCompare(index, index + 3, -1, index + 1, JsonType.String, new Type[] { Type.CloseArray });
        if (retIndex != -1)
        {
          index = retIndex; continue;
        }
        retIndex = doCompare(index, index + 3, -1, index + 1, JsonType.String, new Type[] { Type.Comma });
        if (retIndex != -1)
        {
          index = retIndex; continue;
        }
      }
      int retIndex = buildType(index, JsonType.Value, Type.Number);
      if (retIndex != index)
      {
        index = retIndex;
      }
      else
      {
        retIndex = buildType(index, JsonType.Null, Type.Null);
        if (retIndex != index)
        {
          index = retIndex;
        }
        else
        {
          retIndex = buildType(index, JsonType.True, Type.True);
          if (retIndex != index)
          {
            index = retIndex;
          }
          else
          {
            retIndex = buildType(index, JsonType.False, Type.False);
            if (retIndex != index)
            {
              index = retIndex;
            }
            else
            {
              retIndex = buildOpen(index, JsonType.Object, Type.OpenObject, errorNodes);
              if (retIndex != index)
              {
                index = retIndex;
              }
              else
              {
                retIndex = buildOpen(index, JsonType.Array, Type.OpenArray, errorNodes);
                if (retIndex != index)
                {
                  index = retIndex;
                }
                else
                {
                  retIndex = buildCloseWithComma(index, JsonType.Object, Type.OpenObject, Type.CloseObject);
                  if (retIndex != index)
                  {
                    index = retIndex;
                  }
                  else
                  {
                    retIndex = buildCloseWithComma(index, JsonType.Array, Type.OpenArray, Type.CloseArray);
                    if (retIndex != index)
                    {
                      index = retIndex;
                    }
                    else
                    {
                      retIndex = buildClose(index, JsonType.Object, Type.OpenObject, Type.CloseObject);
                      if (retIndex != index)
                      {
                        index = retIndex;
                      }
                      else
                      {
                        retIndex = buildClose(index, JsonType.Array, Type.OpenArray, Type.CloseArray);
                        if (retIndex != index)
                        {
                          index = retIndex;
                        }
                        else
                        {
                          errorNodes.add((Node)nodes.get(index));
                          index++;
                          parseMatched = false;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    int stepBack = 0;
    if (parseMatched) {
      stepBack = 1;
    }
    if (errorNodes.size() > 0)
    {
      List<JsonNode> reparsedNodes = reparseErrorNodes(errorNodes);
      stepBack = ((JsonNode)jsonNodes.get(jsonNodes.size() - 1)).getJsonType() == JsonType.End ? stepBack + 1 : stepBack;
      jsonNodes.addAll(jsonNodes.size() - stepBack, reparsedNodes);
      errorNodes.clear();
    }
    return jsonNodes;
  }
  
  private List<JsonNode> reparseErrorNodes(List<Node> errorNodes)
  {
    List<JsonNode> reparsedJsonNodes = new ArrayList();
    List<Node> reparsedNodes = new ArrayList();
    for (int continueIndex = 0; continueIndex < errorNodes.size(); continueIndex++)
    {
      int startIndex = continueIndex;
      int nodesPos;
      if (isNodeType(continueIndex, errorNodes, new Type[] { Type.Quote }))
      {
        boolean stringBuilt = false;
        if (!isNodeType(continueIndex + 1, errorNodes, new Type[] { Type.String }))
        {
          for (int i = continueIndex + 1; i < errorNodes.size(); i++) {
            if (isNodeType(i, errorNodes, new Type[] { Type.Quote }))
            {
              Node newNode = convertToString((Node)errorNodes.get(continueIndex), (Node)errorNodes.get(i));
              reparsedNodes.add((Node)errorNodes.get(continueIndex));
              reparsedNodes.add(newNode);
              reparsedNodes.add((Node)errorNodes.get(i));
              continueIndex = i + 1;
              stringBuilt = true;
              break;
            }
          }
        }
        else if (errorNodes.size() >= continueIndex + 3)
        {
          reparsedNodes.addAll(errorNodes.subList(continueIndex, continueIndex + 3));
          continueIndex += 3;
          stringBuilt = true;
        }
        if ((stringBuilt) && (continueIndex == errorNodes.size()))
        {
          JsonNode newJsonNode = new JsonNode(null, (Node)reparsedNodes.get(1), JsonType.String);
          reparsedJsonNodes.add(newJsonNode);
          for (Node node : reparsedNodes) {
            node.setOwner(newJsonNode);
          }
          int nodesPos = nodes.indexOf(errorNodes.get(startIndex));
          nodes.removeAll(errorNodes.subList(startIndex, continueIndex));
          nodes.addAll(nodesPos, reparsedNodes);
          reparsedNodes.clear();
          break;
        }
        if (stringBuilt) {
          if (isNodeType(continueIndex, errorNodes, new Type[] { Type.Comma }))
          {
            JsonNode newJsonNode = new JsonNode(null, (Node)reparsedNodes.get(1), JsonType.String);
            reparsedJsonNodes.add(newJsonNode);
            reparsedNodes.add((Node)errorNodes.get(continueIndex));
            for (Node node : reparsedNodes) {
              node.setOwner(newJsonNode);
            }
            int nodesPos = nodes.indexOf(errorNodes.get(startIndex));
            nodes.removeAll(errorNodes.subList(startIndex, continueIndex + 1));
            nodes.addAll(nodesPos, reparsedNodes);
            reparsedNodes.clear();
            continue;
          }
        }
        int nodesPos;
        if (stringBuilt) {
          if (isNodeType(continueIndex, errorNodes, new Type[] { Type.CloseArray, Type.CloseObject }))
          {
            JsonNode newJsonNode = new JsonNode(null, (Node)reparsedNodes.get(1), JsonType.String);
            reparsedJsonNodes.add(newJsonNode);
            JsonNode endNode = new JsonNode(null, (Node)errorNodes.get(continueIndex), JsonType.End);
            reparsedJsonNodes.add(endNode);
            for (Node node : reparsedNodes) {
              node.setOwner(newJsonNode);
            }
            JsonNode parent = objectArrayStack.size() > 0 ? (JsonNode)objectArrayStack.remove(0) : null;
            if (parent != null) {
              ((Node)errorNodes.get(continueIndex)).setOwner(parent);
            }
            reparsedNodes.add((Node)errorNodes.get(continueIndex));
            if (errorNodes.size() > continueIndex + 1) {
              if (isNodeType(continueIndex + 1, errorNodes, new Type[] { Type.Comma }))
              {
                if (parent != null) {
                  ((Node)errorNodes.get(continueIndex + 1)).setOwner(parent);
                }
                reparsedNodes.add((Node)errorNodes.get(continueIndex + 1));
                continueIndex++;
              }
            }
            nodesPos = nodes.indexOf(errorNodes.get(startIndex));
            nodes.removeAll(errorNodes.subList(startIndex, continueIndex + 1));
            nodes.addAll(nodesPos, reparsedNodes);
            reparsedNodes.clear();
            continue;
          }
        }
        if (stringBuilt) {
          if (isNodeType(continueIndex, errorNodes, new Type[] { Type.Colon }))
          {
            int nodesPos;
            if (errorNodes.size() > continueIndex + 1) {
              if (isNodeType(continueIndex + 1, errorNodes, new Type[] { Type.False, Type.Null, Type.Number, Type.True, Type.OpenArray, Type.OpenObject }))
              {
                JsonType jsonType = nodeTypeToJsonType(((Node)errorNodes.get(continueIndex + 1)).getType());
                JsonNode newJsonNode = new JsonNode((Node)reparsedNodes.get(1), (Node)errorNodes.get(continueIndex + 1), jsonType);
                reparsedJsonNodes.add(newJsonNode);
                reparsedNodes.add((Node)errorNodes.get(continueIndex));
                reparsedNodes.add((Node)errorNodes.get(continueIndex + 1));
                continueIndex++;
                for (Node node : reparsedNodes) {
                  node.setOwner(newJsonNode);
                }
                nodesPos = nodes.indexOf(errorNodes.get(startIndex));
                nodes.removeAll(errorNodes.subList(startIndex, continueIndex + 1));
                nodes.addAll(nodesPos, reparsedNodes);
                reparsedNodes.clear();
                if ((jsonType != JsonType.Array) && (jsonType != JsonType.Object)) {
                  continue;
                }
                objectArrayStack.add(0, newJsonNode);
                
                continue;
              }
            }
            if (continueIndex + 2 < errorNodes.size())
            {
              if (isNodeType(continueIndex + 1, errorNodes, new Type[] { Type.Quote })) {
                if (!isNodeType(continueIndex + 2, errorNodes, new Type[] { Type.String }))
                {
                  f
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd