aboutsummaryrefslogtreecommitdiff
path: root/src/test/resources-noncompilable
diff options
context:
space:
mode:
authorAndrei Selkin <andreyselkin@gmail.com>2016-02-14 11:25:21 +0300
committerRoman Ivanov <ivanov-jr@mail.ru>2016-02-15 05:48:10 -0800
commit4c3a5dcdd0e264fe708cfcc65bd2f36092c5bfa4 (patch)
tree5adee271acb352429a336cbc3fb134813df6428a /src/test/resources-noncompilable
parent0fe6a5534885066ed358a047867445d470036897 (diff)
downloadcheckstyle-4c3a5dcdd0e264fe708cfcc65bd2f36092c5bfa4.tar.gz
Issue #903: Skip type annotations from validation of ModifierOrderCheck
Diffstat (limited to 'src/test/resources-noncompilable')
-rw-r--r--src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/InputTypeAnnotations.java86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/InputTypeAnnotations.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/InputTypeAnnotations.java
new file mode 100644
index 000000000..a92f940f0
--- /dev/null
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/InputTypeAnnotations.java
@@ -0,0 +1,86 @@
+//Compilable with Java8
+package com.puppycrawl.tools.checkstyle.checks.modifier;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+public class InputTypeAnnotations {
+
+ // Simple type definitions with type annotations
+ private @TypeAnnotation String hello = "Hello, World!";
+ private @TypeAnnotation final String jdk = "JDK8";
+ @TypeAnnotation private String projectName = "Checkstyle";
+
+ // We can use type Annotations with generic type arguments
+ private Map.@TypeAnnotation Entry entry;
+ // Type annotations can also be applied to nested types
+ private List<@TypeAnnotation String> strings;
+
+ // Constructors with type annotations
+ {
+ new @TypeAnnotation Object();
+ }
+
+ static {
+ new @TypeAnnotation Object();
+ }
+
+ public void foo1() {
+ new @TypeAnnotation Object();
+ }
+
+ // Type annotations work with nested (non static) class constructors too
+ public void foo2() {
+ InputTypeAnnotations myObject = new InputTypeAnnotations();
+ myObject.new @TypeAnnotation Nested();
+ }
+
+ // Type casts
+ public void foo3() {
+ String myString = (@TypeAnnotation String) new Object();
+
+ }
+
+ // Type annotations with method arguments
+ private void foo4(final @TypeAnnotation String parameterName) { }
+
+ // Inheritance
+ class MySerializableClass<T> implements @TypeAnnotation Serializable { }
+
+ // Nested type annotations
+ Map<@TypeAnnotation String, @TypeAnnotation List<@TypeAnnotation String>> documents;
+
+ // Apply type annotations to intersection types
+ public <E extends @TypeAnnotation Comparator<E> & @TypeAnnotation Comparable> void foo5() { }
+
+ // Including parameter bounds and wildcard bounds
+ class Folder<F extends @TypeAnnotation File> { }
+ Collection<? super @TypeAnnotation File> c;
+ List<@TypeAnnotation ? extends Comparable<T>> unchangeable;
+
+ // Throwing exceptions
+ void foo6() throws @TypeAnnotation IOException { }
+
+ // Type annotations in instanceof statements
+ public void foo7() {
+ boolean isNonNull = "string" instanceof @TypeAnnotation String;
+
+ }
+
+ class Nested { }
+
+ class T { }
+}
+
+@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER,
+ ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
+@interface TypeAnnotation {
+} \ No newline at end of file