Debian Codegraph @

src/com/google/errorprone/annotations/CompatibleWith.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 /*
2 * Copyright 2016 The Error Prone Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.errorprone.annotations;
18
19 import java.lang.annotation.Documented;
20 import java.lang.annotation.ElementType;
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.lang.annotation.Target;
24 import java.util.Collection;
25
26 /**
27 * Declares that a parameter to a method must be "compatible with" one of the type parameters in the
28 * method's enclosing class, or on the method itself. "Compatible with" means that there can exist a
29 * "reference casting conversion" from one type to the other (JLS 5.5.1).
30 *
31 * <p>For example, {@link Collection#contains} would be annotated as follows:
32 *
33 * <pre>{@code
34 * interface Collection<E> {
35 * boolean contains(@CompatibleWith("E") Object o);
36 * }
37 * }</pre>
38 *
39 * <p>To indicate that invocations of {@link Collection#contains} must be passed an argument whose
40 * type is compatible with the generic type argument of the Collection instance:
41 *
42 * <pre>{@code
43 * Collection<String> stringCollection = ...;
44 * boolean shouldBeFalse = stringCollection.contains(42); // BUG! int isn't compatible with String
45 * }</pre>
46 *
47 * <p>Note: currently, this annotation can't be used if the method overrides another method that has
48 * {@code @CompatibleWith} already present.
49 */
50 @Documented
51 @Retention(RetentionPolicy.CLASS)
52 @Target(ElementType.PARAMETER)
53 public @interface CompatibleWith {
54 String value();
55 }