diff options
author | Ivan Sopov <sopov.ivan@gmail.com> | 2014-02-19 22:34:10 +0200 |
---|---|---|
committer | Ivan Sopov <sopov.ivan@gmail.com> | 2014-03-04 19:18:11 +0200 |
commit | f1efb27670a93690577f1bae17fc9dcbd88a795d (patch) | |
tree | b4c1b1405c4b2cfb30bb3f3e6429c4ecd89798a2 /src/test/resources/com/puppycrawl/tools/checkstyle/grammars | |
parent | 1cdaeaaa4fbf02a7388f1fcbea1c86ef0ea32fed (diff) | |
download | checkstyle-f1efb27670a93690577f1bae17fc9dcbd88a795d.tar.gz |
moving to standard directory layout
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/grammars')
13 files changed, 287 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/Bug3553541.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/Bug3553541.java new file mode 100644 index 000000000..18758d8f1 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/Bug3553541.java @@ -0,0 +1,17 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +import java.util.List; +import java.util.ArrayList; + +// Demonstrates the bug #3553541 +class Bug3553541 +{ + List<? super long[]> a; + { + a = new ArrayList<long[]>(); + } + List<? super Integer[]> b; + { + b = new ArrayList<Integer[]>(); + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/EofBug1667137.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/EofBug1667137.java new file mode 100644 index 000000000..266895b14 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/EofBug1667137.java @@ -0,0 +1,14 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +// Demonstrates the bug #1667137 +class EofBug1667137 { + + void checkstyleIsBroken() { + EofBug1667137 borkage = new EofBug1667137() { + + <T extends EofBug1667137> T borked(T brokenness) { + return brokenness; + } + }; + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputEmbeddedNullChar.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputEmbeddedNullChar.java Binary files differnew file mode 100644 index 000000000..6c318ebc2 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputEmbeddedNullChar.java diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java new file mode 100644 index 000000000..c743ce294 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java @@ -0,0 +1,9 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for grammar test. + */ +public class InputGrammar +{ + int é = 1; // illegal, unless UTF-8 +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputHexFloat.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputHexFloat.java new file mode 100644 index 000000000..e02ec583c --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputHexFloat.java @@ -0,0 +1,16 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for hex float and double test. + */ +public class InputHexFloat +{ + double f1 = 0x.0P10; + double f2 = 0x1.P-1; + double f3 = 0Xab1P0; + double f4 = 0Xab1ap+20; + double f5 = 0Xab1ap+20D; + double f6 = 0Xab1ap+20d; + double f7 = 0Xab1ap+20f; + double f8 = 0Xab1ap+20F; +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7Diamond.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7Diamond.java new file mode 100644 index 000000000..8b220bc4f --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7Diamond.java @@ -0,0 +1,10 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +import java.util.*; + +public class InputJava7Diamond { + HashMap<String, Integer> map = new HashMap<String, Integer>(); + HashMap<String, Integer> map2 = new HashMap<>(); + HashMap<String, HashMap<Integer, Integer>> map3 = new HashMap<>(); + ArrayList<String> list = new ArrayList<>(); +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7MultiCatch.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7MultiCatch.java new file mode 100644 index 000000000..3162c8886 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7MultiCatch.java @@ -0,0 +1,30 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +import java.io.*; + +/** + * Input for Java 7 multi-catch. + */ +public class InputJava7MultiCatch +{ + public static class CustomException extends Exception { } + public static class AnotherCustomException extends Exception { } + + public static void logException(Exception e) { } + + public static void main(String[] args) { + try { + FileInputStream in = new FileInputStream("InputJava7MultiCatch.java"); + throw new CustomException(); + } catch (FileNotFoundException | CustomException e) { + logException(e); + } + + try { + FileInputStream in = new FileInputStream("InputJava7MultiCatch.java"); + throw new CustomException(); + } catch (final FileNotFoundException | CustomException | test.foo.AnotherCustomException e) { + logException(e); + } + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7NumericalLiterals.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7NumericalLiterals.java new file mode 100644 index 000000000..46d96f30b --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7NumericalLiterals.java @@ -0,0 +1,84 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for Java 7 numerical literals. + */ +public class InputJava7NumericalLiterals +{ + int i1 = 0b00011110; + int i2 = 0B00011110; + int i3 = 0xA; + int i4 = 0x1___A_F; + int i5 = 0b1; + int i6 = 0b1___1_0; + int i7 = 0; + int i8 = 02; + int i9 = 0_123; + int i10 = 1; + int i11 = 1___3; + int i12 = 1_43_43598_7; + + long l1 = 0b00011110L; + long l2 = 0B00011110l; + long l3 = 0xAL; + long l4 = 0x1___A_FL; + long l5 = 0b1L; + long l6 = 0b1___1_0L; + long l7 = 0l; + long l8 = 02L; + long l9 = 0_123l; + long l10 = 1l; + long l11 = 1___3l; + long l12 = 1_43_43598_7L; + long l13 = 1_43_43598_7; // int promoted to long + + // the grammar considers floating point values to be of type "float" by default which is wrong, it should be "double". + + float f1 = .1f; + float f2 = 1.; // double "downgraded" to float + float f3 = 0f; + float f4 = 1e0; // double "downgraded" to float + float f5 = 1e0f; + float f6 = 12.345F; + float f7 = .5____2_1; // double "downgraded" to float + float f8 = 1__42__3.; // double "downgraded" to float + float f9 = 0__2_4__324f; + float f10 = 1_34e0; // double "downgraded" to float + float f11 = 1__1_2e0f; + float f12 = 2_1___2.3__4_5F; + float f13 = 1_34e0__4__3; // double "downgraded" to float + float f14 = 1__1_2e00__000_4f; + float f15 = 2_1___2.3__4_5e00______0_5F; + + double d1 = .1d; + double d2 = 1.D; + double d3 = 0d; + double d4 = 1e0D; + double d5 = 1e0d; + double d6 = 12.345D; + double d7 = .5____2_1d; + double d8 = 1__42__3.D; + double d9 = 0__2_4__324d; + double d10 = 1_34e0d; + double d11 = 1__1_2e0d; + double d12 = 2_1___2.3__4_5D; + double d13 = 1_34e0__4__3d; + double d14 = 1__1_2e00__000_4d; + double d15 = 2_1___2.3__4_5e00______0_5D; + double d16 = 0.12___34; // "float" promoted to double + + float hf1 = 0x.1___AFp1; // double "downgraded" to float + float hf2 = 0x.1___AFp0__0__0f; + float hf3 = 0x2__3_34.4___AFP00_00f; + + double hd1 = 0x.1___AFp1; + double hd2 = 0x.1___AFp0__0__0d; + double hd3 = 0x2__3_34.4___AFP00_00d; + + int doc1 = 1234_5678; + long doc2 = 1_2_3_4__5_6_7_8L; + int doc3 = 0b0001_0010_0100_1000; + double doc4 = 3.141_592_653_589_793d; + double doc5 = 0x1.ffff_ffff_ffff_fP1_023; // Double.MAX_VALUE + +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7StringSwitch.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7StringSwitch.java new file mode 100644 index 000000000..e4cbf3680 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7StringSwitch.java @@ -0,0 +1,20 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for Java 7 String in Switch. + */ +public class InputJava7StringSwitch +{ + public static void main(String[] args) { + String mystr = "value" + "2"; + + switch (mystr) { + case "value1": + break; + case "value2": + break; + default: + break; + } + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7TryWithResources.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7TryWithResources.java new file mode 100644 index 000000000..caeed9c55 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputJava7TryWithResources.java @@ -0,0 +1,39 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for Java 7 try-with-resources. + */ +public class InputJava7TryWithResources +{ + public static class MyResource implements AutoCloseable { + @Override + public void close() throws Exception { } + } + + public static void main(String[] args) throws Exception { + try (MyResource resource = new MyResource()) { } + + try (MyResource resource = new MyResource()) { } + finally { } + + try (MyResource resource = new MyResource();) { } + catch (Exception e) { } + + try (MyResource resource = new MyResource();) { } + catch (Exception e) { } + catch (Throwable t) { } + finally { } + + try (MyResource resource = new MyResource(); MyResource resource2 = new MyResource()) { } + catch (Exception e) { } + catch (Throwable t) { } + finally { } + + try (MyResource resource = new MyResource(); MyResource resource2 = new MyResource();) { } + catch (Exception e) { } + catch (Throwable t) { } + finally { } + + try (@SuppressWarnings("all") final MyResource resource = new MyResource()) { } + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputVararg.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputVararg.java new file mode 100644 index 000000000..6469f07db --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/InputVararg.java @@ -0,0 +1,11 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for vararg test. + */ +public class InputVararg +{ + public static void main(String... args) + { + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java new file mode 100644 index 000000000..87697ea69 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java @@ -0,0 +1,5 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +public class LineCommentAtTheEndOfFile +{ +} // EOF on this line
\ No newline at end of file diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/UnicodeEscape.java b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/UnicodeEscape.java new file mode 100644 index 000000000..945ba160b --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/grammars/UnicodeEscape.java @@ -0,0 +1,32 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +/** + * Input for unicode escapes. + */ +public class UnicodeEscape +{ + char a = '\u005cr'; + char b = '\u005cn'; + char c = '\u005ct'; + char d = '\uuuu005cn'; + char e = '\u005c\u005c'; + char f = '\u005c''; + char g = '"'; + String h = "\u005c""; + String i = "'"; + char j = '\"'; + String k = "\'"; + char l = '\u005C''; + char m = '\uABCD'; + char n = '\u00AB'; + char o = '\u005B'; + char p = '\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu005cr'; // Tests the lookahead + char q = '\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu005D'; + + char wtf1 = '\u005c\u005c'; // This is a legal backslash + String wtf2 = "\\u005c"; // = "\u005c", with a single backslash, and != a backslash! + // There is an ambiguity in the grammar, the interpretation is done as "\\" + "u005c" + //char wtf3 = '\\u005c'; // This is therefore, illegal + + //char z = '\u005cu005c'; /* This is illegal */ +} |