Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 584d1cb

Browse files
committed
DefaultQualifier workaround
1 parent eaf516f commit 584d1cb

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

checker-qual-shim/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is here purely to workaround https://github.com/typetools/checker-framework/issues/6420
2+
3+
We keep a compiletime-only copy of `DefaultQualifier`, with the only change being its @Retention, so that
4+
usages of `DefaultQualifier` within util-core are kept in the compiled jar.

checker-qual-shim/build.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
dependencies {
6+
compileOnly libs.checkerQual
7+
}
8+
9+
indeedOss.activateFeature 'java'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* Checker Framework qualifiers Copyright 2004-present by the Checker Framework developers
3+
*
4+
* <p>MIT License:
5+
*
6+
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
8+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
9+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* <p>The above copyright notice and this permission notice shall be included in all copies or
13+
* substantial portions of the Software.
14+
*
15+
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
package org.checkerframework.framework.qual;
22+
23+
import java.lang.annotation.Annotation;
24+
import java.lang.annotation.Documented;
25+
import java.lang.annotation.ElementType;
26+
import java.lang.annotation.Repeatable;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
/**
32+
* Applied to a declaration of a package, type, method, variable, etc., specifies that the given
33+
* annotation should be the default. The default is applied to type uses within the declaration for
34+
* which no other annotation is explicitly written. (The default is not applied to the "parametric
35+
* locations": class declarations, type parameter declarations, and type parameter uses.) If
36+
* multiple {@code DefaultQualifier} annotations are in scope, the innermost one takes precedence.
37+
* DefaultQualifier takes precedence over {@link DefaultQualifierInHierarchy}.
38+
*
39+
* <p>You may write multiple {@code @DefaultQualifier} annotations (for unrelated type systems, or
40+
* with different {@code locations} fields) at the same location. For example:
41+
*
42+
* <pre>
43+
* &nbsp; @DefaultQualifier(NonNull.class)
44+
* &nbsp; @DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.IMPLICIT_UPPER_BOUND)
45+
* &nbsp; @DefaultQualifier(Tainted.class)
46+
* &nbsp; class MyClass { ... }
47+
* </pre>
48+
*
49+
* <p>This annotation currently has no effect in stub files.
50+
*
51+
* @see org.checkerframework.framework.qual.TypeUseLocation
52+
* @see DefaultQualifierInHierarchy
53+
* @see DefaultFor
54+
* @checker_framework.manual #defaults Default qualifier for unannotated types
55+
*/
56+
@Documented
57+
@Retention(RetentionPolicy.RUNTIME)
58+
@Target({
59+
ElementType.PACKAGE,
60+
ElementType.TYPE,
61+
ElementType.CONSTRUCTOR,
62+
ElementType.METHOD,
63+
ElementType.FIELD,
64+
ElementType.LOCAL_VARIABLE,
65+
ElementType.PARAMETER
66+
})
67+
@Repeatable(DefaultQualifier.List.class)
68+
public @interface DefaultQualifier {
69+
70+
/**
71+
* The Class for the default annotation.
72+
*
73+
* <p>To prevent affecting other type systems, always specify an annotation in your own type
74+
* hierarchy. (For example, do not set {@link
75+
* org.checkerframework.common.subtyping.qual.Unqualified} as the default.)
76+
*/
77+
Class<? extends Annotation> value();
78+
79+
/**
80+
* Returns the locations to which the annotation should be applied.
81+
*
82+
* @return the locations to which the annotation should be applied
83+
*/
84+
TypeUseLocation[] locations() default {TypeUseLocation.ALL};
85+
86+
/**
87+
* A wrapper annotation that makes the {@link DefaultQualifier} annotation repeatable.
88+
*
89+
* <p>Programmers generally do not need to write this. It is created by Java when a programmer
90+
* writes more than one {@link DefaultQualifier} annotation at the same location.
91+
*/
92+
@Documented
93+
@Retention(RetentionPolicy.RUNTIME)
94+
@Target({
95+
ElementType.PACKAGE,
96+
ElementType.TYPE,
97+
ElementType.CONSTRUCTOR,
98+
ElementType.METHOD,
99+
ElementType.FIELD,
100+
ElementType.LOCAL_VARIABLE,
101+
ElementType.PARAMETER
102+
})
103+
public static @interface List {
104+
/**
105+
* Return the repeatable annotations.
106+
*
107+
* @return the repeatable annotations
108+
*/
109+
DefaultQualifier[] value();
110+
}
111+
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ include 'util-core'
99
include 'varexport'
1010
include 'zk'
1111
include 'log4j1dummyshim'
12+
include 'checker-qual-shim'

util-core/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
indeedOss.activateFeature 'library'
22
indeedLibrary.name = 'util-core'
33

4+
configurations {
5+
checkerQualPatch
6+
}
7+
sourceSets.main.compileClasspath = configurations.checkerQualPatch + sourceSets.main.compileClasspath
8+
49
dependencies {
10+
checkerQualPatch project(':checker-qual-shim')
511
implementation project(':varexport')
612
implementation libs.guava
713
implementation libs.slf4jApi

0 commit comments

Comments
 (0)