Skip to content

Convert MSC code Cleanup to Formatter #13233

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

Open
wants to merge 65 commits into
base: main
Choose a base branch
from

Conversation

JustinHennis1
Copy link
Contributor

@JustinHennis1 JustinHennis1 commented Jun 3, 2025

Closes #13227

Removed Cleanup functionality for MSC Code conversion. Added formatter at bottom of preset panel because formatters handle single-field conversion.

Screenshot Before

beforeformat6_2_25

Screenshot After

afterformat6_2_25

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

JustinHennis1 and others added 30 commits April 8, 2025 22:38
…to ktooltip

pulling changes from main to local
…iptions, bug: error when trying to cleanup when editor is open
@JustinHennis1
Copy link
Contributor Author

@koppor I think it's ready for review

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revet changes in sub modules - see https://devdocs.jabref.org/code-howtos/faq.html#submodules

return result.toString();
}
// text contains comma separated codes
String[] codeList = result.toString().split(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use org.jabref.model.entry.KeywordList#parse(java.lang.String, java.lang.Character, java.lang.Character) and then work on KeywordList

Reason: Better data structure and adheres to user configuration (keyword delimiter) and escpaings.

See at other usages of the parser and how to pass the prefernces


At first, I thought:

Suggested change
String[] codeList = result.toString().split(",");
String[] codeList = text.toString().split(",");

but this is wrong, because no escaping treatment etc.

@@ -87,6 +90,13 @@ public FieldFormatterCleanups(boolean enabled, List<FieldFormatterCleanup> actio
this.actions = Objects.requireNonNull(actions);
}

public FieldFormatterCleanups(boolean enabled, List<FieldFormatterCleanup> actions, BibEntryPreferences preferences) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be reviewed in IDE - why this general method is needed - until now, this was not needed - and the formatter worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no way to retrieve BibEntryPreferences so that I could call getKeywordSeperator. This is used to inject preferences so that the formatter can use a dynamic delimiter.

If there is another method of retrieving BibEntryPreferences pleases lmk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is getInstance() deprecated for JabrefCLIPreferences Class? Isn't the point of this class to allow preferences to be accessible globally. @koppor

I feel like it defeats the purpose to implement a Singleton design that isn't easily accessible. 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferences are indeed singleton but nonetheless you should avoid calling get instance as it creates a tight coupling between the two classes and hinders testing.
That's why you should pass or inject them via constructor so you can still mock them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying. @Siedlerchr

That said, do you think my approach was correct?

Creating a new constructor for FieldFormatterCleanups
In JabrefCliPreferences, passing BibEntryPreferences to this constructor
Finally, passing those preferences down to the formatter to get the keyword separator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is your method used? I did I do a mistake at checking out your branch?

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, in this case, it is OK to use Injector.instantiateModelOrService(CliPreferences.class) and then get your preferences for that.

Do this at the latest point in time - and do not initialize a default value ,

Note that you already have

    Character dlim = preferences.getKeywordSeparator();

At this place, use this injector "magic".

Add a javadoc comment to the class that it relies to on Injector.instantiateModelOrService(CliPreferences.class), and add a reason. Maybe "because routing through this dependency causes too much changes."

Copy link
Contributor Author

@JustinHennis1 JustinHennis1 Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is your method used? I did I do a mistake at checking out your branch?

image

My fault, I think I forgot to change this (I was testing setter vs constructor injection), I put it in this method of JabRefCliPreferences initially.
image

@koppor
Copy link
Member

koppor commented Jun 7, 2025

@JustinHennis1 Could you try to revert the change in the sub module - see https://devdocs.jabref.org/code-howtos/faq.html#submodules

Which git client did you use? Maybe, we can search for a bug report there and ask all developers of JabRef to give a +1 there. (the bug is that ignore = all is not handled by the git client)

@JustinHennis1
Copy link
Contributor Author

@JustinHennis1 Could you try to revert the change in the sub module - see https://devdocs.jabref.org/code-howtos/faq.html#submodules

Which git client did you use? Maybe, we can search for a bug report there and ask all developers of JabRef to give a +1 there. (the bug is that ignore = all is not handled by the git client)

I'm using Git CMD on my Windows Laptop. I just merged main back into my fork, did that fix it?

@koppor
Copy link
Member

koppor commented Jun 11, 2025

I'm using Git CMD on my Windows Laptop. I just merged main back into my fork, did that fix it?

The diff doesn't show any changes, thus this worked :)

@JustinHennis1
Copy link
Contributor Author

@koppor

👋 Hey, I completed the following:

  • made changes so that we use Injector to instantiate JabrefCliPreferences in the ConvertMSCCodesFormatter.
  • changed ConvertMSCCodesFormatterTest back to using the default constructor.
  • added comments in JabrefCliPreferences specifying why constructor was made public as well as the reason for the changes (without being made public, a java.lang access exception is thrown)

@JustinHennis1 JustinHennis1 requested a review from koppor June 12, 2025 03:51
Copy link

trag-bot bot commented Jun 12, 2025

@trag-bot didn't find any issues in the code! ✅✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make ConvertMSCCodesCleanup a Formatter
3 participants