Skip to content

Issue #4058: RightCurly: false negative in ALONE and anonymous classes#4173

Closed
therootusr wants to merge 1 commit intocheckstyle:masterfrom
therootusr:issue_4058
Closed

Issue #4058: RightCurly: false negative in ALONE and anonymous classes#4173
therootusr wants to merge 1 commit intocheckstyle:masterfrom
therootusr:issue_4058

Conversation

@therootusr
Copy link

Issue #4058 : Added LITERAL_NEW to the list of accepted tokens for RightCurlyCheck. RightCurlyCheck with option 'ALONE' for anonymous classes. Added UT

@therootusr
Copy link
Author

@romani @MEZk kindly review. Thanks

// -@cs[JavaNCSS] getDetails() method is a huge SWITCH, it has to be monolithic
// -@cs[ExecutableStatementCount] getDetails() method is a huge SWITCH, it has to be monolithic
// -@cs[NPathComplexity] getDetails() method is a huge SWITCH, it has to be monolithic
private static Details getDetails(DetailAST ast) {
Copy link
Author

Choose a reason for hiding this comment

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

This function was exactly at the thresholds for the complexity checks and statement counts. So, had to restructure it. Also restructuring might prove to be useful in the future when more tokens might need to be added to the check

Copy link
Contributor

Choose a reason for hiding this comment

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

This change is definitely making the new code hard to review.

Copy link
Author

Choose a reason for hiding this comment

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

@rnveach Should I make two commits then ? One for refactoring one for adding LITERAL_NEW ?

Copy link
Contributor

@rnveach rnveach Apr 12, 2017

Choose a reason for hiding this comment

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

I think so but wait for someone else to agree. @romani @MEZk

@codecov-io
Copy link

codecov-io commented Apr 9, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@bb1e9e0). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #4173   +/-   ##
========================================
  Coverage          ?    100%           
  Complexity        ?    7386           
========================================
  Files             ?     296           
  Lines             ?   16157           
  Branches          ?    3260           
========================================
  Hits              ?   16157           
  Misses            ?       0           
  Partials          ?       0
Impacted Files Coverage Δ Complexity Δ
...ools/checkstyle/checks/blocks/RightCurlyCheck.java 100% <100%> (ø) 56 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb1e9e0...a480ea1. Read the comment docs.

@therootusr
Copy link
Author

therootusr commented Apr 12, 2017

@rnveach please review

details = getDetailsForLoops(ast);
break;
default:
details = getDetailsForDefs(ast);
Copy link
Contributor

@rnveach rnveach Apr 12, 2017

Choose a reason for hiding this comment

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

not all of these are DEFs. Let's just call this 'Other' or 'Misc'.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Will do

Copy link
Author

Choose a reason for hiding this comment

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

Done.

lcurly = ast.getFirstChild();
rcurly = lcurly.getLastChild();
}
final Details details = new Details();
Copy link
Contributor

@rnveach rnveach Apr 12, 2017

Choose a reason for hiding this comment

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

I like the separation the new way gives for each method, but I dislike some of the code it has to copy around.

I am not sure about which of 2 ideas to change this to:

  1. How about we drop the default constructor and make a new one that takes all fields as arguments, then we could make the fields of the class final and rename getDetails to getInstance.
  2. Why don't we transform getDetails into a constructor, and have all these methods populate the fields directly.

Problem with point 2 is assignments could be overlooked since they are split into so many methods.
Problem with point 1 is we are stuck with getDetails as a wrapper for the constructor.

What do you all think?

Copy link
Author

@therootusr therootusr Apr 12, 2017

Choose a reason for hiding this comment

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

Approach 1. seems better. In my humble opinion, approach 2. would make things more complex than they are.

final DetailAST lcurly;
final DetailAST nextToken;
final int tokenType = ast.getType();
if (tokenType == TokenTypes.CLASS_DEF) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a switch since this is probably the most likely spot where we will add missing tokens?

Copy link
Author

@therootusr therootusr Apr 12, 2017

Choose a reason for hiding this comment

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

Yeah, but wouldn't the need for switch also depend on how the details get collected. Perhaps we might not need many branches for different tokens that get added ? I feel this can be managed in issue #3547 ? What do you think ?

* @param ast the given node.
* @return the token which represents next lexical item.
*/
private static DetailAST getNextToken(DetailAST ast) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be a method of Details? It is only used there.
If so, move any other methods that only Details uses to inside it.

Copy link
Author

Choose a reason for hiding this comment

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

Yes. will do.

Copy link
Author

Choose a reason for hiding this comment

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

@rnveach Done.

// -@cs[JavaNCSS] getDetails() method is a huge SWITCH, it has to be monolithic
// -@cs[ExecutableStatementCount] getDetails() method is a huge SWITCH, it has to be monolithic
// -@cs[NPathComplexity] getDetails() method is a huge SWITCH, it has to be monolithic
private static Details getDetails(DetailAST ast) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is definitely making the new code hard to review.

@MEZk
Copy link
Contributor

MEZk commented Apr 12, 2017

@PS-SP
Please, rebase your branch onto the latest master to avoid merge conflicts.

@therootusr therootusr force-pushed the issue_4058 branch 2 times, most recently from f167b8c to 13e08b6 Compare April 13, 2017 03:33
@therootusr
Copy link
Author

therootusr commented Apr 16, 2017

@MEZk @rnveach @romani Please have a look at the UTs and verify if the behaviour is desirable. Thank you.

public String toString() {
return "name:"+s;
}
}; // no violation
Copy link
Contributor

@MEZk MEZk Apr 17, 2017

Choose a reason for hiding this comment

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

@romani @rnveach
I think this is OK too, otherwise ; should be on a new line and that will be weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is ok to me too, lambda didn't require it separated.

start();
super.run();
}
}, // no violation
Copy link
Contributor

Choose a reason for hiding this comment

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

@romani @rnveach
I think this is OK. Do you agree?

run();
}
}
}), // no violation
Copy link
Contributor

Choose a reason for hiding this comment

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

@romani @rnveach
From my point of view this is not OK. There should be a violation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lambda agrees with you.

Copy link
Author

Choose a reason for hiding this comment

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

@romani @MEZk @rnveach
This Point was left out. Regression reports for option alone and alone-or-singleline have been approved. There is still no violation here. Please confirm if a violation is needed here.

Copy link
Member

Choose a reason for hiding this comment

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

As for me, violation should be there for alone and alone-or-singleline, but it should not be there at same http://checkstyle.sourceforge.net/property_types.html#rcurly

    Thread t = new Thread(new Runnable() {

    }); // this is OK, allowed for better code readability

Copy link
Author

Choose a reason for hiding this comment

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

@romani
Done for same and alone. As far as alone_or_singleline goes, isAnonInnerClassInit prevents an error. This method was added in this commit

Copy link
Member

Choose a reason for hiding this comment

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

As far as alone_or_singleline goes, isAnonInnerClassInit prevents an error.

make sense to have no error.

protected Object clone() {
return new Object() { @Override protected void finalize() { "".toString(); } }; // violation
}
}); // no violation
Copy link
Contributor

Choose a reason for hiding this comment

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

@romani @rnveach
This is a controversial example. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Lambda gives a violation.

Copy link
Author

Choose a reason for hiding this comment

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

@romani @MEZk @rnveach
This Point was left out. Regression reports for option alone and alone-or-singleline have been approved. There is still no violation here. Please confirm if a violation is needed here.

Copy link
Author

Choose a reason for hiding this comment

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

Done. There is a violation for this now.

@MEZk
Copy link
Contributor

MEZk commented Apr 17, 2017

@PS-SP
Please, rebase once again.

@therootusr
Copy link
Author

@romani Please have an look and let me know if you like the refactoring

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

@PS-SP , you provided big refactoring to Check it is hard to catch changes that are related to new token support.

Please split refactoring to separate PR , let us merge it, and this PR (after rebase) will be easy to read and validate.
NO issue is required, in commit message you can use "minor: " prefix.

@Vladlis
Copy link
Contributor

Vladlis commented Jul 26, 2017

this PR can be continued after GSoC

@romani
Copy link
Member

romani commented Aug 31, 2017

we released 8.2 version, please rebase all your PRs to our latest master to avoid CI problems

@romani
Copy link
Member

romani commented Dec 10, 2017

@PS-SP , sorry for delay in reply, please rebase one more time to let me review, this PR is hanging too long.

@therootusr
Copy link
Author

@romani yeah it has been hanging for so long. I also couldn't follow it, sorry. Will update.

@therootusr therootusr force-pushed the issue_4058 branch 2 times, most recently from d724fa6 to da8ba1f Compare December 20, 2017 15:37
@therootusr
Copy link
Author

@romani updated PR. Please have a look once.

@romani
Copy link
Member

romani commented Dec 25, 2017

@PS-SP ,
logic update is not obvious, ... while Im doing code review
please generate regressions reports for new token for each option.

@romani
Copy link
Member

romani commented Jun 1, 2018

@PS-SP , I would appreciate if you rebase your PR on latest master.

Reports "all the old tokens" have no changes that is good.

Diff report - new token - option: alone

looks good.

Diff report - new token - option: alone-singleline

looks good.


Diff report - new token - option: same

https://4058-rightcurly-new-same.netlify.com/apache-jsecurity/#A1 this is false positive.
Code is:

         frame.setVisible(true);
         frame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                 System.exit(0);
             }
         });  // violation!!!!!

but in same mode specification http://checkstyle.sourceforge.net/property_types.html#rcurly we have the same case:

    Thread t = new Thread(new Runnable() {
        .....
    }); // this is OK, allowed for better code readability

Please explain this change in behavior.

@therootusr therootusr force-pushed the issue_4058 branch 2 times, most recently from 0a71ee0 to 3e2da61 Compare June 2, 2018 15:03
@rnveach
Copy link
Contributor

rnveach commented Jun 2, 2018

@PS-SP there is a PMD failure.

@therootusr
Copy link
Author

@rnveach
Yeah it's with respect to cyclomatic complexity for getDetails method. I Should we exclude getDetails method from this ? It seems quite readable now. If we can not exclude it then one way would be to merge a few cases in the switch in getDetails method and merge the corresponding methods too.
Can you please suggest other methods to refactor it without decreasing readability.

@romani
I will get back to you with an explanation or otherwise a fix regarding the regression you pointed out.

@rnveach
Copy link
Contributor

rnveach commented Jun 2, 2018

Should we exclude getDetails method from this ?

Unless you can very easily merge tokens together, I would just exclude it. It is just one big switch case is all.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

@PS-SP ,

please add your PMD case to exclude at https://github.com/checkstyle/checkstyle/blob/master/config/pmd.xml#L261

items to confirm:

details = new Details(lcurly, rcurly, nextToken, false);
}
else {
details = new Details();
Copy link
Member

Choose a reason for hiding this comment

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

@PS-SP , please explain for what case you need this ?
Details withtout details, looks strange.

Copy link
Author

@therootusr therootusr Jun 2, 2018

Choose a reason for hiding this comment

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

LITERAL_NEW not only represents anonymous classes but also object(OBJECT1 = new Object();) and array instantiations(new String[] {"br", } or ar = new int[4];). Hence we first check if a LITERAL_NEW type of AST actually represents an anonymous class and if it does then we return a proper Details object.

If it doesn't then we return a dummy Details object without any details to avoid NullPointerException here

if-else branch can be removed by making the variable details non-final.

Copy link
Member

Choose a reason for hiding this comment

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

Please remove default c-tor and lets use existing c-tor will all arguments explicitly defined.

not only represents anonymous classes but also object and array

So here is point, please name method exactly what it does getDetailsForAnonymousClassOrObjectOrArray

ar = new int[4];

no details should be in this case only, please add it to UT input file that you created.

new String[] {"br", }

this case should do have right curly, and we need to find it and put in Details. This is should be separate processing branch in IF-ELSE.
code should be like:

if (isAnonymous()) {
} else if (isArrayInitialization()) {
} else {
  // it is array creation without curly braces
 details = new Details(null, null, null, false);
}

If it doesn't then we return a dummy Details object without any details to avoid NullPointerException here

All other methods getDetailsXXXXX also can return Detail object full of nulls inside, but they use the same c-tor. Please reuse it.

Copy link
Author

Choose a reason for hiding this comment

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

Please remove default c-tor and lets use existing c-tor will all arguments explicitly defined.

Done.

So here is point, please name method exactly what it does

Done.

no details should be in this case only, please add it to UT input file that you created.

Added another test, testBracePolicyAloneForArrayInit.

this case should do have right curly, and we need to find it and put in Details. This is should be separate processing branch in IF-ELSE.

Done.

@therootusr therootusr force-pushed the issue_4058 branch 3 times, most recently from ca14566 to 4574711 Compare June 4, 2018 01:59
@romani romani removed the incomplete label Jun 4, 2018
…ns for RightCurlyCheck. RightCurlyCheck with option 'ALONE' for anonymous classes. Added UT
@therootusr
Copy link
Author

@romani
Updated PR.

  1. Lots of array initialization in our source codes have rcurly not alone on line leading to CI failure. Should the policy be changed to ALONE_OR_SINGLELINE and source be modified accordingly. There are 171 errors or so, suppressing all of them looks to be an inefficient option.

  2. There's nuance attached with array initialization without a new keyword. Please have a look at InputRightCurlyBracePolicyAloneForArrayInit.java#L20 and InputRightCurlyBracePolicyAloneForArrayInit.java#L79

@romani
Copy link
Member

romani commented Jun 5, 2018

Please have a look at

completely ok to make them as violations.

Should the policy be changed to ALONE_OR_SINGLELINE and source be modified accordingl

I am pretty ok with following mode for NEW.
@rnveach , how do you like this style.
I like idea to allow } to be on the same line as , and ) ... in the same time as we allow ; next to }. We should add this to xdoc. In new blocks placing ; on new line is completely weird.

Patch below show problematic cases + }).collect(Collectors.toSet()); there should be violation as ")" is ok, but ".collect" should be on separate line.
Below is fix for all checkstyle violations:

diff --git a/config/checkstyle_checks.xml b/config/checkstyle_checks.xml
index a97d53e..c2cf1b9 100644
--- a/config/checkstyle_checks.xml
+++ b/config/checkstyle_checks.xml
@@ -228,10 +228,13 @@
       <property name="tokens" value="LITERAL_FINALLY"/>
       <property name="tokens" value="LITERAL_IF"/>
       <property name="tokens" value="LITERAL_TRY"/>
-      <property name="tokens" value="LITERAL_NEW"/>
       <property name="option" value="alone"/>
     </module>
     <module name="RightCurly">
+      <property name="tokens" value="LITERAL_NEW"/>
+      <property name="option" value="alone_or_singleline"/>
+    </module>
+    <module name="RightCurly">
       <property name="tokens" value="LITERAL_DO"/>
       <property name="option" value="same"/>
     </module>
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
index b91ba51..868e38e 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java
@@ -74,7 +74,8 @@ public class FinalParametersCheck extends AbstractCheck {
             TokenTypes.LITERAL_FLOAT,
             TokenTypes.LITERAL_DOUBLE,
             TokenTypes.LITERAL_BOOLEAN,
-            TokenTypes.LITERAL_CHAR, })
+            TokenTypes.LITERAL_CHAR,
+        })
         .collect(Collectors.toSet()));
 
     /**
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalCatchCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalCatchCheck.java
index f1380ab..fd0b3f9 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalCatchCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalCatchCheck.java
@@ -46,9 +46,11 @@ public final class IllegalCatchCheck extends AbstractCheck {
     public static final String MSG_KEY = "illegal.catch";
 
     /** Illegal class names. */
-    private final Set<String> illegalClassNames = Arrays.stream(new String[] {"Exception", "Error",
-        "RuntimeException", "Throwable", "java.lang.Error", "java.lang.Exception",
-        "java.lang.RuntimeException", "java.lang.Throwable", }).collect(Collectors.toSet());
+    private final Set<String> illegalClassNames = Arrays.stream(
+        new String[] {"Exception", "Error",
+            "RuntimeException", "Throwable", "java.lang.Error", "java.lang.Exception",
+            "java.lang.RuntimeException", "java.lang.Throwable",
+        }).collect(Collectors.toSet());
 
     /**
      * Set the list of illegal classes.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
index 8b31ea8..399bd4f 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalThrowsCheck.java
@@ -66,8 +66,8 @@ public final class IllegalThrowsCheck extends AbstractCheck {
     /** Illegal class names. */
     private final Set<String> illegalClassNames = Arrays.stream(
         new String[] {"Error", "RuntimeException", "Throwable", "java.lang.Error",
-                      "java.lang.RuntimeException", "java.lang.Throwable", })
-        .collect(Collectors.toSet());
+                      "java.lang.RuntimeException", "java.lang.Throwable",
+        }).collect(Collectors.toSet());
 
     /** Property for ignoring overridden methods. */
     private boolean ignoreOverriddenMethods = true;
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java
index 322d4c7..56bce2d 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/design/DesignForExtensionCheck.java
@@ -101,8 +101,10 @@ public class DesignForExtensionCheck extends AbstractCheck {
     /**
      * A set of annotations which allow the check to skip the method from validation.
      */
-    private Set<String> ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before", "After",
-        "BeforeClass", "AfterClass", }).collect(Collectors.toSet());
+    private Set<String> ignoredAnnotations = Arrays.stream(
+        new String[] {"Test", "Before", "After",
+            "BeforeClass", "AfterClass",
+        }).collect(Collectors.toSet());
 
     /**
      * Sets annotations which allow the check to skip the method from validation.
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java
index 115555b..51c8479 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java
@@ -78,15 +78,17 @@ public class JavadocStyleCheck
      * The forms and structure tags are not allowed
      */
     private static final Set<String> ALLOWED_TAGS = Collections.unmodifiableSortedSet(
-        Arrays.stream(new String[] {
-            "a", "abbr", "acronym", "address", "area", "b", "bdo", "big",
-            "blockquote", "br", "caption", "cite", "code", "colgroup", "dd",
-            "del", "div", "dfn", "dl", "dt", "em", "fieldset", "font", "h1",
-            "h2", "h3", "h4", "h5", "h6", "hr", "i", "img", "ins", "kbd",
-            "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong",
-            "style", "sub", "sup", "table", "tbody", "td", "tfoot", "th",
-            "thead", "tr", "tt", "u", "ul", "var", })
-        .collect(Collectors.toCollection(TreeSet::new)));
+        Arrays.stream(
+            new String[] {
+                "a", "abbr", "acronym", "address", "area", "b", "bdo", "big",
+                "blockquote", "br", "caption", "cite", "code", "colgroup", "dd",
+                "del", "div", "dfn", "dl", "dt", "em", "fieldset", "font", "h1",
+                "h2", "h3", "h4", "h5", "h6", "hr", "i", "img", "ins", "kbd",
+                "li", "ol", "p", "pre", "q", "samp", "small", "span", "strong",
+                "style", "sub", "sup", "table", "tbody", "td", "tfoot", "th",
+                "thead", "tr", "tt", "u", "ul", "var",
+            }
+        ).collect(Collectors.toCollection(TreeSet::new)));
 
     /** The scope to check. */
     private Scope scope = Scope.PRIVATE;
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheck.java
index 1c85d77..dc241db 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/sizes/OuterTypeNumberCheck.java
@@ -56,7 +56,8 @@ public class OuterTypeNumberCheck extends AbstractCheck {
     @Override
     public int[] getRequiredTokens() {
         return new int[] {TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF,
-            TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF, };
+            TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF,
+        };
     }
 
     @Override
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java
index eb54a96..89158ae 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java
@@ -472,7 +472,8 @@ public class ConfigurationLoaderTest extends AbstractPathTestSupport {
             final Object obj = constructor.newInstance(objParent);
 
             final Class<?>[] param = new Class<?>[] {String.class, String.class,
-                String.class, Attributes.class, };
+                String.class, Attributes.class,
+            };
             final Method method = aClass.getDeclaredMethod("startElement", param);
 
             method.invoke(obj, "", "", "hello", null);
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
index 0c6731d..30dc315 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/MainTest.java
@@ -965,11 +965,14 @@ public class MainTest {
             final LocalizedMessage unableToInstantiateExceptionMessage = new LocalizedMessage(0,
                     Definitions.CHECKSTYLE_BUNDLE,
                     "PackageObjectFactory.unableToInstantiateExceptionMessage",
-                    new String[] {"TestRootModuleChecker", checkstylePackage
-                            + "TestRootModuleChecker, "
-                            + "TestRootModuleCheckerCheck, " + checkstylePackage
-                            + "TestRootModuleCheckerCheck"},
-                    null, getClass(), null);
+                    new String[] {"TestRootModuleChecker",
+                        checkstylePackage
+                                + "TestRootModuleChecker, "
+                                + "TestRootModuleCheckerCheck, "
+                                + checkstylePackage
+                                + "TestRootModuleCheckerCheck",
+                    }
+                    , null, getClass(), null);
             assertEquals("Unexpected output log", errorCounterOneMessage.getMessage() + EOL,
                     systemOut.getLog());
             assertTrue("Unexpected system error log",
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java
index e153db5..1ad175e 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheckTest.java
@@ -443,12 +443,12 @@ public class RightCurlyCheckTest extends AbstractModuleTestSupport {
         checkConfig.addAttribute("option", RightCurlyOption.ALONE.toString());
         checkConfig.addAttribute("tokens", "LITERAL_NEW");
         final String[] expected = {
-                "39:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
-                "52:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
-                "57:17: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 17),
-                "62:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
-                "87:17: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 17),
-                "94:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
+            "39:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
+            "52:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
+            "57:17: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 17),
+            "62:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
+            "87:17: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 17),
+            "94:9: " + getCheckMessage(MSG_KEY_LINE_ALONE, "}", 9),
         };
         verify(checkConfig, getPath("InputRightCurlyBracePolicyAloneForArrayInit.java"),
                 expected);
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
index 3261330..50e3711 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/AbstractJavadocCheckTest.java
@@ -151,10 +151,11 @@ public class AbstractJavadocCheckTest extends AbstractModuleTestSupport {
             singletonList("4: " + getCheckMessage(MSG_JAVADOC_PARSE_RULE_ERROR, 78,
                     "mismatched input '(' expecting <EOF>", "JAVADOC")
         ));
-        verify(createChecker(checkConfig), new File[] {
-            new File(getPath("InputAbstractJavadocParsingErrors.java")),
-            new File(getPath("InputAbstractJavadocInvalidAtSeeReference.java")), },
-                expectedMessages);
+        verify(createChecker(checkConfig),
+            new File[] {
+                new File(getPath("InputAbstractJavadocParsingErrors.java")),
+                new File(getPath("InputAbstractJavadocInvalidAtSeeReference.java")),
+            }, expectedMessages);
         assertEquals("Error is unexpected", "", systemErr.getLog());
     }
 
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/gui/MainFrameModelTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/gui/MainFrameModelTest.java
index ea209bc..23b39a8 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/gui/MainFrameModelTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/gui/MainFrameModelTest.java
@@ -144,7 +144,8 @@ public class MainFrameModelTest extends AbstractModuleTestSupport {
         PowerMockito.when(ParseMode.values()).thenReturn(
                 new ParseMode[] {
                     ParseMode.PLAIN_JAVA, ParseMode.JAVA_WITH_COMMENTS,
-                    ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS, unknownParseMode, });
+                    ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS, unknownParseMode,
+                });
 
         try {
             model.setParseMode(unknownParseMode);

@romani romani removed their assignment Jun 5, 2018
@rnveach
Copy link
Contributor

rnveach commented Jun 5, 2018

I like idea to allow } to be on the same line as , and ) ... in the same time as we allow ; next to }.

If we switch to this then we will have to re-evaluate other tokens.
As I pointed out at #4173 (comment) and #4173 (comment) , lambda will give a violation.

I am fine with } being on the same line as ) or , .

@romani
Copy link
Member

romani commented Jun 5, 2018

@rnveach

, lambda will give a violation.

Please provide example (and cli result probably) to let understand clearly what you mean.

If we switch to this then we will have to re-evaluate other tokens.

We do not need to. I my patch only new token is under new option. I do not see a reason to review and think about other tokens. If you see a reason please share it, but it definitely separate issue.

@therootusr
Copy link
Author

@romani @rnveach
so

method_call(new String[] {

});

shouldn't give any violations ?

If yes, then I suppose the rcurly from an anon class instantiation shouldn't either ?

@rnveach
Copy link
Contributor

rnveach commented Jun 5, 2018

Please provide example (and cli result probably) to let understand clearly what you mean.

I'm not sure what I used for those posts, but here is one based off current discussions.

$ cat TestClass.java
public class TestClass {
    void method() {
        someMethod(() -> {String.CASE_INSENSITIVE_ORDER.equals("Hello world two!");});
    }

    public void someMethod(Runnable r) {
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="RightCurly">
  <property name="option" value="ALONE_OR_SINGLELINE"/>
  <property name="tokens" value="LAMBDA"/>
</module>
    </module>
</module>

$ java -jar checkstyle-8.10.1-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:3:84: '}' at column 84 should be alone on a line. [RightCurly]
Audit done.
Checkstyle ends with 1 errors.

@romani
Copy link
Member

romani commented Jun 6, 2018

, but here is one based off current discussions.

thanks a lot, this is what I expected.

===========================

Looks like we did not pay much attention to Issue discussion and how to make it during GSoC hurry and rushed to implementation.
lets come back to issue/design discussion - #4058 (comment)

I am calling back my approval for changes in ALONE_OR_SINGLELINE.
For NEW token new mode should be created. It is better to discuss it separately.

@romani
Copy link
Member

romani commented Jun 18, 2018

@PS-SP , I terribly sorry but I do not see future in this PR, sorry for wasting your time on it.
Decision was tough for me, it took me a while to analyze the issue. But good is that we prevented bad design to appear public to whole java community.

New issue is created - #5945 , some part of code might be reused but .... looks like it is better to make new code from scratch.

Please do last confirmation that you are ok to close PR.
Sorry.

@therootusr
Copy link
Author

@romani
I am totally fine with closing this PR. I too agree that there are too many design complications involved right now and we need to sort them out step by step. Also, the code here may also be helpful for #5945.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants