Ask Your Question
0

What is the method to make the Spotless Java code formatter apply the 'this' keyword on local fields and methods?

asked 2022-07-31 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-07-15 21:00:00 +0000

huitzilopochtli gravatar image

To make the Spotless Java code formatter apply the 'this' keyword on local fields and methods, you can use the following configuration in your .spotless.yaml file:

java:
  googleJavaFormat:
    style: AOSP
    onlyIf:
      - hasUnformattedCode
  additionalFileMatchers: []

filters:
- type: replace
  pattern: "([a-zA-Z0-9_]+)\\("
  replacement: "this.$1("
  exclude:
    - "src/main/java/*.proto"

This configuration uses the Google Java Format to format the code and adds a replace filter that applies the 'this' keyword on local fields and methods. The exclude property is used to exclude any proto files that may cause issues with the regex pattern.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-07-31 11:00:00 +0000

Seen: 10 times

Last updated: Jul 15 '22