From b517cdc0bb16c6cf2fe62f64cf15ffd71683f953 Mon Sep 17 00:00:00 2001 From: Albert Tregnaghi Date: Thu, 12 Oct 2023 22:02:28 +0200 Subject: [PATCH] Introduce comment history to keep comments #24 --- .../de/jcup/hijson/document/CommentEntry.java | 34 +++++++++++++ .../jcup/hijson/document/CommentHistory.java | 18 +++++++ .../document/CommentHistorySupport.java | 37 ++++++++++++++ .../hijson/document/JSONFormatSupport.java | 3 +- .../hijson/document/SimpleJsonFormatter.java | 15 ++++++ .../DefaultHighspeedJSONModelBuilder.java | 1 - .../document/SimpleJsonFormatterTest.java | 50 +++++++++++++++++++ 7 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentEntry.java create mode 100644 highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistory.java create mode 100644 highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistorySupport.java create mode 100644 highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/SimpleJsonFormatter.java create mode 100644 highspeed-json-editor-plugin/src/test/java/de/jcup/hijson/document/SimpleJsonFormatterTest.java diff --git a/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentEntry.java b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentEntry.java new file mode 100644 index 0000000..3ebf63f --- /dev/null +++ b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentEntry.java @@ -0,0 +1,34 @@ +package de.jcup.hijson.document; + +public class CommentEntry { + + private String comment; + + private int line; + private int column; + + public int getLine() { + return line; + } + + public void setLine(int line) { + this.line = line; + } + + public int getColumn() { + return column; + } + + public void setColumn(int column) { + this.column = column; + } + + public void setComment(String comment) { + this.comment=comment; + } + + public String getComment() { + return comment; + } + +} diff --git a/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistory.java b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistory.java new file mode 100644 index 0000000..2d2e8d7 --- /dev/null +++ b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistory.java @@ -0,0 +1,18 @@ +package de.jcup.hijson.document; + +import java.util.ArrayList; +import java.util.List; + +public class CommentHistory { + + + List list = new ArrayList<>(); + + public void addComment(int line, int column, String comment) { + CommentEntry entry = new CommentEntry(); + entry.setComment(comment); + entry.setLine(line); + entry.setColumn(column); + } + +} diff --git a/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistorySupport.java b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistorySupport.java new file mode 100644 index 0000000..38bd173 --- /dev/null +++ b/highspeed-json-editor-plugin/src/main/java/de/jcup/hijson/document/CommentHistorySupport.java @@ -0,0 +1,37 @@ +package de.jcup.hijson.document; + +public class CommentHistorySupport { + + private SimpleJsonFormatter simpleFormatter = new SimpleJsonFormatter(); + + public CommentHistory ceateCommentHistory(String json) { + CommentHistory history = new CommentHistory(); + /* FIXME de-jcup , 2023: handle comments hwich are in own line special: must be removed for line handling + * means simple formatter must have two ways of formatting... first the new line comments are contained, + * afterwards remove those as well to get the target line numbers... */ + String jsonWithoutEmptyNewLines= simpleFormatter.formatJson(json); + String[] lines = jsonWithoutEmptyNewLines.split("\n"); + + for (int lineNumber=0;lineNumber