Skip to content
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

Refactor deprecated part of ProtectedTermsFormatter #3720

Merged
merged 9 commits into from
Feb 15, 2018

Conversation

lenhard
Copy link
Member

@lenhard lenhard commented Feb 14, 2018

Just a code cleanup PR.

This removes the deprecated part of the ProtectedTermsFormatter so that we have a few deprecation warnings less.


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

@lenhard lenhard added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers type: code-quality Issues related to code or architecture decisions labels Feb 14, 2018
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

The code of course looks good! It would be nice however to push the dependency on globals out of the logic package.

@@ -42,7 +43,7 @@
public static final List<Formatter> CASE_CHANGERS = Arrays.asList(
new CapitalizeFormatter(),
new LowerCaseFormatter(),
new ProtectTermsFormatter(),
new ProtectTermsFormatter(Globals.protectedTermsLoader),
Copy link
Member

Choose a reason for hiding this comment

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

Can you try to remove the dependency on Globals from the logic classes? I think it is better to have static constructor methods here (accepting e.g. the terms loader as parameter) instead of static lists. Not sure how many classes are using these fields right now...

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out this is way harder than expected. There are several other static classes (e.g. Cleanups) that depend on this. I'll try to get this extracted somehow, but the current version definitely is not functional.

@lenhard lenhard removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 14, 2018
@lenhard lenhard changed the title Refactor deprecated part of ProtectedTermsFormatter [WIP] Refactor deprecated part of ProtectedTermsFormatter Feb 14, 2018
@lenhard
Copy link
Member Author

lenhard commented Feb 15, 2018

Ok, I tried to extract the static dependency to the ProtectedTermsLoader. Doing this via method parameters is insane change propagation. It goes from the formatters to the cleanups to the BibTexParser and then you have to change practically the entire logic package. This is similar to the FileUpdateMonitor and not a feasible path of action. We don't want to insert ten parameters into every method in logic because something down in the stack might need it.

Instead I did something else: The ProtectedTermsFormatter does implement the Formatter interface, but it does not fit into the Formatter framework. It is the only formatter that is dependent on external configuration and preferences. Because of this, I took it out of the framework classes and add it in the GUI, in those classes that actually need it and that have the necessary information to construct an instance of it. This results in little code changes. That's much better than propagating method parameters everywhere.

This PR is again ready for review.

@lenhard lenhard changed the title [WIP] Refactor deprecated part of ProtectedTermsFormatter Refactor deprecated part of ProtectedTermsFormatter Feb 15, 2018
@lenhard lenhard added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 15, 2018
public static List<Formatter> getAvailableFormatters() {
return Collections.unmodifiableList(availableFormatters);
public static List<Formatter> getBuiltInFormatters() {
List<Formatter> availableFormatters = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

Why not just new ArrayList(formatters.getAll())?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, done.

private static final String REGEX = "regex";

private static final int LENGTH_OF_REGEX_PREFIX = REGEX.length();

private Formatters() {
}

public static final List<Formatter> getConverters() {
List<Formatter> converters = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case it is a defensive copy. The reference to the internal list should not escape the method, because the callers could modify it (which happens in the case of the case changers).

@@ -45,7 +47,8 @@ public ProtectedTermsMenu(TextArea opener) {

private void updateFiles() {
externalFiles.getItems().clear();
for (ProtectedTermsList list : Globals.protectedTermsLoader.getProtectedTermsLists()) {
ProtectedTermsLoader loader = Globals.protectedTermsLoader;
for (ProtectedTermsList list : loader.getProtectedTermsLists()) {
Copy link
Member

Choose a reason for hiding this comment

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

When I get the braces right, it would make sense to directly use a stream to filter the ! isInternalList and then only iterate the result collection and apply the actions on them

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the loop has side effects (adding to externalFiles), so you cannot trivially rephrase that as a lambda. Since it's also not actually the target of the PR, I would prefer not to do this change.

Copy link
Member

Choose a reason for hiding this comment

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

That's not what I meant:
You could split that in two parts: First filter all !internal things and return the result as a Collection/List.
Second step you can iterate that result collection (a smaller result set) like it is done now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, if you really want, there you go. Not that this matters, there is a one digit number of lists here ;-)

@Siedlerchr
Copy link
Member

From my pov it's a go now..I think we can merge it.

@Siedlerchr Siedlerchr merged commit b2c2f13 into master Feb 15, 2018
@Siedlerchr Siedlerchr deleted the cleanup-protected-terms branch February 15, 2018 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers type: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants