Skip to content

Introduce formatter to remove word-enclosing braces#11253

Merged
koppor merged 24 commits into
JabRef:mainfrom
rohit-garga:fix-for-issue-11251
May 13, 2024
Merged

Introduce formatter to remove word-enclosing braces#11253
koppor merged 24 commits into
JabRef:mainfrom
rohit-garga:fix-for-issue-11251

Conversation

@rohit-garga

Copy link
Copy Markdown
Contributor

Closes #11222

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • 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.

@rohit-garga

Copy link
Copy Markdown
Contributor Author

It's not clear to me why fetcher tests are failing, they failed even after I reverted my changes. Can you help please @koppor

@Siedlerchr

Copy link
Copy Markdown
Member

You can ignore the failing fetcher tests. They often have problems due to network errors or changed data. Only relevant if you changed soemthing at the Fetchers itself

@koppor

koppor commented Apr 26, 2024

Copy link
Copy Markdown
Member

@rohit-garga Due to the nature of tests, it is not easy to run all. Sorry for that.

Partially running works.

E.g., all tests in logic

image

Then select "test"

image

Also works for architecture and model.

Does not work for gui. There, you need to choose guiTest.

@rohit-garga

Copy link
Copy Markdown
Contributor Author

Understood, thanks! Let me know when you get chance to review :)

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some small comment.

I fixed other things locally, but I don't have push rights to your brunch. Thus, I will submit a PR.

* Adds {} brackets around acronyms, month names and countries to preserve their case.
*
* Related formatter: {@link org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter}
* Related formatter: {@link RemoveEnclosingBracesFormatter}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No import for JavaDoc classes please

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not fixed, but checkstyle did not complain. Thus, I let it go.

@koppor koppor mentioned this pull request Apr 29, 2024
6 tasks
@koppor

koppor commented Apr 29, 2024

Copy link
Copy Markdown
Member

I have only small comments, but explaining these was more hard than "just doing" it. -- I had no write rights to fix minor issues. Thus, I filed a PR: rohit-garga#1


@Override
public String getKey() {
return "remove_braces";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think, this is the "old" formatter?

Since it is used in .layout files, please don't change the name. Otherwise, we need to add support for alias names....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I could not find references to this key anywhere in the code so I made this more descriptive. Reverting this

@rohit-garga

Copy link
Copy Markdown
Contributor Author

Hi @koppor ,
I need some help-

1.) We changed the formatter to return the string value instead of null. This does not work, because in the test case, we pass an empty string in the constructor, but a parser will get null not an empty string. For example

PersonNameSuggestionProviderTest.completeLowercaseBeginningOfNameReturnsName
Expected :[Author{givenName='Vassilis', givenNameAbbreviated='V.', namePrefix='', familyName='Kostakos', nameSuffix=''}]
Actual :[Author{givenName='Vassilis', givenNameAbbreviated='V.', namePrefix='null', familyName='Kostakos', nameSuffix='null'}]

2.)

FormatterTest.formatOfNullThrowsException

All formatters need to throw a null pointer exception when we run format(null). In our test cases, there are many instances of tests where we pass null in the constructor for Author.java.

One easy solution would be
1.) Return null whenever we get an empty string/ null.
2.) We add a try-catch in the author constructor, so we can catch null pointer exceptions and continue.

@koppor

koppor commented May 4, 2024

Copy link
Copy Markdown
Member

@rohit-garga Step 1 is OK. Step 2: Use an if instead of try/catch, because control flow should not be done using exceptions 😅

@rohit-garga rohit-garga requested a review from koppor May 7, 2024 03:11

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for continuing this. Minor comments remain.

* Adds {} brackets around acronyms, month names and countries to preserve their case.
*
* Related formatter: {@link org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter}
* Related formatter: {@link RemoveEnclosingBracesFormatter}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not fixed, but checkstyle did not complain. Thus, I let it go.

*
* @return first name of the author (may consist of several tokens)
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this empty line here? JavaDoc comments should be as close as possible to the method.

* Example: <code>authors = {Oliver Kopp and others}</code>. This is then appearing as "Oliver Kopp et al.".
* In the context of BibTeX key generation, this is "Kopp+" (<code>+</code> for "et al.") and not "KO".
*/
public static final RemoveWordEnclosingAndOuterEnclosingBracesFormatter FORMATTER = new RemoveWordEnclosingAndOuterEnclosingBracesFormatter();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very wrong position of the variable. See the javadoc above. This DOES NOT match the new variable, but the OTHERS variable.

Please move the variable two lines down (and separate the next one by an empty line, too)

@rohit-garga rohit-garga requested a review from koppor May 9, 2024 06:10
@koppor koppor added this pull request to the merge queue May 13, 2024
@koppor

koppor commented May 13, 2024

Copy link
Copy Markdown
Member

@rohit-garga Thank you for the follow-ups. I think, the null handling is now OK. Someone touching the code later will see. 😅

Merged via the queue into JabRef:main with commit 0eab5dc May 13, 2024
@rohit-garga rohit-garga deleted the fix-for-issue-11251 branch May 13, 2024 18:18
Siedlerchr added a commit that referenced this pull request May 19, 2024
* upstream/main:
  Update latex citations status in JavaFx thread (#11302)
  Remove EnglishStemAnalyzer and use EnglishAnalyzer (#11301)
  Fix comment (#11299)
  Try gradle build speedup (#11300)
  Remove obsolete step (#11295)
  Bump com.fasterxml.jackson.dataformat:jackson-dataformat-yaml (#11290)
  Remove outdated pdf indexed files from Lucene index (#11293)
  Bump src/main/resources/csl-styles from `5338902` to `434df0a` (#11292)
  Bump org.mockito:mockito-core from 5.11.0 to 5.12.0 (#11291)
  Bump com.fasterxml.jackson.datatype:jackson-datatype-jsr310 (#11289)
  Bump com.dlsc.gemsfx:gemsfx from 2.12.0 to 2.16.0 (#11287)
  Bump org.openrewrite.recipe:rewrite-recipe-bom from 2.9.0 to 2.11.0 (#11288)
  Introduce formatter to remove word-enclosing braces (#11253)
  Try parallel tests (#9797)
  Store preview divider pos in entry editor (#11285)
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.

Introduce formatter to remove word-enclosing braces

3 participants