Skip to content

[java] Allow numbers in utility class names by default - #1134

Merged
jsotuyod merged 9 commits into
masterfrom
oowekyala-patch-1
May 24, 2018
Merged

jsotuyod merged 9 commits into
masterfrom
oowekyala-patch-1

Conversation

@oowekyala

@oowekyala oowekyala commented May 22, 2018 •

Copy link
Copy Markdown
Member

Refs #1065, this is an oversight
Resolves #1096

@oowekyala oowekyala added this to the 6.4.0 milestone May 22, 2018
@adangel

adangel commented May 22, 2018

Copy link
Copy Markdown
Member

@oowekyala While you are at it, would it make sense to update the pattern to be [A-Z][a-zA-Z]+(Utils?|Helper)? See #1096 (comment)

@oowekyala

Copy link
Copy Markdown
Member Author

I think allowing both Util and Utils makes sense, but I'm not so sure about Helper. A helper class is not necessarily a utility class, and I think Helper is no more legitimate than say Builder in the example list provided in #1096. Using Utils? seems universal enough, and more specific conventions can be configured on a per-ruleset basis

@oowekyala

Copy link
Copy Markdown
Member Author

Though it probably would make sense to whitelist utility classes that only have a static void main(String[]) method

@oowekyala oowekyala added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label May 22, 2018
@oowekyala oowekyala added is:waiting-for-review is:low-impact Used for changesets that can be reviewed very quickly, e.g. because they're not user-facing. and removed is:WIP For PRs that are not fully ready, or issues that are actively being tackled labels May 22, 2018
@jsotuyod

Copy link
Copy Markdown
Member

@oowekyala amazing! I for one support the inclusion of the Helper suffix... I've used it myself quite often and see value in it. Helper classes aren't necessarily utility classes (they may not be static members only), but every utility class is a helper class (see Wikipedia), so if we find a utility class and it's named a helper, well, that's technically correct.

@oowekyala oowekyala added is:WIP For PRs that are not fully ready, or issues that are actively being tackled and removed is:waiting-for-review labels May 22, 2018
@oowekyala

Copy link
Copy Markdown
Member Author

@jsotuyod Ok I see, I think you're right. I'll make the change

@oowekyala oowekyala added is:waiting-for-review and removed is:WIP For PRs that are not fully ready, or issues that are actively being tackled labels May 23, 2018


private boolean isMainMethod(ASTAnyTypeBodyDeclaration bodyDeclaration) {
if (!DeclarationKind.METHOD.equals(bodyDeclaration.getKind())) {

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.

Since DeclarationKind.METHOD is a enum, I would compare it simply with == or directly != in that case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, I thought CompareObjectsWithEquals would have complained

&& "main".equals(decl.getMethodName())
&& decl.getResultType().isVoid()
&& decl.getFormalParameters().getParameterCount() == 1
&& String[].class.equals(decl.getFormalParameters().iterator().next().getType());

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.

Would that cover the varargs case

public static void main(String ... args) { }

too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure it does, but we can add a test case

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.

yes, it does. Vararg types are resolved to arrays.

@oowekyala

Copy link
Copy Markdown
Member Author

Note for the one to merge: the branch needs to be deleted from this repo (it doesn't come from my fork). I tried to do the edit on the web UI thinking github would use my fork for the branch but well...

@jsotuyod
jsotuyod merged commit c80cfd6 into master May 24, 2018
jsotuyod added a commit that referenced this pull request May 24, 2018
@oowekyala
oowekyala deleted the oowekyala-patch-1 branch May 24, 2018 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

is:low-impact Used for changesets that can be reviewed very quickly, e.g. because they're not user-facing. is:waiting-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants