-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new parseJabRefComment with unit test #12145
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
fix logic check string contains a valid json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do differently.
I highlighted the idea using the diff:
Check for jabref-meta-0.1.0
string at the beginning of the comment. Then remove that line. The remainder of the comment is the complete JSON.
Do NOT read the JSON as BibEntry. It is NOT a BibEntry. It is META data for JabRef. E.g., preferences etc.
Background: JabRef displys BibEntrys in the main table - and settings in dialog. We do not render settings in the main table.
} catch ( | ||
JsonSyntaxException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkstyle is somewhat broken, please reduce to one line.
1. read json as metadata 2. small refactor to remove a not in use `LOGGER` in `MetaData`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.
You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.
@@ -339,7 +342,7 @@ private void parseAndAddEntry(String type) { | |||
} | |||
} | |||
|
|||
private void parseJabRefComment(Map<String, String> meta) { | |||
void parseJabRefComment(Map<String, String> meta) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs @VisibileForTesting
?
} | ||
} | ||
|
||
private void parseCommentToJson(String comment, Map<String, String> meta) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - it should return the JSOn object.
The following call should be rewritten:
MetaData metaData = metaDataParser.parse(
meta,
importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
meta
should be a record of
Map<String, String> v5metaData
JsonObject v6metaData
And then be handled accordingliny in org.jabref.logic.importer.fileformat.BibtexParser#metaDataParser
.
|
||
@AllowedToUseLogic("because it needs access to citation pattern and cleanups") | ||
public class MetaData { | ||
|
||
public static final String META_FLAG = "jabref-meta: "; | ||
public static final String META_FLAG_010 = "jabref-meta-0.1.0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the string Version
in the constant name:
public static final String META_FLAG_010 = "jabref-meta-0.1.0"; | |
public static final String META_FLAG_VERSION_010 = "jabref-meta-0.1.0"; |
rewrite metaDataParser.parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
fix wrong input
@@ -386,7 +390,23 @@ private void parseJabRefComment(Map<String, String> meta) { | |||
} catch (ParseException ex) { | |||
parserResult.addException(ex); | |||
} | |||
} else if (comment.substring(0, Math.min(comment.length(), MetaData.META_FLAG_VERSION_010.length())).equals(MetaData.META_FLAG_VERSION_010)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java strings support startsWith
. I think, this should be used here instead of this complicated thign.
} | ||
} | ||
|
||
private JsonObject parseCommentToJson(String comment, Map<String, String> meta) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the map as parameter. It should not be modified.
The JsonObject should be separate - to enable handling v5.x meta data (Map) and v6.x metadata (JSON)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, return Optional<JsonObject>
(which is more modern Java)
Pattern pattern = Pattern.compile("\\{.*}", Pattern.DOTALL); | ||
Matcher matcher = pattern.matcher(comment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, just doing comments.substring(MetaData.META_FLAG_VERSION_010)
should to the trick. - No need for more checking here.
@@ -97,6 +100,77 @@ public MetaData parse(Map<String, String> data, Character keywordSeparator) thro | |||
return parse(new MetaData(), data, keywordSeparator); | |||
} | |||
|
|||
public MetaData parse(JsonObject data, Character keywordSeparator) throws ParseException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add JavaDoc - I don't get this.
I think, this should not be in this PR for now - We only focus on the JSON - and then, we can work on the parsing of the JSON.
return parse(new MetaData(), data, keywordSeparator); | ||
} | ||
|
||
public MetaData parse(MetaData metaData, JsonObject data, Character keywordSeparator) throws ParseException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add JavaDoc - I don't get this.
I think, this should not be in this PR for now - We only focus on the JSON - and then, we can work on the parsing of the JSON.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if change is visible to the user)