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

New Check: RightCurlyOfExpression #5945

Open
romani opened this Issue Jun 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@romani
Copy link
Member

romani commented Jun 18, 2018

based on discussion at #4058 (PR #4173)

right curly of expression block is different from other blocks so rules or RightCurly Check does not work well as for example for alone results in weird code as } in expression is always followed by smth, same does not make sense .

Array Creation Expressions
Lambda expression
Class Instance Creation Expressions

on_same_line

ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before", "After",
        "BeforeClass", "AfterClass", }).collect(Collectors.toSet());
final Class<?>[] param = new Class<?>[] {String.class, String.class,
       String.class, Attributes.class,};
someMethod(() -> {"Hello".equals("Hello world two!");}); 
new Object() { @Override protected void finalize() { "".toString(); }  int b = 10; };

on_new_line

ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before", "After",
        "BeforeClass", "AfterClass",
}).collect(Collectors.toSet());
final Class<?>[] param = new Class<?>[] {String.class, String.class,
       String.class, Attributes.class,
};
someMethod(() -> {"Hello".equals("Hello world two!");
}); 
new Object() { @Override protected void finalize() { "".toString(); }  int b = 10; 
};

on_new_line_or_singleline

ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before",}).collect(Collectors.toSet());
ignoredAnnotations = Arrays.stream(new String[] {"Test", "Before", "After",
        "BeforeClass", "AfterClass",
}).collect(Collectors.toSet());
final Class<?>[] param = new Class<?>[] {String.class, String.class,
       String.class, Attributes.class,
};
final Class<?>[] param = new Class<?>[] {String.class, Attributes.class, };
someMethod(() -> {"Hello".equals("Hello world two!");}); 
someMethod(() -> {
   "Hello".equals("Hello world two!");
}); 
new Object() { @Override protected void finalize() { "".toString(); }  int b = 10; };
new Object() { @Override protected void finalize() { "".toString(); }  int b = 10;
};

more examples of code from our repo - at this comment

For multi-dimensional arrays we validate only outer curly brace

int array[][] = { {1, 2}, {3,4} };

we will validate only "};".

case where we validate only outer "}":

        java.util.Map<String, String> map2 = new LinkedHashMap<String, String>() {{
            put("Hello", "World");
            put("first", "second");
            put("polygene", "lubricants");
            put("alpha", "betical");  } // ATTENTION: here is "}", Check should not care
        };

Looks like token set for Check should LAMBDA and NEW.

On the moment of implementation, we need to recheck google style is case there become more details on how to format code of lambda. We need answer from google on this point, see google/styleguide#112 .

@rnveach

This comment has been minimized.

Copy link
Member

rnveach commented Jun 18, 2018

xdoc in #5947 has to be updated to point to new check

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