[java formatter] c style comments formatting supported. Note, only single line comments or comments with each line starting with asterisks will be formatted, since by using /* and */ you

This commit is contained in:
yarik
2017-06-20 14:48:26 +03:00
parent c4cfcf98b6
commit ced545552a
34 changed files with 272 additions and 87 deletions
@@ -12,7 +12,7 @@ public class Main {
BinaryOperator<Integer> min = Math::min;
String foo = "xyz";
/*check*/
/*check*/
boolean b = selector.andThen(Collections.singleton(/* "xyz" here */ "xyz")::contains).apply(/* foo here */ foo);
}
}
@@ -3,8 +3,8 @@ import java.util.List;
public class Main {
public static void test(List<CharSequence> list) {
/*before dot*/
/*after dot*/
/*before dot*/
/*after dot*/
list.stream()
/*before dot2*/./*after dot2*/map(cs -> /*length!!!*/ cs.subSequence(/*subsequence*/1, 5).length()).forEach(System.out::println);
}
@@ -3,7 +3,7 @@ import java.util.List;
public class Main {
public static void test(List<CharSequence> list) {
/*out of body*/
/*out of body*/
list.stream().map(cs -> cs/*in body*/.subSequence(1, 5).length()).forEach(System.out::println);
}
}
@@ -2,10 +2,10 @@
import java.util.stream.Stream;
class Test {
void foo(Stream<String> stringStream ) {
stringStream.filter(name -> name.startsWith("A") && name.//comment2
length() > 1//comment
/*comment1*/
).findAny();
}
void foo(Stream<String> stringStream ) {
stringStream.filter(name -> name.startsWith("A") && name.//comment2
length() > 1//comment
/*comment1*/
).findAny();
}
}
@@ -2,9 +2,9 @@
import java.util.stream.Stream;
class Test {
void foo(Stream<String> stringStream ) {
stringStream.filt<caret>er(name -> name.startsWith("A"))//comment
.filter(a -> a.//comment2
length() > 1 /*comment1*/).findAny();
}
void foo(Stream<String> stringStream ) {
stringStream.filt<caret>er(name -> name.startsWith("A"))//comment
.filter(a -> a.//comment2
length() > 1 /*comment1*/).findAny();
}
}
@@ -11,10 +11,10 @@ public class Main {
}
public Number testOptionalComments(Optional<MyList> strList) {
/* optional is present */
/*return something */
/* optional is absent */
/* return null*/
/* optional is present */
/*return something */
/* optional is absent */
/* return null*/
return strList.map(myList -> myList.size() > /*too big*/ 1 ? myList.get(1) : 1.0).orElse(null);
}
}
@@ -8,11 +8,11 @@ class T {
}
else if (s.startsWith("@")) {
return s.substring(1); // return comment
/* inline 1 *//* inline 2 */
/* inline 1 *//* inline 2 */
}
else if (s.startsWith("#")) {
return "#"; // return comment
/* inline */
/* inline */
}
return s; // return comment
}
@@ -21,7 +21,7 @@ public class Main {
}
public static List<String> testUseName() {
/*limit*/
/*limit*/
List<String> list = new ArrayList<>();
long limit = 20;
for (String x = ""; ; x = x /* add "a" */ + "a") {
@@ -10,7 +10,7 @@ public class Test {
// comment2
System.out.println("hello");
/*in return */
/*in return */
String s = "foo" + //inline
"bar";
}
@@ -4,8 +4,8 @@ import java.util.function.Function;
public class Test {
public static void main(String[] args) {
/* bar */
/* who-hoo */
/* bar */
/* who-hoo */
String s = "foo";
}
}
@@ -4,7 +4,7 @@ import java.util.function.Function;
public class Test {
public static void main(String[] args) {
/* bar */
/* bar */
String s = ("a" +/* who-hoo */ "x") + "foo";
}
}
@@ -2,7 +2,7 @@
class Test {
public int test(String s1, String s2) {
return Integer.compare(s1.length(), s2.length());
/*otherwise bigger*/
/*otherwise bigger*/
}
public int test2(String s1, String s2) {
@@ -3,9 +3,9 @@ public class Test {
public void test(String s1, String s2) {
System.out.println(Integer.compare(s1.length(), s2.length()));
System.out.println(Integer.compare(s2.length(), s1.length()));
/*greater!*/
/*less!*/
/*equal!*/
/*greater!*/
/*less!*/
/*equal!*/
System.out.println(Integer.compare(s1.length(), s2.length()));
System.out.println(Integer.compare(s2.length(), s1.length()));
System.out.println(Integer.compare(s2.length(), s1.length()));
@@ -4,7 +4,7 @@ import java.util.Arrays;
class Test {
long cnt() {
/*count*/
/*count*/
return (long) Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
}
}
@@ -4,7 +4,7 @@ import java.util.Arrays;
class Test {
int cnt() {
/*inside*/
/*inside*/
return Arrays.asList('d', 'e', 'f').size();
}
}
@@ -3,6 +3,6 @@
import java.util.Arrays;
class Test {
/*count*/
/*count*/
long cnt = (long) Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
}
@@ -7,7 +7,7 @@ public class Main {
private String str;
public void testGetOrDefault(Map<String, String> map, String key, Main other) {
/* output none */
/* output none */
System.out.println(/* output map value */ map.getOrDefault("k", NONE));
}
}
@@ -11,7 +11,7 @@ public class Test {
"d", "1", "e", /* this is also 1*/ "1", "f", "1", "g", "1", // G is important!
"h", "1", "i", "1",
/* Finally J */
/* why not putting comment inside the call expression? */"j", "1");
/* Finally J */
/* why not putting comment inside the call expression? */"j", "1");
}
}
@@ -3,7 +3,7 @@ import java.util.stream.Stream;
public class Test {
public void test() {
/*redundant*/
/*redundant*/
System.out.println(Stream.of(/*just one number*/123).count());
}
}
@@ -36,8 +36,8 @@ public class Main {
public boolean ternaryFnMrGenericComment(List<String> list, Function<String, Boolean> fn, boolean b) {
return list.stream().allMatch(b ? // select
/* comment */ String::isEmpty :
/* comment2 */fn::apply);
/* comment */ String::isEmpty :
/* comment2 */fn::apply);
}
public <T extends Boolean> boolean doubleTernaryMr(List<String> list, boolean b, boolean b2) {
@@ -49,7 +49,7 @@ public class Main {
}
public boolean anyMatchBooleanValue(List<String> list) {
/* ditto boolean!*/
/* ditto boolean!*/
return list.stream().anyMatch(String::isEmpty);
}
@@ -5,7 +5,7 @@ import java.util.List;
public class Main {
void test(List<String> list) {
// hello
/* in return */
/* in return */
long count = list.stream()
.peek(System.out::println)
.count();
@@ -3,17 +3,17 @@
import java.util.List;
public class Main {
void test(List<String> list) {
long count = list.stream()
.peek(e -> {
if(e.isEmpty()) {
System.out.println("Empty line passed!");
throw new IllegalArgumentException();
}
// hello
/* in return */
})
.count();
System.out.println(count);
}
void test(List<String> list) {
long count = list.stream()
.peek(e -> {
if(e.isEmpty()) {
System.out.println("Empty line passed!");
throw new IllegalArgumentException();
}
// hello
/* in return */
})
.count();
System.out.println(count);
}
}
@@ -4,7 +4,7 @@ import java.util.*;
class Test {
public void testToArray(List<String[]> data) {
/*generate array*/
/*generate array*/
String[][] array = data.subList(0, /*max number*/ 10).toArray(new String[0][]);
}
}
@@ -3,17 +3,17 @@
import java.util.List;
public class Main {
void test(List<String> list) {
long count = list.stream()
.ma<caret>p(e -> {
if(e.isEmpty()) {
System.out.println("Empty line passed!");
throw new IllegalArgumentException();
}
// hello
return /* in return */ e;
})
.count();
System.out.println(count);
}
void test(List<String> list) {
long count = list.stream()
.ma<caret>p(e -> {
if(e.isEmpty()) {
System.out.println("Empty line passed!");
throw new IllegalArgumentException();
}
// hello
return /* in return */ e;
})
.count();
System.out.println(count);
}
}
@@ -1,5 +1,5 @@
class Test {
/*
*/
/*
*/
}
@@ -1,5 +1,5 @@
class Test {
/*and comment here*///comment
/*and comment here*///comment
public static final String xxx = "";
{