diff --git a/.github/workflows/jspecify.yml b/.github/workflows/jspecify.yml new file mode 100644 index 00000000000..d3d8a5fb417 --- /dev/null +++ b/.github/workflows/jspecify.yml @@ -0,0 +1,36 @@ +name: JSpecify JDK CI tests + +on: + pull_request: + push: + branches: [ "main" ] + +jobs: + build_jdk: + name: Build the JSpecify JDK + runs-on: ubuntu-latest + permissions: + contents: read + env: + JAVA_VERSION: 23 + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 23 + uses: actions/setup-java@v4 + with: + java-version: 23 + distribution: 'temurin' + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install --only-upgrade apt + sudo apt-get install gcc-10 g++-10 libxrandr-dev libxtst-dev libcups2-dev libasound2-dev + - name: Install jtreg + run: | + wget https://builds.shipilev.net/jtreg/jtreg-7.5%2B1.zip -O /tmp/jtreg.zip + unzip /tmp/jtreg.zip -d /tmp/ + - name: Configure the JDK + run: bash ./configure --with-jtreg=/tmp/jtreg --disable-warnings-as-errors + - name: Build the JDK + run: make jdk + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 210d53be658..b2e81d0ad84 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,8 +35,9 @@ on: inputs: platforms: description: 'Platform(s) to execute on (comma separated, e.g. "linux-x64, macos, aarch64")' - required: true - default: 'linux-x64, linux-x64-variants, linux-cross-compile, alpine-linux-x64, macos-x64, macos-aarch64, windows-x64, windows-aarch64, docs' + required: false + default: '' + # default: 'linux-x64, linux-x64-variants, linux-cross-compile, alpine-linux-x64, macos-x64, macos-aarch64, windows-x64, windows-aarch64, docs' configure-arguments: description: 'Additional configure arguments' required: false @@ -120,7 +121,9 @@ jobs: return fi done - echo 'true' + # echo 'true' + # WMD: Assume empty means no platforms + echo 'false' return else # Check for all acceptable platform names @@ -163,6 +166,7 @@ jobs: uses: ./.github/workflows/build-linux.yml with: platform: linux-x64 + debug-levels: '[ "debug" ]' gcc-major-version: '10' configure-arguments: ${{ github.event.inputs.configure-arguments }} make-arguments: ${{ github.event.inputs.make-arguments }} diff --git a/checker-qual.jar b/checker-qual.jar deleted file mode 100644 index 7a2befb269d..00000000000 Binary files a/checker-qual.jar and /dev/null differ diff --git a/createjdkJAR.sh b/createjdkJAR.sh deleted file mode 100755 index f5fe373cbc4..00000000000 --- a/createjdkJAR.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/bash - -JAVAVERSION=11 - -rm -r jdk${JAVAVERSION} -mkdir jdk${JAVAVERSION} -rm jdk${JAVAVERSION}/Patch_Modules_argfile -touch jdk${JAVAVERSION}/Patch_Modules_argfile -for i in `find ./build/*/jdk/modules -maxdepth 1 -mindepth 1 -type d` ; do - echo "Coverting `basename $i` to jar" - jar --create --file=$i.annotated.jar --module-version=1.0 -C $i . - echo "--patch-module `basename $i`=\${CURRENT_JDK_FOLDER}/`basename $i`.annotated.jar" >> jdk${JAVAVERSION}/Patch_Modules_argfile - mv ./build/*/jdk/modules/`basename $i`.annotated.jar ./jdk${JAVAVERSION}/ -done - diff --git a/make/CompileInterimLangtools.gmk b/make/CompileInterimLangtools.gmk index dbb23de093c..1c33775cb02 100644 --- a/make/CompileInterimLangtools.gmk +++ b/make/CompileInterimLangtools.gmk @@ -89,6 +89,9 @@ TARGETS += $(COPY_PREVIEW_FEATURES) # would require the source files to be copied into directories named after the # actual interim modules. +## DON'T PUT COMMAS within this macro definition, as in +# --add-exports java.base/org.checkerframework.checker.builder.qual=java.compiler.interim,jdk.compiler.interim \ + # Param 1 - Name of module to compile define SetupInterimModule $$(eval $$(call SetupJavaCompilation, BUILD_$1.interim, \ @@ -112,6 +115,8 @@ define SetupInterimModule DISABLED_WARNINGS := module options, \ JAVAC_FLAGS := \ --module-path $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules \ + -cp $(TOPDIR)/src/java.base/share/classes/ \ + --add-reads $1.interim=ALL-UNNAMED \ $$(INTERIM_LANGTOOLS_ADD_EXPORTS) \ --patch-module java.base=$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim \ --add-exports java.base/jdk.internal.javac=java.compiler.interim \ diff --git a/make/CopyInterimTZDB.gmk b/make/CopyInterimTZDB.gmk index e2704b32975..383441e4d76 100644 --- a/make/CopyInterimTZDB.gmk +++ b/make/CopyInterimTZDB.gmk @@ -38,6 +38,10 @@ define tzdb_copyfiles $(call MakeTargetDir) $(RM) '$@' $(SED) -e "s/package java.time.zone/package build.tools.tzdb/" \ + -e "s/import org.jspecify.annotations.NullMarked;//" \ + -e "s/import org.jspecify.annotations.Nullable;//" \ + -e "s/@NullMarked//" \ + -e "s/@Nullable //" \ < $(<) > $@ endef diff --git a/make/autoconf/spec.gmk.template b/make/autoconf/spec.gmk.template index 18770c6d360..5d937297aa8 100644 --- a/make/autoconf/spec.gmk.template +++ b/make/autoconf/spec.gmk.template @@ -697,6 +697,7 @@ INTERIM_LANGTOOLS_ARGS := \ --add-modules $(INTERIM_LANGTOOLS_MODULES_COMMA) \ --module-path $(BUILDTOOLS_OUTPUTDIR)/interim_langtools_modules \ --patch-module java.base=$(BUILDTOOLS_OUTPUTDIR)/gensrc/java.base.interim \ + -cp $(TOPDIR)/src/java.base/share/classes/ \ $(INTERIM_LANGTOOLS_ADD_EXPORTS) \ # JAVAC_MAIN_CLASS := -m jdk.compiler.interim/com.sun.tools.javac.Main diff --git a/make/common/JavaCompilation.gmk b/make/common/JavaCompilation.gmk index 59ea23d359b..0e479fd73de 100644 --- a/make/common/JavaCompilation.gmk +++ b/make/common/JavaCompilation.gmk @@ -270,7 +270,7 @@ define SetupJavaCompilationBody endif # Allow overriding on the command line - JAVA_WARNINGS_ARE_ERRORS ?= -Werror + JAVA_WARNINGS_ARE_ERRORS ?= # Tell javac to do exactly as told and no more PARANOIA_FLAGS := -implicit:none -Xprefer:source -XDignore.symbol.file=true -encoding ascii diff --git a/make/langtools/build.properties b/make/langtools/build.properties index b82d9155806..cd7a14351b3 100644 --- a/make/langtools/build.properties +++ b/make/langtools/build.properties @@ -24,10 +24,10 @@ # #javac configuration for "normal build" (these will be passed to the bootstrap compiler): -javac.opts = -XDignore.symbol.file=true -Xlint:all,-deprecation,-exports -Werror -g:source,lines,vars +javac.opts = -XDignore.symbol.file=true -Xlint:all,-deprecation,-exports -g:source,lines,vars #version used to compile build tools -javac.build.opts = -XDignore.symbol.file=true -Xlint:all,-deprecation,-options -Werror -g:source,lines,vars +javac.build.opts = -XDignore.symbol.file=true -Xlint:all,-deprecation,-options -g:source,lines,vars javac.build.source = 8 javac.build.target = 8 diff --git a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java index 114c82c5229..0998638d691 100644 --- a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java +++ b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java @@ -2613,6 +2613,10 @@ private boolean readAttribute(ClassFile cf, FeatureDescription feature, Attribut ((MethodDescription) feature).classParameterAnnotations = parameterAnnotations2Description(cf.constant_pool, attr); break; + case "RuntimeInvisibleTypeAnnotations": + case "RuntimeVisibleTypeAnnotations": + // TODO(wmdietl): What should happen to type annotations? + break; case Attribute.Module: { assert feature instanceof ModuleHeaderDescription; ModuleHeaderDescription header = diff --git a/src/java.base/share/classes/java/io/DataOutputStream.java b/src/java.base/share/classes/java/io/DataOutputStream.java index 61c298b2f48..8fa93ee050a 100644 --- a/src/java.base/share/classes/java/io/DataOutputStream.java +++ b/src/java.base/share/classes/java/io/DataOutputStream.java @@ -28,6 +28,9 @@ import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; + +import jdk.internal.access.JavaLangAccess; +import jdk.internal.access.SharedSecrets; import jdk.internal.util.ByteArray; import static jdk.internal.util.ModifiedUtf.putChar; diff --git a/src/java.base/share/classes/java/lang/Runtime.java b/src/java.base/share/classes/java/lang/Runtime.java index 661348b6297..02a4fcf2324 100644 --- a/src/java.base/share/classes/java/lang/Runtime.java +++ b/src/java.base/share/classes/java/lang/Runtime.java @@ -124,7 +124,7 @@ */ @NullMarked -public class Runtime { +public class Runtime { private static final Runtime currentRuntime = new Runtime(); private static Version version; @@ -177,7 +177,6 @@ private Runtime() {} * @see #removeShutdownHook * @see #halt(int) */ - public void exit(int status) { Shutdown.exit(status); } @@ -368,6 +367,7 @@ public Process exec(String command) throws IOException { * @see #exec(String[], String[], File) * @see ProcessBuilder */ + @Deprecated(since="18") public Process exec(String command, String @Nullable [] envp) throws IOException { return exec(command, envp, null); } diff --git a/src/java.base/share/classes/java/net/DatagramSocket.java b/src/java.base/share/classes/java/net/DatagramSocket.java index 1c3b17128e6..b9801c02cd5 100644 --- a/src/java.base/share/classes/java/net/DatagramSocket.java +++ b/src/java.base/share/classes/java/net/DatagramSocket.java @@ -25,7 +25,6 @@ package java.net; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index f6f09d24b4a..632bab0c809 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -25,10 +25,6 @@ package java.nio.file; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.checker.signedness.qual.PolySigned; -import org.checkerframework.framework.qual.AnnotatedFor; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; @@ -3173,7 +3169,7 @@ public static List readAllLines(Path path) throws IOException { * StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified * (optional specific exception) */ - public static Path write(Path path, @PolySigned byte[] bytes, OpenOption... options) + public static Path write(Path path, byte[] bytes, OpenOption... options) throws IOException { // ensure bytes is not null before opening file diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 3fb41218f4c..c9eaf5a105e 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -385,7 +385,7 @@ else if (cmp > 0) * @see List#reversed List.reversed */ @SuppressWarnings({"rawtypes", "unchecked"}) - public static void reverse( List list) { + public static void reverse(List list) { int size = list.size(); if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) { for (int i=0, mid=size>>1, j=size-1; i list) { * @throws UnsupportedOperationException if the specified list or * its list-iterator does not support the {@code set} operation. */ - public static void shuffle( List list) { + public static void shuffle(List list) { Random rnd = r; if (rnd == null) r = rnd = new Random(); // harmless race. @@ -522,7 +522,7 @@ public static void shuffle(List list, RandomGenerator rnd) { * @since 1.4 */ @SuppressWarnings({"rawtypes", "unchecked"}) - public static void swap( List list, int i, int j) { + public static void swap(List list, int i, int j) { // instead of using a raw type here, it's possible to capture // the wildcard but it will require a call to a supplementary // private method @@ -551,7 +551,7 @@ private static void swap(Object[] arr, int i, int j) { * @throws UnsupportedOperationException if the specified list or its * list-iterator does not support the {@code set} operation. */ - public static void fill( List list, T obj) { + public static void fill(List list, T obj) { int size = list.size(); if (size < FILL_THRESHOLD || list instanceof RandomAccess) { @@ -804,7 +804,7 @@ public static > T max(Collection list, int distance) { + public static void rotate(List list, int distance) { if (list instanceof RandomAccess || list.size() < ROTATE_THRESHOLD) rotate1(list, distance); else @@ -929,8 +929,7 @@ private static void rotate2(List list, int distance) { * is no such occurrence. * @since 1.4 */ - - public static int indexOfSubList( List source, List target) { + public static int indexOfSubList(List source, List target) { int sourceSize = source.size(); int targetSize = target.size(); int maxCandidate = sourceSize - targetSize; @@ -983,8 +982,7 @@ public static int indexOfSubList( List source, List target) { * is no such occurrence. * @since 1.4 */ - - public static int lastIndexOfSubList( List source, List target) { + public static int lastIndexOfSubList(List source, List target) { int sourceSize = source.size(); int targetSize = target.size(); int maxCandidate = sourceSize - targetSize; @@ -1046,6 +1044,7 @@ public static int lastIndexOfSubList( List source, List target) { * returned. * @return an unmodifiable view of the specified collection. */ + @SuppressWarnings("unchecked") public static Collection unmodifiableCollection(Collection c) { if (c.getClass() == UnmodifiableCollection.class) { return (Collection) c; @@ -1069,19 +1068,14 @@ static class UnmodifiableCollection implements Collection, Serializable { this.c = c; } - - public int size() {return c.size();} - + public int size() {return c.size();} public boolean isEmpty() {return c.isEmpty();} public boolean contains(@Nullable Object o) {return c.contains(o);} - public @Nullable Object[] toArray() {return c.toArray();} - public T[] toArray(T[] a) {return c.toArray(a);} public T[] toArray(IntFunction f) {return c.toArray(f);} public String toString() {return c.toString();} - public Iterator iterator() { return new Iterator<>() { private final Iterator i = c.iterator(); @@ -1131,7 +1125,6 @@ public void forEach(Consumer action) { public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } - @SuppressWarnings("unchecked") @Override public Spliterator spliterator() { @@ -1662,18 +1655,12 @@ private static class UnmodifiableMap keySet() { return keySet; } - public Set> entrySet() { if (entrySet==null) entrySet = new UnmodifiableEntrySet<>(m.entrySet()); @@ -1732,7 +1718,6 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } - @Override public V putIfAbsent(K key, V value) { throw new UnsupportedOperationException(); @@ -2093,13 +2078,10 @@ static class UnmodifiableSortedMap m) {super(m); sm = m; } public Comparator comparator() { return sm.comparator(); } - public SortedMap subMap(K fromKey, K toKey) { return new UnmodifiableSortedMap<>(sm.subMap(fromKey, toKey)); } - public SortedMap headMap(K toKey) { return new UnmodifiableSortedMap<>(sm.headMap(toKey)); } - public SortedMap tailMap(K fromKey) { return new UnmodifiableSortedMap<>(sm.tailMap(fromKey)); } public K firstKey() { return sm.firstKey(); } @@ -2158,7 +2140,6 @@ private static class EmptyNavigableMap()); } @Override - public NavigableSet navigableKeySet() { return emptyNavigableSet(); } @@ -2239,26 +2220,20 @@ public Entry pollFirstEntry() { throw new UnsupportedOperationException(); } public Entry pollLastEntry() { throw new UnsupportedOperationException(); } - public NavigableMap descendingMap() { return unmodifiableNavigableMap(nm.descendingMap()); } - public NavigableSet navigableKeySet() { return unmodifiableNavigableSet(nm.navigableKeySet()); } - public NavigableSet descendingKeySet() { return unmodifiableNavigableSet(nm.descendingKeySet()); } - public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { return unmodifiableNavigableMap( nm.subMap(fromKey, fromInclusive, toKey, toInclusive)); } - public NavigableMap headMap(K toKey, boolean inclusive) { return unmodifiableNavigableMap(nm.headMap(toKey, inclusive)); } - public NavigableMap tailMap(K fromKey, boolean inclusive) { return unmodifiableNavigableMap(nm.tailMap(fromKey, inclusive)); } } @@ -2328,22 +2303,18 @@ static class SynchronizedCollection implements Collection, Serializable { this.mutex = Objects.requireNonNull(mutex); } - - public int size() { + public int size() { synchronized (mutex) {return c.size();} } - public boolean isEmpty() { synchronized (mutex) {return c.isEmpty();} } public boolean contains(@Nullable Object o) { synchronized (mutex) {return c.contains(o);} } - public @Nullable Object[] toArray() { synchronized (mutex) {return c.toArray();} } - public T[] toArray(T[] a) { synchronized (mutex) {return c.toArray(a);} } @@ -2351,7 +2322,6 @@ public boolean contains(@Nullable Object o) { synchronized (mutex) {return c.toArray(f);} } - public Iterator iterator() { return c.iterator(); // Must be manually synched by user! } @@ -2390,7 +2360,6 @@ public void forEach(Consumer consumer) { public boolean removeIf(Predicate filter) { synchronized (mutex) {return c.removeIf(filter);} } - @Override public Spliterator spliterator() { return c.spliterator(); // Must be manually synched by user! @@ -2913,20 +2882,15 @@ private static class SynchronizedMap keySet() { } } - public Set> entrySet() { synchronized (mutex) { if (entrySet==null) @@ -3002,7 +2964,6 @@ public void forEach(BiConsumer action) { public void replaceAll(BiFunction function) { synchronized (mutex) {m.replaceAll(function);} } - @Override public V putIfAbsent(K key, V value) { synchronized (mutex) {return m.putIfAbsent(key, value);} @@ -3121,20 +3082,17 @@ public Comparator comparator() { synchronized (mutex) {return sm.comparator();} } - public SortedMap subMap(K fromKey, K toKey) { synchronized (mutex) { return new SynchronizedSortedMap<>( sm.subMap(fromKey, toKey), mutex); } } - public SortedMap headMap(K toKey) { synchronized (mutex) { return new SynchronizedSortedMap<>(sm.headMap(toKey), mutex); } } - public SortedMap tailMap(K fromKey) { synchronized (mutex) { return new SynchronizedSortedMap<>(sm.tailMap(fromKey),mutex); @@ -3249,7 +3207,6 @@ public Entry pollFirstEntry() public Entry pollLastEntry() { synchronized (mutex) { return nm.pollLastEntry(); } } - public NavigableMap descendingMap() { synchronized (mutex) { return @@ -3261,14 +3218,12 @@ public NavigableSet keySet() { return navigableKeySet(); } - public NavigableSet navigableKeySet() { synchronized (mutex) { return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex); } } - public NavigableSet descendingKeySet() { synchronized (mutex) { return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex); @@ -3276,27 +3231,23 @@ public NavigableSet descendingKeySet() { } - public SortedMap subMap(K fromKey, K toKey) { synchronized (mutex) { return new SynchronizedNavigableMap<>( nm.subMap(fromKey, true, toKey, false), mutex); } } - public SortedMap headMap(K toKey) { synchronized (mutex) { return new SynchronizedNavigableMap<>(nm.headMap(toKey, false), mutex); } } - public SortedMap tailMap(K fromKey) { synchronized (mutex) { return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex); } } - public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { synchronized (mutex) { return new SynchronizedNavigableMap<>( @@ -3304,7 +3255,6 @@ public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, bool } } - public NavigableMap headMap(K toKey, boolean inclusive) { synchronized (mutex) { return new SynchronizedNavigableMap<>( @@ -3312,7 +3262,6 @@ public NavigableMap headMap(K toKey, boolean inclusive) { } } - public NavigableMap tailMap(K fromKey, boolean inclusive) { synchronized (mutex) { return new SynchronizedNavigableMap<>( @@ -3423,14 +3372,10 @@ private String badElementMsg(Object o) { this.type = Objects.requireNonNull(type, "type"); } - - public int size() { return c.size(); } - + public int size() { return c.size(); } public boolean isEmpty() { return c.isEmpty(); } public boolean contains(@Nullable Object o) { return c.contains(o); } - public @Nullable Object[] toArray() { return c.toArray(); } - public T[] toArray(T[] a) { return c.toArray(a); } public T[] toArray(IntFunction f) { return c.toArray(f); } public String toString() { return c.toString(); } @@ -3447,7 +3392,6 @@ public boolean retainAll(Collection coll) { return c.retainAll(coll); } - public Iterator iterator() { // JDK-6363904 - unwrapped iterator could be typecast to // ListIterator with unsafe set() @@ -3510,7 +3454,6 @@ public boolean addAll(Collection coll) { public boolean removeIf(Predicate filter) { return c.removeIf(filter); } - @Override public Spliterator spliterator() {return c.spliterator();} @Override @@ -4004,14 +3947,9 @@ private String badValueMsg(Object value) { this.valueType = Objects.requireNonNull(valueType); } - - public int size() { return m.size(); } - + public int size() { return m.size(); } public boolean isEmpty() { return m.isEmpty(); } - - public boolean containsKey(@Nullable Object key) { return m.containsKey(key); } - public boolean containsValue(@Nullable Object v) { return m.containsValue(v); } public V get(@Nullable Object key) { return m.get(key); } public V remove(@Nullable Object key) { return m.remove(key); } @@ -4022,7 +3960,6 @@ private String badValueMsg(Object value) { public int hashCode() { return m.hashCode(); } public String toString() { return m.toString(); } - public V put(K key, V value) { typeCheck(key, value); return m.put(key, value); @@ -4051,7 +3988,6 @@ public void putAll(Map t) { private transient Set> entrySet; - public Set> entrySet() { if (entrySet==null) entrySet = new CheckedEntrySet<>(m.entrySet(), valueType); @@ -4069,7 +4005,6 @@ public void replaceAll(BiFunction function) { m.replaceAll(typeCheck(function)); } - @Override public V putIfAbsent(K key, V value) { typeCheck(key, value); @@ -4145,9 +4080,7 @@ static class CheckedEntrySet subMap(K fromKey, K toKey) { return checkedSortedMap(sm.subMap(fromKey, toKey), keyType, valueType); } - public SortedMap headMap(K toKey) { return checkedSortedMap(sm.headMap(toKey), keyType, valueType); } - public SortedMap tailMap(K fromKey) { return checkedSortedMap(sm.tailMap(fromKey), keyType, valueType); } @@ -4529,7 +4459,6 @@ public Entry pollLastEntry() { : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } - public NavigableMap descendingMap() { return checkedNavigableMap(nm.descendingMap(), keyType, valueType); } @@ -4538,46 +4467,38 @@ public NavigableSet keySet() { return navigableKeySet(); } - public NavigableSet navigableKeySet() { return checkedNavigableSet(nm.navigableKeySet(), keyType); } - public NavigableSet descendingKeySet() { return checkedNavigableSet(nm.descendingKeySet(), keyType); } @Override - public NavigableMap subMap(K fromKey, K toKey) { return checkedNavigableMap(nm.subMap(fromKey, true, toKey, false), keyType, valueType); } @Override - public NavigableMap headMap(K toKey) { return checkedNavigableMap(nm.headMap(toKey, false), keyType, valueType); } @Override - public NavigableMap tailMap(K fromKey) { return checkedNavigableMap(nm.tailMap(fromKey, true), keyType, valueType); } - public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { return checkedNavigableMap(nm.subMap(fromKey, fromInclusive, toKey, toInclusive), keyType, valueType); } - public NavigableMap headMap(K toKey, boolean inclusive) { return checkedNavigableMap(nm.headMap(toKey, inclusive), keyType, valueType); } - public NavigableMap tailMap(K fromKey, boolean inclusive) { return checkedNavigableMap(nm.tailMap(fromKey, inclusive), keyType, valueType); } @@ -4741,22 +4662,17 @@ private static class EmptySet @java.io.Serial private static final long serialVersionUID = 1582296315990362920L; - public Iterator iterator() { return emptyIterator(); } - - public int size() {return 0;} - + public int size() {return 0;} public boolean isEmpty() {return true;} public void clear() {} public boolean contains(@Nullable Object obj) {return false;} public boolean containsAll(Collection c) { return c.isEmpty(); } - public @Nullable Object[] toArray() { return new Object[0]; } - public T[] toArray(T[] a) { if (a.length > 0) a[0] = null; @@ -4773,7 +4689,6 @@ public boolean removeIf(Predicate filter) { Objects.requireNonNull(filter); return false; } - @Override public Spliterator spliterator() { return Spliterators.emptySpliterator(); } @@ -4873,7 +4788,6 @@ private static class EmptyList @java.io.Serial private static final long serialVersionUID = 8842843931221139166L; - public Iterator iterator() { return emptyIterator(); } @@ -4881,19 +4795,15 @@ public ListIterator listIterator() { return emptyListIterator(); } - - public int size() {return 0;} - + public int size() {return 0;} public boolean isEmpty() {return true;} public void clear() {} public boolean contains(@Nullable Object obj) {return false;} public boolean containsAll(Collection c) { return c.isEmpty(); } - public @Nullable Object[] toArray() { return new Object[0]; } - public T[] toArray(T[] a) { if (a.length > 0) a[0] = null; @@ -4929,7 +4839,6 @@ public void forEach(Consumer action) { Objects.requireNonNull(action); } - @Override public Spliterator spliterator() { return Spliterators.emptySpliterator(); } @@ -5024,20 +4933,14 @@ private static class EmptyMap keySet() {return emptySet();} public Collection values() {return emptySet();} - public Set> entrySet() {return emptySet();} public boolean equals(Object o) { @@ -5062,7 +4965,6 @@ public void replaceAll(BiFunction function) { Objects.requireNonNull(function); } - @Override public V putIfAbsent(K key, V value) { throw new UnsupportedOperationException(); @@ -5216,13 +5118,11 @@ private static class SingletonSet SingletonSet(E e) {element = e;} - public Iterator iterator() { return singletonIterator(element); } - - public int size() {return 1;} + public int size() {return 1;} public boolean contains(@Nullable Object o) {return eq(o, element);} @@ -5231,7 +5131,6 @@ public Iterator iterator() { public void forEach(Consumer action) { action.accept(element); } - @Override public Spliterator spliterator() { return singletonSpliterator(element); @@ -5262,7 +5161,7 @@ public int hashCode() { /** * @serial include */ - private static class SingletonList + private static class SingletonList extends AbstractList implements RandomAccess, Serializable { @@ -5272,17 +5171,13 @@ private static class SingletonList @SuppressWarnings("serial") // Conditionally serializable private final E element; - @SuppressWarnings({"inconsistent.constructor.type", "super.invocation.invalid"}) - SingletonList(E obj) {element = obj;} - public Iterator iterator() { return singletonIterator(element); } - - public int size() {return 1;} + public int size() {return 1;} public boolean contains(@Nullable Object obj) {return eq(obj, element);} @@ -5308,7 +5203,6 @@ public void replaceAll(UnaryOperator operator) { @Override public void sort(Comparator c) { } - @Override public Spliterator spliterator() { return singletonSpliterator(element); @@ -5354,14 +5248,9 @@ private static class SingletonMap keySet() { return keySet; } - public Set> entrySet() { if (entrySet==null) entrySet = Collections.singleton( @@ -5405,7 +5293,6 @@ public void replaceAll(BiFunction function) { throw new UnsupportedOperationException(); } - @Override public V putIfAbsent(K key, V value) { throw new UnsupportedOperationException(); @@ -5501,8 +5388,7 @@ private static class CopiesList element = e; } - - public int size() { + public int size() { return n; } @@ -5540,7 +5426,6 @@ public Object[] toArray() { return a; } - @SuppressWarnings("unchecked") public T[] toArray(T[] a) { final int n = this.n; @@ -5625,7 +5510,6 @@ public Stream parallelStream() { return IntStream.range(0, n).parallel().mapToObj(i -> element); } - @Override public Spliterator spliterator() { return stream().spliterator(); @@ -5854,7 +5738,7 @@ static boolean eq(Object o1, Object o2) { * @throws NullPointerException if {@code c} is null * @since 1.5 */ - public static int frequency(Collection c, @Nullable Object o) { + public static int frequency(Collection c, @Nullable Object o) { int result = 0; if (o == null) { for (Object e : c) @@ -5985,7 +5869,7 @@ public static boolean disjoint(Collection c1, Collection c2) { * @since 1.5 */ @SafeVarargs - public static boolean addAll( Collection c, T... elements) { + public static boolean addAll(Collection c, T... elements) { boolean result = false; for (T element : elements) result |= c.add(element); @@ -6045,18 +5929,13 @@ private static class SetFromMap extends AbstractSet< } public void clear() { m.clear(); } - - public int size() { return m.size(); } - + public int size() { return m.size(); } public boolean isEmpty() { return m.isEmpty(); } public boolean contains(@Nullable Object o) { return m.containsKey(o); } public boolean remove(@Nullable Object o) { return m.remove(o) != null; } public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; } - public Iterator iterator() { return s.iterator(); } - public @Nullable Object[] toArray() { return s.toArray(); } - public T[] toArray(T[] a) { return s.toArray(a); } public String toString() { return s.toString(); } public int hashCode() { return s.hashCode(); } @@ -6076,7 +5955,6 @@ public boolean removeIf(Predicate filter) { return s.removeIf(filter); } - @Override public Spliterator spliterator() {return s.spliterator();} @Override @@ -6225,17 +6103,12 @@ static class AsLIFOQueue extends AbstractQueue public E peek() { return q.peekFirst(); } public E element() { return q.getFirst(); } public void clear() { q.clear(); } - - public int size() { return q.size(); } - + public int size() { return q.size(); } public boolean isEmpty() { return q.isEmpty(); } public boolean contains(@Nullable Object o) { return q.contains(o); } public boolean remove(@Nullable Object o) { return q.remove(o); } - public Iterator iterator() { return q.iterator(); } - public @Nullable Object[] toArray() { return q.toArray(); } - public T[] toArray(T[] a) { return q.toArray(a); } public T[] toArray(IntFunction f) { return q.toArray(f); } public String toString() { return q.toString(); } @@ -6251,7 +6124,6 @@ static class AsLIFOQueue extends AbstractQueue public boolean removeIf(Predicate filter) { return q.removeIf(filter); } - @Override public Spliterator spliterator() {return q.spliterator();} @Override diff --git a/src/java.base/share/classes/java/util/Objects.java b/src/java.base/share/classes/java/util/Objects.java index 9d41bfbf584..760de2a0fbb 100644 --- a/src/java.base/share/classes/java/util/Objects.java +++ b/src/java.base/share/classes/java/util/Objects.java @@ -43,7 +43,7 @@ * @since 1.7 */ @NullMarked -public final class Objects { +public final class Objects { private Objects() { throw new AssertionError("No java.util.Objects instances for you!"); } @@ -62,13 +62,22 @@ private Objects() { * @param b an object to be compared with {@code a} for equality * @see Object#equals(Object) */ - - public static boolean equals( @Nullable Object a, @Nullable Object b) { + public static boolean equals(@Nullable Object a, @Nullable Object b) { return (a == b) || (a != null && a.equals(b)); } - // Define and annotate an overload that is unique to j2cl: b/201433789 - public static boolean equals( @Nullable String a, @Nullable String b); + /** + * Define and annotate an overload that is unique to j2cl: b/201433789. + * + * @param a an object + * @param b an object to be compared with {@code a} for equality + * @return {@code true} if the arguments are equal to each other and + * {@code false} otherwise + * @see Object#equals(Object) + */ + public static boolean equals(@Nullable String a, @Nullable String b) { + return equals((Object) a, b); + } /** * {@return {@code true} if the arguments are deeply equal to each other @@ -85,8 +94,7 @@ public static boolean equals( @Nullable Object a, @Nullable Object b) { * @see Arrays#deepEquals(Object[], Object[]) * @see Objects#equals(Object, Object) */ - - public static boolean deepEquals( @Nullable Object a, @Nullable Object b) { + public static boolean deepEquals(@Nullable Object a, @Nullable Object b) { if (a == b) return true; else if (a == null || b == null) @@ -102,8 +110,7 @@ else if (a == null || b == null) * @param o an object * @see Object#hashCode */ - - public static int hashCode( @Nullable Object o) { + public static int hashCode(@Nullable Object o) { return o != null ? o.hashCode() : 0; } @@ -132,8 +139,7 @@ public static int hashCode( @Nullable Object o) { * @see Arrays#hashCode(Object[]) * @see List#hashCode */ - - public static int hash( @Nullable Object... values) { + public static int hash(@Nullable Object... values) { return Arrays.hashCode(values); } @@ -146,8 +152,7 @@ public static int hash( @Nullable Object... values) { * @see Object#toString * @see String#valueOf(Object) */ - - public static String toString( @Nullable Object o) { + public static String toString(@Nullable Object o) { return String.valueOf(o); } @@ -161,8 +166,7 @@ public static String toString( @Nullable Object o) { * {@code null} * @see Objects#toString(Object) */ - - public static @Nullable String toString( @Nullable Object o, @Nullable String nullDefault) { + public static @Nullable String toString(@Nullable Object o, @Nullable String nullDefault) { return (o != null) ? o.toString() : nullDefault; } @@ -208,8 +212,7 @@ public static String toIdentityString(Object o) { * @see Comparable * @see Comparator */ - - public static int compare( @Nullable T a, @Nullable T b, Comparator c) { + public static int compare(@Nullable T a, @Nullable T b, Comparator c) { return (a == b) ? 0 : c.compare(a, b); } @@ -273,9 +276,7 @@ public static T requireNonNull(@Nullable T obj, @Nullable String message) { * @see java.util.function.Predicate * @since 1.8 */ - - - public static boolean isNull( @Nullable Object obj) { + public static boolean isNull(@Nullable Object obj) { return obj == null; } @@ -291,9 +292,7 @@ public static boolean isNull( @Nullable Object obj) { * @see java.util.function.Predicate * @since 1.8 */ - - - public static boolean nonNull( @Nullable Object obj) { + public static boolean nonNull(@Nullable Object obj) { return obj != null; } @@ -309,7 +308,7 @@ public static boolean nonNull( @Nullable Object obj) { * {@code defaultObj} is {@code null} * @since 9 */ - public static T requireNonNullElse(@Nullable T obj, @Nullable T defaultObj) { + public static T requireNonNullElse(@Nullable T obj, @Nullable T defaultObj) { return (obj != null) ? obj : requireNonNull(defaultObj, "defaultObj"); } @@ -352,9 +351,7 @@ public static T requireNonNullElseGet(@Nullable T obj, Supplier T requireNonNull( @Nullable T obj, Supplier messageSupplier) { + public static T requireNonNull(@Nullable T obj, Supplier messageSupplier) { if (obj == null) throw new NullPointerException(messageSupplier == null ? null : messageSupplier.get()); diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index 65e6234fbc2..5531cda02bd 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -1515,7 +1515,7 @@ public synchronized Object computeIfAbsent(Object key, @Override public synchronized @Nullable Object compute(Object key, - BiFunction remappingFunction) { + BiFunction remappingFunction) { return map.compute(key, remappingFunction); } diff --git a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java index e8ec11282e3..26e26bd75c8 100644 --- a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java +++ b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java @@ -35,8 +35,6 @@ package java.util.concurrent; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.framework.qual.AnnotatedFor; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -79,9 +77,8 @@ * @since 1.5 * @author Doug Lea */ -@AnnotatedFor({"interning"}) @NullMarked -public abstract @UsesObjectEquals class AbstractExecutorService implements ExecutorService { +public abstract class AbstractExecutorService implements ExecutorService { /** * Constructor for subclasses to call. diff --git a/src/java.base/share/classes/java/util/concurrent/Executors.java b/src/java.base/share/classes/java/util/concurrent/Executors.java index 77d4814c1b7..8b7ae89627e 100644 --- a/src/java.base/share/classes/java/util/concurrent/Executors.java +++ b/src/java.base/share/classes/java/util/concurrent/Executors.java @@ -35,8 +35,6 @@ package java.util.concurrent; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.framework.qual.AnnotatedFor; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -73,9 +71,8 @@ * @since 1.5 * @author Doug Lea */ -@AnnotatedFor({"interning"}) @NullMarked -public @UsesObjectEquals class Executors { +public class Executors { /** * Creates a thread pool that reuses a fixed number of threads diff --git a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java index 61a985739ad..2376bdbabfc 100644 --- a/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java +++ b/src/java.base/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java @@ -35,7 +35,6 @@ package java.util.concurrent; -import org.checkerframework.dataflow.qual.Pure; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -1053,7 +1052,6 @@ public boolean remove(Object x) { } } - @Pure public int size() { final ReentrantLock lock = this.lock; lock.lock(); @@ -1064,7 +1062,6 @@ public int size() { } } - @Pure public boolean isEmpty() { return size() == 0; } diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java index 751096a9e54..20d64405da6 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceArray.java @@ -37,8 +37,6 @@ import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.framework.qual.AnnotatedFor; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; @@ -56,9 +54,8 @@ * @author Doug Lea * @param The base class of elements held in this array */ -@AnnotatedFor({"interning"}) @NullMarked -public @UsesObjectEquals class AtomicReferenceArray implements java.io.Serializable { +public class AtomicReferenceArray implements java.io.Serializable { private static final long serialVersionUID = -6209656149925076980L; private static final VarHandle AA = MethodHandles.arrayElementVarHandle(Object[].class); diff --git a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java index e1b600904d4..52d62dda62d 100644 --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java @@ -35,8 +35,6 @@ package java.util.concurrent.atomic; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.framework.qual.AnnotatedFor; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -90,9 +88,8 @@ * @param The type of the object holding the updatable field * @param The type of the field */ -@AnnotatedFor({"interning"}) @NullMarked -public abstract @UsesObjectEquals class AtomicReferenceFieldUpdater { +public abstract class AtomicReferenceFieldUpdater { /** * Creates and returns an updater for objects with the given field. diff --git a/src/java.base/share/classes/java/util/concurrent/locks/AbstractOwnableSynchronizer.java b/src/java.base/share/classes/java/util/concurrent/locks/AbstractOwnableSynchronizer.java index f612636b1ac..0ab183280ce 100644 --- a/src/java.base/share/classes/java/util/concurrent/locks/AbstractOwnableSynchronizer.java +++ b/src/java.base/share/classes/java/util/concurrent/locks/AbstractOwnableSynchronizer.java @@ -35,7 +35,6 @@ package java.util.concurrent.locks; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; @@ -52,7 +51,7 @@ * @author Doug Lea */ @NullMarked -public abstract @UsesObjectEquals class AbstractOwnableSynchronizer +public abstract class AbstractOwnableSynchronizer implements java.io.Serializable { /** Use serial ID even though all fields transient. */ diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 7486fdd825c..2bdde86cc07 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -134,6 +134,7 @@ exports javax.security.auth.spi; exports javax.security.auth.x500; exports javax.security.cert; + exports org.jspecify.annotations; // additional qualified exports may be inserted at build time diff --git a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKey.java b/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKey.java deleted file mode 100644 index cd9f177bf83..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKey.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.compilermsgs.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A string that is definitely a compiler message key. - * - * @checker_framework.manual #compilermsgs-checker Compiler Message Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownCompilerMessageKey.class) -public @interface CompilerMessageKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKeyBottom.java b/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKeyBottom.java deleted file mode 100644 index 911db2ca01b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/CompilerMessageKeyBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.compilermsgs.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Compiler Message Key type system. Programmers should rarely write this - * type. - * - * @checker_framework.manual #compilermsgs-checker Compiler Message Key Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(CompilerMessageKey.class) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface CompilerMessageKeyBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/UnknownCompilerMessageKey.java b/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/UnknownCompilerMessageKey.java deleted file mode 100644 index 1e8916ee106..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/UnknownCompilerMessageKey.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.compilermsgs.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A {@code String} that might or might not be a compiler message key. - * - * @checker_framework.manual #compilermsgs-checker Compiler Message Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownCompilerMessageKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/package-info.java b/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/package-info.java deleted file mode 100644 index f3c313621e9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/compilermsgs/qual/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Qualifiers for the Compiler Message Key Checker. - * - * @checker_framework.manual #compilermsgs-checker Compiler Message Key Checker - */ -package org.checkerframework.checker.compilermsgs.qual; diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtAlphaCompositingRule.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtAlphaCompositingRule.java deleted file mode 100644 index c6f28499e24..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtAlphaCompositingRule.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Basic alpha compositing rules for combining source and destination colors to achieve blending and - * transparency effects with graphics and images (see {@link java.awt.AlphaComposite} for more - * details). - * - * @see java.awt.AlphaComposite#CLEAR - * @see java.awt.AlphaComposite#SRC - * @see java.awt.AlphaComposite#DST - * @see java.awt.AlphaComposite#SRC_OVER - * @see java.awt.AlphaComposite#DST_OVER - * @see java.awt.AlphaComposite#SRC_IN - * @see java.awt.AlphaComposite#DST_IN - * @see java.awt.AlphaComposite#SRC_OUT - * @see java.awt.AlphaComposite#DST_OUT - * @see java.awt.AlphaComposite#SRC_ATOP - * @see java.awt.AlphaComposite#DST_ATOP - * @see java.awt.AlphaComposite#XOR - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface AwtAlphaCompositingRule {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtColorSpace.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtColorSpace.java deleted file mode 100644 index 0dbe2718055..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtColorSpace.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Color space tags to identify the specific color space of a Color object or, via a ColorModel - * object, of an Image, a BufferedImage, or a GraphicsDevice (see {@link java.awt.color.ColorSpace} - * for more details). - * - * @see java.awt.color.ColorSpace#TYPE_XYZ - * @see java.awt.color.ColorSpace#TYPE_Lab - * @see java.awt.color.ColorSpace#TYPE_Luv - * @see java.awt.color.ColorSpace#TYPE_YCbCr - * @see java.awt.color.ColorSpace#TYPE_Yxy - * @see java.awt.color.ColorSpace#TYPE_RGB - * @see java.awt.color.ColorSpace#TYPE_GRAY - * @see java.awt.color.ColorSpace#TYPE_HSV - * @see java.awt.color.ColorSpace#TYPE_HLS - * @see java.awt.color.ColorSpace#TYPE_CMYK - * @see java.awt.color.ColorSpace#TYPE_CMY - * @see java.awt.color.ColorSpace#TYPE_2CLR - * @see java.awt.color.ColorSpace#TYPE_3CLR - * @see java.awt.color.ColorSpace#TYPE_4CLR - * @see java.awt.color.ColorSpace#TYPE_5CLR - * @see java.awt.color.ColorSpace#TYPE_6CLR - * @see java.awt.color.ColorSpace#TYPE_7CLR - * @see java.awt.color.ColorSpace#TYPE_8CLR - * @see java.awt.color.ColorSpace#TYPE_9CLR - * @see java.awt.color.ColorSpace#TYPE_ACLR - * @see java.awt.color.ColorSpace#TYPE_BCLR - * @see java.awt.color.ColorSpace#TYPE_CCLR - * @see java.awt.color.ColorSpace#TYPE_DCLR - * @see java.awt.color.ColorSpace#TYPE_ECLR - * @see java.awt.color.ColorSpace#TYPE_FCLR - * @see java.awt.color.ColorSpace#CS_sRGB - * @see java.awt.color.ColorSpace#CS_LINEAR_RGB - * @see java.awt.color.ColorSpace#CS_CIEXYZ - * @see java.awt.color.ColorSpace#CS_PYCC - * @see java.awt.color.ColorSpace#CS_GRAY - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface AwtColorSpace {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtCursorType.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtCursorType.java deleted file mode 100644 index 7e78009279e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtCursorType.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * AwtCursorType. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface AwtCursorType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtFlowLayout.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtFlowLayout.java deleted file mode 100644 index a5bc81f1a5d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/AwtFlowLayout.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Line alignments in a flow layout (see {@link java.awt.FlowLayout} for more details). - * - * @see java.awt.FlowLayout#LEFT - * @see java.awt.FlowLayout#CENTER - * @see java.awt.FlowLayout#RIGHT - * @see java.awt.FlowLayout#LEADING - * @see java.awt.FlowLayout#TRAILING - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface AwtFlowLayout {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/Fenum.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/Fenum.java deleted file mode 100644 index 6ad5cc97218..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/Fenum.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A generic fake enumeration qualifier that is parameterized by a name. It is written in source - * code as, for example, {@code @Fenum("cardSuit")} and {@code @Fenum("faceValue")}, which would be - * distinct fake enumerations. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface Fenum { - String value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumBottom.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumBottom.java deleted file mode 100644 index 5607bd08156..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumBottom.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Fenum type system. Programmers should rarely write this type. - * - *

Its relationships are set up via the FenumAnnotatedTypeFactory. - * - * @checker_framework.manual #propkey-checker Property File Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -// Subtype relationships are set up by passing this class as a bottom -// to the multigraph hierarchy constructor. -@SubtypeOf({}) -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface FenumBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumTop.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumTop.java deleted file mode 100644 index 764b7f3e632..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumTop.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The top of the fake enumeration type hierarchy. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({}) -@DefaultFor({TypeUseLocation.LOCAL_VARIABLE, TypeUseLocation.RESOURCE_VARIABLE}) -public @interface FenumTop {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumUnqualified.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumUnqualified.java deleted file mode 100644 index 4eeaf969214..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/FenumUnqualified.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * An unqualified type. Such a type is incomparable to (that is, neither a subtype nor a supertype - * of) any fake enum type. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) // empty target prevents programmers from writing this in a program -@SubtypeOf({FenumTop.class}) -@DefaultQualifierInHierarchy -@DefaultFor(TypeUseLocation.EXCEPTION_PARAMETER) -public @interface FenumUnqualified {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/PolyFenum.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/PolyFenum.java deleted file mode 100644 index d203d9a861a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/PolyFenum.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the fake enum type system. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(FenumTop.class) -public @interface PolyFenum {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingBoxOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingBoxOrientation.java deleted file mode 100644 index 1c079d5d7fa..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingBoxOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingBoxOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingBoxOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingCompassDirection.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingCompassDirection.java deleted file mode 100644 index f89cd2dbd29..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingCompassDirection.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingCompassDirection. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingCompassDirection {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingElementOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingElementOrientation.java deleted file mode 100644 index 8935db1e0d2..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingElementOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingElementOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingElementOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingHorizontalOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingHorizontalOrientation.java deleted file mode 100644 index 569f8604fc2..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingHorizontalOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingHorizontalOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SwingBoxOrientation.class) -public @interface SwingHorizontalOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingSplitPaneOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingSplitPaneOrientation.java deleted file mode 100644 index d555bf175e3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingSplitPaneOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingSplitPaneOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingSplitPaneOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTextOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTextOrientation.java deleted file mode 100644 index 84833e6103d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTextOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingTextOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingTextOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitleJustification.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitleJustification.java deleted file mode 100644 index ac51e16cc98..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitleJustification.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Vertical orientations for the title text of a {@link javax.swing.border.TitledBorder}. - * - * @see javax.swing.border.TitledBorder#DEFAULT_JUSTIFICATION - * @see javax.swing.border.TitledBorder#LEFT - * @see javax.swing.border.TitledBorder#CENTER - * @see javax.swing.border.TitledBorder#RIGHT - * @see javax.swing.border.TitledBorder#LEADING - * @see javax.swing.border.TitledBorder#TRAILING - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingTitleJustification {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitlePosition.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitlePosition.java deleted file mode 100644 index e3ca36f90b1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingTitlePosition.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Justifications for the title text of a {@link javax.swing.border.TitledBorder}. - * - * @see javax.swing.border.TitledBorder#DEFAULT_POSITION - * @see javax.swing.border.TitledBorder#ABOVE_TOP - * @see javax.swing.border.TitledBorder#TOP - * @see javax.swing.border.TitledBorder#BELOW_TOP - * @see javax.swing.border.TitledBorder#ABOVE_BOTTOM - * @see javax.swing.border.TitledBorder#BOTTOM - * @see javax.swing.border.TitledBorder#BELOW_BOTTOM - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FenumTop.class) -public @interface SwingTitlePosition {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingVerticalOrientation.java b/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingVerticalOrientation.java deleted file mode 100644 index 7a70857ddc8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/fenum/qual/SwingVerticalOrientation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.fenum.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * SwingVerticalOrientation. - * - * @checker_framework.manual #fenum-checker Fake Enum Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SwingBoxOrientation.class) -public @interface SwingVerticalOrientation {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/FormatUtil.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/FormatUtil.java deleted file mode 100644 index 953f09a8476..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/FormatUtil.java +++ /dev/null @@ -1,325 +0,0 @@ -package org.checkerframework.checker.formatter; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.IllegalFormatConversionException; -import java.util.IllegalFormatException; -import java.util.Map; -import java.util.MissingFormatArgumentException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.checkerframework.checker.formatter.qual.ConversionCategory; -import org.checkerframework.checker.formatter.qual.ReturnsFormat; -import org.checkerframework.checker.regex.qual.Regex; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** This class provides a collection of utilities to ease working with format strings. */ -@AnnotatedFor("nullness") -public class FormatUtil { - - /** - * A representation of a format specifier, which is represented by "%..." in the format string. - * Indicates how to convert a value into a string. - */ - private static class Conversion { - /** The index in the argument list. */ - private final int index; - /** The conversion category. */ - private final ConversionCategory cath; - - /** - * Construct a new Conversion. - * - * @param index the index in the argument list - * @param c the conversion character - */ - public Conversion(char c, int index) { - this.index = index; - this.cath = ConversionCategory.fromConversionChar(c); - } - - /** - * Returns the index in the argument list. - * - * @return the index in the argument list - */ - int index() { - return index; - } - - /** - * Returns the conversion category. - * - * @return the conversion category - */ - ConversionCategory category() { - return cath; - } - } - - /** - * Returns if the format string is satisfiable, and if the format's parameters match the passed - * {@link ConversionCategory}s. Otherwise an {@link Error} is thrown. - * - * @param format a format string - * @param cc an array of conversion categories - * @return the {@code format} argument - * @throws IllegalFormatException if the format string is incompatible with the conversion - * categories - */ - // TODO introduce more such functions, see RegexUtil for examples - @ReturnsFormat - public static String asFormat(String format, ConversionCategory... cc) - throws IllegalFormatException { - ConversionCategory[] fcc = formatParameterCategories(format); - if (fcc.length != cc.length) { - throw new ExcessiveOrMissingFormatArgumentException(cc.length, fcc.length); - } - - for (int i = 0; i < cc.length; i++) { - if (cc[i] != fcc[i]) { - throw new IllegalFormatConversionCategoryException(cc[i], fcc[i]); - } - } - - return format; - } - - /** - * Throws an exception if the format is not syntactically valid. - * - * @param format a format string - * @throws IllegalFormatException if the format string is invalid - */ - public static void tryFormatSatisfiability(String format) throws IllegalFormatException { - @SuppressWarnings({ - "unused", // called for side effect, to see if it throws an exception - "nullness:argument.type.incompatible" // it's not documented, but String.format permits - // a null array, which it treats as matching any format string - }) - String unused = String.format(format, (Object[]) null); - } - - /** - * Returns a {@link ConversionCategory} for every conversion found in the format string. - * - *

Throws an exception if the format is not syntactically valid. - */ - public static ConversionCategory[] formatParameterCategories(String format) - throws IllegalFormatException { - tryFormatSatisfiability(format); - - int last = -1; // index of last argument referenced - int lasto = -1; // last ordinary index - int maxindex = -1; - - Conversion[] cs = parse(format); - Map conv = new HashMap<>(); - - for (Conversion c : cs) { - int index = c.index(); - switch (index) { - case -1: // relative index - break; - case 0: // ordinary index - lasto++; - last = lasto; - break; - default: // explicit index - last = index - 1; - break; - } - maxindex = Math.max(maxindex, last); - Integer lastKey = last; - conv.put( - last, - ConversionCategory.intersect( - conv.containsKey(lastKey) - ? conv.get(lastKey) - : ConversionCategory.UNUSED, - c.category())); - } - - ConversionCategory[] res = new ConversionCategory[maxindex + 1]; - for (int i = 0; i <= maxindex; ++i) { - Integer key = i; // autoboxing prevents recognizing that containsKey => get() != null - res[i] = conv.containsKey(key) ? conv.get(key) : ConversionCategory.UNUSED; - } - return res; - } - - /** - * A regex that matches a format specifier. Its syntax is specified in the See {@code - * Formatter} documentation. - * - *

-     * %[argument_index$][flags][width][.precision][t]conversion
-     * group 1            2      3      4           5 6
-     * 
- * - * For dates and times, the [t] is required and precision must not be provided. For types other - * than dates and times, the [t] must not be provided. - */ - private static final @Regex(6) String formatSpecifier = - "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])"; - /** The capturing group for the optional {@code t} character. */ - private static final int formatSpecifierT = 5; - /** - * The capturing group for the last character in a format specifier, which is the conversion - * character unless the {@code t} character was given. - */ - private static final int formatSpecifierConversion = 6; - - /** - * A Pattern that matches a format specifier. - * - * @see #formatSpecifier - */ - private static @Regex(6) Pattern fsPattern = Pattern.compile(formatSpecifier); - - /** - * Return the index, in the argument list, of the value that will be formatted by the matched - * format specifier. - * - * @param m a matcher that matches a format specifier - * @return the index of the argument to format - */ - private static int indexFromFormat(Matcher m) { - int index; - String s = m.group(1); - if (s != null) { // explicit index - index = Integer.parseInt(s.substring(0, s.length() - 1)); - } else { - String group2 = m.group(2); // not @Deterministic, so extract into local var - if (group2 != null && group2.contains(String.valueOf('<'))) { - index = -1; // relative index - } else { - index = 0; // ordinary index - } - } - return index; - } - - /** - * Returns the conversion character from a format specifier.. - * - * @param m a matcher that matches a format specifier - * @return the conversion character from the format specifier - */ - @SuppressWarnings( - "nullness:dereference.of.nullable") // group formatSpecifierConversion always exists - private static char conversionCharFromFormat(@Regex(6) Matcher m) { - String tGroup = m.group(formatSpecifierT); - if (tGroup != null) { - return tGroup.charAt(0); // This is the letter "t" or "T". - } else { - return m.group(formatSpecifierConversion).charAt(0); - } - } - - /** - * Return the conversion character that is in the given format specifier. - * - * @param formatSpecifier a format - * specifier - * @return the conversion character that is in the given format specifier - * @deprecated This method is public only for testing. Use private method {@code - * #conversionCharFromFormat(Matcher)}. - */ - @Deprecated // used only for testing. Use conversionCharFromFormat(Matcher). - public static char conversionCharFromFormat(String formatSpecifier) { - Matcher m = fsPattern.matcher(formatSpecifier); - assert m.find(); - return conversionCharFromFormat(m); - } - - /** - * Parse the given format string, return information about its format specifiers. - * - * @param format a format string - * @return the list of Conversions from the format specifiers in the format string - */ - private static Conversion[] parse(String format) { - ArrayList cs = new ArrayList<>(); - @Regex(7) Matcher m = fsPattern.matcher(format); - while (m.find()) { - char c = conversionCharFromFormat(m); - switch (c) { - case '%': - case 'n': - break; - default: - cs.add(new Conversion(c, indexFromFormat(m))); - } - } - return cs.toArray(new Conversion[cs.size()]); - } - - public static class ExcessiveOrMissingFormatArgumentException - extends MissingFormatArgumentException { - private static final long serialVersionUID = 17000126L; - - private final int expected; - private final int found; - - /** - * Constructs an instance of this class with the actual argument length and the expected - * one. - */ - public ExcessiveOrMissingFormatArgumentException(int expected, int found) { - super("-"); - this.expected = expected; - this.found = found; - } - - public int getExpected() { - return expected; - } - - public int getFound() { - return found; - } - - @Override - public String getMessage() { - return String.format("Expected %d arguments but found %d.", expected, found); - } - } - - public static class IllegalFormatConversionCategoryException - extends IllegalFormatConversionException { - private static final long serialVersionUID = 17000126L; - - private final ConversionCategory expected; - private final ConversionCategory found; - - /** - * Constructs an instance of this class with the mismatched conversion and the expected one. - */ - public IllegalFormatConversionCategoryException( - ConversionCategory expected, ConversionCategory found) { - super( - expected.chars == null || expected.chars.length() == 0 - ? '-' - : expected.chars.charAt(0), - found.types == null ? Object.class : found.types[0]); - this.expected = expected; - this.found = found; - } - - public ConversionCategory getExpected() { - return expected; - } - - public ConversionCategory getFound() { - return found; - } - - @Override - public String getMessage() { - return String.format("Expected category %s but found %s.", expected, found); - } - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ConversionCategory.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ConversionCategory.java deleted file mode 100644 index bf9ee8ce94e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ConversionCategory.java +++ /dev/null @@ -1,307 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; -import java.util.StringJoiner; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * Elements of this enumeration are used in a {@link Format Format} annotation to indicate the valid - * types that may be passed as a format parameter. For example: - * - *
- * - *
{@literal @}Format({ConversionCategory.GENERAL, ConversionCategory.INT})
- * String f = "String '%s' has length %d";
- * String.format(f, "Example", 7);
- * - *
- * - * The annotation indicates that the format string requires any Object as the first parameter - * ({@link ConversionCategory#GENERAL}) and an integer as the second parameter ({@link - * ConversionCategory#INT}). - * - * @see Format - * @checker_framework.manual #formatter-checker Format String Checker - */ -@AnnotatedFor("nullness") -public enum ConversionCategory { - /** Use if the parameter can be of any type. Applicable for conversions b, B, h, H, s, S. */ - GENERAL(null /* everything */, "bBhHsS"), - - /** - * Use if the parameter is of a basic types which represent Unicode characters: char, Character, - * byte, Byte, short, and Short. This conversion may also be applied to the types int and - * Integer when Character.isValidCodePoint(int) returns true. Applicable for conversions c, C. - */ - CHAR(new Class[] {Character.class, Byte.class, Short.class, Integer.class}, "cC"), - - /** - * Use if the parameter is an integral type: byte, Byte, short, Short, int and Integer, long, - * Long, and BigInteger. Applicable for conversions d, o, x, X. - */ - INT( - new Class[] {Byte.class, Short.class, Integer.class, Long.class, BigInteger.class}, - "doxX"), - - /** - * Use if the parameter is a floating-point type: float, Float, double, Double, and BigDecimal. - * Applicable for conversions e, E, f, g, G, a, A. - */ - FLOAT(new Class[] {Float.class, Double.class, BigDecimal.class}, "eEfgGaA"), - - /** - * Use if the parameter is a type which is capable of encoding a date or time: long, Long, - * Calendar, and Date. Applicable for conversions t, T. - */ - @SuppressWarnings("JdkObsolete") - TIME(new Class[] {Long.class, Calendar.class, Date.class}, "tT"), - - /** - * In a format string, multiple conversions may be applied to the same parameter. This is - * seldomly needed, but the following is an example of such use: - * - *
-     *   format("Test %1$c %1$d", (int)42);
-     * 
- * - * In this example, the first parameter is interpreted as both a character and an int, therefore - * the parameter must be compatible with both conversion, and can therefore neither be char nor - * long. This intersection of conversions is called CHAR_AND_INT. - * - *

One other conversion intersection is interesting, namely the intersection of INT and TIME, - * resulting in INT_AND_TIME. - * - *

All other intersection either lead to an already existing type, or NULL, in which case it - * is illegal to pass object's of any type as parameter. - */ - CHAR_AND_INT(new Class[] {Byte.class, Short.class, Integer.class}, null), - - INT_AND_TIME(new Class[] {Long.class}, null), - - /** - * Use if no object of any type can be passed as parameter. In this case, the only legal value - * is null. This is seldomly needed, and indicates an error in most cases. For example: - * - *

-     *   format("Test %1$f %1$d", null);
-     * 
- * - * Only null can be legally passed, passing a value such as 4 or 4.2 would lead to an exception. - */ - NULL(new Class[0], null), - - /** - * Use if a parameter is not used by the formatter. This is seldomly needed, and indicates an - * error in most cases. For example: - * - *
-     *   format("Test %1$s %3$s", "a","unused","b");
-     * 
- * - * Only the first "a" and third "b" parameters are used, the second "unused" parameter is - * ignored. - */ - UNUSED(null /* everything */, null); - - /** Create a new conversion category. */ - ConversionCategory(Class @Nullable [] types, @Nullable String chars) { - this.types = types; - this.chars = chars; - } - - /** The format types. */ - @SuppressWarnings("ImmutableEnumChecker") // TODO: clean this up! - public final Class @Nullable [] types; - - /** The format characters. */ - public final @Nullable String chars; - - /** - * Converts a conversion character to a category. For example: - * - *
{@code
-     * ConversionCategory.fromConversionChar('d') == ConversionCategory.INT
-     * }
- * - * @param c a conversion character - * @return the category for the given conversion character - */ - @SuppressWarnings("nullness:dereference.of.nullable") // `chars` field is non-null for these - public static ConversionCategory fromConversionChar(char c) { - for (ConversionCategory v : new ConversionCategory[] {GENERAL, CHAR, INT, FLOAT, TIME}) { - if (v.chars.contains(String.valueOf(c))) { - return v; - } - } - throw new IllegalArgumentException("Bad conversion character " + c); - } - - private static Set arrayToSet(E[] a) { - return new HashSet<>(Arrays.asList(a)); - } - - public static boolean isSubsetOf(ConversionCategory a, ConversionCategory b) { - return intersect(a, b) == a; - } - - /** - * Returns the intersection of two categories. This is seldomly needed. - * - *
- * - *
-     * ConversionCategory.intersect(INT, TIME) == INT_AND_TIME;
-     * 
- * - *
- * - * @param a a category - * @param b a category - * @return the intersection of the two categories (their greatest lower bound) - */ - public static ConversionCategory intersect(ConversionCategory a, ConversionCategory b) { - if (a == UNUSED) { - return b; - } - if (b == UNUSED) { - return a; - } - if (a == GENERAL) { - return b; - } - if (b == GENERAL) { - return a; - } - - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED and - // GENERAL - Set> as = arrayToSet(a.types); - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED and - // GENERAL - Set> bs = arrayToSet(b.types); - as.retainAll(bs); // intersection - for (ConversionCategory v : - new ConversionCategory[] { - CHAR, INT, FLOAT, TIME, CHAR_AND_INT, INT_AND_TIME, NULL - }) { - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED - // and GENERAL - Set> vs = arrayToSet(v.types); - if (vs.equals(as)) { - return v; - } - } - throw new RuntimeException(); - } - - /** - * Returns the union of two categories. This is seldomly needed. - * - *
- * - *
-     * ConversionCategory.union(INT, TIME) == GENERAL;
-     * 
- * - *
- * - * @param a a category - * @param b a category - * @return the union of the two categories (their least upper bound) - */ - public static ConversionCategory union(ConversionCategory a, ConversionCategory b) { - if (a == UNUSED || b == UNUSED) { - return UNUSED; - } - if (a == GENERAL || b == GENERAL) { - return GENERAL; - } - if ((a == CHAR_AND_INT && b == INT_AND_TIME) || (a == INT_AND_TIME && b == CHAR_AND_INT)) { - // This is special-cased because the union of a.types and b.types - // does not include BigInteger.class, whereas the types for INT does. - // Returning INT here to prevent returning GENERAL below. - return INT; - } - - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED and - // GENERAL - Set> as = arrayToSet(a.types); - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED and - // GENERAL - Set> bs = arrayToSet(b.types); - as.addAll(bs); // union - for (ConversionCategory v : - new ConversionCategory[] { - NULL, CHAR_AND_INT, INT_AND_TIME, CHAR, INT, FLOAT, TIME - }) { - @SuppressWarnings( - "nullness:argument.type.incompatible") // `types` field is null only for UNUSED - // and GENERAL - Set> vs = arrayToSet(v.types); - if (vs.equals(as)) { - return v; - } - } - - return GENERAL; - } - - private String className(Class cls) { - if (cls == Boolean.class) { - return "boolean"; - } - if (cls == Character.class) { - return "char"; - } - if (cls == Byte.class) { - return "byte"; - } - if (cls == Short.class) { - return "short"; - } - if (cls == Integer.class) { - return "int"; - } - if (cls == Long.class) { - return "long"; - } - if (cls == Float.class) { - return "float"; - } - if (cls == Double.class) { - return "double"; - } - return cls.getSimpleName(); - } - - /** Returns a pretty printed {@link ConversionCategory}. */ - @SuppressWarnings( - "nullness:iterating.over.nullable") // `types` field is null only for UNUSED and - // GENERAL - @Pure - @Override - public String toString() { - StringBuilder sb = new StringBuilder(this.name()); - if (this != UNUSED && this != GENERAL) { - StringJoiner sj = new StringJoiner(", ", " conversion category (one of: ", ")"); - for (Class cls : this.types) { - sj.add(className(cls)); - } - sb.append(sj); - } - return sb.toString(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/Format.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/Format.java deleted file mode 100644 index b513d84cfc3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/Format.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation, attached to a String type, indicates that the String may be passed to {@link - * java.util.Formatter#format(String, Object...) Formatter.format} and similar methods. - * - *

The annotation's value represents the valid arguments that may be passed to the format method. - * For example: - * - *

- * - *
- * {@literal @}Format({ConversionCategory.GENERAL, ConversionCategory.INT})
- *  String f = "String '%s' has length %d";
- *  String.format(f, "Example", 7);
- * 
- * - *
- * - * The annotation indicates that the format string requires any Object as the first parameter - * ({@link ConversionCategory#GENERAL}) and an integer as the second parameter ({@link - * ConversionCategory#INT}). - * - * @see ConversionCategory - * @checker_framework.manual #formatter-checker Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownFormat.class) -public @interface Format { - /** - * An array of {@link ConversionCategory}, indicating the types of legal remaining arguments - * when a value of the annotated type is used as the first argument to {@link - * java.util.Formatter#format(String, Object...) Formatter.format} and similar methods. - * - * @return types that can be used as values when a value of this type is the format string - */ - ConversionCategory[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatBottom.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatBottom.java deleted file mode 100644 index 9ce0ec040f5..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Format String type system. Programmers should rarely write this type. - * - * @checker_framework.manual #formatter-checker Format String Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({Format.class, InvalidFormat.class}) -@DefaultFor(value = {TypeUseLocation.LOWER_BOUND}) -public @interface FormatBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatMethod.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatMethod.java deleted file mode 100644 index 4d9254061b3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/FormatMethod.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * If this annotation is attached to a {@link java.util.Formatter#format(String, Object...) - * Formatter.format}-like method, then the first parameter, which must be of type String, is treated - * as a format string for the remaining arguments. The Format String Checker ensures that the - * arguments passed as varargs are compatible with the format string argument, and also permits them - * to be passed to {@link java.util.Formatter#format(String, Object...) Formatter.format}-like - * methods within the body. - * - *

The initial String parameter may optionally be preceded by a Locale parameter. - * - * @checker_framework.manual #formatter-checker Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface FormatMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/InvalidFormat.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/InvalidFormat.java deleted file mode 100644 index cce2d155627..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/InvalidFormat.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation, attached to a {@link java.lang.String String} type, indicates that the string is - * not a legal format string. Passing the string to {@link java.util.Formatter#format(String, - * Object...) Formatter.format} or similar methods will lead to the exception message indicated in - * the annotation's value. - * - * @checker_framework.manual #formatter-checker Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownFormat.class) -public @interface InvalidFormat { - /** - * Using a value of the annotated type as the first argument to {@link - * java.util.Formatter#format(String, Object...) Formatter.format} or similar methods will lead - * to this exception message. - */ - String value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ReturnsFormat.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ReturnsFormat.java deleted file mode 100644 index 2a8d37cba7f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/ReturnsFormat.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Attach this annotation to a method with the following properties: - * - *

    - *
  • The first parameter is a format string. - *
  • The second parameter is a vararg that takes conversion categories. - *
  • The method throws an exception if the format string's format specifiers do not match the - * passed conversion categories. - *
  • On success, the method returns the passed format string unmodified. - *
- * - * An example is {@link org.checkerframework.checker.formatter.FormatUtil#asFormat}. - * - * @checker_framework.manual #formatter-checker Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ReturnsFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/UnknownFormat.java b/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/UnknownFormat.java deleted file mode 100644 index e4da196ae42..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/formatter/qual/UnknownFormat.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.formatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The top qualifier. - * - *

A type annotation indicating that the run-time value might or might not be a valid format - * string. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - * @checker_framework.manual #formatter-checker Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -public @interface UnknownFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/AlwaysSafe.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/AlwaysSafe.java deleted file mode 100644 index 07308112f71..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/AlwaysSafe.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Annotation to override the UI effect on a class, and make a field or method safe for non-UI code - * to use. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UI.class}) -@DefaultQualifierInHierarchy -public @interface AlwaysSafe {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUI.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUI.java deleted file mode 100644 index 7586919ef90..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUI.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * Annotation for the polymorphic-UI effect. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UI.class) -public @interface PolyUI {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIEffect.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIEffect.java deleted file mode 100644 index cf8cc04a7c1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIEffect.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for the polymorphic effect on methods, or on field accesses. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD}) -public @interface PolyUIEffect {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIType.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIType.java deleted file mode 100644 index 20262737d6f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/PolyUIType.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for the polymorphic type declaration. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface PolyUIType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeEffect.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeEffect.java deleted file mode 100644 index 1d529d93ead..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeEffect.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for the concrete safe effect on methods, or on field accesses. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD}) -public @interface SafeEffect {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeType.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeType.java deleted file mode 100644 index a1ced023066..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/SafeType.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Class declaration annotation to make methods default to {@code @AlwaysSafe}. While the normal - * default is already {@code @AlwaysSafe} methods, this is useful for a type inside a package marked - * {@code @UIPackage}. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface SafeType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UI.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UI.java deleted file mode 100644 index 615b4daa42e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UI.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Annotation for the UI effect. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -public @interface UI {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIEffect.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIEffect.java deleted file mode 100644 index 67a6d43e62d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIEffect.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for the concrete UI effect on methods, or on field accesses. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD}) -public @interface UIEffect {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIPackage.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIPackage.java deleted file mode 100644 index 6f0a5f5e04f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIPackage.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Package annotation to make all classes within a package {@code @UIType}. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PACKAGE}) -public @interface UIPackage {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIType.java b/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIType.java deleted file mode 100644 index b3cb66593ee..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/guieffect/qual/UIType.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.checkerframework.checker.guieffect.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Class declaration annotation to make methods default to {@code @UI}. - * - * @checker_framework.manual #guieffect-checker GUI Effect Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface UIType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKey.java b/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKey.java deleted file mode 100644 index ce74615098a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKey.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.i18n.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} is a key into a property file or resource bundle containing - * Localized Strings. - * - * @checker_framework.manual #i18n-checker Internationalization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownLocalizableKey.class) -public @interface LocalizableKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKeyBottom.java b/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKeyBottom.java deleted file mode 100644 index 712244a65c8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/LocalizableKeyBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.i18n.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Internationalization type system. Programmers should rarely write this - * type. - * - * @checker_framework.manual #i18n-checker Internationalization Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(LocalizableKey.class) -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface LocalizableKeyBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/Localized.java b/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/Localized.java deleted file mode 100644 index 32a937aa35a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/Localized.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.checkerframework.checker.i18n.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} type has been localized and formatted for the target output - * locale. - * - * @checker_framework.manual #i18n-checker Internationalization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownLocalized.class) -@QualifierForLiterals({ - // All literals except chars and strings, which may need to be localized. - // (null is bottom by default.) - LiteralKind.INT, - LiteralKind.LONG, - LiteralKind.FLOAT, - LiteralKind.DOUBLE, - LiteralKind.BOOLEAN -}) -public @interface Localized {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalizableKey.java b/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalizableKey.java deleted file mode 100644 index 71a8448dccf..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalizableKey.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.i18n.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} type has an unknown localizable key property. - * - * @checker_framework.manual #i18n-checker Internationalization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownLocalizableKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalized.java b/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalized.java deleted file mode 100644 index 2bb09803885..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18n/qual/UnknownLocalized.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.i18n.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} type has unknown localization properties. - * - * @checker_framework.manual #i18n-checker Internationalization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownLocalized {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/I18nFormatUtil.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/I18nFormatUtil.java deleted file mode 100644 index 5e537931178..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/I18nFormatUtil.java +++ /dev/null @@ -1,408 +0,0 @@ -package org.checkerframework.checker.i18nformatter; - -import java.text.ChoiceFormat; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.IllegalFormatException; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.checkerframework.checker.i18nformatter.qual.I18nChecksFormat; -import org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory; -import org.checkerframework.checker.i18nformatter.qual.I18nValidFormat; -import org.checkerframework.checker.interning.qual.InternedDistinct; -import org.checkerframework.checker.nullness.qual.EnsuresNonNull; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.checker.nullness.qual.RequiresNonNull; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * This class provides a collection of utilities to ease working with i18n format strings. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@AnnotatedFor("nullness") -public class I18nFormatUtil { - - /** - * Throws an exception if the format is not syntactically valid. - * - * @param format the format string to parse - */ - @SuppressWarnings( - "nullness:argument.type.incompatible") // It's not documented, but passing null as the - // argument array is supported. - public static void tryFormatSatisfiability(String format) throws IllegalFormatException { - MessageFormat.format(format, (Object[]) null); - } - - /** - * Returns a {@link I18nConversionCategory} for every conversion found in the format string. - * - * @param format the format string to parse - * @throws IllegalFormatException if the format is not syntactically valid - */ - public static I18nConversionCategory[] formatParameterCategories(String format) - throws IllegalFormatException { - tryFormatSatisfiability(format); - I18nConversion[] cs = MessageFormatParser.parse(format); - - int maxIndex = -1; - Map conv = new HashMap<>(); - - for (I18nConversion c : cs) { - int index = c.index; - Integer indexKey = index; - conv.put( - indexKey, - I18nConversionCategory.intersect( - c.category, - conv.containsKey(indexKey) - ? conv.get(indexKey) - : I18nConversionCategory.UNUSED)); - maxIndex = Math.max(maxIndex, index); - } - - I18nConversionCategory[] res = new I18nConversionCategory[maxIndex + 1]; - for (int i = 0; i <= maxIndex; i++) { - Integer indexKey = i; - res[i] = - conv.containsKey(indexKey) ? conv.get(indexKey) : I18nConversionCategory.UNUSED; - } - return res; - } - - /** - * Returns true if the format string is satisfiable, and if the format's parameters match the - * passed {@link I18nConversionCategory}s. Otherwise an error is thrown. - * - * @param format a format string - * @param cc a list of expected categories for the string's format specifiers - * @return true if the format string's specifiers are the given categories, in order - */ - // TODO introduce more such functions, see RegexUtil for examples - @I18nChecksFormat - public static boolean hasFormat(String format, I18nConversionCategory... cc) { - I18nConversionCategory[] fcc = formatParameterCategories(format); - if (fcc.length != cc.length) { - return false; - } - - for (int i = 0; i < cc.length; i++) { - if (!I18nConversionCategory.isSubsetOf(cc[i], fcc[i])) { - return false; - } - } - return true; - } - - @I18nValidFormat - public static boolean isFormat(String format) { - try { - formatParameterCategories(format); - } catch (Exception e) { - return false; - } - return true; - } - - private static class I18nConversion { - public int index; - public I18nConversionCategory category; - - public I18nConversion(int index, I18nConversionCategory category) { - this.index = index; - this.category = category; - } - - @Override - public String toString() { - return category.toString() + "(index: " + index + ")"; - } - } - - private static class MessageFormatParser { - - public static int maxOffset; - - /** The locale to use for formatting numbers and dates. Is set in {@link #parse}. */ - private static @MonotonicNonNull Locale locale; - - /** - * An array of formatters, which are used to format the arguments. Is set in {@link #parse}. - */ - private static @MonotonicNonNull List categories; - - /** - * The argument numbers corresponding to each formatter. (The formatters are stored in the - * order they occur in the pattern, not in the order in which the arguments are specified.) - * Is set in {@link #parse}. - */ - private static @MonotonicNonNull List argumentIndices; - - // I think this means the number of format specifiers in the format string. - /** The number of subformats. */ - private static int numFormat; - - // Indices for segments - private static final int SEG_RAW = 0; - private static final int SEG_INDEX = 1; - private static final int SEG_TYPE = 2; - private static final int SEG_MODIFIER = 3; // modifier or subformat - - // Indices for type keywords - private static final int TYPE_NULL = 0; - private static final int TYPE_NUMBER = 1; - private static final int TYPE_DATE = 2; - private static final int TYPE_TIME = 3; - private static final int TYPE_CHOICE = 4; - - private static final String[] TYPE_KEYWORDS = {"", "number", "date", "time", "choice"}; - - // Indices for number modifiers - private static final int MODIFIER_DEFAULT = 0; // common in number and date-time - private static final int MODIFIER_CURRENCY = 1; - private static final int MODIFIER_PERCENT = 2; - private static final int MODIFIER_INTEGER = 3; - - private static final String[] NUMBER_MODIFIER_KEYWORDS = { - "", "currency", "percent", "integer" - }; - - private static final String[] DATE_TIME_MODIFIER_KEYWORDS = { - "", "short", "medium", "long", "full" - }; - - @EnsuresNonNull({"categories", "argumentIndices", "locale"}) - public static I18nConversion[] parse(String pattern) { - MessageFormatParser.categories = new ArrayList<>(); - MessageFormatParser.argumentIndices = new ArrayList<>(); - MessageFormatParser.locale = Locale.getDefault(Locale.Category.FORMAT); - applyPattern(pattern); - - I18nConversion[] ret = new I18nConversion[MessageFormatParser.numFormat]; - for (int i = 0; i < MessageFormatParser.numFormat; i++) { - ret[i] = new I18nConversion(argumentIndices.get(i), categories.get(i)); - } - return ret; - } - - @SuppressWarnings("nullness:dereference.of.nullable") // complex rules for segments[i] - @RequiresNonNull({"argumentIndices", "categories", "locale"}) - private static void applyPattern(String pattern) { - @Nullable StringBuilder[] segments = new StringBuilder[4]; - // Allocate only segments[SEG_RAW] here. The rest are - // allocated on demand. - segments[SEG_RAW] = new StringBuilder(); - - int part = SEG_RAW; - MessageFormatParser.numFormat = 0; - boolean inQuote = false; - int braceStack = 0; - maxOffset = -1; - for (int i = 0; i < pattern.length(); ++i) { - char ch = pattern.charAt(i); - if (part == SEG_RAW) { - if (ch == '\'') { - if (i + 1 < pattern.length() && pattern.charAt(i + 1) == '\'') { - segments[part].append(ch); // handle doubles - ++i; - } else { - inQuote = !inQuote; - } - } else if (ch == '{' && !inQuote) { - part = SEG_INDEX; - if (segments[SEG_INDEX] == null) { - segments[SEG_INDEX] = new StringBuilder(); - } - } else { - segments[part].append(ch); - } - } else { - if (inQuote) { // just copy quotes in parts - segments[part].append(ch); - if (ch == '\'') { - inQuote = false; - } - } else { - switch (ch) { - case ',': - if (part < SEG_MODIFIER) { - if (segments[++part] == null) { - segments[part] = new StringBuilder(); - } - } else { - segments[part].append(ch); - } - break; - case '{': - ++braceStack; - segments[part].append(ch); - break; - case '}': - if (braceStack == 0) { - part = SEG_RAW; - makeFormat(numFormat, segments); - numFormat++; - // throw away other segments - segments[SEG_INDEX] = null; - segments[SEG_TYPE] = null; - segments[SEG_MODIFIER] = null; - } else { - --braceStack; - segments[part].append(ch); - } - break; - case ' ': - // Skip any leading space chars for SEG_TYPE. - if (part != SEG_TYPE || segments[SEG_TYPE].length() > 0) { - segments[part].append(ch); - } - break; - case '\'': - inQuote = true; - segments[part].append(ch); - break; - default: - segments[part].append(ch); - break; - } - } - } - } - if (braceStack == 0 && part != 0) { - maxOffset = -1; - throw new IllegalArgumentException("Unmatched braces in the pattern"); - } - } - - /** Side-effects {@code categories} field, adding to it an I18nConversionCategory. */ - @RequiresNonNull({"argumentIndices", "categories", "locale"}) - private static void makeFormat(int offsetNumber, @Nullable StringBuilder[] textSegments) { - String[] segments = new String[textSegments.length]; - for (int i = 0; i < textSegments.length; i++) { - StringBuilder oneseg = textSegments[i]; - segments[i] = (oneseg != null) ? oneseg.toString() : ""; - } - - // get the argument number - int argumentNumber; - try { - argumentNumber = Integer.parseInt(segments[SEG_INDEX]); // always - // unlocalized! - } catch (NumberFormatException e) { - throw new IllegalArgumentException( - "can't parse argument number: " + segments[SEG_INDEX], e); - } - if (argumentNumber < 0) { - throw new IllegalArgumentException("negative argument number: " + argumentNumber); - } - - int oldMaxOffset = maxOffset; - maxOffset = offsetNumber; - argumentIndices.add(argumentNumber); - - // now get the format - I18nConversionCategory category = null; - if (segments[SEG_TYPE].length() != 0) { - int type = findKeyword(segments[SEG_TYPE], TYPE_KEYWORDS); - switch (type) { - case TYPE_NULL: - category = I18nConversionCategory.GENERAL; - break; - case TYPE_NUMBER: - switch (findKeyword(segments[SEG_MODIFIER], NUMBER_MODIFIER_KEYWORDS)) { - case MODIFIER_DEFAULT: - case MODIFIER_CURRENCY: - case MODIFIER_PERCENT: - case MODIFIER_INTEGER: - break; - default: // DecimalFormat pattern - try { - new DecimalFormat( - segments[SEG_MODIFIER], - DecimalFormatSymbols.getInstance(locale)); - } catch (IllegalArgumentException e) { - maxOffset = oldMaxOffset; - // invalid decimal subformat pattern - throw e; - } - break; - } - category = I18nConversionCategory.NUMBER; - break; - case TYPE_DATE: - case TYPE_TIME: - int mod = findKeyword(segments[SEG_MODIFIER], DATE_TIME_MODIFIER_KEYWORDS); - if (mod >= 0 && mod < DATE_TIME_MODIFIER_KEYWORDS.length) { - // nothing to do - } else { - // SimpleDateFormat pattern - try { - new SimpleDateFormat(segments[SEG_MODIFIER], locale); - } catch (IllegalArgumentException e) { - maxOffset = oldMaxOffset; - // invalid date subformat pattern - throw e; - } - } - category = I18nConversionCategory.DATE; - break; - case TYPE_CHOICE: - if (segments[SEG_MODIFIER].length() == 0) { - throw new IllegalArgumentException( - "Choice Pattern requires Subformat Pattern: " - + segments[SEG_MODIFIER]); - } - try { - // ChoiceFormat pattern - new ChoiceFormat(segments[SEG_MODIFIER]); - } catch (Exception e) { - maxOffset = oldMaxOffset; - // invalid choice subformat pattern - throw new IllegalArgumentException( - "Choice Pattern incorrect: " + segments[SEG_MODIFIER], e); - } - category = I18nConversionCategory.NUMBER; - break; - default: - maxOffset = oldMaxOffset; - throw new IllegalArgumentException( - "unknown format type: " + segments[SEG_TYPE]); - } - } else { - category = I18nConversionCategory.GENERAL; - } - categories.add(category); - } - - /** - * Return the index of s in list. If not found, return the index of - * s.trim().toLowerCase(Locale.ROOT) in list. If still not found, return -1. - */ - private static final int findKeyword(String s, String[] list) { - for (int i = 0; i < list.length; ++i) { - if (s.equals(list[i])) { - return i; - } - } - - // Try trimmed lowercase. - @SuppressWarnings("interning:assignment.type.incompatible") // test if value changed - @InternedDistinct String ls = s.trim().toLowerCase(Locale.ROOT); - if (ls != s) { // Don't loop if the string trim().toLowerCase returned the same object. - for (int i = 0; i < list.length; ++i) { - if (ls.equals(list[i])) { - return i; - } - } - } - return -1; - } - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nChecksFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nChecksFormat.java deleted file mode 100644 index 8e2a9423af5..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nChecksFormat.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation is used internally to annotate {@link - * org.checkerframework.checker.i18nformatter.I18nFormatUtil#hasFormat} (and will potentially be - * used to annotate more such functions in the future). - * - *

Attach this annotation to a method with the following properties: - * - *

    - *
  • The first parameter is a format string. - *
  • The second parameter is a vararg that takes conversion categories. - *
  • The method returns true if the format string is compatible with the conversion categories. - *
- * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface I18nChecksFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nConversionCategory.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nConversionCategory.java deleted file mode 100644 index 0078d96a22e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nConversionCategory.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; -import java.util.StringJoiner; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * Elements of this enumeration are used in a {@link I18nFormat} annotation to indicate the valid - * types that may be passed as a format parameter. For example: - * - *
{@literal @}I18nFormat({GENERAL, NUMBER}) String f = "{0}{1, number}";
- * MessageFormat.format(f, "Example", 0) // valid
- * - * The annotation indicates that the format string requires any object as the first parameter - * ({@link I18nConversionCategory#GENERAL}) and a number as the second parameter ({@link - * I18nConversionCategory#NUMBER}). - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@AnnotatedFor("nullness") -public enum I18nConversionCategory { - - /** - * Use if a parameter is not used by the formatter. - * - *
-     * MessageFormat.format("{1}", a, b);
-     * 
- * - * Only the second argument ("b") is used. The first argument ("a") is ignored - */ - UNUSED(null /* everything */, null), - - /** Use if the parameter can be of any type. */ - GENERAL(null /* everything */, null), - - /** Use if the parameter can be of date, time, or number types. */ - DATE(new Class[] {Date.class, Number.class}, new String[] {"date", "time"}), - - /** - * Use if the parameter can be of number or choice types. An example of choice: - * - *
{@code
-     * format("{0, choice, 0#zero|1#one|1<{0, number} is more than 1}", 2)
-     * }
- * - * This will print "2 is more than 1". - */ - NUMBER(new Class[] {Number.class}, new String[] {"number", "choice"}); - - @SuppressWarnings("ImmutableEnumChecker") // TODO: clean this up! - public final Class @Nullable [] types; - - @SuppressWarnings("ImmutableEnumChecker") // TODO: clean this up! - public final String @Nullable [] strings; - - I18nConversionCategory(Class @Nullable [] types, String @Nullable [] strings) { - this.types = types; - this.strings = strings; - } - - /** Used by {@link #stringToI18nConversionCategory}. */ - static I18nConversionCategory[] namedCategories = new I18nConversionCategory[] {DATE, NUMBER}; - - /** - * Creates a conversion cagetogry from a string name. - * - *
-     * I18nConversionCategory.stringToI18nConversionCategory("number") == I18nConversionCategory.NUMBER;
-     * 
- * - * @return the I18nConversionCategory associated with the given string - */ - @SuppressWarnings( - "nullness:iterating.over.nullable") // in namedCategories, `strings` field is non-null - public static I18nConversionCategory stringToI18nConversionCategory(String string) { - string = string.toLowerCase(); - for (I18nConversionCategory v : namedCategories) { - for (String s : v.strings) { - if (s.equals(string)) { - return v; - } - } - } - throw new IllegalArgumentException("Invalid format type " + string); - } - - private static Set arrayToSet(E[] a) { - return new HashSet<>(Arrays.asList(a)); - } - - /** - * Return true if a is a subset of b. - * - * @return true if a is a subset of b - */ - public static boolean isSubsetOf(I18nConversionCategory a, I18nConversionCategory b) { - return intersect(a, b) == a; - } - - /** - * Returns the intersection of the two given I18nConversionCategories. - * - *
- * - *
-     * I18nConversionCategory.intersect(DATE, NUMBER) == NUMBER;
-     * 
- * - *
- */ - public static I18nConversionCategory intersect( - I18nConversionCategory a, I18nConversionCategory b) { - if (a == UNUSED) { - return b; - } - if (b == UNUSED) { - return a; - } - if (a == GENERAL) { - return b; - } - if (b == GENERAL) { - return a; - } - - @SuppressWarnings( - "nullness:argument.type.incompatible") // types field is only null in UNUSED and - // GENERAL - Set> as = arrayToSet(a.types); - @SuppressWarnings( - "nullness:argument.type.incompatible") // types field is only null in UNUSED and - // GENERAL - Set> bs = arrayToSet(b.types); - as.retainAll(bs); // intersection - for (I18nConversionCategory v : new I18nConversionCategory[] {DATE, NUMBER}) { - @SuppressWarnings( - "nullness:argument.type.incompatible") // in those values, `types` field is - // non-null - Set> vs = arrayToSet(v.types); - if (vs.equals(as)) { - return v; - } - } - throw new RuntimeException(); - } - - /** - * Returns the union of the two given I18nConversionCategories. - * - *
-     * I18nConversionCategory.intersect(DATE, NUMBER) == DATE;
-     * 
- */ - public static I18nConversionCategory union(I18nConversionCategory a, I18nConversionCategory b) { - if (a == UNUSED || b == UNUSED) { - return UNUSED; - } - if (a == GENERAL || b == GENERAL) { - return GENERAL; - } - if (a == DATE || b == DATE) { - return DATE; - } - return NUMBER; - } - - /** Returns a pretty printed {@link I18nConversionCategory}. */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(this.name()); - if (this.types == null) { - sb.append(" conversion category (all types)"); - } else { - StringJoiner sj = new StringJoiner(", ", " conversion category (one of: ", ")"); - for (Class cls : this.types) { - sj.add(cls.getCanonicalName()); - } - sb.append(sj); - } - return sb.toString(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormat.java deleted file mode 100644 index 63968bc7fa5..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormat.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation, attached to a String type, indicates that the String may be passed to {@link - * java.text.MessageFormat#format(String, Object...) MessageFormat.format}. - * - *

The annotation's value represents the valid arguments that may be passed to the format method. - * For example: - * - *

{@literal @}I18nFormat({I18nConversionCategory.GENERAL, I18nConversionCategory.NUMBER})
- * String f = "{0}{1, number}"; // valid
- * String f = "{0} {1} {2}"; // error, the format string is stronger (more restrictive) than the specifiers.
- * String f = "{0, number} {1, number}"; // error, the format string is stronger (NUMBER is a subtype of GENERAL).
- * 
- * - * The annotation indicates that the format string requires any object as the first parameter - * ({@link I18nConversionCategory#GENERAL}) and a number as the second parameter ({@link - * I18nConversionCategory#NUMBER}). - * - * @see I18nConversionCategory - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(I18nUnknownFormat.class) -public @interface I18nFormat { - /** - * An array of {@link I18nConversionCategory}, indicating the types of legal remaining arguments - * when a value of the annotated type is used as the first argument to {@link - * java.text.MessageFormat#format(String, Object...) Message.format}. - */ - I18nConversionCategory[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatBottom.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatBottom.java deleted file mode 100644 index 44637a30b81..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Internationalization Format String type system. Programmers should rarely - * write this type. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({I18nFormat.class, I18nInvalidFormat.class, I18nFormatFor.class}) -@DefaultFor(value = {TypeUseLocation.LOWER_BOUND}) -public @interface I18nFormatBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatFor.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatFor.java deleted file mode 100644 index 1dc4899c5e7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nFormatFor.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation indicates that when a string of the annotated type is passed as the first - * argument to {@link java.text.MessageFormat#format(String, Object...)}, then the expression that - * is an argument to the annotation can be passed as the remaining arguments, in varargs style. - * - *

The annotation is used to annotate a method to ensure that an argument is of a particular type - * indicated by a format string. - * - *

Example: - * - *

 static void method(@I18nFormatFor("#2") String format, Object... arg2) {...}
- *
- * method("{0, number}", 2);
- * - * This ensures that the second parameter ("#2") can be passed as the remaining arguments of {@link - * java.text.MessageFormat#format(String, Object...)}, when the first argument is {@code "format"}. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(I18nUnknownFormat.class) -public @interface I18nFormatFor { - /** - * Java expression that is an array that can be passed as the second argument to {@link - * java.text.MessageFormat#format(String, Object...)}, when the annotated String is the first - * argument. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nInvalidFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nInvalidFormat.java deleted file mode 100644 index c750d3267c7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nInvalidFormat.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation, attached to a {@link java.lang.String String} type, indicates that if the String - * is passed to {@link java.text.MessageFormat#format(String, Object...)}, an exception will result. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(I18nUnknownFormat.class) -public @interface I18nInvalidFormat { - /** - * Using a value of the annotated type as the first argument to {@link - * java.text.MessageFormat#format(String, Object...)} will lead to this exception message. - */ - String value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nMakeFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nMakeFormat.java deleted file mode 100644 index a9d66415a89..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nMakeFormat.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation is used internally to annotate {@link java.util.ResourceBundle#getString} - * indicating the checker to check if the given key exist in the translation file and annotate the - * result string with the correct format annotation according to the corresponding key's value. This - * is done in {@link org.checkerframework.checker.i18nformatter.I18nFormatterTransfer} - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface I18nMakeFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nUnknownFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nUnknownFormat.java deleted file mode 100644 index f8dbc7d0552..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nUnknownFormat.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The top qualifier. - * - *

A type annotation indicating that the run-time value might or might not be a valid i18n format - * string. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface I18nUnknownFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nValidFormat.java b/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nValidFormat.java deleted file mode 100644 index d43146b2775..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/i18nformatter/qual/I18nValidFormat.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.checkerframework.checker.i18nformatter.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation is used internally to annotate {@link - * org.checkerframework.checker.i18nformatter.I18nFormatUtil#isFormat}. - * - * @checker_framework.manual #i18n-formatter-checker Internationalization Format String Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface I18nValidFormat {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOf.java deleted file mode 100644 index 6db1d09de60..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOf.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.PostconditionAnnotation; -import org.checkerframework.framework.qual.QualifierArgument; - -/** - * Indicates that the value expressions evaluate to an integer whose value is less than the lengths - * of all the given sequences, if the method terminates successfully. - * - *

Consider the following example, from the Index Checker's regression tests: - * - *

- * {@code @EnsuresLTLengthOf(value = "end", targetValue = "array", offset = "#1 - 1")
- *  public void shiftIndex(@NonNegative int x) {
- *      int newEnd = end - x;
- *      if (newEnd < 0) throw new RuntimeException();
- *      end = newEnd;
- *  }
- * }
- * 
- * - * where {@code end} is annotated as {@code @NonNegative @LTEqLengthOf("array") int end;} - * - *

This method guarantees that {@code end} has type {@code @LTLengthOf(value="array", offset="x - - * 1")} after the method returns. This is useful in cases like this one: - * - *

{@code
- * public void useShiftIndex(@NonNegative int x) {
- *    // :: error: (argument.type.incompatible)
- *    Arrays.fill(array, end, end + x, null);
- *    shiftIndex(x);
- *    Arrays.fill(array, end, end + x, null);
- * }
- * }
- * - * The first call to {@code Arrays.fill} is rejected (hence the comment about an error). But, after - * calling {@code shiftIndex(x)}, {@code end} has an annotation that allows the {@code end + x} to - * be accepted as {@code @LTLengthOf("array")}. - * - * @see LTLengthOf - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PostconditionAnnotation(qualifier = LTLengthOf.class) -@InheritedAnnotation -@Repeatable(EnsuresLTLengthOf.List.class) -public @interface EnsuresLTLengthOf { - /** - * The Java expressions that are less than the length of the given sequences on successful - * method termination. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - @JavaExpression - String[] value(); - - /** - * Sequences, each of which is longer than the each of the expressions' value on successful - * method termination. - */ - @JavaExpression - @QualifierArgument("value") - String[] targetValue(); - - /** - * This expression plus each of the value expressions is less than the length of the sequence on - * successful method termination. The {@code offset} element must ether be empty or the same - * length as {@code targetValue}. - * - * @return the offset expressions - */ - @JavaExpression - @QualifierArgument("offset") - String[] offset() default {}; - - /** - * A wrapper annotation that makes the {@link EnsuresLTLengthOf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresLTLengthOf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @PostconditionAnnotation(qualifier = LTLengthOf.class) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresLTLengthOf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOfIf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOfIf.java deleted file mode 100644 index 56b27f70198..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/EnsuresLTLengthOfIf.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.ConditionalPostconditionAnnotation; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.QualifierArgument; - -/** - * Indicates that the given expressions evaluate to an integer whose value is less than the lengths - * of all the given sequences, if the method returns the given result (either true or false). - * - *

As an example, consider the following method: - * - *

- *      @EnsuresLTLengthOfIf(
- *          expression = "end",
- *          result = true,
- *          targetValue = "array",
- *          offset = "#1 - 1"
- *      )
- *      public boolean tryShiftIndex(@NonNegative int x) {
- *          int newEnd = end - x;
- *          if (newEnd < 0) {
- *             return false;
- *          }
- *          end = newEnd;
- *          return true;
- *      }
- * 
- * - * Calling this function ensures that the field {@code end} of the {@code this} object is of type - * {@code @LTLengthOf(value = "array", offset = "x - 1")}, for the value {@code x} that is passed as - * the argument. This allows the Index Checker to verify that {@code end + x} is an index into - * {@code array} in the following code: - * - *
- *      public void useTryShiftIndex(@NonNegative int x) {
- *          if (tryShiftIndex(x)) {
- *              Arrays.fill(array, end, end + x, null);
- *          }
- *      }
- * 
- * - * @see LTLengthOf - * @see EnsuresLTLengthOf - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@ConditionalPostconditionAnnotation(qualifier = LTLengthOf.class) -@InheritedAnnotation -@Repeatable(EnsuresLTLengthOfIf.List.class) -public @interface EnsuresLTLengthOfIf { - /** - * Java expression(s) that are less than the length of the given sequences after the method - * returns the given result. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** The return value of the method that needs to hold for the postcondition to hold. */ - boolean result(); - - /** - * Sequences, each of which is longer than each of the expressions' value after the method - * returns the given result. - */ - @JavaExpression - @QualifierArgument("value") - String[] targetValue(); - - /** - * This expression plus each of the expressions is less than the length of the sequence after - * the method returns the given result. The {@code offset} element must ether be empty or the - * same length as {@code targetValue}. - * - * @return the offset expressions - */ - @JavaExpression - @QualifierArgument("offset") - String[] offset() default {}; - - /** - * A wrapper annotation that makes the {@link EnsuresLTLengthOfIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresLTLengthOfIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @ConditionalPostconditionAnnotation(qualifier = LTLengthOf.class) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresLTLengthOfIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/GTENegativeOne.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/GTENegativeOne.java deleted file mode 100644 index 034dc325d92..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/GTENegativeOne.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer greater than or equal to -1. ("GTE" stands for - * ``Greater Than or Equal to''.) - * - *

As an example use case, consider the definition of the read() method in java.io.InputStream: - * - *

- *
- *      Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255.
- *      If no byte is available because the end of the stream has been reached, the value -1 is returned.
- *      This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
- *      A subclass must provide an implementation of this method.
- *
- *      Returns: the next byte of data, or -1 if the end of the stream is reached.
- *      Throws: IOException - if an I/O error occurs.
- *
- *     {@code public abstract @GTENegativeOne int read() throws IOException;}
- * 
- * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({LowerBoundUnknown.class}) -public @interface GTENegativeOne {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/HasSubsequence.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/HasSubsequence.java deleted file mode 100644 index 4c8c22c4848..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/HasSubsequence.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; - -/** - * The annotated sequence contains a subsequence that is equal to the value of some other - * expression. This annotation permits the Upper Bound Checker to translate indices for one sequence - * into indices for the other sequence. - * - *

Consider the following example: - * - *


- *  class IntSubArray {
- *    {@literal @}HasSubsequence(subsequence = "this", from = "this.start", to = "this.end")
- *    int [] array;
- *    {@literal @}IndexFor("array") int start;
- *    {@literal @}IndexOrHigh("array") int end;
- *  }
- * 
- * - * The above annotations mean that the value of an {@code IntSubArray} object is equal to a - * subsequence of its {@code array} field. - * - *

These annotations imply the following relationships among {@code @}{@link IndexFor} - * annotations: - * - *

    - *
  • If {@code i} is {@code @IndexFor("this")}, then {@code start + i} is - * {@code @IndexFor("array")}. - *
  • If {@code j} is {@code @IndexFor("array")}, then {@code j - start } is - * {@code @IndexFor("this")}. - *
- * - * When assigning an array {@code a} to {@code array}, 4 facts need to be true: - * - *
    - *
  • {@code start} is {@code @NonNegative}. - *
  • {@code end} is {@code @LTEqLengthOf("a")}. - *
  • {@code start} is {@code @LessThan("end + 1")}. - *
  • the value of {@code this} equals {@code array[start..end-1]} - *
- * - * The Index Checker verifies the first 3 facts, but always issues a warning because it cannot prove - * the 4th fact. The programmer should should manually verify that the {@code subsequence} field is - * equal to the given subsequence and then suppress the warning. - * - *

For an example of how this annotation is used in practice, see the test GuavaPrimitives.java - * in /checker/tests/index/. - * - *

This annotation may only be written on fields. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD}) -public @interface HasSubsequence { - /** An expression that evaluates to the subsequence. */ - @JavaExpression - String subsequence(); - - /** The index into this where the subsequence starts. */ - @JavaExpression - String from(); - - /** The index into this, immediately past where the subsequence ends. */ - @JavaExpression - String to(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexFor.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexFor.java deleted file mode 100644 index f8795553996..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexFor.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An integer that can be used to index any of the given sequences. - * - *

For example, an expression with type {@code @IndexFor({"a", "b"})} is non-negative and is less - * than both {@code a.length} and {@code b.length}. The sequences {@code a} and {@code b} might have - * different lengths. - * - *

The - * {@code String.charAt(int)} method is declared as - * - *

{@code
- * class String {
- *   char charAt(@IndexFor("this") index) { ... }
- * }
- * }
- * - *

Writing {@code @IndexFor("arr")} is equivalent to writing {@link NonNegative @NonNegative} - * {@link LTLengthOf @LTLengthOf("arr")}, and that is how it is treated internally by the checker. - * Thus, if you write an {@code @IndexFor("arr")} annotation, you might see warnings about - * {@code @NonNegative} or {@code @LTLengthOf}. - * - * @see NonNegative - * @see LTLengthOf - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface IndexFor { - /** Sequences that the annotated expression is a valid index for. */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrHigh.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrHigh.java deleted file mode 100644 index e00fdaae2b1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrHigh.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An integer that, for each of the given sequences, is either a valid index or is equal to the - * sequence's length. - * - *

The - * {@code Arrays.binarySearch} method is declared as - * - *

{@code
- * class Arrays {
- *   int binarySearch(Object[] a, @IndexFor("#1") int fromIndex, @IndexOrHigh("#1") int toIndex, Object key)
- * }
- * }
- * - *

Writing {@code @IndexOrHigh("arr")} is equivalent to writing {@link NonNegative @NonNegative} - * {@link LTEqLengthOf @LTEqLengthOf("arr")}, and that is how it is treated internally by the - * checker. Thus, if you write an {@code @IndexFor("arr")} annotation, you might see warnings about - * {@code @NonNegative} or {@code @LTEqLengthOf}. - * - * @see NonNegative - * @see LTLengthOf - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface IndexOrHigh { - /** - * Sequences that the annotated expression is a valid index for or is equal to the lengeth of. - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrLow.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrLow.java deleted file mode 100644 index b73b548d583..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/IndexOrLow.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An integer that is either -1 or is a valid index for each of the given sequences. - * - *

The - * {@code String.indexOf(String)} method is declared as - * - *


- *   class String {
- *    {@literal @}IndexOrLow("this") int indexOf(String str) { ... }
- *   }
- * 
- * - *

Writing {@code @IndexOrLow("arr")} is equivalent to writing {@link - * GTENegativeOne @GTENegativeOne} {@link LTLengthOf @LTLengthOf("arr")}, and that is how it is - * treated internally by the checker. Thus, if you write an {@code @IndexOrLow("arr")} annotation, - * you might see warnings about {@code @GTENegativeOne} or {@code @LTLengthOf}. - * - * @see GTENegativeOne - * @see LTLengthOf - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface IndexOrLow { - /** Sequences that the annotated expression is a valid index for (or it's -1). */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTEqLengthOf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTEqLengthOf.java deleted file mode 100644 index f64e0b4b18e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTEqLengthOf.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer whose value is less than or equal to the lengths - * of all the given sequences. ("LTEq" stands for "Less than or equal to".) - * - *

For example, an expression with type {@code @LTLengthOf({"a", "b"})} is less than or equal to - * both {@code a.length} and {@code b.length}. The sequences {@code a} and {@code b} might have - * different lengths. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UpperBoundUnknown.class) -public @interface LTEqLengthOf { - /** Sequences, each of which is at least as long as the annotated expression's value. */ - @JavaExpression - public String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTLengthOf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTLengthOf.java deleted file mode 100644 index 2e9acb6e818..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTLengthOf.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer whose value is less than the lengths of all the - * given sequences. This annotation is rarely used; it is more common to use {@code @}{@link - * IndexFor}. - * - *

For example, an expression with type {@code @LTLengthOf({"a", "b"})} is less than both {@code - * a.length} and {@code b.length}. The sequences {@code a} and {@code b} might have different - * lengths. - * - *

The {@code @LTLengthOf} annotation takes an optional {@code offset} element. If it is - * nonempty, then the annotated expression plus the expression in {@code offset[i]} is less than the - * length of the sequence specified by {@code value[i]}. - * - *

For example, suppose expression {@code e} has type {@code @LTLengthOf(value = {"a", "b"}, - * offset = {"-1", "x"})}. Then {@code e - 1} is less than {@code a.length}, and {@code e + x} is - * less than {@code b.length}. - * - *

It is an error to write a {@code LTLengthOf} annotation with a different number of sequences - * and offsets, if an offset is included. - * - * @see IndexFor - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(LTEqLengthOf.class) -public @interface LTLengthOf { - /** Sequences, each of which is longer than the annotated expression's value. */ - @JavaExpression - public String[] value(); - - /** - * This expression plus the annotated expression is less than the length of the sequence. The - * {@code offset} element must ether be empty or the same length as {@code value}. - * - *

The expressions in {@code offset} may be addition/subtraction of any number of Java - * expressions. For example, {@code @LessThanLengthOf(value = "a", offset = "x + y + 2"}}. - */ - @JavaExpression - String[] offset() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTOMLengthOf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTOMLengthOf.java deleted file mode 100644 index 0754c4f91a0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LTOMLengthOf.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer whose value is at least 2 less than the lengths - * of all the given sequences. - * - *

For example, an expression with type {@code @LTLengthOf({"a", "b"})} is less than or equal to - * both {@code a.length-2} and {@code b.length-2}. Equivalently, it is less than both {@code - * a.length-1} and {@code b.length-1}. The sequences {@code a} and {@code b} might have different - * lengths. - * - *

In the annotation's name, "LTOM" stands for "less than one minus". - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(LTLengthOf.class) -public @interface LTOMLengthOf { - /** - * Sequences, each of whose lengths is at least 1 larger than the annotated expression's value. - */ - @JavaExpression - public String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LengthOf.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LengthOf.java deleted file mode 100644 index 643ca431281..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LengthOf.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An integer that, for each of the given sequences, is equal to the sequence's length. - * - *

This is treated as an {@link IndexOrHigh} annotation internally. This is an implementation - * detail that may change in the future, when this type may be used to implement more precise - * refinements. - * - *

The usual use case for the {@code LengthOf} annotation is in the defintions of custom - * collections. Consider the signature of java.lang.String#length(): - * - *

- *
- *     {@code public @LengthOf("this") int length()}
- * 
- * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -// Has target of METHOD so that it is stored as a declaration annotation and the SameLen Checker can -// read it. -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER, ElementType.METHOD}) -public @interface LengthOf { - /** Sequences that the annotated expression is equal to the length of. */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThan.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThan.java deleted file mode 100644 index 54ca4a7bafc..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThan.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the relationship between values with a byte, short, char, int, or long - * type. - * - *

If an expression's type has this annotation, then at run time, the expression evaluates to a - * value that is less than the value of the expression in the annotation. - * - *

{@code @LessThan("end + 1")} is equivalent to {@code @LessThanOrEqual("end")}. - * - *

Subtyping: - * - *

    - *
  • {@code @LessThan({"a", "b"}) <: @LessThan({"a"})} - *
  • {@code @LessThan({"a", "b"})} is not related to {@code @LessThan({"a", "c"})}. - *
- * - * @checker_framework.manual #index-inequalities Index Chceker Inequalities - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({LessThanUnknown.class}) -// TODO: I chose to implement less than rather than greater than because in most of the case studies -// false positives, the bigger value is final or effectively final, so it can appear in a dependent -// annotation without causing soundness issues. -public @interface LessThan { - /** - * The annotated expression's value is less than this expression. - * - *

The expressions in {@code value} may be addition/subtraction of any number of Java - * expressions. For example, {@code @LessThan(value = "x + y + 2"}}. - * - *

The expression in {@code value} must be final or constant or the addition/subtract of - * final or constant expressions. - */ - @JavaExpression - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanBottom.java deleted file mode 100644 index 422f87e6806..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanBottom.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The bottom type in the LessThan type system. Programmers should rarely write this type. - * - * @checker_framework.manual #index-inequalities Index Chceker Inequalities - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({LessThan.class}) -public @interface LessThanBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanUnknown.java deleted file mode 100644 index 3b456c3469d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LessThanUnknown.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The top qualifier for the LessThan type hierarchy. It indicates that no other expression is known - * to be larger than the annotated one. - * - * @checker_framework.manual #index-inequalities Index Chceker Inequalities - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface LessThanUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundBottom.java deleted file mode 100644 index 3cfe92bdd59..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundBottom.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type of the lower bound type system. A variable annotated with this value cannot take - * on any integer values. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({Positive.class}) -public @interface LowerBoundBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundUnknown.java deleted file mode 100644 index f9c9031d5e8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/LowerBoundUnknown.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to value that might be -2 or lower. This is the top type for - * the Lower Bound type system. It should not have to be written by a programmer. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface LowerBoundUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/NegativeIndexFor.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/NegativeIndexFor.java deleted file mode 100644 index 310ff971e19..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/NegativeIndexFor.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression is between {@code -1} and {@code -a.length - 1}, inclusive, for each - * sequence {@code a} listed in the annotation. - * - *

This type should rarely (if ever) be written by programmers. It is inferred by the - * SearchIndexChecker when the result of a call to one of the JDK's binary search methods (like - * {@code Arrays.binarySearch}) is known to be less than zero. For example, consider the following - * code: - * - *

- *
- *     int index = Arrays.binarySearch(array, target);
- *     if (index < 0) {
- *          // index's type here is @NegativeIndexFor("array")
- *          index = index * -1;
- *          // now index's type is @IndexFor("array")
- *     }
- * 
- * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SearchIndexFor.class) -public @interface NegativeIndexFor { - /** - * Sequences for which this value is a "negative index"; that is, the expression is in the range - * {@code -1} to {@code -a.length - 1}, inclusive, for each sequence {@code a} given here. - */ - @JavaExpression - public String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/NonNegative.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/NonNegative.java deleted file mode 100644 index 40806f19a32..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/NonNegative.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer greater than or equal to 0. - * - *

Consider the following example, from a collection that wraps an array. This constructor - * creates the {@code delegate} array, which must have a non-negative size. - * - *

{@code
- * ArrayWrapper(@NonNegative int size) { delegate = new Object[size]; }
- * }
- * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({GTENegativeOne.class}) -public @interface NonNegative {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyIndex.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyIndex.java deleted file mode 100644 index fa5c811ee6c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyIndex.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Lower Bound and Upper Bound type systems. - * - *

Writing {@code @PolyIndex} is equivalent to writing {@link PolyUpperBound @PolyUpperBound} - * {@link PolyLowerBound @PolyLowerBound}, and that is how it is treated internally by the checker. - * Thus, if you write an {@code @PolyIndex} annotation, you might see warnings about - * {@code @PolyUpperBound} or {@code @PolyLowerBound}. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - * @see PolyUpperBound - * @see PolyLowerBound - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UpperBoundUnknown.class) -public @interface PolyIndex {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLength.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLength.java deleted file mode 100644 index 4d5123723a7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLength.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * Syntactic sugar for both @PolyValue and @PolySameLen. - * - * @see org.checkerframework.common.value.qual.PolyValue - * @see PolySameLen - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UpperBoundUnknown.class) -public @interface PolyLength {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLowerBound.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLowerBound.java deleted file mode 100644 index 824609a8f5e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyLowerBound.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Lower Bound type system. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(LowerBoundUnknown.class) -public @interface PolyLowerBound {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolySameLen.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolySameLen.java deleted file mode 100644 index 89e7fc431af..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolySameLen.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the SameLen type system. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(SameLenUnknown.class) -public @interface PolySameLen {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyUpperBound.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyUpperBound.java deleted file mode 100644 index c8eaa92a5d2..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/PolyUpperBound.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Upper Bound type system. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UpperBoundUnknown.class) -public @interface PolyUpperBound {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/Positive.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/Positive.java deleted file mode 100644 index 7321a024340..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/Positive.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer greater than or equal to 1. - * - *

As an example of a use-case for this type, consider the following code: - * - *

{@code
- * if (arr.length > 0) {
- *    int j = arr[arr.length - 1];
- * }
- * }
- * - * Without the knowing that {@code arr.length} is positive, the Index Checker cannot verify that - * accessing the last element of the array is safe - there might not be a last element! - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({NonNegative.class}) -public @interface Positive {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLen.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLen.java deleted file mode 100644 index ab5d54c8800..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLen.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression whose type has this annotation evaluates to a value that is a sequence, and that - * sequence has the same length as the given sequences. For example, if {@code b}'s type is - * annotated with {@code @SameLen("a")}, then {@code a} and {@code b} have the same length. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SameLenUnknown.class) -public @interface SameLen { - /** A list of other sequences with the same length. */ - @JavaExpression - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenBottom.java deleted file mode 100644 index df9b82b2a19..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenBottom.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the SameLen type system. Programmers should rarely write this type. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(SameLen.class) -public @interface SameLenBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenUnknown.java deleted file mode 100644 index f090c956e1b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SameLenUnknown.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This type represents any variable that isn't known to have the same length as another sequence. - * This is the top type of the Same Length type system. Programmers should not need to write this - * type. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface SameLenUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexBottom.java deleted file mode 100644 index 54ac9ebcb4d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexBottom.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Search Index type system. Programmers should rarely write this type. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(NegativeIndexFor.class) -public @interface SearchIndexBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexFor.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexFor.java deleted file mode 100644 index 227922e0211..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexFor.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to an integer whose length is between {@code -a.length - 1} - * and {@code a.length - 1}, inclusive, for all sequences {@code a} listed in the annotation. - * - *

This is the return type of {@link java.util.Arrays#binarySearch(Object[],Object) {@code - * Arrays.binarySearch}} in the JDK. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SearchIndexUnknown.class) -public @interface SearchIndexFor { - /** - * Sequences for which the annotated expression has the type of the result of a call to {@link - * java.util.Arrays#binarySearch(Object[],Object) {@code Arrays.binarySearch}}. - */ - @JavaExpression - public String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexUnknown.java deleted file mode 100644 index 75bc3432bf3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SearchIndexUnknown.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The top type for the SearchIndex type system. This indicates that the Index checker does not know - * any arrays that this integer is a {@link SearchIndexFor search index} for. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface SearchIndexUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexBottom.java deleted file mode 100644 index 797aea403e6..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexBottom.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Substring Index type system. Programmers should rarely write this type. - * - * @checker_framework.manual #index-substringindex Index Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(SubstringIndexFor.class) -public @interface SubstringIndexBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexFor.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexFor.java deleted file mode 100644 index 21dcfd9b17d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexFor.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The annotated expression evaluates to either -1 or a non-negative integer less than the lengths - * of all the given sequences. The annotation {@code @SubstringIndexFor(args)} is like - * {@literal @}{@link NonNegative} {@literal @}{@link LTLengthOf}(args), except that - * {@code @SubstringIndexFor(args)} additionally permits the value -1. - * - *

When multiple values or offsets are given, they are considered pairwise. For example, - * {@code @SubstringIndexFor(value={"a", "b"}, offset={"c", "d"})} is equivalent to writing both - * {@code @SubstringIndexFor(value="a", offset="c")} and {@code @SubstringIndexFor(value="b", - * offset="d")}. - * - *

The return types of JDK methods {@link java.lang.String#indexOf(String) String.indexOf} and - * {@link java.lang.String#lastIndexOf(String) String.lastIndexOf} are annotated - * {@code @SubstringIndexFor(value="this",offset="#1.length()-1")}. This means that the returned - * value is either -1 or it is less than or equal to the length of the receiver sequence minus the - * length of the sequence passed as the first argument. - * - *

The name of this annotation, "substring index for", is intended to mean that the annotated - * expression is a index of a substring (returned by {@code indexOf} or similar methods) for the - * specified sequence. - * - * @checker_framework.manual #index-substringindex Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SubstringIndexUnknown.class) -public @interface SubstringIndexFor { - /** - * Sequences, each of which is longer than the annotated expression plus the corresponding - * {@code offset}. (Exception: the annotated expression is also allowed to have the value -1.) - */ - @JavaExpression - public String[] value(); - - /** - * This expression plus the annotated expression is less than the length of the corresponding - * sequence in the {@code value} array. (Exception: the annotated expression is also allowed to - * have the value -1.) - * - *

The {@code offset} array must either be empty or the same length as {@code value}. - * - *

The expressions in {@code offset} may be addition/subtraction of any number of Java - * expressions. For example, {@code @SubstringIndexFor(value = "a", offset = "b.length() - 1")}. - */ - @JavaExpression - public String[] offset(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexUnknown.java deleted file mode 100644 index 94c4480d38a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/SubstringIndexUnknown.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The top type for the Substring Index type system. This indicates that the Index Checker does not - * know any sequences that this integer is a {@link SubstringIndexFor substring index} for. - * - * @checker_framework.manual #index-substringindex Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface SubstringIndexUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundBottom.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundBottom.java deleted file mode 100644 index 3b6bb74880f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundBottom.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Upper Bound type system. Programmers should rarely write this type. - * - * @checker_framework.manual #index-checker Index Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(LTOMLengthOf.class) -public @interface UpperBoundBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundUnknown.java deleted file mode 100644 index 8548028b56e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/index/qual/UpperBoundUnknown.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.index.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A variable not known to have a relation to any sequence length. This is the top type of the Upper - * Bound type system. Programmers should not need to write this type. - * - * @checker_framework.manual #index-checker Index Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UpperBoundUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/FBCBottom.java b/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/FBCBottom.java deleted file mode 100644 index 23e2ff4a4cf..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/FBCBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.initialization.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the initialization type system. Programmers should rarely write this type. - * - *

The "FBC" in the name stands for "Freedom Before Commitment", an approach that the - * Initialization Checker builds upon. - * - * @checker_framework.manual #initialization-checker Initialization Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({UnderInitialization.class, Initialized.class}) -public @interface FBCBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/Initialized.java b/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/Initialized.java deleted file mode 100644 index 48c2bb426ab..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/Initialized.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.checkerframework.checker.initialization.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * This type qualifier belongs to the freedom-before-commitment initialization tracking type-system. - * This type-system is not used on its own, but in conjunction with some other type-system that - * wants to ensure safe initialization. For instance, {@link - * org.checkerframework.checker.nullness.NullnessChecker} uses freedom-before-commitment to track - * initialization of {@link NonNull} fields. - * - *

This type qualifier indicates that the object has been fully initialized; reading fields from - * such objects is fully safe and yields objects of the correct type. - * - * @checker_framework.manual #initialization-checker Initialization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownInitialization.class) -@DefaultQualifierInHierarchy -@DefaultFor({ - TypeUseLocation.IMPLICIT_UPPER_BOUND, - TypeUseLocation.IMPLICIT_LOWER_BOUND, - TypeUseLocation.EXCEPTION_PARAMETER -}) -public @interface Initialized {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/NotOnlyInitialized.java b/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/NotOnlyInitialized.java deleted file mode 100644 index 89dc52e996f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/NotOnlyInitialized.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.initialization.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A declaration annotation for fields that indicates that a client might observe the field storing - * values that are {@link org.checkerframework.checker.initialization.qual.Initialized}, {@link - * org.checkerframework.checker.initialization.qual.UnderInitialization}, or {@link - * org.checkerframework.checker.initialization.qual.UnknownInitialization}, regardless of the - * initialization type annotation on the field's type. This is necessary to allow circular - * initialization as supported by freedom-before-commitment. - * - * @checker_framework.manual #initialization-checker Initialization Checker - */ -@Documented -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface NotOnlyInitialized {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnderInitialization.java b/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnderInitialization.java deleted file mode 100644 index dc120906431..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnderInitialization.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.checkerframework.checker.initialization.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This type qualifier indicates that an object is (definitely) in the process of being - * constructed/initialized. The type qualifier also indicates how much of the object has already - * been initialized. Please see the manual for examples of how to use the annotation (the link - * appears below). - * - *

Consider a class {@code B} that is a subtype of {@code A}. At the beginning of the constructor - * of {@code B}, {@code this} has the type {@code @UnderInitialization(A.class)}, since all fields - * of {@code A} have been initialized by the super-constructor. Inside the constructor body, as soon - * as all fields of {@code B} are initialized, then the type of {@code this} changes to - * {@code @UnderInitialization(B.class)}. - * - *

Code is allowed to store potentially not-fully-initialized objects in the fields of a - * partially-initialized object, as long as all initialization is complete by the end of the - * constructor. - * - *

What type qualifiers on the field are considered depends on the checker; for instance, the - * {@link org.checkerframework.checker.nullness.NullnessChecker} considers {@link NonNull}. The - * initialization type system is not used on its own, but in conjunction with some other type-system - * that wants to ensure safe initialization. - * - *

When an expression has type {@code @UnderInitialization}, then no aliases that are typed - * differently may exist. - * - * @checker_framework.manual #initialization-checker Initialization Checker - * @checker_framework.manual #underinitialization-examples Examples of the @UnderInitialization - * annotation - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownInitialization.class) -public @interface UnderInitialization { - /** - * The type-frame down to which the expression (of this type) has been initialized at least - * (inclusive). That is, an expression of type {@code @UnderInitialization(T.class)} has all - * type-frames initialized starting at {@code Object} down to (and including) {@code T}. - * - * @return the type whose fields are fully initialized - */ - Class value() default Object.class; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnknownInitialization.java b/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnknownInitialization.java deleted file mode 100644 index cf24af714f5..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/initialization/qual/UnknownInitialization.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.checkerframework.checker.initialization.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * This type qualifier indicates how much of an object has been fully initialized. An object is - * fully initialized when each of its fields contains a value that satisfies the field's - * declaration. - * - *

An expression of type {@code @UnknownInitialization(T.class)} refers to an object that has all - * fields of {@code T} (and any super-classes) initialized. Just {@code @UnknownInitialization} is - * equivalent to {@code @UnknownInitialization(Object.class)}. Please see the manual for examples of - * how to use the annotation (the link appears below). - * - *

Reading a field of an object of type {@code @UnknownInitialization} might yield a value that - * does not correspond to the declared type qualifier for that field. For instance, consider a - * non-null field: - * - *

@NonNull Object f;
- * - * In a partially-initialized object, field {@code f} might be {@code null} despite its - * {@literal @}{@link NonNull} type annotation. - * - *

What type qualifiers on the field are considered depends on the checker; for instance, the - * {@link org.checkerframework.checker.nullness.NullnessChecker} considers {@link NonNull}. The - * initialization type system is not used on its own, but in conjunction with some other type-system - * that wants to ensure safe initialization. - * - * @checker_framework.manual #initialization-checker Initialization Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultFor({TypeUseLocation.LOCAL_VARIABLE, TypeUseLocation.RESOURCE_VARIABLE}) -public @interface UnknownInitialization { - /** - * The type-frame down to which the expression (of this type) has been initialized at least - * (inclusive). That is, an expression of type {@code @UnknownInitialization(T.class)} has all - * type-frames initialized starting at {@code Object} down to (and including) {@code T}. - * - * @return the type whose fields are fully initialized - */ - Class value() default Object.class; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/CompareToMethod.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/CompareToMethod.java deleted file mode 100644 index 8fc5212de46..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/CompareToMethod.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * Method declaration annotation that indicates a method has a specification like {@code - * compareTo()} or {@code compare()}. The Interning Checker permits use of {@code if (this == arg) { - * return 0; }} or {@code if (arg1 == arg2) { return 0; }} within the body. - * - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@InheritedAnnotation -public @interface CompareToMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/EqualsMethod.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/EqualsMethod.java deleted file mode 100644 index 727024e2759..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/EqualsMethod.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * Method declaration annotation that indicates a method has a specification like {@code equals()}. - * The Interning Checker permits use of {@code this == arg} within the body. Can also be applied to - * a static two-argument method, in which case {@code arg1 == arg2} is permitted within the body. - * - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@InheritedAnnotation -public @interface EqualsMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/FindDistinct.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/FindDistinct.java deleted file mode 100644 index adda1fa7e68..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/FindDistinct.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This formal parameter annotation indicates that the method searches for the given value, using - * reference equality ({@code ==}). - * - *

Within the method, the formal parameter should be compared with {@code ==} rather than with - * {@code equals()}. However, any value may be passed to the method, and the Interning Checker does - * not verify that use of {@code ==} within the method is logically correct. - * - * @see org.checkerframework.checker.interning.InterningChecker - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PARAMETER}) -public @interface FindDistinct {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternMethod.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternMethod.java deleted file mode 100644 index 9157a728860..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternMethod.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * Method declaration annotation used to indicate that this method may be invoked on an uninterned - * object and that it returns an interned object. - * - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -@InheritedAnnotation -public @interface InternMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/Interned.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/Interned.java deleted file mode 100644 index 946fb68c0b9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/Interned.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeKind; - -/** - * Indicates that a variable has been interned, i.e., that the variable refers to the canonical - * representation of an object. - * - *

To specify that all objects of a given type are interned, annotate the class declaration: - * - *

- *   public @Interned class MyInternedClass { ... }
- * 
- * - * This is equivalent to annotating every use of MyInternedClass, in a declaration or elsewhere. For - * example, enum classes are implicitly so annotated. - * - *

This annotation is associated with the {@link - * org.checkerframework.checker.interning.InterningChecker}. - * - * @see org.checkerframework.checker.interning.InterningChecker - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownInterned.class) -@QualifierForLiterals({LiteralKind.PRIMITIVE, LiteralKind.STRING}) // everything but NULL -@DefaultFor( - typeKinds = { - TypeKind.BOOLEAN, - TypeKind.BYTE, - TypeKind.CHAR, - TypeKind.DOUBLE, - TypeKind.FLOAT, - TypeKind.INT, - TypeKind.LONG, - TypeKind.SHORT - }) -public @interface Interned {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternedDistinct.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternedDistinct.java deleted file mode 100644 index 7c6aa725c29..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/InternedDistinct.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Indicates that no other value is {@code equals()} to the given value. Therefore, it is correct to - * use == to test an InternedDistinct value for equality against any other value. - * - *

This is a stronger property than {@link Interned}, but a weaker property than every value of a - * Java type being interned. - * - * @see org.checkerframework.checker.interning.InterningChecker - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Interned.class) -@DefaultFor(value = {TypeUseLocation.LOWER_BOUND}) -public @interface InternedDistinct {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/PolyInterned.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/PolyInterned.java deleted file mode 100644 index fb657e40706..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/PolyInterned.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Interning type system. - * - *

Any method written using @PolyInterned conceptually has two versions: one in which every - * instance of @PolyInterned has been replaced by @Interned, and one in which every instance - * of @PolyInterned has been erased. - * - * @checker_framework.manual #interning-checker Interning Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownInterned.class) -public @interface PolyInterned {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UnknownInterned.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UnknownInterned.java deleted file mode 100644 index e170645f2af..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UnknownInterned.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The top qualifier for the Interning Checker. It indicates lack of knowledge about whether values - * are interned or not. It is not written by programmers, but is used internally by the type system. - * - *

This annotation is associated with the {@link - * org.checkerframework.checker.interning.InterningChecker}. - * - * @see org.checkerframework.checker.interning.InterningChecker - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownInterned {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UsesObjectEquals.java b/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UsesObjectEquals.java deleted file mode 100644 index d4b734e9557..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/interning/qual/UsesObjectEquals.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.checker.interning.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Class declaration to indicate the class does not override {@code equals(Object)}, and therefore - * {@code a.equals(b)} and {@code a == b} behave identically. - * - *

A class may be annotated @UsesObjectEquals if neither it, nor any of its supertypes or - * subtypes, overrides {@code equals}. Therefore, it cannot be written on {@code Object} itself. It - * is most commonly written on a direct subclass of {@code Object}. - * - *

This annotation is associated with the {@link - * org.checkerframework.checker.interning.InterningChecker}. - * - * @see org.checkerframework.checker.interning.InterningChecker - * @checker_framework.manual #interning-checker Interning Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -public @interface UsesObjectEquals {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeld.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeld.java deleted file mode 100644 index f2186a1656e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeld.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.PostconditionAnnotation; - -/** - * Indicates that the given expressions are held if the method terminates successfully. - * - * @see EnsuresLockHeldIf - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #ensureslockheld-examples Example use of @EnsuresLockHeld - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PostconditionAnnotation(qualifier = LockHeld.class) -@InheritedAnnotation -@Repeatable(EnsuresLockHeld.List.class) -public @interface EnsuresLockHeld { - /** - * Returns Java expressions whose values are locks that are held after successful method - * termination. - * - * @return Java expressions whose values are locks that are held after successful method - * termination - * @see Syntax of - * Java expressions - */ - String[] value(); - - /** - * A wrapper annotation that makes the {@link EnsuresLockHeld} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresLockHeld} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @PostconditionAnnotation(qualifier = LockHeld.class) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresLockHeld[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeldIf.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeldIf.java deleted file mode 100644 index 5b5c264edaa..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/EnsuresLockHeldIf.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.ConditionalPostconditionAnnotation; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * Indicates that the given expressions are held if the method terminates successfully and returns - * the given result (either true or false). - * - * @see EnsuresLockHeld - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #ensureslockheld-examples Example use of @EnsuresLockHeldIf - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@ConditionalPostconditionAnnotation(qualifier = LockHeld.class) -@InheritedAnnotation -@Repeatable(EnsuresLockHeldIf.List.class) -public @interface EnsuresLockHeldIf { - /** - * Returns Java expressions whose values are locks that are held after the method returns the - * given result. - * - * @return Java expressions whose values are locks that are held after the method returns the - * given result - * @see Syntax of - * Java expressions - */ - // It would be clearer for users if this field were named "lock". - // However, method ContractUtils.getConditionalPostconditions in the CF implementation assumes - // that conditional postconditions have a field named "expression". - String[] expression(); - - /** - * Returns the return value of the method under which the postconditions hold. - * - * @return the return value of the method under which the postconditions hold - */ - boolean result(); - - /** - * A wrapper annotation that makes the {@link EnsuresLockHeldIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresLockHeldIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @ConditionalPostconditionAnnotation(qualifier = LockHeld.class) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresLockHeldIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardSatisfied.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardSatisfied.java deleted file mode 100644 index 0bed9f5750b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardSatisfied.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * If a variable {@code x} has type {@code @GuardSatisfied}, then all lock expressions for {@code - * x}'s value are held. - * - *

Written on a formal parameter (including the receiver), this annotation indicates that the - * {@literal @}{@link GuardedBy} type for the corresponding actual argument at the method call site - * is unknown at the method definition site, but any lock expressions that guard it are known to be - * held prior to the method call. - * - *

For example, the formal parameter of the String copy constructor, {@link String#String(String - * s)}, is annotated with {@code @GuardSatisfied}. This requires that all locks guarding the actual - * argument are held when the constructor is called. However, the definition of the constructor does - * not need to know what those locks are (and it cannot know, because the constructor can be called - * by arbitrary code). - * - * @see GuardedBy - * @see Holding - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-checker-polymorphism-example Lock Checker polymorphism example - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE_USE) -@TargetLocations({TypeUseLocation.RECEIVER, TypeUseLocation.PARAMETER, TypeUseLocation.RETURN}) -@SubtypeOf(GuardedByUnknown.class) // TODO: Should @GuardSatisfied be in its own hierarchy? -public @interface GuardSatisfied { - /** - * The index on the GuardSatisfied polymorphic qualifier. Defaults to -1 so that the user can - * write any index starting from 0. - */ - int value() default -1; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedBy.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedBy.java deleted file mode 100644 index 5e7b74902c0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedBy.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeKind; -import org.checkerframework.framework.qual.TypeUseLocation; -import org.checkerframework.framework.qual.UpperBoundFor; - -/** - * Indicates that a thread may dereference the value referred to by the annotated variable only if - * the thread holds all the given lock expressions. - * - *

{@code @GuardedBy({})} is the default type qualifier. - * - *

The argument is a string or set of strings that indicates the expression(s) that must be held, - * using the syntax of - * Java expressions described in the manual. The expressions evaluate to an intrinsic (built-in, - * synchronization) monitor or an explicit {@link java.util.concurrent.locks.Lock}. The expression - * {@code ""} is also permitted; the type {@code @GuardedBy("") Object o} indicates that - * the value referenced by {@code o} is guarded by the intrinsic (monitor) lock of the value - * referenced by {@code o}. - * - *

Two {@code @GuardedBy} annotations with different argument expressions are unrelated by - * subtyping. - * - * @see Holding - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-examples-guardedby Example use of @GuardedBy - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(GuardedByUnknown.class) -@DefaultQualifierInHierarchy -// These are required because the default for local variables is @GuardedByUnknown, but if the local -// variable is one of these type kinds, the default should be @GuardedByUnknown. -@DefaultFor( - value = {TypeUseLocation.EXCEPTION_PARAMETER, TypeUseLocation.UPPER_BOUND}, - typeKinds = { - TypeKind.BOOLEAN, - TypeKind.BYTE, - TypeKind.CHAR, - TypeKind.DOUBLE, - TypeKind.FLOAT, - TypeKind.INT, - TypeKind.LONG, - TypeKind.SHORT - }, - types = {String.class, Void.class}) -@UpperBoundFor( - typeKinds = { - TypeKind.BOOLEAN, - TypeKind.BYTE, - TypeKind.CHAR, - TypeKind.DOUBLE, - TypeKind.FLOAT, - TypeKind.INT, - TypeKind.LONG, - TypeKind.SHORT - }, - types = String.class) -public @interface GuardedBy { - /** - * The Java value expressions that need to be held. - * - * @see Syntax of - * Java expressions - */ - @JavaExpression - String[] value() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByBottom.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByBottom.java deleted file mode 100644 index 91a66e38316..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the GuardedBy type system. Programmers should rarely write this type. - * - *

If a variable {@code x} has type {@code @GuardedByBottom}, then the value referred to by - * {@code x} is {@code null} (or dead code) and can never be dereferenced. - * - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({GuardedBy.class, GuardSatisfied.class}) -public @interface GuardedByBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByUnknown.java deleted file mode 100644 index 08def367e70..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/GuardedByUnknown.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * It is unknown what locks guard the value referred to by the annotated variable. Therefore, the - * value can never be dereferenced. The locks that guard it might not even be in scope (might be - * inaccessible) at the location where the {@code @GuardedByUnknown} annotation is written. - * - *

{@code @GuardedByUnknown} is the top of the GuardedBy qualifier hierarchy. Any value can be - * assigned into a variable of type {@code @GuardedByUnknown}. - * - * @checker_framework.manual #lock-checker Lock Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -public @interface GuardedByUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/Holding.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/Holding.java deleted file mode 100644 index 27bfc5786d2..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/Holding.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PreconditionAnnotation; - -/** - * Indicates a method precondition: the specified expressions must be held when the annotated method - * is invoked. - * - *

The argument is a string or set of strings that indicates the expression(s) that must be held, - * using the syntax of - * Java expressions described in the manual. The expressions evaluate to an intrinsic (built-in, - * synchronization) monitor, or an explicit {@link java.util.concurrent.locks.Lock}. - * - * @see GuardedBy - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-examples-holding Example use of @Holding - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PreconditionAnnotation(qualifier = LockHeld.class) -public @interface Holding { - /** - * The Java expressions that need to be held. - * - * @see Syntax of - * Java expressions - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockHeld.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockHeld.java deleted file mode 100644 index d77d8c0842f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockHeld.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that an expression is used as a lock and the lock is known to be held on the current - * thread. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - * @see LockPossiblyHeld - * @checker_framework.manual #lock-checker Lock Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) -@SubtypeOf(LockPossiblyHeld.class) // This is the bottom type in this hierarchy -@InvisibleQualifier -public @interface LockHeld {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java deleted file mode 100644 index f9216d78b8d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Indicates that an expression is not known to be {@link LockHeld}. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - * @see LockHeld - * @checker_framework.manual #lock-checker Lock Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) -@InvisibleQualifier -@SubtypeOf({}) // The top type in the hierarchy -@DefaultQualifierInHierarchy -@DefaultFor(value = TypeUseLocation.LOWER_BOUND, types = Void.class) -@QualifierForLiterals(LiteralKind.NULL) -public @interface LockPossiblyHeld {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockingFree.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockingFree.java deleted file mode 100644 index e9737ea034e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/LockingFree.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * The method neither acquires nor releases locks, nor do any of the methods that it calls. More - * specifically, the method is not {@code synchronized}, it contains no {@code synchronized} blocks, - * it contains no calls to {@code lock} or {@code unlock}, and it contains no calls to other - * non-{@code @LockingFree} methods. - * - *

{@code @LockingFree} provides a stronger guarantee than {@code @}{@link ReleasesNoLocks} and a - * weaker guarantee than {@code @}{@link SideEffectFree}. - * - * @see MayReleaseLocks - * @see ReleasesNoLocks - * @see SideEffectFree - * @see Pure - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-lockingfree-example Example use of @LockingFree - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@InheritedAnnotation -public @interface LockingFree {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/MayReleaseLocks.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/MayReleaseLocks.java deleted file mode 100644 index 80742faa252..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/MayReleaseLocks.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * The method, or one of the methods it calls, might release locks that were held prior to the - * method being called. You can write this when you are certain the method releases locks, or when - * you don't know whether the method releases locks. - * - * @see ReleasesNoLocks - * @see LockingFree - * @see org.checkerframework.dataflow.qual.SideEffectFree - * @see org.checkerframework.dataflow.qual.Pure - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-lockingfree-example Example use of @MayReleaseLocks - * @checker_framework.manual #annotating-libraries Annotating libraries - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@InheritedAnnotation -public @interface MayReleaseLocks {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/PolyGuardedBy.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/PolyGuardedBy.java deleted file mode 100644 index a0ff940d74c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/PolyGuardedBy.java +++ /dev/null @@ -1,37 +0,0 @@ -/* -TODO: Implement the functionality for @PolyGuardedBy and uncomment this. - -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the GuardedBy type system. - * Indicates that it is unknown what the guards are or whether they are held. - * An expression whose type is {@code @PolyGuardedBy} cannot be dereferenced. - * Hence, unlike for {@code @GuardSatisfied}, when an expression of type {@code @PolyGuardedBy} - * is the LHS of an assignment, the locks guarding the RHS do not need to be held. - * - *

Any method written using {@code @PolyGuardedBy} conceptually has an - * arbitrary number of versions: one in which every instance of - * {@code @PolyGuardedBy} has been replaced by {@code @}{@link GuardedByUnknown}, - * one in which every instance of {@code @PolyGuardedBy} has been - * replaced by {@code @}{@link GuardedByBottom}, and ones in which every - * instance of {@code @PolyGuardedBy} has been replaced by {@code @}{@link GuardedBy}, - * for every possible combination of map arguments. - * - * @see GuardedBy - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -// @PolymorphicQualifier(GuardedByUnknown.class) -// @Documented -// @Retention(RetentionPolicy.RUNTIME) -// @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -// public @interface PolyGuardedBy {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/ReleasesNoLocks.java b/src/java.base/share/classes/org/checkerframework/checker/lock/qual/ReleasesNoLocks.java deleted file mode 100644 index dc43239f906..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/lock/qual/ReleasesNoLocks.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.checkerframework.checker.lock.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.framework.qual.InheritedAnnotation; - -/** - * The method maintains a strictly nondecreasing lock held count on the current thread for any locks - * that were held prior to the method call. The same property must in general be true of all the - * methods it calls, which should themselves be annotated as {@code @ReleasesNoLocks} or a stronger - * annotation such as {@code @}{@link SideEffectFree}. - * - *

The method might acquire locks but then release them, or might acquire locks but not release - * them (in which case it should also be annotated with {@literal @}{@link EnsuresLockHeld} or - * {@literal @}{@link EnsuresLockHeldIf}). - * - *

This is the default for methods being type-checked that have no {@code @}{@link LockingFree}, - * {@code @}{@link MayReleaseLocks}, {@code @}{@link SideEffectFree}, or {@code @}{@link Pure} - * annotation. - * - *

{@code @ReleasesNoLocks} provides a guarantee unlike {@code @}{@link MayReleaseLocks}, which - * provides no guarantees. However, {@code @ReleasesNoLocks} provides a weaker guarantee than - * {@code @}{@link LockingFree}. - * - * @see MayReleaseLocks - * @see LockingFree - * @see SideEffectFree - * @see Pure - * @checker_framework.manual #lock-checker Lock Checker - * @checker_framework.manual #lock-lockingfree-example Example use of @ReleasesNoLocks - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@InheritedAnnotation -public @interface ReleasesNoLocks {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/NullnessUtil.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/NullnessUtil.java deleted file mode 100644 index 127a55e80bc..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/NullnessUtil.java +++ /dev/null @@ -1,309 +0,0 @@ -package org.checkerframework.checker.nullness; - -import org.checkerframework.checker.nullness.qual.EnsuresNonNull; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * Utility class for the Nullness Checker. - * - *

To avoid the need to write the NullnessUtil class name, do: - * - *

import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
- * - * or - * - *
import static org.checkerframework.checker.nullness.NullnessUtil.*;
- * - *

Runtime Dependency: If you use this class, you must distribute (or link to) {@code - * checker-qual.jar}, along with your binaries. Or, you can can copy this class into your own - * project. - */ -@SuppressWarnings({ - "nullness", // Nullness utilities are trusted regarding nullness. - "cast" // Casts look redundant if Nullness Checker is not run. -}) -@AnnotatedFor("nullness") -public final class NullnessUtil { - - private NullnessUtil() { - throw new AssertionError("shouldn't be instantiated"); - } - - /** - * A method that suppresses warnings from the Nullness Checker. - * - *

The method takes a possibly-null reference, unsafely casts it to have the @NonNull type - * qualifier, and returns it. The Nullness Checker considers both the return value, and also the - * argument, to be non-null after the method call. Therefore, the {@code castNonNull} method can - * be used either as a cast expression or as a statement. The Nullness Checker issues no - * warnings in any of the following code: - * - *


-     *   // one way to use as a cast:
-     *  {@literal @}NonNull String s = castNonNull(possiblyNull1);
-     *
-     *   // another way to use as a cast:
-     *   castNonNull(possiblyNull2).toString();
-     *
-     *   // one way to use as a statement:
-     *   castNonNull(possiblyNull3);
-     *   possiblyNull3.toString();`
-     * }
- * - * The {@code castNonNull} method is intended to be used in situations where the programmer - * definitively knows that a given reference is not null, but the type system is unable to make - * this deduction. It is not intended for defensive programming, in which a programmer cannot - * prove that the value is not null but wishes to have an earlier indication if it is. See the - * Checker Framework Manual for further discussion. - * - *

The method throws {@link AssertionError} if Java assertions are enabled and the argument - * is {@code null}. If the exception is ever thrown, then that indicates that the programmer - * misused the method by using it in a circumstance where its argument can be null. - * - * @param the type of the reference - * @param ref a reference of @Nullable type, that is non-null at run time - * @return the argument, casted to have the type qualifier @NonNull - */ - public static @EnsuresNonNull("#1") @NonNull T castNonNull( - @Nullable T ref) { - assert ref != null : "Misuse of castNonNull: called with a null argument"; - return (@NonNull T) ref; - } - - /** - * Suppress warnings from the Nullness Checker, with a custom error message. See {@link - * #castNonNull(Object)} for documentation. - * - * @see #castNonNull(Object) - * @param the type of the reference - * @param ref a reference of @Nullable type, that is non-null at run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull - */ - public static @EnsuresNonNull("#1") @NonNull T castNonNull( - @Nullable T ref, String message) { - assert ref != null : "Misuse of castNonNull: called with a null argument: " + message; - return (@NonNull T) ref; - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [] castNonNullDeep(T @Nullable [] arr) { - return (@NonNull T[]) castNonNullArray(arr, null); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [] castNonNullDeep(T @Nullable [] arr, String message) { - return (@NonNull T[]) castNonNullArray(arr, message); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type of the component type of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][] castNonNullDeep(T @Nullable [] @Nullable [] arr) { - return (@NonNull T[][]) castNonNullArray(arr, null); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type of the component type of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][] castNonNullDeep(T @Nullable [] @Nullable [] arr, String message) { - return (@NonNull T[][]) castNonNullArray(arr, message); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type (three levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][] castNonNullDeep(T @Nullable [] @Nullable [] @Nullable [] arr) { - return (@NonNull T[][][]) castNonNullArray(arr, null); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type (three levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][] castNonNullDeep( - T @Nullable [] @Nullable [] @Nullable [] arr, String message) { - return (@NonNull T[][][]) castNonNullArray(arr, message); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][][] castNonNullDeep( - T @Nullable [] @Nullable [] @Nullable [] @Nullable [] arr) { - return (@NonNull T[][][][]) castNonNullArray(arr, null); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type (four levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][][] castNonNullDeep( - T @Nullable [] @Nullable [] @Nullable [] @Nullable [] arr, String message) { - return (@NonNull T[][][][]) castNonNullArray(arr, message); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type (four levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][][][] castNonNullDeep( - T @Nullable [] @Nullable [] @Nullable [] @Nullable [] @Nullable [] arr) { - return (@NonNull T[][][][][]) castNonNullArray(arr, null); - } - - /** - * Like castNonNull, but whereas that method only checks and casts the reference itself, this - * traverses all levels of the argument array. The array is recursively checked to ensure that - * all elements at every array level are non-null. - * - * @param the component type (five levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if this method is misused - * @return the argument, casted to have the type qualifier @NonNull at all levels - * @see #castNonNull(Object) - */ - public static @EnsuresNonNull("#1") - @NonNull T @NonNull [][][][][] castNonNullDeep( - T @Nullable [] @Nullable [] @Nullable [] @Nullable [] @Nullable [] arr, - String message) { - return (@NonNull T[][][][][]) castNonNullArray(arr, message); - } - - /** - * The implementation of castNonNullDeep. - * - * @param the component type (five levels in) of the array - * @param arr an array all of whose elements, and their elements recursively, are non-null at - * run time - * @param message text to include if there is a non-null value, or null to use uncustomized - * message - * @return the argument, casted to have the type qualifier @NonNull at all levels - */ - private static @NonNull T @NonNull [] castNonNullArray( - T @Nullable [] arr, @Nullable String message) { - assert arr != null - : "Misuse of castNonNullArray: called with a null array argument" - + ((message == null) ? "" : (": " + message)); - for (int i = 0; i < arr.length; ++i) { - assert arr[i] != null - : "Misuse of castNonNull: called with a null array element" - + ((message == null) ? "" : (": " + message)); - checkIfArray(arr[i], message); - } - return (@NonNull T[]) arr; - } - - /** - * If the argument is an array, requires it to be non-null at all levels. - * - * @param ref a value; if an array, all of its elements, and their elements recursively, are - * non-null at run time - * @param message text to include if there is a non-null value, or null to use uncustomized - * message - */ - private static void checkIfArray(@NonNull Object ref, @Nullable String message) { - assert ref != null - : "Misuse of checkIfArray: called with a null argument" - + ((message == null) ? "" : (": " + message)); - Class comp = ref.getClass().getComponentType(); - if (comp != null) { - // comp is non-null for arrays, otherwise null. - if (comp.isPrimitive()) { - // Nothing to do for arrays of primitive type: primitives are - // never null. - } else { - castNonNullArray((Object[]) ref, message); - } - } - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/Opt.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/Opt.java deleted file mode 100644 index 36a93442c0c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/Opt.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.checkerframework.checker.nullness; - -import java.util.NoSuchElementException; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; -import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * Utility class for the Nullness Checker, providing every method in {@link java.util.Optional}, but - * written for possibly-null references rather than for the {@code Optional} type. - * - *

To avoid the need to write the {@code Opt} class name at invocation sites, do: - * - *

import static org.checkerframework.checker.nullness.Opt.orElse;
- * - * or - * - *
import static org.checkerframework.checker.nullness.Opt.*;
- * - *

Runtime Dependency: If you use this class, you must distribute (or link to) {@code - * checker-qual.jar}, along with your binaries. Or, you can can copy this class into your own - * project. - * - * @see java.util.Optional - */ -@AnnotatedFor("nullness") -public final class Opt { - - /** The Opt class cannot be instantiated. */ - private Opt() { - throw new AssertionError("shouldn't be instantiated"); - } - - /** - * If primary is non-null, returns it, otherwise throws NoSuchElementException. - * - * @param the type of the argument - * @param primary a non-null value to return - * @return {@code primary} if it is non-null - * @throws NoSuchElementException if primary is null - * @see java.util.Optional#get() - */ - // `primary` is @NonNull; otherwise, the method could throw an exception. - public static T get(T primary) { - if (primary == null) { - throw new NoSuchElementException("No value present"); - } - return primary; - } - - /** - * Returns true if primary is non-null, false if primary is null. - * - * @see java.util.Optional#isPresent() - */ - @EnsuresNonNullIf(expression = "#1", result = true) - public static boolean isPresent(@Nullable Object primary) { - return primary != null; - } - - /** - * If primary is non-null, invoke the specified consumer with the value, otherwise do nothing. - * - * @see java.util.Optional#ifPresent(Consumer) - */ - public static void ifPresent(T primary, Consumer<@NonNull ? super @NonNull T> consumer) { - if (primary != null) { - consumer.accept(primary); - } - } - - /** - * If primary is non-null, and its value matches the given predicate, return the value. If - * primary is null or its non-null value does not match the predicate, return null. - * - * @see java.util.Optional#filter(Predicate) - */ - public static @Nullable T filter( - T primary, Predicate<@NonNull ? super @NonNull T> predicate) { - if (primary == null) { - return null; - } else { - return predicate.test(primary) ? primary : null; - } - } - - /** - * If primary is non-null, apply the provided mapping function to it and return the result. If - * primary is null, return null. - * - * @see java.util.Optional#map(Function) - */ - public static @Nullable U map( - T primary, Function<@NonNull ? super @NonNull T, ? extends U> mapper) { - if (primary == null) { - return null; - } else { - return mapper.apply(primary); - } - } - - // flatMap would have the same signature and implementation as map - - /** - * Return primary if it is non-null. If primary is null, return other. - * - * @see java.util.Optional#orElse(Object) - */ - public static @NonNull T orElse(T primary, @NonNull T other) { - return primary != null ? primary : other; - } - - /** - * Return primary if it is non-null. If primary is null, invoke {@code other} and return the - * result of that invocation. - * - * @see java.util.Optional#orElseGet(Supplier) - */ - public static @NonNull T orElseGet(T primary, Supplier other) { - return primary != null ? primary : other.get(); - } - - /** - * Return primary if it is non-null. If primary is null, throw an exception to be created by the - * provided supplier. - * - * @see java.util.Optional#orElseThrow(Supplier) - */ - // `primary` is @NonNull; otherwise, the method could throw an exception. - public static T orElseThrow( - T primary, Supplier exceptionSupplier) throws X { - if (primary != null) { - return primary; - } else { - throw exceptionSupplier.get(); - } - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/AssertNonNullIfNonNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/AssertNonNullIfNonNull.java deleted file mode 100644 index 93150087869..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/AssertNonNullIfNonNull.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that if the method returns a non-null value, then the value expressions are also - * non-null. - * - *

WARNING: Type-checking for this annotation is not implemented at present. - * - *

Here is an example use: - * - *


- *    {@literal @}AssertNonNullIfNonNull("id")
- *    {@literal @}Pure
- *     public @Nullable Long getId() {
- *         return id;
- *     }
- * 
- * - * Note the direction of the implication. This annotation says that if the result is non-null, then - * the variable {@code id} is also non-null. The annotation does not say that if {@code id} is - * non-null, then the result is non-null. (There is not currently a way to say the latter, though it - * would also be useful.) - * - *

You should not write a formal parameter name or {@code this} as the argument of this - * annotation. In those cases, use the {@link PolyNull} annotation instead. - * - * @see NonNull - * @see PolyNull - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface AssertNonNullIfNonNull { - - /** - * Java expression(s) that are non-null after the method returns a non-null value. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyFor.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyFor.java deleted file mode 100644 index b9498fcd675..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyFor.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.PostconditionAnnotation; -import org.checkerframework.framework.qual.QualifierArgument; - -/** - * Indicates that the value expressions evaluate to a value that is a key in all the given maps, if - * the method terminates successfully. - * - *

Consider the following method from {@code java.util.Map}: - * - *

- * @EnsuresKeyFor(value="key", map="this")
- * public @Nullable V put(K key, V value) { ... }
- * 
- * - *

This method guarantees that {@code key} has type {@code @KeyFor("this")} after the method - * returns. - * - * @see KeyFor - * @see EnsuresKeyForIf - * @checker_framework.manual #map-key-checker Map Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PostconditionAnnotation(qualifier = KeyFor.class) -@InheritedAnnotation -@Repeatable(EnsuresKeyFor.List.class) -public @interface EnsuresKeyFor { - /** - * Java expressions that are keys in the given maps on successful method termination. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] value(); - - /** - * Returns Java expressions whose values are maps, each of which contains each expression value - * as a key (after successful method termination). - * - * @return Java expressions whose values are maps, each of which contains each expression value - * as a key (after successful method termination) - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - @JavaExpression - @QualifierArgument("value") - String[] map(); - - /** - * A wrapper annotation that makes the {@link EnsuresKeyFor} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresKeyFor} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @PostconditionAnnotation(qualifier = KeyFor.class) - @InheritedAnnotation - @interface List { - /** - * Returns the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresKeyFor[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyForIf.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyForIf.java deleted file mode 100644 index 82c184c7abd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresKeyForIf.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.ConditionalPostconditionAnnotation; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.QualifierArgument; - -/** - * Indicates that the given expressions evaluate to a value that is a key in all the given maps, if - * the method returns the given result (either true or false). - * - *

As an example, consider the following method in {@code java.util.Map}: - * - *

- *   @EnsuresKeyForIf(result=true, expression="key", map="this")
- *   public boolean containsKey(String key) { ... }
- * 
- * - * If an invocation {@code m.containsKey(k)} returns true, then the type of {@code k} can be - * inferred to be {@code @KeyFor("m")}. - * - * @see KeyFor - * @see EnsuresKeyFor - * @checker_framework.manual #map-key-checker Map Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@ConditionalPostconditionAnnotation(qualifier = KeyFor.class) -@InheritedAnnotation -@Repeatable(EnsuresKeyForIf.List.class) -public @interface EnsuresKeyForIf { - /** The value the method must return, in order for the postcondition to hold. */ - boolean result(); - - /** - * Java expressions that are keys in the given maps after the method returns the given result. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns Java expressions whose values are maps, each of which contains each expression value - * as a key (after the method returns the given result). - * - * @return Java expressions whose values are maps, each of which contains each expression value - * as a key (after the method returns the given result) - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - @JavaExpression - @QualifierArgument("value") - String[] map(); - - /** - * A wrapper annotation that makes the {@link EnsuresKeyForIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresKeyForIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @ConditionalPostconditionAnnotation(qualifier = KeyFor.class) - @InheritedAnnotation - @interface List { - /** - * Returns the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresKeyForIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNull.java deleted file mode 100644 index 109f2ace91c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNull.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.PostconditionAnnotation; - -// TODO: In a fix for https://tinyurl.com/cfissue/1917, add the text: -// Every prefix expression is also non-null; for example, {@code -// @EnsuresNonNull(expression="a.b.c")} implies that both {@code a.b} and {@code a.b.c} are -// non-null. -/** - * Indicates that the value expressions are non-null, if the method terminates successfully. - * - *

This postcondition annotation is useful for methods that initialize a field: - * - *


- * {@literal @}EnsuresNonNull("theMap")
- *  public static void initialize() {
- *    theMap = new HashMap<>();
- *  }
- * 
- * - * It can also be used for a method that fails if a given expression is null: - * - *

- *  /** Throws an exception if the argument is null. */
- * {@literal @}EnsuresNonNull("#1")
- *  void assertNonNull(Object arg) { ... }
- * 
- * - * @see NonNull - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PostconditionAnnotation(qualifier = NonNull.class) -@InheritedAnnotation -@Repeatable(EnsuresNonNull.List.class) -public @interface EnsuresNonNull { - /** - * Returns Java expressions that are {@link NonNull} after successful method termination. - * - * @return Java expressions that are {@link NonNull} after successful method termination - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] value(); - - /** - * A wrapper annotation that makes the {@link EnsuresNonNull} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresNonNull} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @PostconditionAnnotation(qualifier = NonNull.class) - @InheritedAnnotation - @interface List { - /** - * Returns the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresNonNull[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNullIf.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNullIf.java deleted file mode 100644 index 415e52a4f0b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/EnsuresNonNullIf.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.ConditionalPostconditionAnnotation; -import org.checkerframework.framework.qual.InheritedAnnotation; - -// TODO: In a fix for https://tinyurl.com/cfissue/1917, add the text: -// Every prefix expression is also non-null; for example, -// {@code @EnsuresNonNullIf(expression="a.b.c", results=true)} implies that both {@code a.b} and -// {@code a.b.c} are non-null if the method returns {@code true}. -/** - * Indicates that the given expressions are non-null, if the method returns the given result (either - * true or false). - * - *

Here are ways this conditional postcondition annotation can be used: - * - *

Method parameters: A common example is that the {@code equals} method is annotated as - * follows: - * - *

{@code   @EnsuresNonNullIf(expression="#1", result=true)
- *   public boolean equals(@Nullable Object obj) { ... }}
- * - * because, if {@code equals} returns true, then the first (#1) argument to {@code equals} was not - * null. - * - *

Fields: The value expressions can refer to fields, even private ones. For example: - * - *

{@code   @EnsuresNonNullIf(expression="this.derived", result=true)
- *   public boolean isDerived() {
- *     return (this.derived != null);
- *   }}
- * - * As another example, an {@code Iterator} may cache the next value that will be returned, in which - * case its {@code hasNext} method could be annotated as: - * - *
{@code   @EnsuresNonNullIf(expression="next_cache", result=true)
- *   public boolean hasNext() {
- *     if (next_cache == null) {
- *       return false;
- *     }
- *     ...
- *   }}
- * - * An {@code EnsuresNonNullIf} annotation that refers to a private field is useful for verifying - * that client code performs needed checks in the right order, even if the client code cannot - * directly affect the field. - * - *

Method calls: If {@link Class#isArray()} returns true, then {@link - * Class#getComponentType()} returns non-null. You can express this relationship as: - * - *

{@code   @EnsuresNonNullIf(expression="getComponentType()", result=true)
- *   public native @Pure boolean isArray();}
- * - * You can write two {@code @EnsuresNonNullIf} annotations on a single method: - * - *

- *     @EnsuresNonNullIf(expression="outputFile", result=true)
- *     @EnsuresNonNullIf(expression="memoryOutputStream", result=false)
- *     public boolean isThresholdExceeded() { ... }
- * 
- * - * @see NonNull - * @see EnsuresNonNull - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@ConditionalPostconditionAnnotation(qualifier = NonNull.class) -@InheritedAnnotation -@Repeatable(EnsuresNonNullIf.List.class) -public @interface EnsuresNonNullIf { - /** - * Returns Java expression(s) that are non-null after the method returns the given result. - * - * @return Java expression(s) that are non-null after the method returns the given result - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns the return value of the method under which the postcondition holds. - * - * @return the return value of the method under which the postcondition holds - */ - boolean result(); - - /** - * * A wrapper annotation that makes the {@link EnsuresNonNullIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresNonNullIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @ConditionalPostconditionAnnotation(qualifier = NonNull.class) - @InheritedAnnotation - @interface List { - /** - * Returns the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresNonNullIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyFor.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyFor.java deleted file mode 100644 index c79d650e2e3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyFor.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.JavaExpression; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the value assigned to the annotated variable is a key for at least the given - * map(s). - * - *

The value of the annotation is the reference name of the map. Suppose that {@code config} is a - * {@code Map}. Then the declaration - * - *

{@code   @KeyFor("config") String key = "HOSTNAME"; }
- * - * indicates that "HOSTNAME" is a key in {@code config}. - * - *

The value of the annotation can also be a set of reference names of the maps. If {@code - * defaultConfig} is also a {@code Map}, then - * - *

{@code   @KeyFor({"config","defaultConfig"}) String key = "HOSTNAME"; }
- * - * indicates that "HOSTNAME" is a key in {@code config} and in {@code defaultConfig}. - * - *

You do not usually need to write {@code @KeyFor} on the key type in a map. That is, you can - * declare variable {@code Map myMap;} and the Nullness Checker will apply - * {@code @KeyFor} as appropriate. If you redundantly write {@code @KeyFor}, as in {@code - * Map<@KeyFor("myMap") String, Integer> myMap;}, then your code is more verbose, and more seriously - * the Nullness Checker will issue errors when calling methods such as {@code Map.put}. - * - * @see EnsuresKeyFor - * @see EnsuresKeyForIf - * @checker_framework.manual #map-key-checker Map Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownKeyFor.class) -public @interface KeyFor { - /** - * Java expression(s) that evaluate to a map for which the annotated type is a key. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - @JavaExpression - public String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyForBottom.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyForBottom.java deleted file mode 100644 index c87995610ed..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/KeyForBottom.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Map Key type system. Programmers should rarely write this type. - * - *

There are no values of this type (not even {@code null}). - * - * @checker_framework.manual #map-key-checker Map Key Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf(KeyFor.class) -public @interface KeyForBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/MonotonicNonNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/MonotonicNonNull.java deleted file mode 100644 index 7eacf3f7677..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/MonotonicNonNull.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.MonotonicQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that once the field (or variable) becomes non-null, it never becomes null again. There - * is no guarantee that the field ever becomes non-null, but if it does, it will stay non-null. - * - *

Example use cases include lazy initialization and framework-based initialization in a - * lifecycle method other than the constructor. - * - *

A monotonically non-null field has these two properties: - * - *

    - *
  1. The field may be assigned only non-null values. - *
  2. The field may be re-assigned as often as desired. - *
- * - *

When the field is first read within a method, the field cannot be assumed to be non-null. - * After a check that a {@code MonotonicNonNull} field holds a non-null value, all subsequent - * accesses within that method can be assumed to be non-null, even after arbitrary external - * method calls that might access the field. - * - *

{@code MonotonicNonNull} gives stronger guarantees than {@link Nullable}. After a check that a - * {@link Nullable} field holds a non-null value, only accesses until the next non-{@link - * org.checkerframework.dataflow.qual.SideEffectFree} method is called can be assumed to be - * non-null. - * - *

To indicate that a {@code MonotonicNonNull} or {@code Nullable} field is non-null whenever a - * particular method is called, use {@link RequiresNonNull}. - * - *

Final fields are treated as MonotonicNonNull by default. - * - *

This annotation is associated with the {@link - * org.checkerframework.checker.nullness.NullnessChecker}. - * - * @see EnsuresNonNull - * @see RequiresNonNull - * @see MonotonicQualifier - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE_USE) -@SubtypeOf(Nullable.class) -@MonotonicQualifier(NonNull.class) -public @interface MonotonicNonNull {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/NonNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/NonNull.java deleted file mode 100644 index ae3b403665f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/NonNull.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeKind; -import org.checkerframework.framework.qual.TypeUseLocation; -import org.checkerframework.framework.qual.UpperBoundFor; - -/** - * If an expression's type is qualified by {@code @NonNull}, then the expression never evaluates to - * {@code null}. - * - *

For fields of a class, the {@link NonNull} annotation indicates that this field is never - * {@code null} after the class has been fully initialized. For static fields, the {@link - * NonNull} annotation indicates that this field is never {@code null} after the containing - * class is initialized. See {@link - * org.checkerframework.checker.initialization.InitializationChecker} for more details. - * - *

This annotation is rarely written in source code, because it is the default. - * - * @see Nullable - * @see MonotonicNonNull - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(MonotonicNonNull.class) -@QualifierForLiterals(LiteralKind.STRING) -@DefaultQualifierInHierarchy -@DefaultFor(TypeUseLocation.EXCEPTION_PARAMETER) -@UpperBoundFor( - typeKinds = { - TypeKind.PACKAGE, - TypeKind.INT, - TypeKind.BOOLEAN, - TypeKind.CHAR, - TypeKind.DOUBLE, - TypeKind.FLOAT, - TypeKind.LONG, - TypeKind.SHORT, - TypeKind.BYTE - }) -public @interface NonNull {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/Nullable.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/Nullable.java deleted file mode 100644 index 650d7b0e8f3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/Nullable.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * {@link Nullable} is a type annotation that indicates that the value is not known to be non-null - * (see {@link NonNull}). Only if an expression has a {@link Nullable} type may it be assigned - * {@code null}. - * - *

This annotation is associated with the {@link - * org.checkerframework.checker.nullness.NullnessChecker}. - * - * @see NonNull - * @see MonotonicNonNull - * @see org.checkerframework.checker.nullness.NullnessChecker - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@QualifierForLiterals(LiteralKind.NULL) -@DefaultFor(types = Void.class) -public @interface Nullable {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyKeyFor.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyKeyFor.java deleted file mode 100644 index 6a89836561b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyKeyFor.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Map Key (@KeyFor) type system. - * - *

Any method written using {@code @PolyKeyFor} conceptually has an arbitrary number of versions: - * one in which every instance of {@code @PolyKeyFor} has been replaced by {@code @}{@link - * UnknownKeyFor}, one in which every instance of {@code @}{@link PolyKeyFor} has been replaced by - * {@code @}{@link KeyForBottom}, and ones in which every instance of {@code @PolyKeyFor} has been - * replaced by {@code @}{@code KeyFor}, for every possible combination of map arguments. - * - * @checker_framework.manual #nullness-checker Nullness Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownKeyFor.class) -public @interface PolyKeyFor {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyNull.java deleted file mode 100644 index 1ae6b204c80..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/PolyNull.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the non-null type system. - * - *

Any method written using {@link PolyNull} conceptually has two versions: one in which every - * instance of {@link PolyNull} has been replaced by {@link - * org.checkerframework.checker.nullness.qual.NonNull}, and one in which every instance of {@link - * PolyNull} has been replaced by {@link org.checkerframework.checker.nullness.qual.Nullable}. - * - * @checker_framework.manual #nullness-checker Nullness Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(Nullable.class) -public @interface PolyNull {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/RequiresNonNull.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/RequiresNonNull.java deleted file mode 100644 index cf60d43f3ea..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/RequiresNonNull.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PreconditionAnnotation; - -// TODO: In a fix for https://tinyurl.com/cfissue/1917, add the text: -// Every prefix expression must also be non-null; for example, {@code -// @RequiresNonNull(expression="a.b.c")} implies that both {@code a.b} and {@code a.b.c} must be -// non-null. -/** - * Indicates a method precondition: the method expects the specified expressions to be non-null when - * the annotated method is invoked. - * - *

For example: - * - * - *

- * class MyClass {
- *   @Nullable Object field1;
- *   @Nullable Object field2;
- *
- *   @RequiresNonNull({"field1", "other.field1"})
- *   void method1(@NonNull MyClass other) {
- *     field1.toString();           // OK, this.field1 is known to be non-null
- *     field2.toString();           // error, might throw NullPointerException
- *     other.field1.toString();     // OK, other.field1 is known to be non-null
- *     other.field2.toString();     // error, might throw NullPointerException
- *   }
- *
- *   void method2() {
- *     MyClass other = new MyClass();
- *
- *     field1 = new Object();
- *     other.field1 = new Object();
- *     method1();                   // OK, satisfies method precondition
- *
- *     field1 = null;
- *     other.field1 = new Object();
- *     method1();                   // error, does not satisfy this.field1 method precondition
- *
- *     field1 = new Object();
- *     other.field1 = null;
- *     method1();                   // error, does not satisfy other.field1 method precondition
- *   }
- * 
- * - * Do not use this annotation for formal parameters (instead, give them a {@code @NonNull} type, - * which is the default and need not be written). The {@code @RequiresNonNull} annotation is - * intended for other expressions, such as field accesses or method calls. - * - * @checker_framework.manual #nullness-checker Nullness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@PreconditionAnnotation(qualifier = NonNull.class) -public @interface RequiresNonNull { - /** - * The Java expressions that need to be {@link - * org.checkerframework.checker.nullness.qual.NonNull}. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/UnknownKeyFor.java b/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/UnknownKeyFor.java deleted file mode 100644 index 19e423ca910..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/nullness/qual/UnknownKeyFor.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.checker.nullness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Used internally by the type system; should never be written by a programmer. - * - *

Indicates that the value assigned to the annotated variable is not known to be a key for any - * map. It is the top type qualifier in the {@link KeyFor} hierarchy. It is also the default type - * qualifier. - * - * @checker_framework.manual #map-key-checker Map Key Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -@DefaultFor(value = TypeUseLocation.LOWER_BOUND, types = Void.class) -@QualifierForLiterals(LiteralKind.NULL) -public @interface UnknownKeyFor {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/MaybePresent.java b/src/java.base/share/classes/org/checkerframework/checker/optional/qual/MaybePresent.java deleted file mode 100644 index b37ac127ffd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/MaybePresent.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.optional.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The {@link java.util.Optional Optional} container may or may not contain a value. - * - * @checker_framework.manual #optional-checker Optional Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface MaybePresent {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/PolyPresent.java b/src/java.base/share/classes/org/checkerframework/checker/optional/qual/PolyPresent.java deleted file mode 100644 index e462ed7732a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/PolyPresent.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.optional.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Optional type system. - * - * @checker_framework.manual #optional-checker Optional Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(MaybePresent.class) -public @interface PolyPresent {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/Present.java b/src/java.base/share/classes/org/checkerframework/checker/optional/qual/Present.java deleted file mode 100644 index 90c59e2c849..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/optional/qual/Present.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.optional.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The {@link java.util.Optional Optional} container definitely contains a (non-null) value. - * - * @checker_framework.manual #optional-checker Optional Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({MaybePresent.class}) -public @interface Present {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKey.java b/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKey.java deleted file mode 100644 index 712fc8f4b27..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKey.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.propkey.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} type can be used as key in a property file or resource bundle. - * - * @checker_framework.manual #propkey-checker Property File Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownPropertyKey.class) -public @interface PropertyKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKeyBottom.java b/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKeyBottom.java deleted file mode 100644 index e3b40a9c625..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/PropertyKeyBottom.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.propkey.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the PropertyKeyChecker (and associated checkers) qualifier hierarchy. - * Programmers should rarely write this type. - * - * @checker_framework.manual #propkey-checker Property File Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf(PropertyKey.class) -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface PropertyKeyBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/UnknownPropertyKey.java b/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/UnknownPropertyKey.java deleted file mode 100644 index 89a55a0fb36..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/propkey/qual/UnknownPropertyKey.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.propkey.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates that the {@code String} type has an unknown property key property. - * - * @checker_framework.manual #propkey-checker Property File Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownPropertyKey {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/RegexUtil.java b/src/java.base/share/classes/org/checkerframework/checker/regex/RegexUtil.java deleted file mode 100644 index 157f2cf520b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/RegexUtil.java +++ /dev/null @@ -1,336 +0,0 @@ -// This class should be kept in sync with org.plumelib.util.RegexUtil in the plume-util project. - -package org.checkerframework.checker.regex; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import org.checkerframework.checker.index.qual.GTENegativeOne; -import org.checkerframework.checker.lock.qual.GuardSatisfied; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.checker.regex.qual.Regex; -import org.checkerframework.dataflow.qual.Pure; -import org.checkerframework.dataflow.qual.SideEffectFree; -import org.checkerframework.framework.qual.AnnotatedFor; -import org.checkerframework.framework.qual.EnsuresQualifierIf; - -/** - * Utility methods for regular expressions, most notably for testing whether a string is a regular - * expression. - * - *

For an example of intended use, see section Testing whether a string is a - * regular expression in the Checker Framework manual. - * - *

Runtime Dependency: If you use this class, you must distribute (or link to) {@code - * checker-qual.jar}, along with your binaries. Or, you can can copy this class into your own - * project. - */ -@SuppressWarnings("allcheckers:purity") -@AnnotatedFor("nullness") -public final class RegexUtil { - - /** This class is a collection of methods; it does not represent anything. */ - private RegexUtil() { - throw new Error("do not instantiate"); - } - - /** - * A checked version of {@link PatternSyntaxException}. - * - *

This exception is useful when an illegal regex is detected but the contextual information - * to report a helpful error message is not available at the current depth in the call stack. By - * using a checked PatternSyntaxException the error must be handled up the call stack where a - * better error message can be reported. - * - *

Typical usage is: - * - *

-     * void myMethod(...) throws CheckedPatternSyntaxException {
-     *   ...
-     *   if (! isRegex(myString)) {
-     *     throw new CheckedPatternSyntaxException(...);
-     *   }
-     *   ... Pattern.compile(myString) ...
-     * 
- * - * Simply calling {@code Pattern.compile} would have a similar effect, in that {@code - * PatternSyntaxException} would be thrown at run time if {@code myString} is not a regular - * expression. There are two problems with such an approach. First, a client of {@code myMethod} - * might forget to handle the exception, since {@code PatternSyntaxException} is not checked. - * Also, the Regex Checker would issue a warning about the call to {@code Pattern.compile} that - * might throw an exception. The above usage pattern avoids both problems. - * - * @see PatternSyntaxException - */ - public static class CheckedPatternSyntaxException extends Exception { - - private static final long serialVersionUID = 6266881831979001480L; - - /** The PatternSyntaxException that this is a wrapper around. */ - private final PatternSyntaxException pse; - - /** - * Constructs a new CheckedPatternSyntaxException equivalent to the given {@link - * PatternSyntaxException}. - * - *

Consider calling this constructor with the result of {@link RegexUtil#regexError}. - * - * @param pse the PatternSyntaxException to be wrapped - */ - public CheckedPatternSyntaxException(PatternSyntaxException pse) { - this.pse = pse; - } - - /** - * Constructs a new CheckedPatternSyntaxException. - * - * @param desc a description of the error - * @param regex the erroneous pattern - * @param index the approximate index in the pattern of the error, or {@code -1} if the - * index is not known - */ - public CheckedPatternSyntaxException(String desc, String regex, @GTENegativeOne int index) { - this(new PatternSyntaxException(desc, regex, index)); - } - - /** - * Retrieves the description of the error. - * - * @return the description of the error - */ - public String getDescription() { - return pse.getDescription(); - } - - /** - * Retrieves the error index. - * - * @return the approximate index in the pattern of the error, or {@code -1} if the index is - * not known - */ - public int getIndex() { - return pse.getIndex(); - } - - /** - * Returns a multi-line string containing the description of the syntax error and its index, - * the erroneous regular-expression pattern, and a visual indication of the error index - * within the pattern. - * - * @return the full detail message - */ - @Override - @Pure - public String getMessage(@GuardSatisfied CheckedPatternSyntaxException this) { - return pse.getMessage(); - } - - /** - * Retrieves the erroneous regular-expression pattern. - * - * @return the erroneous pattern - */ - public String getPattern() { - return pse.getPattern(); - } - } - - /** - * Returns true if the argument is a syntactically valid regular expression. - * - * @param s string to check for being a regular expression - * @return true iff s is a regular expression - */ - @Pure - @EnsuresQualifierIf(result = true, expression = "#1", qualifier = Regex.class) - public static boolean isRegex(String s) { - return isRegex(s, 0); - } - - /** - * Returns true if the argument is a syntactically valid regular expression with at least the - * given number of groups. - * - * @param s string to check for being a regular expression - * @param groups number of groups expected - * @return true iff s is a regular expression with {@code groups} groups - */ - @SuppressWarnings({"regex", "all:deterministic"}) // RegexUtil; for purity, catches an exception - @Pure - // @EnsuresQualifierIf annotation is extraneous because this method is special-cased - // in RegexTransfer. - @EnsuresQualifierIf(result = true, expression = "#1", qualifier = Regex.class) - public static boolean isRegex(String s, int groups) { - Pattern p; - try { - p = Pattern.compile(s); - } catch (PatternSyntaxException e) { - return false; - } - return getGroupCount(p) >= groups; - } - - /** - * Returns true if the argument is a syntactically valid regular expression. - * - * @param c char to check for being a regular expression - * @return true iff c is a regular expression - */ - @SuppressWarnings({ - "regex", - "all:purity.not.deterministic.call", - "lock" - }) // RegexUtil; temp value used in pure method is equal up to equals but not up to == - @Pure - @EnsuresQualifierIf(result = true, expression = "#1", qualifier = Regex.class) - public static boolean isRegex(final char c) { - return isRegex(Character.toString(c)); - } - - /** - * Returns null if the argument is a syntactically valid regular expression. Otherwise returns a - * string describing why the argument is not a regex. - * - * @param s string to check for being a regular expression - * @return null, or a string describing why the argument is not a regex - */ - @SideEffectFree - public static @Nullable String regexError(String s) { - return regexError(s, 0); - } - - /** - * Returns null if the argument is a syntactically valid regular expression with at least the - * given number of groups. Otherwise returns a string describing why the argument is not a - * regex. - * - * @param s string to check for being a regular expression - * @param groups number of groups expected - * @return null, or a string describing why the argument is not a regex - */ - @SuppressWarnings({"regex", "not.sef"}) // RegexUtil; - @SideEffectFree - public static @Nullable String regexError(String s, int groups) { - try { - Pattern p = Pattern.compile(s); - int actualGroups = getGroupCount(p); - if (actualGroups < groups) { - return regexErrorMessage(s, groups, actualGroups); - } - } catch (PatternSyntaxException e) { - return e.getMessage(); - } - return null; - } - - /** - * Returns null if the argument is a syntactically valid regular expression. Otherwise returns a - * PatternSyntaxException describing why the argument is not a regex. - * - * @param s string to check for being a regular expression - * @return null, or a PatternSyntaxException describing why the argument is not a regex - */ - @SideEffectFree - public static @Nullable PatternSyntaxException regexException(String s) { - return regexException(s, 0); - } - - /** - * Returns null if the argument is a syntactically valid regular expression with at least the - * given number of groups. Otherwise returns a PatternSyntaxException describing why the - * argument is not a regex. - * - * @param s string to check for being a regular expression - * @param groups number of groups expected - * @return null, or a PatternSyntaxException describing why the argument is not a regex - */ - @SuppressWarnings("regex") // RegexUtil - @SideEffectFree - public static @Nullable PatternSyntaxException regexException(String s, int groups) { - try { - Pattern p = Pattern.compile(s); - int actualGroups = getGroupCount(p); - if (actualGroups < groups) { - return new PatternSyntaxException( - regexErrorMessage(s, groups, actualGroups), s, -1); - } - } catch (PatternSyntaxException pse) { - return pse; - } - return null; - } - - /** - * Returns the argument as a {@code @Regex String} if it is a regex, otherwise throws an error. - * The purpose of this method is to suppress Regex Checker warnings. It should be very rarely - * needed. - * - * @param s string to check for being a regular expression - * @return its argument - * @throws Error if argument is not a regex - */ - @SideEffectFree - // The return type annotation is a conservative bound. - public static @Regex String asRegex(String s) { - return asRegex(s, 0); - } - - /** - * Returns the argument as a {@code @Regex(groups) String} if it is a regex with at least the - * given number of groups, otherwise throws an error. The purpose of this method is to suppress - * Regex Checker warnings. It should be very rarely needed. - * - * @param s string to check for being a regular expression - * @param groups number of groups expected - * @return its argument - * @throws Error if argument is not a regex - */ - @SuppressWarnings("regex") // RegexUtil - @SideEffectFree - // The return type annotation is irrelevant; it is special-cased by - // RegexAnnotatedTypeFactory. - public static @Regex String asRegex(String s, int groups) { - try { - Pattern p = Pattern.compile(s); - int actualGroups = getGroupCount(p); - if (actualGroups < groups) { - throw new Error(regexErrorMessage(s, groups, actualGroups)); - } - return s; - } catch (PatternSyntaxException e) { - throw new Error(e); - } - } - - /** - * Generates an error message for s when expectedGroups are needed, but s only has actualGroups. - * - * @param s string to check for being a regular expression - * @param expectedGroups the number of needed capturing groups - * @param actualGroups the number of groups that {@code s} has - * @return an error message for s when expectedGroups groups are needed, but s only has - * actualGroups groups - */ - @SideEffectFree - private static String regexErrorMessage(String s, int expectedGroups, int actualGroups) { - return "regex \"" - + s - + "\" has " - + actualGroups - + " groups, but " - + expectedGroups - + " groups are needed."; - } - - /** - * Return the count of groups in the argument. - * - * @param p pattern whose groups to count - * @return the count of groups in the argument - */ - @SuppressWarnings({"all:purity", "lock"}) // does not depend on object identity - @Pure - private static int getGroupCount(Pattern p) { - return p.matcher("").groupCount(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PartialRegex.java b/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PartialRegex.java deleted file mode 100644 index 168dc48e353..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PartialRegex.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.regex.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Indicates a String that is not a syntactically valid regular expression. The String itself can be - * stored as a parameter to the annotation, allowing the Regex Checker to verify some concatenations - * of partial regular expression Strings. - * - *

This annotation may not be written in source code; it is an implementation detail of the Regex - * Checker. - * - * @checker_framework.manual #regex-checker Regex Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) // empty target prevents programmers from writing this in a program -@InvisibleQualifier -@SubtypeOf(org.checkerframework.checker.regex.qual.UnknownRegex.class) -public @interface PartialRegex { - - /** - * The String qualified by this annotation. Used to verify concatenation of partial regular - * expressions. Defaults to the empty String. - */ - String value() default ""; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PolyRegex.java b/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PolyRegex.java deleted file mode 100644 index 80e5bffdc56..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/PolyRegex.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.regex.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Regex type system. - * - *

Any method written using {@code @PolyRegex} conceptually has two versions: one in which every - * instance of {@code @PolyRegex String} has been replaced by {@code @Regex String}, and one in - * which every instance of {@code @PolyRegex String} has been replaced by {@code String}. - * - * @checker_framework.manual #regex-checker Regex Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownRegex.class) -public @interface PolyRegex {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/Regex.java b/src/java.base/share/classes/org/checkerframework/checker/regex/qual/Regex.java deleted file mode 100644 index 919a9c804f9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/Regex.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.checker.regex.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * If a type is annotated as {@code @Regex(n)}, then the run-time value is a regular expression with - * n capturing groups. - * - *

For example, if an expression's type is @Regex(2) String, then at run time its value - * will be a legal regular expression with at least two capturing groups. The type states that - * possible run-time values include {@code "(a*)(b*)"}, {@code "a(b?)c(d?)e"}, and {@code - * "(.)(.)(.)"}, but not {@code "hello"} nor {@code "(good)bye"} nor {@code "(a*)(b*)("}. - * - * @checker_framework.manual #regex-checker Regex Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownRegex.class) -public @interface Regex { - /** The number of groups in the regular expression. Defaults to 0. */ - int value() default 0; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/RegexBottom.java b/src/java.base/share/classes/org/checkerframework/checker/regex/qual/RegexBottom.java deleted file mode 100644 index e0f226b752a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/RegexBottom.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.regex.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Regex type system. Programmers should rarely write this type. - * - * @checker_framework.manual #regex-checker Regex Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({Regex.class, org.checkerframework.checker.regex.qual.PartialRegex.class}) -@DefaultFor(value = {TypeUseLocation.LOWER_BOUND}) -public @interface RegexBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/UnknownRegex.java b/src/java.base/share/classes/org/checkerframework/checker/regex/qual/UnknownRegex.java deleted file mode 100644 index ea1948b19ea..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/regex/qual/UnknownRegex.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.regex.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Represents the top of the Regex qualifier hierarchy. - * - * @checker_framework.manual #regex-checker Regex Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@DefaultQualifierInHierarchy -@SubtypeOf({}) -public @interface UnknownRegex {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ArrayWithoutPackage.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ArrayWithoutPackage.java deleted file mode 100644 index 880dcc449ee..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ArrayWithoutPackage.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An identifier or primitive type, followed by any number of array square brackets. - * - *

Example: Foobar[][] Example: Baz22 - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({FullyQualifiedName.class, ClassGetSimpleName.class}) -public @interface ArrayWithoutPackage {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryName.java deleted file mode 100644 index c1a8acb3f1c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryName.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a binary name as defined in the Java Language - * Specification, section 13.1. - * - *

For example, in - * - *

- *  package org.checkerframework.checker.signature;
- *  public class SignatureChecker {
- *    private class Inner {}
- *  }
- * 
- * - * the binary names for the two types are org.checkerframework.checker.signature.SignatureChecker - * and org.checkerframework.checker.signature.SignatureChecker$Inner. - * - *

Binary names and {@linkplain InternalForm internal form} only differ by the use of '.' vs. '/' - * as package separator. - * - *

The binary name should not be confused with the {@linkplain InternalForm internal form}, which - * is a variant of the binary name that actually appears in the class file. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({BinaryNameOrPrimitiveType.class}) -public @interface BinaryName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameOrPrimitiveType.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameOrPrimitiveType.java deleted file mode 100644 index c2d36f78e26..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameOrPrimitiveType.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a primitive type name or a {@link BinaryName binary name}. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({ClassGetName.class, FqBinaryName.class}) -public @interface BinaryNameOrPrimitiveType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameWithoutPackage.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameWithoutPackage.java deleted file mode 100644 index 7a28a75be7e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/BinaryNameWithoutPackage.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a string that is a {@link BinaryName}, an {@link InternalForm}, and a {@link - * ClassGetName}. The string represents a class that is in the unnamed package (also known as the - * default package). - * - *

Examples: - * - *

{@code
- * MyClass
- * MyClass$22
- * }
- * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({BinaryName.class, InternalForm.class}) -public @interface BinaryNameWithoutPackage {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalName.java deleted file mode 100644 index 2261dad5885..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalName.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Canonical names have the same syntactic form as {@link FullyQualifiedName fully-qualified name}s. - * Every canonical name is a fully-qualified name, but not every fully-qualified name is a canonical - * name. - * - *

JLS section - * 6.7 gives the following example: - * - *

- * - * The difference between a fully qualified name and a canonical name can be seen in code such as: - * - *
{@code
- * package p;
- * class O1 { class I {} }
- * class O2 extends O1 {}
- * }
- * - * Both {@code p.O1.I} and {@code p.O2.I} are fully qualified names that denote the member class - * {@code I}, but only {@code p.O1.I} is its canonical name. - * - *
- * - * Given a character sequence that is a fully-qualified name, there is no way to know whether or not - * it is a canonical name, without examining the program it refers to. Therefore, to avoid excessive - * warnings that would have to be suppressed, sometimes a variable that holds a canonical name is - * annotated as {@code @}{@link FullyQualifiedName}. - * - * @see FullyQualifiedName - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({FullyQualifiedName.class, CanonicalNameOrEmpty.class}) -public @interface CanonicalName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalNameOrEmpty.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalNameOrEmpty.java deleted file mode 100644 index bf347b1078c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/CanonicalNameOrEmpty.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Either a {@link CanonicalName} or the empty string. - * - * @see CanonicalName - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface CanonicalNameOrEmpty {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetName.java deleted file mode 100644 index c5bed3923f7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetName.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The type representation used by the {@link Class#getName()}, {@link Class#forName(String)}, and - * {@link Class#forName(String, boolean, ClassLoader)} methods. This format is: - * - *
    - *
  • for any non-array type, the {@link BinaryName binary name} - *
  • for any array type, a format like the {@link FieldDescriptor field descriptor}, but using - * '.' where the field descriptor uses '/' - *
- * - *

Examples include - * - *

- *   java.lang.String
- *   [Ljava.lang.Object;
- *   int
- *   [[[I
- * 
- * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface ClassGetName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetSimpleName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetSimpleName.java deleted file mode 100644 index ca75e879b7f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/ClassGetSimpleName.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The format produced by the {@link Class#getSimpleName()} method. It is an identifier or the empty - * string (for an anonymous class), followed by an number of array square brackets. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface ClassGetSimpleName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiers.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiers.java deleted file mode 100644 index 79e63100fc8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiers.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This is a string that is a valid {@linkplain - * org.checkerframework.checker.signature.qual.FullyQualifiedName fully qualified name} and a valid - * {@linkplain org.checkerframework.checker.signature.qual.BinaryName binary name}. It represents a - * non-array, non-inner class: dot-separated identifiers. - * - *

Examples: int, MyClass, java.lang.Integer - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({DotSeparatedIdentifiersOrPrimitiveType.class, BinaryName.class}) -public @interface DotSeparatedIdentifiers {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiersOrPrimitiveType.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiersOrPrimitiveType.java deleted file mode 100644 index f50ce6cdd9a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/DotSeparatedIdentifiersOrPrimitiveType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This is a string that is a valid {@linkplain - * org.checkerframework.checker.signature.qual.FullyQualifiedName fully qualified name} and a valid - * {@linkplain org.checkerframework.checker.signature.qual.BinaryNameOrPrimitiveType binary name or - * primitive type}. It represents a primitive type or a non-array, non-inner class, where the latter - * is represented by dot-separated identifiers. - * - *

Examples: int, MyClass, java.lang.Integer - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({FullyQualifiedName.class, BinaryNameOrPrimitiveType.class}) -public @interface DotSeparatedIdentifiersOrPrimitiveType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptor.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptor.java deleted file mode 100644 index a0698984186..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptor.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a field descriptor (JVM type format) as defined in the Java Virtual - * Machine Specification, section 4.3.2. - * - *

For example, in - * - *

- *  package org.checkerframework.checker.signature;
- *  public class SignatureChecker {
- *    private class Inner {}
- *  }
- * 
- * - * the field descriptors for the two types are - * Lorg/checkerframework/checker/signature/SignatureChecker; and - * Lorg/checkerframework/checker/signature/SignatureChecker$Inner; . - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface FieldDescriptor {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorForPrimitive.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorForPrimitive.java deleted file mode 100644 index 3b4bb26b766..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorForPrimitive.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a field descriptor (JVM type format) for a primitive as defined in the Java Virtual - * Machine Specification, section 4.3.2. - * - *

Must be one of B, C, D, F, I, J, S, Z. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({FieldDescriptorWithoutPackage.class, Identifier.class}) -public @interface FieldDescriptorForPrimitive {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorWithoutPackage.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorWithoutPackage.java deleted file mode 100644 index ac2817eae6c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FieldDescriptorWithoutPackage.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a {@link FieldDescriptor field descriptor} for a primitive or for an array whose base - * type is primitive or in the unnamed package. - * - *

Examples: I [[J MyClass MyClass$22 [LMyClass; [LMyClass$22 - * - *

Field descriptor (JVM type format) is defined in the Java Virtual - * Machine Specification, section 4.3.2. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({ClassGetName.class, FieldDescriptor.class}) -public @interface FieldDescriptorWithoutPackage {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FqBinaryName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FqBinaryName.java deleted file mode 100644 index 32af0d6646e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FqBinaryName.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An extension of binary name format to represent primitives and arrays. It is just like - * fully-qualified name format, but uses "$" rather than "." to indicate a nested class. - * - *

Examples include - * - *

- *   int
- *   int[][]
- *   java.lang.String
- *   java.lang.String[]
- *   pkg.Outer$Inner
- *   pkg.Outer$Inner[]
- * 
- * - *

This is not a format defined by the Java language or platform, but is a convenient format for - * users to unambiguously specify a type. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface FqBinaryName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FullyQualifiedName.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FullyQualifiedName.java deleted file mode 100644 index 4ddb441e6cc..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/FullyQualifiedName.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A sequence of dot-separated identifiers, followed by any number of array square brackets. - * Represents a fully-qualified name as defined in the Java Language - * Specification, section 6.7. - * - *

Examples: - * - *

{@code
- * int
- * MyClass
- * java.lang.Integer
- * int[][]
- * MyClass[]
- * java.lang.Integer[][][]
- * }
- * - *

in - * - *

- *  package org.checkerframework.checker.signature;
- *  public class SignatureChecker {
- *    private class Inner {}
- *  }
- * 
- * - * the fully-qualified names for the two types are - * org.checkerframework.checker.signature.SignatureChecker and - * org.checkerframework.checker.signature.SignatureChecker.Inner. - * - *

Fully-qualified names and {@linkplain BinaryName binary names} are the same for top-level - * classes and only differ by a '.' vs. '$' for inner classes. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(FqBinaryName.class) -public @interface FullyQualifiedName {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/Identifier.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/Identifier.java deleted file mode 100644 index e434b14d4ba..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/Identifier.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An identifier. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@SubtypeOf({ - DotSeparatedIdentifiers.class, - BinaryNameWithoutPackage.class, - IdentifierOrPrimitiveType.class -}) -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface Identifier {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/IdentifierOrPrimitiveType.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/IdentifierOrPrimitiveType.java deleted file mode 100644 index 64313c883ed..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/IdentifierOrPrimitiveType.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An identifier or a primitive type. - * - *

Example: Foobar, Baz22, int, float - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({ArrayWithoutPackage.class, DotSeparatedIdentifiersOrPrimitiveType.class}) -public @interface IdentifierOrPrimitiveType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/InternalForm.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/InternalForm.java deleted file mode 100644 index cec44eed807..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/InternalForm.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The syntax for binary names that appears in a class file, as defined in the JVM - * Specification, section 4.2. A {@linkplain BinaryName binary name} is conceptually the name - * for the class or interface in a compiled binary, but the actual representation of that name in - * its class file is slightly different. - * - *

Internal form is the same as the binary name, but with periods ({@code .}) replaced by forward - * slashes ({@code /}). - * - *

Programmers more often use the binary name, leaving the internal form as a JVM implementation - * detail. - * - * @see BinaryName - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface InternalForm {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/MethodDescriptor.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/MethodDescriptor.java deleted file mode 100644 index 61f4e703b86..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/MethodDescriptor.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Represents a method descriptor (JVM representation of method signature) as defined in the Java Virtual - * Machine Specification, section 4.3.3. - * - *

Example: - * - *

- *  package edu.cs.washington;
- *  public class BinaryName {
- *    private class Inner {
- *      public void method(Object obj, int i) {}
- *    }
- *  }
- * 
- * - * In this example method descriptor for method 'method': (Ljava/lang/Object;I)Z - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(SignatureUnknown.class) -public @interface MethodDescriptor {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PolySignature.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PolySignature.java deleted file mode 100644 index 89c05ef24bd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PolySignature.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Signature type system. - * - *

Any method written using {@code @PolySignature} conceptually has two versions: one in which - * every instance of {@code @PolySignature String} has been replaced by {@code @Signature String}, - * and one in which every instance of {@code @PolySignature String} has been replaced by {@code - * String}. - * - * @checker_framework.manual #signature-checker Signature Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(SignatureUnknown.class) -public @interface PolySignature {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PrimitiveType.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PrimitiveType.java deleted file mode 100644 index 9d1e72e2209..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/PrimitiveType.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A primitive type. One of: boolean, byte, char, double, float, int, long, short. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@SubtypeOf({IdentifierOrPrimitiveType.class, CanonicalName.class}) -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface PrimitiveType {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureBottom.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureBottom.java deleted file mode 100644 index 842f98ec078..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Signature String type system. Programmers should rarely write this type. - * - * @checker_framework.manual #signature-checker Signature Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({FieldDescriptorForPrimitive.class, PrimitiveType.class, MethodDescriptor.class}) -@DefaultFor({TypeUseLocation.LOWER_BOUND}) -public @interface SignatureBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureUnknown.java b/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureUnknown.java deleted file mode 100644 index ddac82ff3f8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signature/qual/SignatureUnknown.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.signature.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Top qualifier in the type hierarchy. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - * @checker_framework.manual #signature-checker Signature Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) // empty target prevents programmers from writing this in a program -@DefaultQualifierInHierarchy -@SubtypeOf({}) -public @interface SignatureUnknown {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/SignednessUtil.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/SignednessUtil.java deleted file mode 100644 index 948ab11dcbd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/SignednessUtil.java +++ /dev/null @@ -1,523 +0,0 @@ -package org.checkerframework.checker.signedness; - -import java.io.IOException; -import java.io.RandomAccessFile; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import org.checkerframework.checker.signedness.qual.Unsigned; -import org.checkerframework.framework.qual.AnnotatedFor; - -/** - * Provides static utility methods for unsigned values. Most of these re-implement functionality - * that was introduced in JDK 8, making it available in earlier versions of Java. Others provide new - * functionality. {@link SignednessUtilExtra} has more methods that reference packages that Android - * does not provide. - * - * @checker_framework.manual #signedness-utilities Utility routines for manipulating unsigned values - */ -@AnnotatedFor("nullness") -public final class SignednessUtil { - - private SignednessUtil() { - throw new Error("Do not instantiate"); - } - - /** - * Wraps an unsigned byte array into a ByteBuffer. This method is a wrapper around {@link - * java.nio.ByteBuffer#wrap(byte[]) wrap(byte[])}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer wrapUnsigned(@Unsigned byte[] array) { - return ByteBuffer.wrap(array); - } - - /** - * Wraps an unsigned byte array into a ByteBuffer. This method is a wrapper around {@link - * java.nio.ByteBuffer#wrap(byte[], int, int) wrap(byte[], int, int)}, but assumes that the - * input should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer wrapUnsigned(@Unsigned byte[] array, int offset, int length) { - return ByteBuffer.wrap(array, offset, length); - } - - /** - * Gets an unsigned int from the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#getInt() getInt()}, but assumes that the result should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned int getUnsignedInt(ByteBuffer b) { - return b.getInt(); - } - - /** - * Gets an unsigned short from the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#getShort() getShort()}, but assumes that the result should be interpreted - * as unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned short getUnsignedShort(ByteBuffer b) { - return b.getShort(); - } - - /** - * Gets an unsigned byte from the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#get() get()}, but assumes that the result should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned byte getUnsigned(ByteBuffer b) { - return b.get(); - } - - /** - * Gets an unsigned byte from the ByteBuffer b at i. This method is a wrapper around {@link - * java.nio.ByteBuffer#get(int) get(int)}, but assumes that the result should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned byte getUnsigned(ByteBuffer b, int i) { - return b.get(i); - } - - /** - * Populates an unsigned byte array from the ByteBuffer b at i with l bytes. This method is a - * wrapper around {@link java.nio.ByteBuffer#get(byte[] bs, int, int) get(byte[], int, int)}, - * but assumes that the bytes should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer getUnsigned(ByteBuffer b, byte[] bs, int i, int l) { - return b.get(bs, i, l); - } - - /** - * Places an unsigned byte into the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#put(byte) put(byte)}, but assumes that the input should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsigned(ByteBuffer b, @Unsigned byte ubyte) { - return b.put(ubyte); - } - - /** - * Places an unsigned byte into the ByteBuffer b at i. This method is a wrapper around {@link - * java.nio.ByteBuffer#put(int, byte) put(int, byte)}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsigned(ByteBuffer b, int i, @Unsigned byte ubyte) { - return b.put(i, ubyte); - } - - /** - * Places an unsigned int into the IntBuffer b. This method is a wrapper around {@link - * java.nio.IntBuffer#put(int) put(int)}, but assumes that the input should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static IntBuffer putUnsigned(IntBuffer b, @Unsigned int uint) { - return b.put(uint); - } - - /** - * Places an unsigned int into the IntBuffer b at i. This method is a wrapper around {@link - * java.nio.IntBuffer#put(int, int) put(int, int)}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static IntBuffer putUnsigned(IntBuffer b, int i, @Unsigned int uint) { - return b.put(i, uint); - } - - /** - * Places an unsigned int array into the IntBuffer b. This method is a wrapper around {@link - * java.nio.IntBuffer#put(int[]) put(int[])}, but assumes that the input should be interpreted - * as unsigned. - */ - @SuppressWarnings("signedness") - public static IntBuffer putUnsigned(IntBuffer b, @Unsigned int[] uints) { - return b.put(uints); - } - - /** - * Places an unsigned int array into the IntBuffer b at i with length l. This method is a - * wrapper around {@link java.nio.IntBuffer#put(int[], int, int) put(int[], int, int)}, but - * assumes that the input should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static IntBuffer putUnsigned(IntBuffer b, @Unsigned int[] uints, int i, int l) { - return b.put(uints, i, l); - } - - /** - * Gets an unsigned int from the IntBuffer b at i. This method is a wrapper around {@link - * java.nio.IntBuffer#get(int) get(int)}, but assumes that the output should be interpreted as - * unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned int getUnsigned(IntBuffer b, int i) { - return b.get(i); - } - - /** - * Places an unsigned short into the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#putShort(short) putShort(short)}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsignedShort(ByteBuffer b, @Unsigned short ushort) { - return b.putShort(ushort); - } - - /** - * Places an unsigned short into the ByteBuffer b at i. This method is a wrapper around {@link - * java.nio.ByteBuffer#putShort(int, short) putShort(int, short)}, but assumes that the input - * should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsignedShort(ByteBuffer b, int i, @Unsigned short ushort) { - return b.putShort(i, ushort); - } - - /** - * Places an unsigned int into the ByteBuffer b. This method is a wrapper around {@link - * java.nio.ByteBuffer#putInt(int) putInt(int)}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsignedInt(ByteBuffer b, @Unsigned int uint) { - return b.putInt(uint); - } - - /** - * Places an unsigned int into the ByteBuffer b at i. This method is a wrapper around {@link - * java.nio.ByteBuffer#putInt(int, int) putInt(int, int)}, but assumes that the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsignedInt(ByteBuffer b, int i, @Unsigned int uint) { - return b.putInt(i, uint); - } - - /** - * Places an unsigned long into the ByteBuffer b at i. This method is a wrapper around {@link - * java.nio.ByteBuffer#putLong(int, long) putLong(int, long)}, but assumes that the input should - * be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static ByteBuffer putUnsignedLong(ByteBuffer b, int i, @Unsigned long ulong) { - return b.putLong(i, ulong); - } - - /** - * Reads an unsigned char from the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#readChar() readChar()}, but assumes the output should be interpreted - * as unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned char readUnsignedChar(RandomAccessFile f) throws IOException { - return f.readChar(); - } - - /** - * Reads an unsigned int from the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#readInt() readInt()}, but assumes the output should be interpreted - * as unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned int readUnsignedInt(RandomAccessFile f) throws IOException { - return f.readInt(); - } - - /** - * Reads an unsigned long from the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#readLong() readLong()}, but assumes the output should be interpreted - * as unsigned. - */ - @SuppressWarnings("signedness") - public static @Unsigned long readUnsignedLong(RandomAccessFile f) throws IOException { - return f.readLong(); - } - - /** - * Reads up to {@code len} bytes of data from this file into an unsigned array of bytes. This - * method is a wrapper around {@link java.io.RandomAccessFile#read(byte[], int, int) - * read(byte[], int, int)}, but assumes the output should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static int readUnsigned(RandomAccessFile f, @Unsigned byte b[], int off, int len) - throws IOException { - return f.read(b, off, len); - } - - /** - * Reads a file fully into an unsigned byte array. This method is a wrapper around {@link - * java.io.RandomAccessFile#readFully(byte[]) readFully(byte[])}, but assumes the output should - * be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void readFullyUnsigned(RandomAccessFile f, @Unsigned byte b[]) - throws IOException { - f.readFully(b); - } - - /** - * Writes len unsigned bytes to the RandomAccessFile f at offset off. This method is a wrapper - * around {@link java.io.RandomAccessFile#write(byte[], int, int) write(byte[], int, int)}, but - * assumes the input should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsigned(RandomAccessFile f, @Unsigned byte[] bs, int off, int len) - throws IOException { - f.write(bs, off, len); - } - - /** - * Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#writeByte(int) writeByte(int)}, but assumes the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsignedByte(RandomAccessFile f, @Unsigned byte b) throws IOException { - f.writeByte(Byte.toUnsignedInt(b)); - } - - /** - * Writes an unsigned char to the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#writeChar(int) writeChar(int)}, but assumes the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsignedChar(RandomAccessFile f, @Unsigned char c) throws IOException { - f.writeChar(toUnsignedInt(c)); - } - - /** - * Writes an unsigned short to the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#writeShort(int) writeShort(int)}, but assumes the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsignedShort(RandomAccessFile f, @Unsigned short s) - throws IOException { - f.writeShort(Short.toUnsignedInt(s)); - } - - /** - * Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#writeInt(int) writeInt(int)}, but assumes the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsignedInt(RandomAccessFile f, @Unsigned int i) throws IOException { - f.writeInt(i); - } - - /** - * Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper around {@link - * java.io.RandomAccessFile#writeLong(long) writeLong(long)}, but assumes the input should be - * interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void writeUnsignedLong(RandomAccessFile f, @Unsigned long l) throws IOException { - f.writeLong(l); - } - - /** - * Gets an array of unsigned bytes from the ByteBuffer b and stores them in the array bs. This - * method is a wrapper around {@link java.nio.ByteBuffer#get(byte[]) get(byte[])}, but assumes - * that the array of bytes should be interpreted as unsigned. - */ - @SuppressWarnings("signedness") - public static void getUnsigned(ByteBuffer b, @Unsigned byte[] bs) { - b.get(bs); - } - - /** - * Compares two unsigned shorts x and y. - * - * @return a negative number iff x {@literal <} y, a positive number iff x {@literal >} y, and - * zero iff x == y. - */ - @SuppressWarnings("signedness") - public static int compareUnsigned(@Unsigned short x, @Unsigned short y) { - return Integer.compareUnsigned(Short.toUnsignedInt(x), Short.toUnsignedInt(y)); - } - - /** - * Compares two unsigned bytes x and y. - * - * @return a negative number iff x {@literal <} y, a positive number iff x {@literal >} y, and - * zero iff x == y. - */ - @SuppressWarnings("signedness") - public static int compareUnsigned(@Unsigned byte x, @Unsigned byte y) { - return Integer.compareUnsigned(Byte.toUnsignedInt(x), Byte.toUnsignedInt(y)); - } - - /** Produces a string representation of the unsigned short s. */ - @SuppressWarnings("signedness") - public static String toUnsignedString(@Unsigned short s) { - return Long.toString(Short.toUnsignedLong(s)); - } - - /** Produces a string representation of the unsigned short s in base radix. */ - @SuppressWarnings("signedness") - public static String toUnsignedString(@Unsigned short s, int radix) { - return Integer.toUnsignedString(Short.toUnsignedInt(s), radix); - } - - /** Produces a string representation of the unsigned byte b. */ - @SuppressWarnings("signedness") - public static String toUnsignedString(@Unsigned byte b) { - return Integer.toUnsignedString(Byte.toUnsignedInt(b)); - } - - /** Produces a string representation of the unsigned byte b in base radix. */ - @SuppressWarnings("signedness") - public static String toUnsignedString(@Unsigned byte b, int radix) { - return Integer.toUnsignedString(Byte.toUnsignedInt(b), radix); - } - - /* - * Creates a BigInteger representing the same value as unsigned long. - * - * This is a reimplementation of Java 8's - * {@link Long.toUnsignedBigInteger(long)}. - */ - @SuppressWarnings("signedness") - private static @Unsigned BigInteger toUnsignedBigInteger(@Unsigned long l) { - // Java 8 version: return Long.toUnsignedBigInteger(l); - if (l >= 0L) { - return BigInteger.valueOf(l); - } else { - int upper = (int) (l >>> 32); - int lower = (int) l; - - // return (upper << 32) + lower - return BigInteger.valueOf(Integer.toUnsignedLong(upper)) - .shiftLeft(32) - .add(BigInteger.valueOf(Integer.toUnsignedLong(lower))); - } - } - - /** Returns an unsigned short representing the same value as an unsigned byte. */ - public static @Unsigned short toUnsignedShort(@Unsigned byte b) { - return (short) (((int) b) & 0xff); - } - - /** Returns an unsigned long representing the same value as an unsigned char. */ - public static @Unsigned long toUnsignedLong(@Unsigned char c) { - return ((long) c) & 0xffL; - } - - /** Returns an unsigned int representing the same value as an unsigned char. */ - public static @Unsigned int toUnsignedInt(@Unsigned char c) { - return ((int) c) & 0xff; - } - - /** Returns an unsigned short representing the same value as an unsigned char. */ - public static @Unsigned short toUnsignedShort(@Unsigned char c) { - return (short) (((int) c) & 0xff); - } - - /** Returns a float representing the same value as the unsigned byte. */ - public static float toFloat(@Unsigned byte b) { - return toUnsignedBigInteger(Byte.toUnsignedLong(b)).floatValue(); - } - - /** Returns a float representing the same value as the unsigned short. */ - public static float toFloat(@Unsigned short s) { - return toUnsignedBigInteger(Short.toUnsignedLong(s)).floatValue(); - } - - /** Returns a float representing the same value as the unsigned int. */ - public static float toFloat(@Unsigned int i) { - return toUnsignedBigInteger(Integer.toUnsignedLong(i)).floatValue(); - } - - /** Returns a float representing the same value as the unsigned long. */ - public static float toFloat(@Unsigned long l) { - return toUnsignedBigInteger(l).floatValue(); - } - - /** Returns a double representing the same value as the unsigned byte. */ - public static double toDouble(@Unsigned byte b) { - return toUnsignedBigInteger(Byte.toUnsignedLong(b)).doubleValue(); - } - - /** Returns a double representing the same value as the unsigned short. */ - public static double toDouble(@Unsigned short s) { - return toUnsignedBigInteger(Short.toUnsignedLong(s)).doubleValue(); - } - - /** Returns a double representing the same value as the unsigned int. */ - public static double toDouble(@Unsigned int i) { - return toUnsignedBigInteger(Integer.toUnsignedLong(i)).doubleValue(); - } - - /** Returns a double representing the same value as the unsigned long. */ - public static double toDouble(@Unsigned long l) { - return toUnsignedBigInteger(l).doubleValue(); - } - - /** Returns an unsigned byte representing the same value as the float. */ - @SuppressWarnings("signedness") - public static @Unsigned byte byteFromFloat(float f) { - assert f >= 0; - return (byte) f; - } - - /** Returns an unsigned short representing the same value as the float. */ - @SuppressWarnings("signedness") - public static @Unsigned short shortFromFloat(float f) { - assert f >= 0; - return (short) f; - } - - /** Returns an unsigned int representing the same value as the float. */ - @SuppressWarnings("signedness") - public static @Unsigned int intFromFloat(float f) { - assert f >= 0; - return (int) f; - } - - /** Returns an unsigned long representing the same value as the float. */ - @SuppressWarnings("signedness") - public static @Unsigned long longFromFloat(float f) { - assert f >= 0; - return (long) f; - } - - /** Returns an unsigned byte representing the same value as the double. */ - @SuppressWarnings("signedness") - public static @Unsigned byte byteFromDouble(double d) { - assert d >= 0; - return (byte) d; - } - - /** Returns an unsigned short representing the same value as the double. */ - @SuppressWarnings("signedness") - public static @Unsigned short shortFromDouble(double d) { - assert d >= 0; - return (short) d; - } - - /** Returns an unsigned int representing the same value as the double. */ - @SuppressWarnings("signedness") - public static @Unsigned int intFromDouble(double d) { - assert d >= 0; - return (int) d; - } - - /** Returns an unsigned long representing the same value as the double. */ - @SuppressWarnings("signedness") - public static @Unsigned long longFromDouble(double d) { - assert d >= 0; - return (long) d; - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/PolySigned.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/PolySigned.java deleted file mode 100644 index d07dd514656..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/PolySigned.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the signedness type system. - * - * @checker_framework.manual #signedness-checker Signedness Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownSignedness.class) -public @interface PolySigned {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Signed.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Signed.java deleted file mode 100644 index 377e79391ac..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Signed.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeKind; -import org.checkerframework.framework.qual.UpperBoundFor; - -/** - * The value is to be interpreted as signed. That is, if the most significant bit in the bitwise - * representation is set, then the bits should be interpreted as a negative number. - * - * @checker_framework.manual #signedness-checker Signedness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UnknownSignedness.class}) -@DefaultFor( - typeKinds = { - TypeKind.BYTE, - TypeKind.INT, - TypeKind.LONG, - TypeKind.SHORT, - TypeKind.FLOAT, - TypeKind.DOUBLE - }, - types = { - java.lang.Byte.class, - java.lang.Integer.class, - java.lang.Long.class, - java.lang.Short.class, - java.lang.Float.class, - java.lang.Double.class - }) -@UpperBoundFor( - typeKinds = {TypeKind.FLOAT, TypeKind.DOUBLE}, - types = {java.lang.Float.class, java.lang.Double.class}) -public @interface Signed {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignedPositive.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignedPositive.java deleted file mode 100644 index ef4ef02410d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignedPositive.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The expression's value is in the signed positive range; that is, its most significant bit is not - * set. The value has the same interpretation as {@link Signed} and {@link Unsigned} — both - * interpretations are equivalent. - * - *

Programmers should rarely write {@code @SignedPositive}. Instead, the programmer should write - * {@link Signed} or {@link Unsigned} to indicate how the programmer intends the value to be - * interpreted. - * - *

Internally, this is translated to the {@code @}{@link SignednessGlb} annotation. This means - * that programmers do not see this annotation in error messages. - * - * @see SignednessGlb - * @checker_framework.manual #signedness-checker Signedness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface SignedPositive {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessBottom.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessBottom.java deleted file mode 100644 index 243bc6fd6f0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Signedness type system. Programmers should rarely write this type. - * - *

This is the type of the {@code null} literal. - * - * @checker_framework.manual #signedness-checker Signedness Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({SignednessGlb.class}) -public @interface SignednessBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessGlb.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessGlb.java deleted file mode 100644 index 1a7150d14b9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/SignednessGlb.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Client code may interpret the value either as {@link Signed} or as {@link Unsigned}. This - * primarily applies to values whose most significant bit is not set {@link SignedPositive}, and - * thus the value has the same interpretation as signed or unsigned. - * - *

As a special case, the Signedness Checker also applies this annotation to manifest literals. - * This permits a value like {@code -1} or {@code 255} or {@code 0xFF} to be used in both signed and - * unsigned contexts. The Signedness Checker has no way of knowing how a programmer intended a - * literal to be used, so it does not issue warnings for any uses of a literal. (An alternate design - * would require the programmer to explicitly annotate every manifest literal whose most significant - * bit is set. That might detect more errors, at the cost of much greater programmer annotation - * effort.) - * - *

The programmer should not write this annotation. Instead, the programmer should write {@link - * Signed} or {@link Unsigned} to indicate how the programmer intends the value to be interpreted. - * For a value whose most significant bit is not set and different clients may treat it differently - * (say, the return value of certain library routines, or certain constant fields), the programmer - * should write {@code @}{@link SignedPositive} instead of {@code @SignednessGlb}. - * - *

The "Glb" in the name stands for "greatest lower bound", because this type is the greatest - * lower bound of the types {@link Signed} and {@link Unsigned}; that is, this type is a subtype of - * both of those types. - * - * @see SignedPositive - * @checker_framework.manual #signedness-checker Signedness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({Unsigned.class, Signed.class}) -@QualifierForLiterals({LiteralKind.INT, LiteralKind.LONG, LiteralKind.CHAR}) -public @interface SignednessGlb {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/UnknownSignedness.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/UnknownSignedness.java deleted file mode 100644 index 0049b7ceaad..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/UnknownSignedness.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * The value's signedness is not known to the Signedness Checker. This is also used for non-numeric - * values, which cannot have a signedness. - * - * @checker_framework.manual #signedness-checker Signedness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownSignedness {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Unsigned.java b/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Unsigned.java deleted file mode 100644 index 3b8029b6996..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/signedness/qual/Unsigned.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.checkerframework.checker.signedness.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeKind; -import org.checkerframework.framework.qual.UpperBoundFor; - -/** - * The value is to be interpreted as unsigned. That is, if the most significant bit in the bitwise - * representation is set, then the bits should be interpreted as a large positive number rather than - * as a negative number. - * - * @checker_framework.manual #signedness-checker Signedness Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UnknownSignedness.class}) -@DefaultFor( - typeKinds = {TypeKind.CHAR}, - types = {java.lang.Character.class}) -@UpperBoundFor( - typeKinds = {TypeKind.CHAR}, - types = {java.lang.Character.class}) -public @interface Unsigned {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/PolyTainted.java b/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/PolyTainted.java deleted file mode 100644 index 0f481e6ab56..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/PolyTainted.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.tainting.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Tainting type system. - * - * @checker_framework.manual #tainting-checker Tainting Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(Tainted.class) -public @interface PolyTainted {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Tainted.java b/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Tainted.java deleted file mode 100644 index 86187facd49..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Tainted.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.checker.tainting.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Denotes a possibly-tainted value: at run time, the value might be tainted or might be untainted. - * - *

This is the top qualifier of the tainting type system. This annotation is associated with the - * {@link org.checkerframework.checker.tainting.TaintingChecker}. - * - * @see Untainted - * @see org.checkerframework.checker.tainting.TaintingChecker - * @checker_framework.manual #tainting-checker Tainting Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@DefaultQualifierInHierarchy -@SubtypeOf({}) -public @interface Tainted {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Untainted.java b/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Untainted.java deleted file mode 100644 index 83d48f5186b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/tainting/qual/Untainted.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.tainting.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.LiteralKind; -import org.checkerframework.framework.qual.QualifierForLiterals; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Denotes a reference that is untainted, i.e. can be trusted. - * - * @checker_framework.manual #tainting-checker Tainting Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Tainted.class) -@QualifierForLiterals(LiteralKind.STRING) -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface Untainted {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/UnitsTools.java b/src/java.base/share/classes/org/checkerframework/checker/units/UnitsTools.java deleted file mode 100644 index 56f128df42c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/UnitsTools.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.checkerframework.checker.units; - -import org.checkerframework.checker.units.qual.A; -import org.checkerframework.checker.units.qual.C; -import org.checkerframework.checker.units.qual.K; -import org.checkerframework.checker.units.qual.cd; -import org.checkerframework.checker.units.qual.degrees; -import org.checkerframework.checker.units.qual.g; -import org.checkerframework.checker.units.qual.h; -import org.checkerframework.checker.units.qual.kg; -import org.checkerframework.checker.units.qual.km; -import org.checkerframework.checker.units.qual.km2; -import org.checkerframework.checker.units.qual.kmPERh; -import org.checkerframework.checker.units.qual.m; -import org.checkerframework.checker.units.qual.m2; -import org.checkerframework.checker.units.qual.mPERs; -import org.checkerframework.checker.units.qual.mPERs2; -import org.checkerframework.checker.units.qual.min; -import org.checkerframework.checker.units.qual.mm; -import org.checkerframework.checker.units.qual.mm2; -import org.checkerframework.checker.units.qual.mol; -import org.checkerframework.checker.units.qual.radians; -import org.checkerframework.checker.units.qual.s; -import org.checkerframework.framework.qual.AnnotatedFor; - -// TODO: add fromTo methods for all useful unit combinations. - -/** Utility methods to generate annotated types and to convert between them. */ -@SuppressWarnings({"units", "checkstyle:constantname"}) -@AnnotatedFor("nullness") -public class UnitsTools { - // Acceleration - public static final @mPERs2 int mPERs2 = 1; - - // Angle - public static final @radians double rad = 1; - public static final @degrees double deg = 1; - - public static @radians double toRadians(@degrees double angdeg) { - return Math.toRadians(angdeg); - } - - public static @degrees double toDegrees(@radians double angrad) { - return Math.toDegrees(angrad); - } - - // Area - public static final @mm2 int mm2 = 1; - public static final @m2 int m2 = 1; - public static final @km2 int km2 = 1; - - // Current - public static final @A int A = 1; - - // Luminance - public static final @cd int cd = 1; - - // Lengths - public static final @mm int mm = 1; - public static final @m int m = 1; - public static final @km int km = 1; - - public static @m int fromMilliMeterToMeter(@mm int mm) { - return mm / 1000; - } - - public static @mm int fromMeterToMilliMeter(@m int m) { - return m * 1000; - } - - public static @km int fromMeterToKiloMeter(@m int m) { - return m / 1000; - } - - public static @m int fromKiloMeterToMeter(@km int km) { - return km * 1000; - } - - // Mass - public static final @g int g = 1; - public static final @kg int kg = 1; - - public static @kg int fromGramToKiloGram(@g int g) { - return g / 1000; - } - - public static @g int fromKiloGramToGram(@kg int kg) { - return kg * 1000; - } - - // Speed - public static final @mPERs int mPERs = 1; - public static final @kmPERh int kmPERh = 1; - - public static @kmPERh double fromMeterPerSecondToKiloMeterPerHour(@mPERs double mps) { - return mps * 3.6d; - } - - public static @mPERs double fromKiloMeterPerHourToMeterPerSecond(@kmPERh double kmph) { - return kmph / 3.6d; - } - - // Substance - public static final @mol int mol = 1; - - // Temperature - public static final @K int K = 1; - public static final @C int C = 1; - - public static @C int fromKelvinToCelsius(@K int k) { - return k - (int) 273.15; - } - - public static @K int fromCelsiusToKelvin(@C int c) { - return c + (int) 273.15; - } - - // Time - public static final @s int s = 1; - public static final @min int min = 1; - public static final @h int h = 1; - - public static @min int fromSecondToMinute(@s int s) { - return s / 60; - } - - public static @s int fromMinuteToSecond(@min int min) { - return min * 60; - } - - public static @h int fromMinuteToHour(@min int min) { - return min / 60; - } - - public static @min int fromHourToMinute(@h int h) { - return h * 60; - } -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/A.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/A.java deleted file mode 100644 index 270ad8cd510..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/A.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Ampere. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Current.class) -public @interface A { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Acceleration.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Acceleration.java deleted file mode 100644 index fcd64b667de..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Acceleration.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of acceleration. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Acceleration {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Angle.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Angle.java deleted file mode 100644 index bc764db07ad..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Angle.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of measure for angles. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Angle {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Area.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Area.java deleted file mode 100644 index 14dcf9388d2..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Area.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of areas. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Area {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/C.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/C.java deleted file mode 100644 index bdda8f0e55d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/C.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Degree Centigrade (Celsius). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Temperature.class) -public @interface C {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Current.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Current.java deleted file mode 100644 index fc49e8c06e8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Current.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Electric current. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Current {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/K.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/K.java deleted file mode 100644 index 0a20c37766e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/K.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Kelvin (unit of temperature). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Temperature.class) -public @interface K { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Length.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Length.java deleted file mode 100644 index 994acf2651b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Length.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of length. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Length {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Luminance.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Luminance.java deleted file mode 100644 index 0d7dd66d366..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Luminance.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of luminance. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Luminance {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Mass.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Mass.java deleted file mode 100644 index b0337b2a90c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Mass.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of mass. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Mass {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/MixedUnits.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/MixedUnits.java deleted file mode 100644 index 08dcc379015..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/MixedUnits.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * MixedUnits is the result of multiplying or dividing units, where no more specific unit is known - * from a UnitsRelations implementation. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) // forbids a programmer from writing it in a program -@SubtypeOf(UnknownUnits.class) -public @interface MixedUnits {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/PolyUnit.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/PolyUnit.java deleted file mode 100644 index 717616ec89e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/PolyUnit.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the units-of-measure type system implemented by the Units Checker. - * - *

Any method written using @PolyUnit conceptually has many versions: in each one, every instance - * of @PolyUnit has been replaced by a different unit qualifier such as @kg (kilograms) or @h - * (hours). - * - *

The following example shows how method {@code triplePolyUnit} can be used to process either - * meters or seconds: - * - *


- * {@literal @}PolyUnit int triplePolyUnit(@PolyUnit int amount) {
- *    return 3*amount;
- *  }
- *
- *  void testPolyUnit() {
- *   {@literal @}m int m1 = 7 * UnitsTools.m;
- *   {@literal @}m int m2 = triplePolyUnit(m1);
- *
- *   {@literal @}s int sec1 = 7 * UnitsTools.s;
- *   {@literal @}s int sec2 = triplePolyUnit(sec1);
- *
- *    // :: error: (assignment.type.incompatible)
- *   {@literal @}s int sec3 = triplePolyUnit(m1);
- *  }
- * 
- * - * @checker_framework.manual #units-checker Units Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownUnits.class) -public @interface PolyUnit {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Prefix.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Prefix.java deleted file mode 100644 index 437c4e797ab..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Prefix.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.checkerframework.checker.units.qual; - -/** - * SI prefixes. - * - *

From http://en.wikipedia.org/wiki/SI_prefix: - * - *

- * yotta   Y   1000^8     10^24    1000000000000000000000000   Septillion      Quadrillion     1991
- * zetta   Z   1000^7     10^21    1000000000000000000000      Sextillion      Trilliard       1991
- * exa     E   1000^6     10^18    1000000000000000000         Quintillion     Trillion        1975
- * peta    P   1000^5     10^15    1000000000000000            Quadrillion     Billiard        1975
- * tera    T   1000^4     10^12    1000000000000               Trillion        Billion         1960
- * giga    G   1000^3     10^9     1000000000                  Billion         Milliard        1960
- * mega    M   1000^2     10^6     1000000                     Million                         1960
- * kilo    k   1000^1     10^3     1000                        Thousand                        1795
- * hecto   h   1000^2/3   10^2     100                         Hundred                         1795
- * deca    da  1000^1/3   10^1     10                          Ten                             1795
- * 1000^0     10^0     1                           One
- * deci    d   1000^-1/3  10^-1    0.1                         Tenth                           1795
- * centi   c   1000^-2/3  10^-2    0.01                        Hundredth                       1795
- * milli   m   1000^-1    10^-3    0.001                       Thousandth                      1795
- * micro   my  1000^-2    10^-6    0.000001                    Millionth                       1960
- * nano    n   1000^-3    10^-9    0.000000001                 Billionth       Milliardth      1960
- * pico    p   1000^-4    10^-12   0.000000000001              Trillionth      Billionth       1960
- * femto   f   1000^-5    10^-15   0.000000000000001           Quadrillionth   Billiardth      1964
- * atto    a   1000^-6    10^-18   0.000000000000000001        Quintillionth   Trillionth      1964
- * zepto   z   1000^-7    10^-21   0.000000000000000000001     Sextillionth    Trilliardth     1991
- * yocto   y   1000^-8    10^-24   0.000000000000000000000001  Septillionth    Quadrillionth   1991
- * 
- * - * @checker_framework.manual #units-checker Units Checker - */ -public enum Prefix { - /** SI prefix for 10^24. */ - yotta, - /** SI prefix for 10^21. */ - zetta, - /** SI prefix for 10^18. */ - exa, - /** SI prefix for 10^15. */ - peta, - /** SI prefix for 10^12. */ - tera, - /** SI prefix for 10^9. */ - giga, - /** SI prefix for 10^6. */ - mega, - /** SI prefix for 10^3. */ - kilo, - /** SI prefix for 10^2. */ - hecto, - /** SI prefix for 10^1. */ - deca, - /** SI prefix for 10^0, or 1. */ - one, - /** SI prefix for 10^-1. */ - deci, - /** SI prefix for 10^-2. */ - centi, - /** SI prefix for 10^-3. */ - milli, - /** SI prefix for 10^-6. */ - micro, - /** SI prefix for 10^-9. */ - nano, - /** SI prefix for 10^-12. */ - pico, - /** SI prefix for 10^-15. */ - femto, - /** SI prefix for 10^-18. */ - atto, - /** SI prefix for 10^-21. */ - zepto, - /** SI prefix for 10^-24. */ - yocto -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Speed.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Speed.java deleted file mode 100644 index 94fe348e037..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Speed.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of speed. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Speed {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Substance.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Substance.java deleted file mode 100644 index 214f981fefc..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Substance.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of substance, such as mole (@{@link mol}). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Substance {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Temperature.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Temperature.java deleted file mode 100644 index e251f8c2179..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Temperature.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of temperature. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Temperature {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Time.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/Time.java deleted file mode 100644 index ecf7b9128d4..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/Time.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Units of time. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(UnknownUnits.class) -public @interface Time {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsBottom.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsBottom.java deleted file mode 100644 index 8e1f45413ec..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Units type system. Programmers should rarely write this type. - * - * @checker_framework.manual #units-checker Units Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({}) // needs to be done programmatically -@DefaultFor(TypeUseLocation.LOWER_BOUND) -public @interface UnitsBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsMultiple.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsMultiple.java deleted file mode 100644 index f1f6c097a01..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsMultiple.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Define the relation between a base unit and the current unit. - * - *

TODO: add support for factors and more general formulas? E.g. it would be cool if the relation - * hour → minute and Fahrenheit → Celsius could be expressed. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -public @interface UnitsMultiple { - /** - * Returns the base unit to use. - * - * @return the base unit to use - */ - Class quantity(); - - /** - * Returns the scaling prefix. - * - * @return the scaling prefix - */ - Prefix prefix() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsRelations.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsRelations.java deleted file mode 100644 index 562d65c2703..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnitsRelations.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * Specify the class that knows how to handle the meta-annotated unit when put in relation (plus, - * multiply, ...) with another unit. - * - * @see org.checkerframework.checker.units.UnitsRelations - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -public @interface UnitsRelations { - /** - * Returns the UnitsRelations subclass to use. - * - * @return the UnitsRelations subclass to use - */ - // The more precise type is Class, - // but org.checkerframework.checker.units.UnitsRelations is not in checker-qual.jar, nor can - // it be since it uses AnnotatedTypeMirrors. So use a less precise type and check that it - // is a subclass in UnitsAnnotatedTypeFactory. - Class value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnknownUnits.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnknownUnits.java deleted file mode 100644 index 70d98c07bc9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/UnknownUnits.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * UnknownUnits is the top type of the type hierarchy. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownUnits {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/cd.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/cd.java deleted file mode 100644 index bf17fdb0e00..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/cd.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Candela (unit of luminance). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Luminance.class) -@SuppressWarnings("checkstyle:typename") -public @interface cd { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/degrees.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/degrees.java deleted file mode 100644 index a4d7ae62b67..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/degrees.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Degrees. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Angle.class) -@SuppressWarnings("checkstyle:typename") -public @interface degrees {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/g.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/g.java deleted file mode 100644 index 2b7f08c4057..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/g.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Gram. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Mass.class) -@SuppressWarnings("checkstyle:typename") -public @interface g { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/h.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/h.java deleted file mode 100644 index 6a568a9fd5a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/h.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Hour. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Time.class) -// TODO: support arbitrary factors? -// @UnitsMultiple(quantity=s.class, factor=3600) -@SuppressWarnings("checkstyle:typename") -public @interface h {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/kg.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/kg.java deleted file mode 100644 index 714cdfb2972..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/kg.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Kilogram. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Mass.class) -@UnitsMultiple(quantity = g.class, prefix = Prefix.kilo) -@SuppressWarnings("checkstyle:typename") -public @interface kg {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/km.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/km.java deleted file mode 100644 index c2cb32d87dd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/km.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Kilometer. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Length.class) -@UnitsMultiple(quantity = m.class, prefix = Prefix.kilo) -@SuppressWarnings("checkstyle:typename") -public @interface km {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/km2.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/km2.java deleted file mode 100644 index 590d0fe2584..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/km2.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Square kilometer. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Area.class) -@SuppressWarnings("checkstyle:typename") -public @interface km2 {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/kmPERh.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/kmPERh.java deleted file mode 100644 index 28abf4bd1c0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/kmPERh.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Kilometer per hour. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Speed.class) -@SuppressWarnings("checkstyle:typename") -public @interface kmPERh {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/m.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/m.java deleted file mode 100644 index c3b94628ed7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/m.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Meter. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Length.class) -// This is the default: -// @UnitsRelations(org.checkerframework.checker.units.UnitsRelationsDefault.class) -// If you want an alias for "m", e.g. "Meter", simply create that -// annotation and add this meta-annotation: -// @UnitsMultiple(quantity=m.class, prefix=Prefix.one) -@SuppressWarnings("checkstyle:typename") -public @interface m { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/m2.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/m2.java deleted file mode 100644 index 4f7c29fe76c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/m2.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Square meter. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Area.class) -@SuppressWarnings("checkstyle:typename") -public @interface m2 { - // does this make sense? Is it multiple of (m^2)? Or (multiple of m)^2? - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs.java deleted file mode 100644 index ab97dfb9465..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Meter per second. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Speed.class) -@SuppressWarnings("checkstyle:typename") -public @interface mPERs { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs2.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs2.java deleted file mode 100644 index 0af7169340f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mPERs2.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Meter per second squared. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Acceleration.class) -@SuppressWarnings("checkstyle:typename") -public @interface mPERs2 { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/min.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/min.java deleted file mode 100644 index b729aa02c23..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/min.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Minute. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Time.class) -@SuppressWarnings("checkstyle:typename") -// TODO: @UnitsMultiple(quantity=s.class, factor=60) -public @interface min {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm.java deleted file mode 100644 index dff99618b66..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Millimeter. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Length.class) -@UnitsMultiple(quantity = m.class, prefix = Prefix.milli) -@SuppressWarnings("checkstyle:typename") -public @interface mm {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm2.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm2.java deleted file mode 100644 index 2e5569887cb..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mm2.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Square millimeter. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Area.class) -@SuppressWarnings("checkstyle:typename") -public @interface mm2 {} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mol.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/mol.java deleted file mode 100644 index b02a1441e30..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/mol.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Mole (unit of {@link Substance}). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Substance.class) -@SuppressWarnings("checkstyle:typename") -public @interface mol { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/radians.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/radians.java deleted file mode 100644 index 9cc186db201..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/radians.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Radians. - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Angle.class) -@SuppressWarnings("checkstyle:typename") -public @interface radians { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/checker/units/qual/s.java b/src/java.base/share/classes/org/checkerframework/checker/units/qual/s.java deleted file mode 100644 index ed5d5234f9c..00000000000 --- a/src/java.base/share/classes/org/checkerframework/checker/units/qual/s.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.checker.units.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A second (1/60 of a minute). - * - * @checker_framework.manual #units-checker Units Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf(Time.class) -@SuppressWarnings("checkstyle:typename") -public @interface s { - Prefix value() default Prefix.one; -} diff --git a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/LeakedToResult.java b/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/LeakedToResult.java deleted file mode 100644 index 5484eee29d7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/LeakedToResult.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.checkerframework.common.aliasing.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation is used on a formal parameter to indicate that the parameter may be returned, but - * it is not otherwise leaked. (A parameter is leaked if it is stored in a field where it could be - * accessed later, and in that case this annotation would not apply.) - * - *

For example, the receiver parameter of {@link StringBuffer#append(String s)} is annotated as - * {@code @LeakedToResult}, because the method returns the updated receiver. - * - * @see NonLeaked - * @checker_framework.manual #aliasing-checker Aliasing Checker - *

TODO: This annotation is currently trusted. A verification must be implemented. - */ - -// This is a type qualifier because of a checker framework limitation (Issue 383), but its -// hierarchy is ignored. Once the stub parser gets updated to read non-type-qualifiers -// annotations on stub files, this annotation won't be a type qualifier anymore. - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE}) -@SubtypeOf({NonLeaked.class}) -public @interface LeakedToResult {} diff --git a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeAliased.java b/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeAliased.java deleted file mode 100644 index d17d6b6e9e1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeAliased.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.common.aliasing.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultFor; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * An expression with this type might have an alias. In other words, some other expression, - * evaluated at the same program point, might evaluate to the exact same object value. - * - * @see Unique - * @checker_framework.manual #aliasing-checker Aliasing Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -@DefaultFor( - value = {TypeUseLocation.UPPER_BOUND, TypeUseLocation.LOWER_BOUND}, - types = Void.class) -public @interface MaybeAliased {} diff --git a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeLeaked.java b/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeLeaked.java deleted file mode 100644 index 9038b6b75b0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/MaybeLeaked.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.common.aliasing.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * Temporary type qualifier: - * - *

This is the default type qualifier for the Leaked hierarchy. - * - *

Once the stub parser gets updated to read non-type-qualifier annotations on stub files (Issue - * 383), this annotation can be removed, and {@link NonLeaked} and {@link LeakedToResult} can be - * made to be type annotations but not type qualifiers and not in a type hierarchy. - * - * @checker_framework.manual #aliasing-checker Aliasing Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({}) -@DefaultQualifierInHierarchy -@SubtypeOf({LeakedToResult.class}) -@InvisibleQualifier -public @interface MaybeLeaked {} diff --git a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/NonLeaked.java b/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/NonLeaked.java deleted file mode 100644 index 2caa5c1c69f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/NonLeaked.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.checkerframework.common.aliasing.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This annotation is used on a formal parameter to indicate that the parameter is not leaked - * (stored in a location that could be accessed later) nor returned by the method body. - * - *

For example, the parameter of {@link String#String(String s)} is {@code @NonLeaked}, because - * the method only uses the parameter to make a copy of it. - * - * @see LeakedToResult - * @checker_framework.manual #aliasing-checker Aliasing Checker - *

TODO: This annotation is currently trusted. A verification must be implemented. - */ - -// This is a type qualifier because of a checker framework limitation (Issue 383), but its -// hierarchy is ignored. Once the stub parser gets updated to read non-type-qualifiers -// annotations on stub files, this annotation won't be a type qualifier anymore. - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE}) -@SubtypeOf({}) -public @interface NonLeaked {} diff --git a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/Unique.java b/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/Unique.java deleted file mode 100644 index 61945114567..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/aliasing/qual/Unique.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.common.aliasing.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type has no aliases. In other words, no other expression, evaluated at - * the same program point, would evaluate to the exact same object value. - * - *

A constructor's return type should be annotated with {@code @Unique} if the constructor does - * not leak references to the constructed object. For example, the {@code String()} constructor - * return type is annotated as {@code @Unique}. - * - * @see MaybeAliased - * @checker_framework.manual #aliasing-checker Aliasing Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({MaybeAliased.class}) -public @interface Unique {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassBound.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassBound.java deleted file mode 100644 index d8505f0aa51..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassBound.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This represents a {@code Class} object whose run-time value is equal to or a subtype of one of - * the arguments. - * - * @checker_framework.manual #methodval-and-classval-checkers ClassVal Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UnknownClass.class}) -public @interface ClassBound { - /** - * The binary - * name of the class or classes that upper-bound the values of this Class object. - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassVal.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassVal.java deleted file mode 100644 index ec489eba0f3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassVal.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This represents a {@link java.lang.Class Class<T>} object where the set of possible values - * of T is known at compile time. If only one argument is given, then the exact value of T is known. - * If more than one argument is given, then the value of T is one of those classes. - * - * @checker_framework.manual #methodval-and-classval-checkers ClassVal Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UnknownClass.class}) -public @interface ClassVal { - /** - * The binary - * name of the class that this Class object represents. - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassValBottom.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassValBottom.java deleted file mode 100644 index 757845f4e03..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ClassValBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the ClassVal type system. Programmers should rarely write this type. - * - * @checker_framework.manual #methodval-and-classval-checkers ClassVal Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({ClassVal.class, ClassBound.class}) -public @interface ClassValBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ForName.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ForName.java deleted file mode 100644 index 93773fbae40..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/ForName.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Class.forName}. Their signature is - * - *


- *  @ClassVal("name") Class method(@ForName String name) {...}
- * 
- * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface ForName {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetClass.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetClass.java deleted file mode 100644 index bd97c1aae91..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetClass.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Object.getClassName}. Their signature is:
- * {@code @}{@link ClassBound}{@code ("ReceiverType") Class method(ReceiverType this) {...}} - * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface GetClass {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetConstructor.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetConstructor.java deleted file mode 100644 index 0ca3d27f4a8..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetConstructor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Class.getConstructor}, whose signature is:
- * {@code {@link MethodVal}(classname=c, methodname="", params=p) Constructor - * method(Class this, Object... params)} - * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface GetConstructor {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetMethod.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetMethod.java deleted file mode 100644 index f1aba337dea..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/GetMethod.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Class.getMethod} and {@code Class.getDeclaredMethod}, whose - * signature is:
- * {@code {@link MethodVal}(classname=c, methodname=m, params=p) Method getMyMethod(Class this, - * String m, Object... params)} - * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface GetMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/Invoke.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/Invoke.java deleted file mode 100644 index 431631cc0e1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/Invoke.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Method.invoke}, whose signature is:
- * {@code Object method({@link MethodVal}(classname=c, methodname=m, params=p) Method this, Object - * obj, Object... args)} - * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface Invoke {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodVal.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodVal.java deleted file mode 100644 index 7087e3ee2a6..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodVal.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * This represents a set of {@link java.lang.reflect.Method Method} or {@link - * java.lang.reflect.Constructor Constructor} values. If an expression's type has - * {@code @MethodVal}, then the expression's run-time value is one of those values. - * - *

Each of {@code @MethodVal}'s argument lists must be of equal length, and { className[i], - * methodName[i], params[i] } represents one of the {@code Method} or {@code Constructor} values in - * the set. - * - * @checker_framework.manual #methodval-and-classval-checkers MethodVal Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({UnknownMethod.class}) -public @interface MethodVal { - /** - * The binary - * name of the class that declares this method. - */ - String[] className(); - - /** - * The name of the method that this Method object represents. Use {@code } for - * constructors. - */ - String[] methodName(); - - /** The number of parameters to the method. */ - int[] params(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodValBottom.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodValBottom.java deleted file mode 100644 index c99f8740ccf..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/MethodValBottom.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the MethodVal type system. Programmers should rarely write this type. - * - * @checker_framework.manual #methodval-and-classval-checkers MethodVal Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({MethodVal.class}) -public @interface MethodValBottom {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/NewInstance.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/NewInstance.java deleted file mode 100644 index 5efda6c186a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/NewInstance.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation for methods like {@code Constructor.newInstance}, whose signature is:
- * {@code T method(}{@link MethodVal}{@code (classname=c, methodname="", params=p) Constructor - * this, Object... args)} - * - * @checker_framework.manual #reflection-resolution Reflection resolution - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface NewInstance {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownClass.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownClass.java deleted file mode 100644 index f89c5e9f2c5..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownClass.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Represents a Class object whose run-time value is not known at compile time. Also represents - * non-Class values. - * - *

This annotation is the default in the hierarchy. - * - * @checker_framework.manual #methodval-and-classval-checkers ClassVal Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownClass {} diff --git a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownMethod.java b/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownMethod.java deleted file mode 100644 index 34547759c13..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/reflection/qual/UnknownMethod.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.checkerframework.common.reflection.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Represents a {@link java.lang.reflect.Method Method} or {@link java.lang.reflect.Constructor - * Constructor} expression whose run-time value is not known at compile time. Also represents - * non-Method, non-Constructor values. - * - *

This annotation is the default in the hierarchy. - * - * @checker_framework.manual #methodval-and-classval-checkers MethodVal Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@InvisibleQualifier -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownMethod {} diff --git a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/BottomThis.java b/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/BottomThis.java deleted file mode 100644 index 99dd4fcb56b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/BottomThis.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.common.returnsreceiver.qual; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type for the Returns Receiver Checker's type system. Programmers should rarely write - * this type. - * - * @checker_framework.manual #returns-receiver-checker Returns Receiver Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@SubtypeOf({UnknownThis.class}) -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -public @interface BottomThis {} diff --git a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/This.java b/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/This.java deleted file mode 100644 index 4d30a59c72a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/This.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.checkerframework.common.returnsreceiver.qual; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * Write {@code @This} on the return type of a method that always returns its receiver ({@code - * this}). For example: - * - *


- * class MyBuilder {
- *   @This MyBuilder setName(String name) {
- *     this.name = name;
- *     return this;
- *   }
- * }
- * 
- * - *

Strictly speaking, this is a polymorphic annotation, but when you write it on a return type, - * the Returns Receiver Checker automatically adds it to the receiver, so the above method is - * equivalent to: - * - *


- * @This MyBuilder setName(@This MyBuilder this, String name) {
- *   this.name = name;
- *   return this;
- * }
- * 
- * - *

While it would be natural to make {@code @This} the default annotation for receivers, it leads - * to false positives warnings due to https://github.com/typetools/checker-framework/issues/2931, - * so this defaulting is currently elided. - * - * @checker_framework.manual #returns-receiver-checker Returns Receiver Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier -@TargetLocations({TypeUseLocation.RECEIVER, TypeUseLocation.RETURN}) -public @interface This {} diff --git a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/UnknownThis.java b/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/UnknownThis.java deleted file mode 100644 index 107d5f837ed..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/returnsreceiver/qual/UnknownThis.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.checkerframework.common.returnsreceiver.qual; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.*; - -/** - * The top type for the Returns Receiver Checker's type system. Values of the annotated type might - * be the receiver ({@code this}) or might not. Programmers should rarely write this type. - * - * @checker_framework.manual #returns-receiver-checker Returns Receiver Checker - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@DefaultQualifierInHierarchy -@SubtypeOf({}) -@QualifierForLiterals(LiteralKind.NULL) -@DefaultFor(value = TypeUseLocation.LOWER_BOUND) -public @interface UnknownThis {} diff --git a/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Bottom.java b/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Bottom.java deleted file mode 100644 index b60bf2f570e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Bottom.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.checkerframework.common.subtyping.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * A special annotation intended solely for representing the bottom type in the qualifier hierarchy. - * It should not be used! Instead, each type system should define its own dedicated bottom type. - * - *

This qualifier is used automatically if the existing qualifiers do not have a bottom type. - * This only works the user never runs two type systems together. Furthermore, because it has no - * {@code @RetentionPolicy} meta-annotation, this qualifier will not be stored in bytecode. So, only - * use this qualifier during prototyping of very simple type systems. For realistic systems, - * introduce a top and bottom qualifier that gets stored in bytecode. - * - *

To use this qualifier, the type system designer needs to use methods like {@code - * org.checkerframework.framework.type.treeannotator.ImplicitsTreeAnnotator#addTreeKind(com.sun.source.tree.Tree.Kind, - * javax.lang.model.element.AnnotationMirror)} to add default annotations and needs to manually add - * the bottom qualifier to the qualifier hierarchy. - * - * @see org.checkerframework.framework.type.QualifierHierarchy#getBottomAnnotations() - * @checker_framework.manual #subtyping-checker Subtyping Checker - */ -@Documented -@SubtypeOf({}) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -public @interface Bottom {} diff --git a/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Unqualified.java b/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Unqualified.java deleted file mode 100644 index 638071d145b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/subtyping/qual/Unqualified.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.common.subtyping.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * A special annotation intended solely for representing an unqualified type in the qualifier - * hierarchy, as an argument to {@link SubtypeOf#value()}, in a type qualifier declaration. - * - *

This annotation may not be written in source code; it is an implementation detail of the - * checker. - * - *

Use this qualifier only when experimenting with very simple type systems. For any more - * realistic type systems, introduce a top and bottom qualifier that gets stored in bytecode. - * - * @checker_framework.manual #subtyping-checker Subtyping Checker - */ -@Documented -@Retention(RetentionPolicy.SOURCE) // don't store in class file -@Target({}) // empty target prevents programmers from writing this in a program. -@InvisibleQualifier -@SubtypeOf({}) -// At the moment defaulting is done in SubtypingATF to prevent errors in checker-framework-inference -// @DefaultFor(TypeUseLocation.OTHERWISE) -public @interface Unqualified {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCall.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCall.java deleted file mode 100644 index e680208f030..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCall.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Report all calls of a method that has this annotation, including calls of methods that override - * this method. Note that calls through a supertype, where the method is not annotated, cannot be - * reported. - * - *

For example, assume three classes A, B, and C, that each implement/override a method m and A - * <: B <: C. Assume that B.m is annotated as ReportCall. Calls of A.m and B.m will then be - * reported, but calls of C.m will not be reported, even though the C reference might point to a B - * object. Therefore, add the ReportCall annotation high enough in the subtype hierarchy. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ReportCall {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCreation.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCreation.java deleted file mode 100644 index 689691c4d9b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportCreation.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Report all instantiations of a class/interface that has this annotation, including any subclass. - * Report all invocations of a particular constructor. (There is no overriding of constructors, so - * use on a constructor reports only that particular constructor.) - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.CONSTRUCTOR}) -public @interface ReportCreation {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportInherit.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportInherit.java deleted file mode 100644 index f3582f0ae67..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportInherit.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Report all types that extend/implement a type that has this annotation. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ReportInherit {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportOverride.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportOverride.java deleted file mode 100644 index 2dfebef5963..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportOverride.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Report all methods that override a method with this annotation. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ReportOverride {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportReadWrite.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportReadWrite.java deleted file mode 100644 index 2fe05324491..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportReadWrite.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Report all read or write access to a field with this annotation. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ReportReadWrite {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUnqualified.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUnqualified.java deleted file mode 100644 index 2354ceffe07..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUnqualified.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation intended solely for representing an unqualified type in the qualifier hierarchy for - * the Report Checker. - */ -@Documented -@Retention(RetentionPolicy.SOURCE) // do not store in class file -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -@InvisibleQualifier -public @interface ReportUnqualified {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUse.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUse.java deleted file mode 100644 index 91b7f646529..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportUse.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Report all uses of a type that has this annotation. Can also be used on a package. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PACKAGE, ElementType.TYPE}) -public @interface ReportUse {} diff --git a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportWrite.java b/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportWrite.java deleted file mode 100644 index f7bf265fc3d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/util/report/qual/ReportWrite.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.common.util.report.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Report all write accesses to a field with this annotation. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ReportWrite {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLen.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLen.java deleted file mode 100644 index ac7dbb7410b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLen.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the length of an array or a string. If an expression's type has this - * annotation, then at run time, the expression evaluates to an array or a string whose length is - * one of the annotation's arguments. - * - *

For example, {@code String @ArrayLen(2) []} is the type for an array of two strings, and - * {@code String @ArrayLen({1, 2, 4, 8}) []} is the type for an array that contains 1, 2, 4, or 8 - * strings. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({UnknownVal.class}) -public @interface ArrayLen { - /** The possible lengths of the array. */ - int[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLenRange.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLenRange.java deleted file mode 100644 index a1dc709dbf0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/ArrayLenRange.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type evaluates to an array or a string whose length is in the given - * range. The bounds are inclusive; for example, {@code @ArrayLenRange(from=6, to=9)} represents an - * array or a string with four possible values for its length: 6, 7, 8, and 9. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf(UnknownVal.class) -public @interface ArrayLenRange { - /** Smallest value in the range, inclusive. */ - int from() default 0; - /** Largest value in the range, inclusive. */ - int to() default Integer.MAX_VALUE; -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/BoolVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/BoolVal.java deleted file mode 100644 index cc88fde7bc3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/BoolVal.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the possible values for a bool type. If an expression's type has this - * annotation, then at run time, the expression evaluates to one of the annotation's arguments. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({UnknownVal.class}) -public @interface BoolVal { - /** The values that the expression might evaluate to. */ - boolean[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/BottomVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/BottomVal.java deleted file mode 100644 index 6c71fbe1ee0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/BottomVal.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; -import org.checkerframework.framework.qual.TargetLocations; -import org.checkerframework.framework.qual.TypeUseLocation; - -/** - * The bottom type in the Constant Value type system. Programmers should rarely write this type. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - * @checker_framework.manual #bottom-type the bottom type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@TargetLocations({TypeUseLocation.EXPLICIT_LOWER_BOUND, TypeUseLocation.EXPLICIT_UPPER_BOUND}) -@SubtypeOf({ - ArrayLen.class, - BoolVal.class, - DoubleVal.class, - IntVal.class, - StringVal.class, - ArrayLenRange.class, - IntRange.class, - IntRangeFromPositive.class, - IntRangeFromGTENegativeOne.class, - IntRangeFromNonNegative.class -}) -@InvisibleQualifier -public @interface BottomVal {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/DoubleVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/DoubleVal.java deleted file mode 100644 index cd180efdcd3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/DoubleVal.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the possible values for a double or float type. If an expression's type - * has this annotation, then at run time, the expression evaluates to one of the annotation's - * arguments. - * - *

Annotation for values - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({UnknownVal.class}) -public @interface DoubleVal { - /** The values that the expression might evaluate to. */ - double[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/EnsuresMinLenIf.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/EnsuresMinLenIf.java deleted file mode 100644 index 239f2c741be..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/EnsuresMinLenIf.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.ConditionalPostconditionAnnotation; -import org.checkerframework.framework.qual.InheritedAnnotation; -import org.checkerframework.framework.qual.QualifierArgument; - -/** - * Indicates that the value of the given expression is a sequence containing at least the given - * number of elements, if the method returns the given result (either true or false). - * - *

When the annotated method returns {@code result}, then all the expressions in {@code - * expression} are considered to be {@code MinLen(targetValue)}. - * - * @see MinLen - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@ConditionalPostconditionAnnotation(qualifier = MinLen.class) -@InheritedAnnotation -@Repeatable(EnsuresMinLenIf.List.class) -public @interface EnsuresMinLenIf { - /** - * Returns Java expression(s) that are a sequence with the given minimum length after the method - * returns {@link #result}. - * - * @return an array of Java expression(s), each of which is a sequence with the given minimum - * length after the method returns {@link #result} - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns the return value of the method under which the postcondition to hold. - * - * @return the return value of the method under which the postcondition to hold - */ - boolean result(); - - /** - * Returns the minimum number of elements in the sequence. - * - * @return the minimum number of elements in the sequence - */ - @QualifierArgument("value") - int targetValue() default 0; - - /** - * A wrapper annotation that makes the {@link EnsuresMinLenIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresMinLenIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @ConditionalPostconditionAnnotation(qualifier = MinLen.class) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresMinLenIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRange.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRange.java deleted file mode 100644 index 5ee28577902..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRange.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type evaluates to an integral value (byte, short, char, int, or long) in - * the given range. The bounds are inclusive. For example, the following declaration allows the 12 - * values 0, 1, ..., 11: - * - *

{@code @IntRange(from=0, to=11) int month;}
- * - *

If only one of the {@code to} and {@code from} fields is set, then the other will default to - * the max/min value of the type of the variable that is annotated. (In other words, the defaults - * {@code Long.MIN_VALUE} and {@code Long.MAX_VALUE} are used only for \code{long}; appropriate - * values are used for other types.) - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf(UnknownVal.class) -public @interface IntRange { - /** Smallest value in the range, inclusive. */ - long from() default Long.MIN_VALUE; - /** Largest value in the range, inclusive. */ - long to() default Long.MAX_VALUE; -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromGTENegativeOne.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromGTENegativeOne.java deleted file mode 100644 index fc65c4a9f20..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromGTENegativeOne.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type is exactly the same as an {@link IntRange} annotation whose {@code - * from} field is {@code -1} and whose {@code to} field is {@code Integer.MAX_VALUE}. However, this - * annotation is derived from an {@code org.checkerframework.checker.index.qual.GTENegativeOne} - * annotation. - * - *

IntRangeFromGTENegativeOne annotations derived from GTENegativeOne annotations are used to - * create IntRange annotations, but IntRangeFromGTENegativeOne annotations are not checked when they - * appear on the left hand side of expressions. Therefore, the Index Checker MUST be run on any code - * with @GTENegativeOne annotations on the left-hand side of expressions, since the Value Checker - * will derive information from them but not check them. - * - *

It is an error to write this annotation directly. {@code @GTENegativeOne} or {@code - * IntRange(from = -1, to = Integer.MAX_VALUE)} should always be written instead. This annotation is - * not retained in bytecode, but is replaced with {@code @UnknownVal}, so that it is not enforced on - * method boundaries. The {@code @GTENegativeOne} annotation it replaced is retained in bytecode by - * the Lower Bound Checker instead. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({}) -@SubtypeOf(UnknownVal.class) -public @interface IntRangeFromGTENegativeOne {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromNonNegative.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromNonNegative.java deleted file mode 100644 index 434ff259de3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromNonNegative.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type is exactly the same as an {@link IntRange} annotation whose {@code - * from} field is {@code 0} and whose {@code to} field is {@code Integer.MAX_VALUE}. However, this - * annotation is derived from an {@code org.checkerframework.checker.index.qual.NonNegative} - * annotation. - * - *

IntRangeFromNonNegative annotations derived from NonNegative annotations are used to create - * IntRange annotations, but IntRangeFromNonNegative annotations are not checked when they appear on - * the left hand side of expressions. Therefore, the Index Checker MUST be run on any code - * with @NonNegative annotations on the left-hand side of expressions, since the Value Checker will - * derive information from them but not check them. - * - *

It is an error to write this annotation directly. {@code @NonNegative} or {@code IntRange(from - * = 0, to = Integer.MAX_VALUE)} should always be written instead. This annotation is not retained - * in bytecode, but is replaced with {@code @UnknownVal}, so that it is not enforced on method - * boundaries. The {@code @NonNegative} annotation it replaced is retained in bytecode by the Lower - * Bound Checker instead. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({}) -@SubtypeOf(UnknownVal.class) -public @interface IntRangeFromNonNegative {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromPositive.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromPositive.java deleted file mode 100644 index 4941505975a..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntRangeFromPositive.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An expression with this type is exactly the same as an {@link IntRange} annotation whose {@code - * from} field is {@code 1} and whose {@code to} field is {@code Integer.MAX_VALUE}. However, this - * annotation is derived from an {@code org.checkerframework.checker.index.qual.Positive} - * annotation. - * - *

IntRangeFromPositive annotations derived from Positive annotations are used to create IntRange - * annotations, but IntRangeFromPositive annotations are not checked when they appear on the left - * hand side of expressions. Therefore, the Index Checker MUST be run on any code with @Positive - * annotations on the left-hand side of expressions, since the Value Checker will derive information - * from them but not check them. - * - *

It is an error to write this annotation directly. {@code @Positive} or {@code IntRange(from = - * 1, to = Integer.MAX_VALUE)} should always be written instead. This annotation is not retained in - * bytecode, but is replaced with {@code @UnknownVal}, so that it is not enforced on method - * boundaries. The {@code @Positive} annotation it replaced is retained in bytecode by the Lower - * Bound Checker instead. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({}) -@SubtypeOf(UnknownVal.class) -public @interface IntRangeFromPositive {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/IntVal.java deleted file mode 100644 index ad9658ab1f4..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/IntVal.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the possible values for a byte, short, char, int, or long type. If an - * expression's type has this annotation, then at run time, the expression evaluates to one of the - * annotation's arguments. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({UnknownVal.class}) -public @interface IntVal { - /** The values that the expression might evaluate to. */ - long[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLen.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLen.java deleted file mode 100644 index 0290b93b321..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLen.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * The value of the annotated expression is a sequence containing at least the given number of - * elements. An alias for an {@link ArrayLenRange} annotation with a {@code from} field and the - * maximum possible value for an array length ({@code Integer.MAX_VALUE}) as its {@code to} field. - * - *

This annotation is used extensively by the Index Chcker. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -public @interface MinLen { - /** The minimum number of elements in this sequence. */ - int value() default 0; -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLenFieldInvariant.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLenFieldInvariant.java deleted file mode 100644 index d11a0aa5c0f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/MinLenFieldInvariant.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.FieldInvariant; - -/** - * A specialization of {@link FieldInvariant} for specifying the minimum length of an array. A class - * can be annotated with both this annotation and a {@link FieldInvariant} annotation. - * - * @checker_framework.manual #field-invariants Field invariants - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -public @interface MinLenFieldInvariant { - - /** - * Min length of the array. Must be greater than the min length of the array as declared in the - * superclass. - */ - int[] minLen(); - - /** - * The field that has an array length qualifier in the class on which the field invariant is - * written. The field must be final and declared in a superclass. - */ - String[] field(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/PolyValue.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/PolyValue.java deleted file mode 100644 index 8ae998b9b7f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/PolyValue.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.PolymorphicQualifier; - -/** - * A polymorphic qualifier for the Constant Value Checker. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@PolymorphicQualifier(UnknownVal.class) -public @interface PolyValue {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/StaticallyExecutable.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/StaticallyExecutable.java deleted file mode 100644 index 7dc91cbd95f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/StaticallyExecutable.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * StaticallyExecutable is a method annotation that indicates that the compiler is allowed to run - * the method at compile time, if all of the method's arguments are compile-time constants. It is - * used by the Constant Value Checker. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface StaticallyExecutable {} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/StringVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/StringVal.java deleted file mode 100644 index 458a456fd06..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/StringVal.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation indicating the possible values for a String type. If an expression's type has this - * annotation, then at run time, the expression evaluates to one of the annotation's arguments. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({UnknownVal.class}) -public @interface StringVal { - /** The values that the expression might evaluate to. */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/common/value/qual/UnknownVal.java b/src/java.base/share/classes/org/checkerframework/common/value/qual/UnknownVal.java deleted file mode 100644 index bcc6b9d1186..00000000000 --- a/src/java.base/share/classes/org/checkerframework/common/value/qual/UnknownVal.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.checkerframework.common.value.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * UnknownVal is a type annotation indicating that the expression's value is not known at compile - * type. - * - * @checker_framework.manual #constant-value-checker Constant Value Checker - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -public @interface UnknownVal {} diff --git a/src/java.base/share/classes/org/checkerframework/dataflow/qual/Deterministic.java b/src/java.base/share/classes/org/checkerframework/dataflow/qual/Deterministic.java deleted file mode 100644 index 5d2825cadc7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/dataflow/qual/Deterministic.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.checkerframework.dataflow.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A method is called deterministic if it returns the same value (according to {@code ==}) - * every time it is called with the same parameters and in the same environment. The parameters - * include the receiver, and the environment includes all of the Java heap (that is, all fields of - * all objects and all static variables). - * - *

Determinism refers to the return value during a non-exceptional execution. If a method throws - * an exception, the Throwable does not have to be exactly the same object on each invocation (and - * generally should not be, to capture the correct stack trace). - * - *

This annotation is important to pluggable type-checking because, after a call to a - * {@code @Deterministic} method, flow-sensitive type refinement can assume that anything learned - * about the first invocation is true about subsequent invocations (so long as no - * non-{@code @}{@link SideEffectFree} method call intervenes). For example, the following code - * never suffers a null pointer exception, so the Nullness Checker need not issue a warning: - * - *

{@code
- * if (x.myDeterministicMethod() != null) {
- *   x.myDeterministicMethod().hashCode();
- * }
- * }
- * - *

Note that {@code @Deterministic} guarantees that the result is identical according to {@code - * ==}, not just equal according to {@code equals()}. This means that writing - * {@code @Deterministic} on a method that returns a reference (including a String) is often - * erroneous unless the returned value is cached or interned. - * - *

Also see {@link Pure}, which means both deterministic and {@link SideEffectFree}. - * - *

Analysis: The Checker Framework performs a conservative analysis to verify a - * {@code @Deterministic} annotation. The Checker Framework issues a warning if the method uses any - * of the following Java constructs: - * - *

    - *
  1. Assignment to any expression, except for local variables (and method parameters). - *
  2. A method invocation of a method that is not {@link Deterministic}. - *
  3. Construction of a new object. - *
  4. Catching any exceptions. This restriction prevents a method from obtaining a reference to a - * newly-created exception object and using these objects (or some property thereof) to change - * the method's return value. For instance, the following method must be forbidden. - * - *
    @Deterministic
    - * int f() {
    - *   try {
    - *     int b = 0;
    - *     int a = 1/b;
    - *   } catch (Throwable t) {
    - *     return t.hashCode();
    - *   }
    - *   return 0;
    - * }
    - * 
    - *
- * - * A constructor can be {@code @Pure}, but a constructor invocation is not deterministic - * since it returns a different new object each time. TODO: Side-effect-free constructors could be - * allowed to set their own fields. - * - *

Note that the rules for checking currently imply that every {@code Deterministic} method is - * also {@link SideEffectFree}. This might change in the future; in general, a deterministic method - * does not need to be side-effect-free. - * - *

These rules are conservative: any code that passes the checks is deterministic, but the - * Checker Framework may issue false positive warnings, for code that uses one of the forbidden - * constructs but is deterministic nonetheless. - * - *

In fact, the rules are so conservative that checking is currently disabled by default, but can - * be enabled via the {@code -AcheckPurityAnnotations} command-line option. - * - *

This annotation is inherited by subtypes, just as if it were meta-annotated with - * {@code @InheritedAnnotation}. - * - * @checker_framework.manual #type-refinement-purity Side effects, determinism, purity, and - * flow-sensitive analysis - */ -// @InheritedAnnotation cannot be written here, because "dataflow" project cannot depend on -// "framework" project. -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface Deterministic {} diff --git a/src/java.base/share/classes/org/checkerframework/dataflow/qual/Pure.java b/src/java.base/share/classes/org/checkerframework/dataflow/qual/Pure.java deleted file mode 100644 index d6c309b73a1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/dataflow/qual/Pure.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.dataflow.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * {@code Pure} is a method annotation that means both {@link SideEffectFree} and {@link - * Deterministic}. The more important of these, when performing pluggable type-checking, is usually - * {@link SideEffectFree}. - * - *

This annotation is inherited by subtypes, just as if it were meta-annotated with - * {@code @InheritedAnnotation}. - * - * @checker_framework.manual #type-refinement-purity Side effects, determinism, purity, and - * flow-sensitive analysis - */ -// @InheritedAnnotation cannot be written here, because "dataflow" project cannot depend on -// "framework" project. -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface Pure { - /** The type of purity. */ - public static enum Kind { - /** The method has no visible side effects. */ - SIDE_EFFECT_FREE, - - /** The method returns exactly the same value when called in the same environment. */ - DETERMINISTIC - } -} diff --git a/src/java.base/share/classes/org/checkerframework/dataflow/qual/SideEffectFree.java b/src/java.base/share/classes/org/checkerframework/dataflow/qual/SideEffectFree.java deleted file mode 100644 index b3942c2a25d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/dataflow/qual/SideEffectFree.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.checkerframework.dataflow.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A method is called side-effect-free if it has no visible side-effects, such as setting a - * field of an object that existed before the method was called. - * - *

Only the visible side effects are important. The method is allowed to cache the answer to a - * computationally expensive query, for instance. It is also allowed to modify newly-created - * objects, and a constructor is side-effect-free if it does not modify any objects that existed - * before it was called. - * - *

This annotation is important to pluggable type-checking because if some fact about an object - * is known before a call to such a method, then the fact is still known afterwards, even if the - * fact is about some non-final field. When any non-{@code @SideEffectFree} method is called, then a - * pluggable type-checker must assume that any field of any accessible object might have been - * modified, which annuls the effect of flow-sensitive type refinement and prevents the pluggable - * type-checker from making conclusions that are obvious to a programmer. - * - *

Also see {@link Pure}, which means both side-effect-free and {@link Deterministic}. - * - *

Analysis: The Checker Framework performs a conservative analysis to verify a - * {@code @SideEffectFree} annotation. The Checker Framework issues a warning if the method uses any - * of the following Java constructs: - * - *

    - *
  1. Assignment to any expression, except for local variables and method parameters. - *
  2. A method invocation of a method that is not {@code @SideEffectFree}. - *
  3. Construction of a new object where the constructor is not {@code @SideEffectFree}. - *
- * - * These rules are conservative: any code that passes the checks is side-effect-free, but the - * Checker Framework may issue false positive warnings, for code that uses one of the forbidden - * constructs but is side-effect-free nonetheless. In particular, a method that caches its result - * will be rejected. - * - *

In fact, the rules are so conservative that checking is currently disabled by default, but can - * be enabled via the {@code -AcheckPurityAnnotations} command-line option. - * - *

This annotation is inherited by subtypes, just as if it were meta-annotated with - * {@code @InheritedAnnotation}. - * - * @checker_framework.manual #type-refinement-purity Side effects, determinism, purity, and - * flow-sensitive analysis - */ -// @InheritedAnnotation cannot be written here, because "dataflow" project cannot depend on -// "framework" project. -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface SideEffectFree {} diff --git a/src/java.base/share/classes/org/checkerframework/dataflow/qual/TerminatesExecution.java b/src/java.base/share/classes/org/checkerframework/dataflow/qual/TerminatesExecution.java deleted file mode 100644 index 412c4be48ec..00000000000 --- a/src/java.base/share/classes/org/checkerframework/dataflow/qual/TerminatesExecution.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.checkerframework.dataflow.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * {@code TerminatesExecution} is a method annotation that indicates that a method terminates the - * execution of the program. This can be used to annotate methods such as {@code System.exit()}, or - * methods that unconditionally throw an exception. - * - *

The annotation enables flow-sensitive type refinement to be more precise. For example, after - * - *

- * if (x == null) {
- *   System.err.println("Bad value supplied");
- *   System.exit(1);
- * }
- * 
- * - * the Nullness Checker can determine that {@code x} is non-null. - * - *

The annotation is a trusted annotation, meaning that it is not checked whether the - * annotated method really does terminate the program. - * - *

This annotation is inherited by subtypes, just as if it were meta-annotated with - * {@code @InheritedAnnotation}. - * - * @checker_framework.manual #type-refinement Automatic type refinement (flow-sensitive type - * qualifier inference) - */ -// @InheritedAnnotation cannot be written here, because "dataflow" project cannot depend on -// "framework" project. -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -public @interface TerminatesExecution {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/AnnotatedFor.java b/src/java.base/share/classes/org/checkerframework/framework/qual/AnnotatedFor.java deleted file mode 100644 index f6be7e33c50..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/AnnotatedFor.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that this class has been annotated for the given type system. For example, - * {@code @AnnotatedFor({"nullness", "regex"})} indicates that the class has been annotated with - * annotations such as {@code @Nullable} and {@code @Regex}. - * - *

You should only use this annotation in a partially-annotated library. There is no point to - * using it in a fully-annotated library nor in an application that does not export APIs for - * clients. - * - *

This annotation has no effect unless the {@code - * -AuseConservativeDefaultsForUncheckedCode=source} command-line argument is supplied. Ordinarily, - * the {@code -AuseConservativeDefaultsForUncheckedCode=source} command-line argument causes - * unannotated locations to be defaulted using conservative defaults, and it suppresses all - * warnings. However, a class with a relevant {@code @AnnotatedFor} annotation is always defaulted - * normally (typically using the CLIMB-to-top rule), and typechecking warnings are issued. - * - * @checker_framework.manual #compiling-libraries Compiling partially-annotated libraries - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE}) -public @interface AnnotatedFor { - /** - * Returns the type systems for which the class has been annotated. Legal arguments are any - * string that may be passed to the {@code -processor} command-line argument: the - * fully-qualified class name for the checker, or a shorthand for built-in checkers. Using the - * annotation with no arguments, as in {@code @AnnotatedFor({})}, has no effect. - * - * @return the type systems for which the class has been annotated - * @checker_framework.manual #shorthand-for-checkers Short names for built-in checkers - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/CFComment.java b/src/java.base/share/classes/org/checkerframework/framework/qual/CFComment.java deleted file mode 100644 index c6ed6140cf9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/CFComment.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * This annotation is for comments related to the Checker Framework. - * - *

Using {@code @CFComment} makes it easy to find Checker-Framework-related comments, and to copy - * those comments from one version of a codebase to another (using the Annotation File Utilities). - * - *

Here is an example: - * - *


- * {@literal @}CFComment("interning: factory methods guarantee that all elements are interned")
- *  public class MyClass {
- *   {@literal @}CFComment({"nullness: non-null return type is more specific than in superclass",
- *                "signedness: comment related to Signedness type system"})
- *    public String myMethod() { ... }
- * }
- * 
- * - *

As a matter of style, programmers should use this annotation on the most deeply nested element - * to which the comment applies (e.g., local variable rather than method, and method rather than - * class). - * - * @checker_framework.manual #library-tips-dont-change-the-code Don't change the code - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -public @interface CFComment { - /** - * Comments about Checker Framework annotations. The text is not interpreted by the Checker - * Framework. - * - *

If you prefix each comment by the name of the type system, the comments are easier to - * understand and search for. - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/ConditionalPostconditionAnnotation.java b/src/java.base/share/classes/org/checkerframework/framework/qual/ConditionalPostconditionAnnotation.java deleted file mode 100644 index ac65025991e..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/ConditionalPostconditionAnnotation.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates that an annotation E is a conditional postcondition annotation, - * i.e., E is a type-specialized version of {@link EnsuresQualifierIf} or {@link - * EnsuresQualifierIf.List}. - * - *

    - *
  • If E is a type-specialized version of {@link EnsuresQualifierIf}, it must have - *
      - *
    • an element {@code expression} that is an array of {@code String}s, analogous to - * {@link EnsuresQualifierIf#expression()}, and - *
    • an element {@code result} with the same meaning as {@link - * EnsuresQualifierIf#result()}. - *
    - *
  • If E is a type-specialized version of {@link EnsuresQualifierIf.List}, it must have an - * element {@code value} that is an array of conditional postcondition annotations, analogous - * to {@link EnsuresQualifierIf.List#value()}. - *
- * - *

The established postcondition P has type specified by the {@code qualifier} field of this - * annotation. If the annotation E has elements annotated by {@link QualifierArgument}, their values - * are copied to the arguments (elements) of annotation P with the same names. Different element - * names may be used in E and P, if a {@link QualifierArgument} in E gives the name of the - * corresponding element in P. - * - *

For example, the following code declares a postcondition annotation for the {@link - * org.checkerframework.common.value.qual.MinLen} qualifier: - * - *


- * {@literal @}ConditionalPostconditionAnnotation(qualifier = MinLen.class)
- * {@literal @}Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
- * public {@literal @}interface EnsuresMinLen {
- *   String[] expression();
- *   boolean result();
- *   {@literal @}QualifierArgument("value")
- *   int targetValue() default 0;
- * 
- * - * The {@code expression} element holds the expressions to which the qualifier applies and {@code - * targetValue} holds the value for the {@code value} argument of {@link - * org.checkerframework.common.value.qual.MinLen}. - * - *

The following code then uses the annotation on a method that ensures {@code field} to be - * {@code @MinLen(4)} upon returning {@code true}. - * - *


- * {@literal @}EnsuresMinLenIf(expression = "field", result = true, targetValue = 4")
- * public boolean isFieldBool() {
- *   return field == "true" || field == "false";
- * }
- * 
- * - * @see EnsuresQualifier - * @see QualifierArgument - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE}) -public @interface ConditionalPostconditionAnnotation { - /** - * The qualifier that will be established as a postcondition. - * - *

This element is analogous to {@link EnsuresQualifierIf#qualifier()}. - */ - Class qualifier(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/Covariant.java b/src/java.base/share/classes/org/checkerframework/framework/qual/Covariant.java deleted file mode 100644 index ac79c2e99db..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/Covariant.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A marker annotation, written on a class declaration, that signifies that one or more of the - * class's type parameters can be treated covariantly. For example, if {@code MyClass} has a single - * type parameter that is treated covariantly, and if {@code B} is a subtype of {@code A}, then - * {@code SomeClass} is a subtype of {@code SomeClass}. - * - *

Ordinarily, Java treats type parameters invariantly: {@code SomeClass} is unrelated to - * (neither a subtype nor a supertype of) {@code SomeClass}. - * - *

It is only safe to mark a type parameter as covariant if clients use the type parameter in a - * read-only way: clients read values of that type but never modify them. - * - *

This property is not checked; the {@code @Covariant} is simply trusted. - * - *

Here is an example use: - * - *

{@code @Covariant(0)
- * public interface Iterator { ... }
- * }
- * - * @checker_framework.manual #covariant-type-parameters Covariant type parameters - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface Covariant { - /** The zero-based indices of the type parameters that should be treated covariantly. */ - int[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultFor.java b/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultFor.java deleted file mode 100644 index 6d695562873..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultFor.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation applied to the declaration of a type qualifier. It specifies that the given - * annotation should be the default for: - * - *
    - *
  • all uses at a particular location, - *
  • all uses of a particular type, and - *
  • all uses of a particular kind of type. - *
- * - *

The default applies to every match for any of this annotation's conditions. - * - * @see TypeUseLocation - * @see DefaultQualifier - * @see DefaultQualifierInHierarchy - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface DefaultFor { - /** - * Returns the locations to which the annotation should be applied. - * - * @return the locations to which the annotation should be applied - */ - TypeUseLocation[] value() default {}; - - /** - * Returns {@link TypeKind}s of types for which an annotation should be implicitly added. - * - * @return {@link TypeKind}s of types for which an annotation should be implicitly added - */ - TypeKind[] typeKinds() default {}; - - /** - * Returns {@link Class}es for which an annotation should be applied. For example, if - * {@code @MyAnno} is meta-annotated with {@code @DefaultFor(classes=String.class)}, then every - * occurrence of {@code String} is actually {@code @MyAnno String}. - * - * @return {@link Class}es for which an annotation should be applied - */ - Class[] types() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifier.java deleted file mode 100644 index 7089c382dd3..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifier.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Applied to a declaration of a package, type, method, variable, etc., specifies that the given - * annotation should be the default. The default is applied to type uses within the declaration for - * which no other annotation is explicitly written. (The default is not applied to the "parametric - * locations": class declarations, type parameter declarations, and type parameter uses.) If - * multiple {@code DefaultQualifier} annotations are in scope, the innermost one takes precedence. - * DefaultQualifier takes precedence over {@link DefaultQualifierInHierarchy}. - * - *

You may write multiple {@code @DefaultQualifier} annotations (for unrelated type systems, or - * with different {@code locations} fields) at the same location. For example: - * - *

- *   @DefaultQualifier(NonNull.class)
- *   @DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.IMPLICIT_UPPER_BOUND)
- *   @DefaultQualifier(Tainted.class)
- *   class MyClass { ... }
- * 
- * - *

This annotation currently has no effect in stub files. - * - * @see org.checkerframework.framework.qual.TypeUseLocation - * @see DefaultQualifierInHierarchy - * @see DefaultFor - * @checker_framework.manual #defaults Default qualifier for unannotated types - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({ - ElementType.PACKAGE, - ElementType.TYPE, - ElementType.CONSTRUCTOR, - ElementType.METHOD, - ElementType.FIELD, - ElementType.LOCAL_VARIABLE, - ElementType.PARAMETER -}) -@Repeatable(DefaultQualifier.List.class) -public @interface DefaultQualifier { - - /** - * The Class for the default annotation. - * - *

To prevent affecting other type systems, always specify an annotation in your own type - * hierarchy. (For example, do not set {@link - * org.checkerframework.common.subtyping.qual.Unqualified} as the default.) - */ - Class value(); - - /** - * Returns the locations to which the annotation should be applied. - * - * @return the locations to which the annotation should be applied - */ - TypeUseLocation[] locations() default {TypeUseLocation.ALL}; - - /** - * A wrapper annotation that makes the {@link DefaultQualifier} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link DefaultQualifier} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ - ElementType.PACKAGE, - ElementType.TYPE, - ElementType.CONSTRUCTOR, - ElementType.METHOD, - ElementType.FIELD, - ElementType.LOCAL_VARIABLE, - ElementType.PARAMETER - }) - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - DefaultQualifier[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierForUse.java b/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierForUse.java deleted file mode 100644 index 961ed0421f9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierForUse.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declaration annotation applied to type declarations to specify the qualifier to be added to - * unannotated uses of the type. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface DefaultQualifierForUse { - /** Qualifier to add to all unannotated uses of the type with this declaration annotation. */ - Class[] value() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierInHierarchy.java b/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierInHierarchy.java deleted file mode 100644 index 69515f78251..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/DefaultQualifierInHierarchy.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the annotated qualifier is the default qualifier in the qualifier hierarchy: it - * applies if the programmer writes no explicit qualifier and no other default has been specified - * for the location. - * - *

Other defaults can be specified for a checker via the {@link DefaultFor} meta-annotation, - * which takes precedence over {@code DefaultQualifierInHierarchy}, or via {@link - * org.checkerframework.framework.type.GenericAnnotatedTypeFactory#addCheckedCodeDefaults(org.checkerframework.framework.util.defaults.QualifierDefaults)}. - * - *

The {@link DefaultQualifier} annotation, which targets Java code elements, takes precedence - * over {@code DefaultQualifierInHierarchy}. - * - *

Each type qualifier hierarchy may have at most one qualifier marked as {@code - * DefaultQualifierInHierarchy}. - * - * @checker_framework.manual #effective-qualifier The effective qualifier on a type (defaults and - * inference) - * @see org.checkerframework.framework.qual.DefaultQualifier - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface DefaultQualifierInHierarchy {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifier.java deleted file mode 100644 index ec1dbdbd396..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifier.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A postcondition annotation to indicate that a method ensures that certain expressions have a - * certain type qualifier once the method has successfully terminated. The expressions for which the - * qualifier holds after the method's execution are indicated by {@code expression} and are - * specified using a string. The qualifier is specified by the {@code qualifier} annotation element. - * - *

Here is an example use: - * - *


- *  {@literal @}EnsuresQualifier(expression = "p.f1", qualifier = Odd.class)
- *   void oddF1_1() {
- *       p.f1 = null;
- *   }
- * 
- * - * Some type systems have specialized versions of this annotation, such as {@code - * org.checkerframework.checker.nullness.qual.EnsuresNonNull} and {@code - * org.checkerframework.checker.lock.qual.EnsuresLockHeld}. - * - * @see EnsuresQualifierIf - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@InheritedAnnotation -@Repeatable(EnsuresQualifier.List.class) -public @interface EnsuresQualifier { - /** - * Returns the Java expressions for which the qualifier holds after successful method - * termination. - * - * @return the Java expressions for which the qualifier holds after successful method - * termination - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns the qualifier that is guaranteed to hold on successful termination of the method. - * - * @return the qualifier that is guaranteed to hold on successful termination of the method - */ - Class qualifier(); - - /** - * A wrapper annotation that makes the {@link EnsuresQualifier} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresQualifier} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresQualifier[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifierIf.java b/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifierIf.java deleted file mode 100644 index 6aad619d1db..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/EnsuresQualifierIf.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A conditional postcondition annotation to indicate that a method ensures that certain expressions - * have a certain qualifier once the method has terminated, and if the result is as indicated by - * {@code result}. The expressions for which the qualifier holds after the method's execution are - * indicated by {@code expression} and are specified using a string. The qualifier is specified by - * the {@code qualifier} annotation element. - * - *

Here is an example use: - * - *


- *   {@literal @}EnsuresQualifierIf(result = true, expression = "#1", qualifier = Odd.class)
- *    boolean isOdd(final int p1, int p2) {
- *        return p1 % 2 == 1;
- *    }
- * 
- * - *

This annotation is only applicable to methods with a boolean return type. - * - *

Some type systems have specialized versions of this annotation, such as {@code - * org.checkerframework.checker.nullness.qual.EnsuresNonNullIf} and {@code - * org.checkerframework.checker.lock.qual.EnsuresLockHeldIf}. - * - * @see EnsuresQualifier - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -@InheritedAnnotation -@Repeatable(EnsuresQualifierIf.List.class) -public @interface EnsuresQualifierIf { - /** - * Returns the Java expressions for which the qualifier holds if the method terminates with - * return value {@link #result()}. - * - * @return the Java expressions for which the qualifier holds if the method terminates with - * return value {@link #result()} - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns the qualifier that is guaranteed to hold if the method terminates with return value - * {@link #result()}. - * - * @return the qualifier that is guaranteed to hold if the method terminates with return value - * {@link #result()} - */ - Class qualifier(); - - /** - * Returns the return value of the method that needs to hold for the postcondition to hold. - * - * @return the return value of the method that needs to hold for the postcondition to hold - */ - boolean result(); - - /** - * A wrapper annotation that makes the {@link EnsuresQualifierIf} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link EnsuresQualifierIf} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - @InheritedAnnotation - @interface List { - /** - * Return the repeatable annotations. - * - * @return the repeatable annotations - */ - EnsuresQualifierIf[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/FieldInvariant.java b/src/java.base/share/classes/org/checkerframework/framework/qual/FieldInvariant.java deleted file mode 100644 index e59798066bd..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/FieldInvariant.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Specifies that a field's type, in the class on which this annotation is written, is a subtype of - * its declared type. The field must be declared in a superclass and must be final. - * - *

The {@code @FieldInvariant} annotation does not currently accommodate type qualifiers with - * attributes, such as {@code @MinLen(1)}. In this case, the type system should implement its own - * field invariant annotation and override {@link - * org.checkerframework.framework.type.AnnotatedTypeFactory#getFieldInvariantDeclarationAnnotations()} - * and {@link - * org.checkerframework.framework.type.AnnotatedTypeFactory#getFieldInvariants(javax.lang.model.element.TypeElement)}. - * See {@link org.checkerframework.common.value.qual.MinLenFieldInvariant} for example. - * - * @checker_framework.manual #field-invariants Field invariants - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -@Inherited -public @interface FieldInvariant { - - /** - * The qualifier on the field. Must be a subtype of the qualifier on the declaration of the - * field. - */ - Class[] qualifier(); - - /** - * The field that has a more precise type, in the class on which the {@code FieldInvariant} - * annotation is written. The field must be declared in a superclass and must be {@code final}. - */ - String[] field(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/FromByteCode.java b/src/java.base/share/classes/org/checkerframework/framework/qual/FromByteCode.java deleted file mode 100644 index 11522ff6a1f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/FromByteCode.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * If a method is annotated with this declaration annotation, then its signature is not written in a - * stub file and the method is not declared in source. This annotation is added in - * AnnotatedTypeFactory. (If a method is already annotated with @FromStubFile, this annotation is - * not added.) - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, ElementType.PACKAGE}) -@SubtypeOf({}) -public @interface FromByteCode {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/FromStubFile.java b/src/java.base/share/classes/org/checkerframework/framework/qual/FromStubFile.java deleted file mode 100644 index d829774593f..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/FromStubFile.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * If a method is annotated with this declaration annotation, then its signature was read from a - * stub file. It is added by the StubParser and is not visible to the end user. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, ElementType.PACKAGE}) -public @interface FromStubFile {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/HasQualifierParameter.java b/src/java.base/share/classes/org/checkerframework/framework/qual/HasQualifierParameter.java deleted file mode 100644 index 5865b90f0b7..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/HasQualifierParameter.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This is a declaration annotation that applies to type declarations and packages. On a type, it - * means that the class conceptually takes a type qualifier parameter, though there is nowhere to - * write it because the class hard-codes a Java basetype rather than taking a type parameter. - * Writing {@code HasQualifierParameter} on a package is the same as writing it on each class in - * that package. - * - *

Writing {@code @HasQualifierParameter} on a type declaration has two effects. - * - *

    - *
  1. Invariant subtyping is used for occurrences of the type: no two occurrences of the type - * with different qualifiers have a subtyping relationship. - *
  2. The polymorphic qualifier is the default for all occurrences of that type in its own - * compilation unit, including as the receiver, as another formal parameter, or as a return - * type. - *
- * - * Here is an example of the effect of invariant subtyping. Suppose we have the following - * declaration: - * - *
- *  {@code @HasQualifierParameter}
- *   class StringBuffer { ... }
- * 
- * - * Then {@code @Tainted StringBuffer} is unrelated to {@code @Untainted StringBuffer}. - * - *

The type hierarchy looks like this: - * - *

- *
- *                       {@code @Tainted} Object
- *                      /       |       \
- *                     /        |       {@code @Tainted} Date
- *                   /          |               |
- *                  /           |               |
- *                 /   {@code @Untainted} Object       |
- *                /             |       \       |
- *  {@code @Tainted} StringBuffer      |      {@code @Untainted} Date
- *             |                |
- *             |      {@code @Untainted} StringBuffer
- *             |                |
- *  {@code @Tainted} MyStringBuffer    |
- *                              |
- *                    {@code @Untainted} MyStringBuffer
- * 
- * - *

This annotation may not be written on the same class as {@code NoQualifierParameter} for the - * same hierarchy. - * - *

When {@code @HasQualifierParameter} is written on a package, it is equivalent to writing it on - * each class in that package with the same arguments, including classes in sub-packages. It can be - * disabled on a specific class by writing {@code @NoQualifierParameter} on that class. - * - * @see NoQualifierParameter - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.PACKAGE}) -public @interface HasQualifierParameter { - - /** - * Class of the top qualifier for the hierarchy for which this class has a qualifier parameter. - * - * @return the value - */ - Class[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/IgnoreInWholeProgramInference.java b/src/java.base/share/classes/org/checkerframework/framework/qual/IgnoreInWholeProgramInference.java deleted file mode 100644 index 588bf67a145..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/IgnoreInWholeProgramInference.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation can be used two ways: - * - *

1. As a meta-annotation indicating that an annotation type prevents whole-program inference. - * For example, if the definition of {@code @Inject} is meta-annotated with - * {@code @IgnoreInWholeProgramInference}:
- * {@code @IgnoreInWholeProgramInference}
- * {@code @interface Inject {}}
- * then no type qualifier will be inferred for any field annotated by {@code @Inject}. - * - *

This is appropriate for fields that are set reflectively, so there are no calls in client code - * that type inference can learn from. Examples of qualifiers that should be meta-annotated with - * {@code @IgnoreInWholeProgramInference} include {@code @Inject}, {@code @Singleton}, - * and {@code @Option}. - * - *

2. As a field annotation indicating that no type qualifier will be inferred for the field it - * annotates. - * - *

See - * org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenes#updateFromFieldAssignment - * - * @checker_framework.manual #whole-program-inference-ignores-some-code Whole-program inference - * ignores some code - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD}) -public @interface IgnoreInWholeProgramInference {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/InheritedAnnotation.java b/src/java.base/share/classes/org/checkerframework/framework/qual/InheritedAnnotation.java deleted file mode 100644 index 7a89dcb225d..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/InheritedAnnotation.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** A meta-annotation that specifies if an annotation should be inherited. */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface InheritedAnnotation {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/InvisibleQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/InvisibleQualifier.java deleted file mode 100644 index 1925dc085d0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/InvisibleQualifier.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation indicating that an annotation is a type qualifier that should not be visible in - * output. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface InvisibleQualifier {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/JavaExpression.java b/src/java.base/share/classes/org/checkerframework/framework/qual/JavaExpression.java deleted file mode 100644 index 18e01ca3bb9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/JavaExpression.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation to use on an element of a dependent type qualifier to specify which elements of the - * annotation should be interpreted as Java expressions. The type of the element must be an array of - * Strings. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface JavaExpression {} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/LiteralKind.java b/src/java.base/share/classes/org/checkerframework/framework/qual/LiteralKind.java deleted file mode 100644 index 403415f4402..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/LiteralKind.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Specifies kinds of literal trees. - * - *

These correspond to the *_LITERAL constants in {@link com.sun.source.tree.Tree.Kind}. However, - * that enum is in the tools.jar which is not on the user's classpath by default. This enum is used - * by meta-annotations, such as {@link QualifierForLiterals}, instead. - */ -// https://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html#bootclass -public enum LiteralKind { - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#NULL_LITERAL} trees. */ - NULL, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#INT_LITERAL} trees. */ - INT, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#LONG_LITERAL} trees. */ - LONG, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#FLOAT_LITERAL} trees. */ - FLOAT, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#DOUBLE_LITERAL} trees. */ - DOUBLE, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#BOOLEAN_LITERAL} trees. */ - BOOLEAN, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#CHAR_LITERAL} trees. */ - CHAR, - /** Corresponds to {@link com.sun.source.tree.Tree.Kind#STRING_LITERAL} trees. */ - STRING, - /** Shorthand for all other LiteralKind constants, other than PRIMITIVE. */ - ALL, - /** - * Shorthand for all primitive LiteralKind constants: INT, LONG, FLOAT, DOUBLE, BOOLEAN, CHAR. - */ - PRIMITIVE; - - /** - * Returns all LiteralKinds except for ALL and PRIMITIVE (which are shorthands for groups of - * other LiteralKinds). - * - * @return list of LiteralKinds except for ALL and PRIMITIVE - */ - public static List allLiteralKinds() { - List list = new ArrayList<>(Arrays.asList(values())); - list.remove(ALL); - list.remove(PRIMITIVE); - return list; - } - - /** - * Returns the primitive {@code LiteralKind}s: INT, LONG, FLOAT, DOUBLE, BOOLEAN, CHAR. This is - * all LiteralKinds except for NULL, STRING, and ones that are shorthands for groups of other - * LiteralKinds. - * - * @return list of LiteralKinds except for NULL and STRING - */ - public static List primitiveLiteralKinds() { - return new ArrayList<>(Arrays.asList(INT, LONG, FLOAT, DOUBLE, BOOLEAN, CHAR)); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/MonotonicQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/MonotonicQualifier.java deleted file mode 100644 index 25232ebf100..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/MonotonicQualifier.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates that a qualifier indicates that an expression goes monotonically - * from a type qualifier {@code T} to another qualifier {@code S}. The annotation {@code S} is - * called the target of the monotonic qualifier, and has to be indicated by {@link - * MonotonicQualifier#value()}. - * - *

This meta-annotation can be used on the declaration of the monotonic qualifier used for the - * type-system at hand, and is often called {@code MonoT} if the target is {@code T}. The subtyping - * hierarchy has to be defined as follows: - * - *

{@code
- * T <: MonoT <: S
- * }
- * - * where {@code <:} indicates the subtyping relation. - * - *

An expression of a monotonic type can only be assigned expressions of the target type {@code - * T}. This means that an expression of the monotonic type {@code MonoT} cannot be assigned to a - * variable of the same type. - * - *

Reading an expression of a monotonic type {@code MonoT} might always yield an expression of - * type {@code S}. However, once it has been observed that a variable has the target type {@code T}, - * the monotonic property ensures that it will stay of type {@code T} for the rest of the program - * execution. This is even true if arbitrary other code is executed. - * - *

Note that variables of a monotonic type can be re-assigned arbitrarily often, but only with - * expressions of the target type. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE}) -public @interface MonotonicQualifier { - Class value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/NoDefaultQualifierForUse.java b/src/java.base/share/classes/org/checkerframework/framework/qual/NoDefaultQualifierForUse.java deleted file mode 100644 index c82472cd159..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/NoDefaultQualifierForUse.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declaration annotation applied to type declarations to specify that the annotation on the type - * declaration should not be applied to unannotated uses of the type. Instead, another default - * should be applied based on the location of the type or some other defaulting rule. - * - * @checker_framework.manual #creating-debugging-options Debugging Options - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface NoDefaultQualifierForUse { - /** Top qualifier in hierarchies for which no default annotation for use should be applied. */ - Class[] value() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/NoQualifierParameter.java b/src/java.base/share/classes/org/checkerframework/framework/qual/NoQualifierParameter.java deleted file mode 100644 index 858033a5836..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/NoQualifierParameter.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This is a declaration annotation that applies to type declarations. Some classes conceptually - * take a type qualifier parameter. This annotations indicates that this class explicitly does not - * do so. If {@code HasQualifierParameter} is enabled by default, for example, by writing {@code - * HasQualifierParameter} on a package, then this annotation can disable it for a specific class. - * - *

One or more top qualifiers must be given for the hierarchies for which there are no qualifier - * parameters. This annotation may not be written on the same class as {@code HasQualifierParameter} - * for the same hierarchy. - * - * @see HasQualifierParameter - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface NoQualifierParameter { - - /** - * Class of the top qualifier for the hierarchy for which this class has no qualifier parameter. - * - * @return the value - */ - Class[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/PolymorphicQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/PolymorphicQualifier.java deleted file mode 100644 index c47a25f15d4..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/PolymorphicQualifier.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates that an annotation is a polymorphic type qualifier. - * - *

Any method written using a polymorphic type qualifier conceptually has two or more versions - * — one version for each qualifier in the qualifier hierarchy. In each version of the method, - * all instances of the polymorphic type qualifier are replaced by one of the other type qualifiers. - * - * @checker_framework.manual #qualifier-polymorphism Qualifier polymorphism - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE}) -@AnnotatedFor("nullness") -public @interface PolymorphicQualifier { - /** - * Indicates which type system this annotation refers to (optional, and usually unnecessary). - * When multiple type hierarchies are supported by a single type system, then each polymorphic - * qualifier needs to indicate which sub-hierarchy it belongs to. Do so by passing the top - * qualifier from the given hierarchy. - * - * @return the top qualifier in the hierarchy of this qualifier - */ - // We use the meaningless Annotation.class as default value and - // then ensure there is a single top qualifier to use. - Class value() default Annotation.class; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/PostconditionAnnotation.java b/src/java.base/share/classes/org/checkerframework/framework/qual/PostconditionAnnotation.java deleted file mode 100644 index 3d60bad7991..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/PostconditionAnnotation.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates that an annotation E is a postcondition annotation, i.e., E is a - * type-specialized version of {@link EnsuresQualifier} or of {@link EnsuresQualifier.List}. - * - *

    - *
  • If E is a type-specialized version of {@link EnsuresQualifier}, its {@code value} element - * must be an array of {@code String}s, analogous to {@link EnsuresQualifier#expression()}. - *
  • If E is a type-specialized version of {@link EnsuresQualifier.List}, its {@code value} - * element must be an array of postcondition annotations, analogous to {@link - * EnsuresQualifier.List#value()}. - *
- * - *

The established postcondition P has type specified by the {@code qualifier} field of this - * annotation. If the annotation E has elements annotated by {@link QualifierArgument}, their values - * are copied to the arguments (elements) of annotation P with the same names. Different element - * names may be used in E and P, if a {@link QualifierArgument} in E gives the name of the - * corresponding element in P. - * - *

For example, the following code declares a postcondition annotation for the {@link - * org.checkerframework.common.value.qual.MinLen} qualifier: - * - *


- * {@literal @}PostconditionAnnotation(qualifier = MinLen.class)
- * {@literal @}Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
- * public {@literal @}interface EnsuresMinLen {
- *   String[] value();
- *   {@literal @}QualifierArgument("value")
- *   int targetValue() default 0;
- * 
- * - * The {@code value} element holds the expressions to which the qualifier applies and {@code - * targetValue} holds the value for the {@code value} argument of {@link - * org.checkerframework.common.value.qual.MinLen}. - * - *

The following code then uses the annotation on a method that ensures {@code field} to be - * {@code @MinLen(2)} upon return. - * - *


- * {@literal @}EnsuresMinLen(value = "field", targetValue = 2")
- * public void setField(String argument) {
- *   field = "(" + argument + ")";
- * }
- * 
- * - * @see EnsuresQualifier - * @see QualifierArgument - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE}) -public @interface PostconditionAnnotation { - /** - * The qualifier that will be established as a postcondition. - * - *

This element is analogous to {@link EnsuresQualifier#qualifier()}. - */ - Class qualifier(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/PreconditionAnnotation.java b/src/java.base/share/classes/org/checkerframework/framework/qual/PreconditionAnnotation.java deleted file mode 100644 index 542b1fa13b4..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/PreconditionAnnotation.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates that an annotation R is a precondition annotation, i.e., R is a - * type-specialized version of {@link RequiresQualifier}. The value {@code qualifier} that is - * necessary for a precondition specified with {@link RequiresQualifier} is specified here with the - * value {@code qualifier}. - * - *

The annotation R that is meta-annotated as {@link PreconditionAnnotation} must have an element - * called {@code value} that is an array of {@code String}s of the same format and with the same - * meaning as the value {@code expression} in {@link RequiresQualifier}. - * - *

The established precondition P has type specified by the {@code qualifier} field of this - * annotation. If the annotation R has elements annotated by {@link QualifierArgument}, their values - * are copied to the arguments (elements) of annotation P with the same names. Different element - * names may be used in R and P, if a {@link QualifierArgument} in R gives the name of the - * corresponding element in P. - * - *

For example, the following code declares a precondition annotation for the {@link - * org.checkerframework.common.value.qual.MinLen} qualifier: - * - *


- * {@literal @}PreconditionAnnotation(qualifier = MinLen.class)
- * {@literal @}Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
- * public {@literal @}interface RequiresMinLen {
- *   String[] value();
- *   {@literal @}QualifierArgument("value")
- *   int targetValue() default 0;
- * 
- * - * The {@code value} element holds the expressions to which the qualifier applies and {@code - * targetValue} holds the value for the {@code value} argument of {@link - * org.checkerframework.common.value.qual.MinLen}. - * - *

The following code then uses the annotation on a method that requires {@code field} to be - * {@code @MinLen(2)} upon entry. - * - *


- * {@literal @}RequiresMinLen(value = "field", targetValue = 2")
- * public char getThirdCharacter() {
- *   return field.charAt(2);
- * }
- * 
- * - * @see RequiresQualifier - * @see QualifierArgument - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.ANNOTATION_TYPE}) -public @interface PreconditionAnnotation { - /** The qualifier that must be established as a precondition. */ - Class qualifier(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierArgument.java b/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierArgument.java deleted file mode 100644 index 0a6810569aa..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierArgument.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation to use on an element of a contract annotation to indicate that the element - * specifies the value of an argument of the qualifier. A contract annotation is an annotation - * declared with a {@link PreconditionAnnotation}, {@link PostconditionAnnotation}, or {@link - * ConditionalPostconditionAnnotation} meta-annotation. The meta-annotation specifies the qualifier - * taking the arguments. - * - *

For example, the following code declares a postcondition annotation for the {@link - * org.checkerframework.common.value.qual.MinLen} qualifier, allowing to specify its value: - * - *


- * {@literal @}PostconditionAnnotation(qualifier = MinLen.class)
- * {@literal @}Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
- * public {@literal @}interface EnsuresMinLen {
- *   String[] value();
- *   {@literal @}QualifierArgument("value")
- *   int targetValue() default 0;
- * 
- * - * The {@code value} element holds the expressions to which the qualifier applies and {@code - * targetValue} holds the value for the {@code value} argument of {@link - * org.checkerframework.common.value.qual.MinLen}. - * - * @see PostconditionAnnotation - * @see ConditionalPostconditionAnnotation - * @see PreconditionAnnotation - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface QualifierArgument { - /** - * Specifies the name of the argument of the qualifier, that is passed the values held in the - * annotated element. If the value is omitted or is empty, then the name of the annotated - * element is used as the argument name. - */ - String value() default ""; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierForLiterals.java b/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierForLiterals.java deleted file mode 100644 index 134c8a7c6d0..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/QualifierForLiterals.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that indicates what qualifier should be given to literals. - * {@code @QualifierForLiterals} is equivalent to {@code @QualfierForLiterals(LiteralKind.ALL)} - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface QualifierForLiterals { - /** - * The kinds of literals whose types have this qualifier. For example, if {@code @MyAnno} is - * meta-annotated with {@code @QualifierForLiterals(LiteralKind.STRING)}, then a literal {@code - * String} constant such as {@code "hello world"} has type {@code @MyAnno String}, but - * occurrences of {@code String} in the source code are not affected. - * - *

For String literals, also see the {@link #stringPatterns} annotation element/field. - */ - LiteralKind[] value() default {}; - - /** - * A string literal that matches any of these patterns has this qualifier. - * - *

If patterns for multiple qualifers match, then the string literal is given the greatest - * lower bound of all the matches. - */ - String[] stringPatterns() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/RelevantJavaTypes.java b/src/java.base/share/classes/org/checkerframework/framework/qual/RelevantJavaTypes.java deleted file mode 100644 index c238470df68..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/RelevantJavaTypes.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation on a SourceChecker subclass to specify which Java types are processed by the - * checker. The checker's type qualifiers may only appear on the given types and their subtypes - * — in source code, internally in the compiler, or in class files. - * - *

If a checker is not annotated with this annotation, then the checker's qualifiers may appear - * on any type. - * - *

This is orthogonal to Java's {@code @Target} annotation; each enforces a different type of - * restriction on what can be written in source code. - * - * @checker_framework.manual #creating-relevant-java-types Relevant Java types - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -public @interface RelevantJavaTypes { - /** - * Classes that are processed by the checker. - * - *

{@code Object[].class} implies that the checker processes all array types. No distinction - * among array types is currently made, and no other array class should be supplied to - * {@code @RelevantJavaTypes}. - * - *

A boxed type, such as {@code Integer.class}, implies that the checker processes both the - * boxed type {@code Integer} and the unboxed primitive type {@code int}. - */ - Class[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/RequiresQualifier.java b/src/java.base/share/classes/org/checkerframework/framework/qual/RequiresQualifier.java deleted file mode 100644 index 78839a0afb9..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/RequiresQualifier.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A precondition annotation to indicate that a method requires certain expressions to have a - * certain qualifier at the time of the call to the method. The expressions for which the annotation - * must hold after the method's execution are indicated by {@code expression} and are specified - * using a string. The qualifier is specified by {@code qualifier}. - * - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@Repeatable(RequiresQualifier.List.class) -public @interface RequiresQualifier { - /** - * Returns the Java expressions for which the annotation need to be present. - * - * @return the Java expressions for which the annotation need to be present - * @checker_framework.manual #java-expressions-as-arguments Syntax of Java expressions - */ - String[] expression(); - - /** - * Returns the qualifier that is required. - * - * @return the qualifier that is required - */ - Class qualifier(); - - /** - * A wrapper annotation that makes the {@link RequiresQualifier} annotation repeatable. - * - *

Programmers generally do not need to write this. It is created by Java when a programmer - * writes more than one {@link RequiresQualifier} annotation at the same location. - */ - @Documented - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - @interface List { - /** - * Returns the repeatable annotations. - * - * @return the repeatable annotations - */ - RequiresQualifier[] value(); - } -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/StubFiles.java b/src/java.base/share/classes/org/checkerframework/framework/qual/StubFiles.java deleted file mode 100644 index 64dbeff0700..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/StubFiles.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation on a SourceChecker subclass to provide additional stub files that should be used in - * addition to {@code jdk.astub}. This allows larger compound checkers to separate the annotations - * into multiple files, or to provide annotations for non-JDK classes. - * - *

This annotation is not inherited. That means that if a checker with this annotation is - * subclassed, then this annotation must be copied to the subclass and the stub file must also be - * copied to the directory that contains the subclass. - * - * @checker_framework.manual #creating-a-checker-annotated-jdk Annotated JDK - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface StubFiles { - /** - * Stub file names. These are basenames: they include the extension (usually ".astub"), but no - * directory component. - */ - String[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/SubtypeOf.java b/src/java.base/share/classes/org/checkerframework/framework/qual/SubtypeOf.java deleted file mode 100644 index 2061db91ee6..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/SubtypeOf.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation to specify all the qualifiers that the given qualifier is an immediate subtype - * of. This provides a declarative way to specify the type qualifier hierarchy. (Alternatively, the - * hierarchy can be defined procedurally by subclassing {@link - * org.checkerframework.framework.type.QualifierHierarchy} or {@link - * org.checkerframework.framework.type.TypeHierarchy}.) - * - *

Example: - * - *

 @SubtypeOf( { Nullable.class } )
- * public @interface NonNull {}
- * 
- * - *

For the top qualifier in the qualifier hierarchy (i.e., the qualifier that is a supertype of - * all other qualifiers in the given hierarchy), use an empty set of values: - * - *

 @SubtypeOf( {} )
- * public @interface Nullable {}
- *
- * @SubtypeOf( {} )
- * public @interface MaybeAliased {}
- * 
- * - *

Together, all the {@code @SubtypeOf} meta-annotations fully describe the type qualifier - * hierarchy. - * - * @checker_framework.manual #creating-declarative-hierarchy Declaratively defining the qualifier - * hierarchy - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -@AnnotatedFor("nullness") -public @interface SubtypeOf { - /** An array of the supertype qualifiers of the annotated qualifier. */ - Class[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/TargetLocations.java b/src/java.base/share/classes/org/checkerframework/framework/qual/TargetLocations.java deleted file mode 100644 index 01e58af03fb..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/TargetLocations.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation that restricts the type-use locations where a type qualifier may be written. - * When written together with {@code @Target({ElementType.TYPE_USE})}, the given type qualifier may - * be written only at locations listed in the {@code @TargetLocations(...)} meta-annotation. - * {@code @Target({ElementType.TYPE_USE})} together with no {@code @TargetLocations(...)} means that - * the qualifier can be written on any type use. - * - *

This enables a type system designer to permit a qualifier to be written only in certain - * locations. For example, some type systems' top and bottom qualifier (such as {@link - * org.checkerframework.checker.nullness.qual.KeyForBottom}) should only be written on an explicit - * wildcard upper or lower bound. This meta-annotation is a declarative, coarse-grained approach to - * enable that. A {@code org.checkerframework.common.basetype.TypeValidator} must be implemented if - * finer-grained control is necessary. - */ -// TODO: Verify this meta-annotation (step 3 in -// https://github.com/typetools/checker-framework/issues/1919). -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface TargetLocations { - /** Type uses at which the qualifier is permitted to be written in source code. */ - TypeUseLocation[] value(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/TypeKind.java b/src/java.base/share/classes/org/checkerframework/framework/qual/TypeKind.java deleted file mode 100644 index e80c6fd573b..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/TypeKind.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.checkerframework.framework.qual; - -/** - * Specifies kinds of types. - * - *

These correspond to the constants in {@link javax.lang.model.type.TypeKind}. However, that - * enum is not available on Android and a warning is produced. So this enum is used instead. - * - * @checker_framework.manual #creating-type-introduction Declaratively specifying default - * annotations - */ -public enum TypeKind { - /** Corresponds to {@link javax.lang.model.type.TypeKind#BOOLEAN} types. */ - BOOLEAN, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#BYTE} types. */ - BYTE, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#SHORT} types. */ - SHORT, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#INT} types. */ - INT, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#LONG} types. */ - LONG, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#CHAR} types. */ - CHAR, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#FLOAT} types. */ - FLOAT, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#DOUBLE} types. */ - DOUBLE, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#VOID} types. */ - VOID, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#NONE} types. */ - NONE, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#NULL} types. */ - NULL, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#ARRAY} types. */ - ARRAY, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#DECLARED} types. */ - DECLARED, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#ERROR} types. */ - ERROR, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#TYPEVAR} types. */ - TYPEVAR, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#WILDCARD} types. */ - WILDCARD, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#PACKAGE} types. */ - PACKAGE, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#EXECUTABLE} types. */ - EXECUTABLE, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#OTHER} types. */ - OTHER, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#UNION} types. */ - UNION, - - /** Corresponds to {@link javax.lang.model.type.TypeKind#INTERSECTION} types. */ - INTERSECTION; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/TypeUseLocation.java b/src/java.base/share/classes/org/checkerframework/framework/qual/TypeUseLocation.java deleted file mode 100644 index ac90e878657..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/TypeUseLocation.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.checkerframework.framework.qual; - -/** - * Specifies the locations to which a {@link DefaultQualifier} annotation applies. - * - *

The order of enums is important. Defaults are applied in this order. In particular, this means - * that OTHERWISE and ALL should be last. - * - * @see DefaultQualifier - * @see javax.lang.model.element.ElementKind - */ -public enum TypeUseLocation { - - /** Apply default annotations to all unannotated raw types of fields. */ - FIELD, - - /** - * Apply default annotations to all unannotated raw types of local variables, casts, and - * instanceof. - * - *

TODO: should cast/instanceof be separated? - */ - LOCAL_VARIABLE, - - /** Apply default annotations to all unannotated raw types of resource variables. */ - RESOURCE_VARIABLE, - - /** Apply default annotations to all unannotated raw types of exception parameters. */ - EXCEPTION_PARAMETER, - - /** Apply default annotations to all unannotated raw types of receiver types. */ - RECEIVER, - - /** Apply default annotations to all unannotated raw types of formal parameter types. */ - PARAMETER, - - /** Apply default annotations to all unannotated raw types of return types. */ - RETURN, - - /** Apply default annotations to all unannotated raw types of constructor result types. */ - CONSTRUCTOR_RESULT, - - /** - * Apply default annotations to unannotated lower bounds for type variables and wildcards both - * explicit ones in {@code extends} clauses, and implicit upper bounds when no explicit {@code - * extends} or {@code super} clause is present. - */ - LOWER_BOUND, - - /** - * Apply default annotations to unannotated, but explicit lower bounds: {@code } - */ - EXPLICIT_LOWER_BOUND, - - /** - * Apply default annotations to unannotated, but implicit lower bounds: {@code } {@code }. - */ - IMPLICIT_LOWER_BOUND, - - /** - * Apply default annotations to unannotated upper bounds: both explicit ones in {@code extends} - * clauses, and implicit upper bounds when no explicit {@code extends} or {@code super} clause - * is present. - * - *

Especially useful for parametrized classes that provide a lot of static methods with the - * same generic parameters as the class. - * - *

TODO: more doc, relation to other UPPER_BOUND - */ - UPPER_BOUND, - - /** - * Apply default annotations to unannotated, but explicit upper bounds: {@code }. - * - *

TODO: more doc, relation to other UPPER_BOUND - */ - EXPLICIT_UPPER_BOUND, - - /** - * Apply default annotations to unannotated type variables: {@code }. - * - *

TODO: more doc, relation to other UPPER_BOUND - */ - IMPLICIT_UPPER_BOUND, - - /** Apply if nothing more concrete is provided. TODO: clarify relation to ALL. */ - OTHERWISE, - - /** - * Apply default annotations to all type uses other than uses of type parameters. Does not allow - * any of the other constants. Usually you want OTHERWISE. - */ - ALL; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/Unused.java b/src/java.base/share/classes/org/checkerframework/framework/qual/Unused.java deleted file mode 100644 index f0d00d15217..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/Unused.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that the field may not be accessed if the receiver is of the specified qualifier type - * (or any supertype). - * - *

This property is verified by the checker that type-checks the {@code when} element value - * qualifier. - * - *

Example Consider a class, {@code Table}, with a locking field, {@code lock}. The lock - * is used when a {@code Table} instance is shared across threads. When running in a local thread, - * the {@code lock} field ought not to be used. - * - *

You can declare this behavior in the following way: - * - *

{@code
- * class Table {
- *   private @Unused(when=LocalToThread.class) final Lock lock;
- *   ...
- * }
- * }
- * - * The checker for {@code @LocalToThread} would issue an error for the following code: - * - *
  @LocalToThread Table table = ...;
- *   ... table.lock ...;
- * 
- * - * @checker_framework.manual #unused-fields Unused fields - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD}) -public @interface Unused { - /** - * The field that is annotated with @Unused may not be accessed via a receiver that is annotated - * with the "when" annotation. - */ - Class when(); -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/UpperBoundFor.java b/src/java.base/share/classes/org/checkerframework/framework/qual/UpperBoundFor.java deleted file mode 100644 index 98aebcd7658..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/UpperBoundFor.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.checkerframework.framework.qual; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A meta-annotation applied to the declaration of a type qualifier. It specifies that the - * annotation should be the upper bound for - * - *
    - *
  • all uses of a particular type, and - *
  • all uses of a particular kind of type. - *
- * - * An example is the declaration - * - *

- * {@literal @}DefaultFor(classes=String.class)
- * {@literal @}interface MyAnno {}
- * 
- * - *

The upper bound applies to every occurrence of the given classes and also to every occurrence - * of the given type kinds. - * - * @checker_framework.manual #upper-bound-for-use Upper bound of qualifiers on uses of a given type - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.ANNOTATION_TYPE) -public @interface UpperBoundFor { - /** - * Returns {@link TypeKind}s of types that get an upper bound. The meta-annotated annotation is - * the upper bound. - * - * @return {@link TypeKind}s of types that get an upper bound - */ - TypeKind[] typeKinds() default {}; - - /** - * Returns {@link Class}es that should get an upper bound. The meta-annotated annotation is the - * upper bound. - * - * @return {@link Class}es that get an upper bound - */ - Class[] types() default {}; -} diff --git a/src/java.base/share/classes/org/checkerframework/framework/qual/package-info.java b/src/java.base/share/classes/org/checkerframework/framework/qual/package-info.java deleted file mode 100644 index 8fc168e5385..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/qual/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Contains the basic annotations to be used by all type systems and meta-annotations to qualify - * annotations (qualifiers). - * - *

They may serve as documentation for the type qualifiers, and aid the Checker Framework to - * infer the relations between the type qualifiers. - * - * @checker_framework.manual #creating-a-checker Writing a checker - */ -package org.checkerframework.framework.qual; diff --git a/src/java.base/share/classes/org/checkerframework/framework/util/PurityUnqualified.java b/src/java.base/share/classes/org/checkerframework/framework/util/PurityUnqualified.java deleted file mode 100644 index 4c51c1bc0b1..00000000000 --- a/src/java.base/share/classes/org/checkerframework/framework/util/PurityUnqualified.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.checkerframework.framework.util; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.checkerframework.framework.qual.DefaultQualifierInHierarchy; -import org.checkerframework.framework.qual.InvisibleQualifier; -import org.checkerframework.framework.qual.SubtypeOf; - -/** - * An annotation intended solely for representing an unqualified type in the qualifier hierarchy for - * the Purity Checker. - * - * @checker_framework.manual #purity-checker Purity Checker - */ -@Documented -@Retention(RetentionPolicy.SOURCE) // do not store in .class file -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@SubtypeOf({}) -@DefaultQualifierInHierarchy -@InvisibleQualifier -public @interface PurityUnqualified {} diff --git a/src/java.base/share/classes/org/jspecify/annotations/NonNull.java b/src/java.base/share/classes/org/jspecify/annotations/NonNull.java new file mode 100644 index 00000000000..814096e89dc --- /dev/null +++ b/src/java.base/share/classes/org/jspecify/annotations/NonNull.java @@ -0,0 +1,96 @@ +/* + * Copyright 2022 The JSpecify Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jspecify.annotations; + +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated type + * usage (commonly a parameter type or return type) is considered to exclude {@code null} + * as a value; rarely needed within {@linkplain NullMarked null-marked} code. + * + *

This annotation serves two primary purposes: + * + *

    + *
  • To mark any sporadic non-null type usages inside a scope that is not ready to be fully + * {@link NullMarked} yet. + *
  • To perform a non-null projection of a type variable, explained below. + *
+ * + *

For a comprehensive introduction to JSpecify, please see jspecify.org. + * + *

Non-null projection

+ * + *

In the following example, {@code MyOptional}'s type parameter {@code T} accepts only non-null + * type arguments, but {@code MyList}'s type parameter {@code E} will accept either a non-null or + * nullable type argument. + * + *

{@code
+ * // All the below is null-marked code
+ *
+ * class MyOptional { ... }
+ *
+ * interface MyList {
+ *   // Returns the first non-null element, if such element exists.
+ *   MyOptional firstNonNull() { ... } // problem here!
+ * }
+ *
+ * MyList<@Nullable String> maybeNulls = ...
+ * MyList nonNulls = ...
+ * }
+ * + *

Because {@code MyOptional} accepts only non-null type arguments, we need both {@code + * maybeNulls.firstNonNull()} and {@code nonNulls.firstNonNull()} to produce the same return type: + * {@code MyOptional!} (see notation). + * However, as specified above, they won't do that. In fact, there is a problem with the {@code + * firstNonNull} signature, since the type argument {@code String?} would not meet the requirements + * of {@code MyOptional}'s type parameter. + * + *

The solution is to project the type argument to its non-null counterpart: + * + *

{@code
+ * // Returns the first non-null element, if such element exists.
+ * MyOptional<@NonNull E> firstNonNull() { ... } // problem fixed!
+ * }
+ * + *

Here, {@code @NonNull E} selects the non-null form of the type argument, whether it was + * already non-null or not, which is just what we need in this scenario. + * + *

If {@code E} has a non-null upper bound, then the apparent projection {@code @NonNull E} is + * redundant but harmless. + * + *

Nullable projection serves the equivalent purpose in + * the opposite direction, and is far more commonly useful. + * + *

If a type variable has all its usages being projected in one direction or the other, it + * should be given a non-null upper bound, and any non-null projections can then be removed. + * + *

Where it is applicable

+ * + *

{@code @NonNull} is applicable in all the same + * locations as {@link Nullable}. + */ +@Documented +@Target(TYPE_USE) +@Retention(RUNTIME) +public @interface NonNull {} diff --git a/src/java.base/share/classes/org/jspecify/annotations/NullMarked.java b/src/java.base/share/classes/org/jspecify/annotations/NullMarked.java new file mode 100644 index 00000000000..44e95104874 --- /dev/null +++ b/src/java.base/share/classes/org/jspecify/annotations/NullMarked.java @@ -0,0 +1,112 @@ +/* + * Copyright 2018-2020 The JSpecify Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jspecify.annotations; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.MODULE; +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated element and the code transitively {@linkplain + * javax.lang.model.element.Element#getEnclosedElements() enclosed} within it are null-marked + * code: there, type usages are generally considered to exclude {@code null} as a value unless + * specified otherwise. Using this annotation avoids the need to write {@link NonNull @NonNull} many + * times throughout your code. + * + *

For a comprehensive introduction to JSpecify, please see jspecify.org. + * + *

Effects of being null-marked

+ * + *

Within null-marked code, as a general rule, a type usage is considered non-null (to + * exclude {@code null} as a value) unless explicitly annotated as {@link Nullable}. However, there + * are several special cases to address. + * + *

Special cases

+ * + *

Within null-marked code: + * + *

    + *
  • We might expect the type represented by a wildcard (like the {@code ?} in {@code + * List}) to be non-null, but it isn't necessarily. It's non-null only if it {@code + * extends} a non-null type (like in {@code List}), or if the class + * in use accepts only non-null type arguments (such as if {@code List} were declared as + * {@code class List}). But if {@code List} does accept nullable type + * arguments, then the wildcards seen in {@code List} and {@code List} must + * include {@code null}, because they have no "upper bound". (Why?) + *
      + *
    • Conversely, a type parameter is always considered to have an upper bound; when + * none is given explicitly, {@code Object} is filled in by the compiler. The example + * {@code class MyList} is interpreted identically to {@code class MyList}: in both cases the type argument in {@code MyList<@Nullable Foo>} is + * out-of-bounds, so the list elements are always non-null. (Why?) + *
    + *
  • Otherwise, being null-marked has no consequence for any type usage where {@code @Nullable} + * and {@code @NonNull} are not applicable, + * such as the root type of a local variable declaration. + *
  • When a type variable has a nullable upper bound, such as the {@code E} in {@code class + * Foo}), an unannotated usage of this type variable is not + * considered nullable, non-null, or even of "unspecified" nullness. Rather it has + * parametric nullness. In order to support both nullable and non-null type arguments + * safely, the {@code E} type itself must be handled strictly: as if nullable when + * "read from", but as if non-null when "written to". (Contrast with {@code class Foo}, where usages of {@code E} are simply non-null, just like usages of {@code + * String} are.) + *
  • By using {@link NullUnmarked}, an element within null-marked code can be excluded and made + * null-unmarked, exactly as if there were no enclosing {@code @NullMarked} element at all. + *
+ * + *

Where it can be used

+ * + * {@code @NullMarked} and {@link NullUnmarked @NullUnmarked} can be used on any package, class, + * method, or constructor declaration; {@code @NullMarked} can be used on a module declaration as + * well. Special considerations: + * + *
    + *
  • To apply this annotation to an entire (single) package, create a {@code + * package-info.java} file there. This is recommended so that newly-created classes will + * be null-marked by default. This annotation has no effect on "subpackages". Warning: + * if the package does not belong to a module, be very careful: it can easily happen that + * different versions of the package-info file are seen and used in different circumstances, + * causing the same classes to be interpreted inconsistently. For example, a package-info file + * from a {@code test} source path might hide the corresponding one from the {@code main} + * source path, or generated code might be compiled without seeing a package-info file at all. + *
  • Although Java permits it to be applied to a record component declaration (as in + * {@code record Foo(@NullMarked String bar) {...}}), this annotation has no meaning when used + * in that way. + *
  • Applying this annotation to an instance method of a generic class is + * acceptable, but is not recommended because it can lead to some confusing situations. + *
  • An advantage of Java modules is that you can make a lot of code null-marked with + * just a single annotation (before the {@code module} keyword). {@link NullUnmarked} is not + * supported on modules, since it's already the default. + *
  • If both {@code @NullMarked} and {@code @NullUnmarked} appear together on the same element, + * neither one is recognized. + *
+ */ +@Documented +@Target({MODULE, PACKAGE, TYPE, METHOD, CONSTRUCTOR}) +@Retention(RUNTIME) +public @interface NullMarked {} diff --git a/src/java.base/share/classes/org/jspecify/annotations/NullUnmarked.java b/src/java.base/share/classes/org/jspecify/annotations/NullUnmarked.java new file mode 100644 index 00000000000..f2da1df9ce6 --- /dev/null +++ b/src/java.base/share/classes/org/jspecify/annotations/NullUnmarked.java @@ -0,0 +1,82 @@ +/* + * Copyright 2022 The JSpecify Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jspecify.annotations; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.ElementType.TYPE; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated element and the code transitively {@linkplain + * javax.lang.model.element.Element#getEnclosedElements() enclosed} within it is null-unmarked + * code: there, type usages generally have unspecified nullness unless explicitly + * annotated otherwise. + * + *

This annotation's purpose is to ease migration of a large existing codebase to null-marked + * status. It makes it possible to "flip the default" for new code added to a class or package even + * before that class or package has been fully migrated. Since new code is the most important code + * to analyze, this is strongly recommended as a temporary measure whenever necessary. However, once + * a codebase has been fully migrated it would be appropriate to ban use of this annotation. + * + *

For a comprehensive introduction to JSpecify, please see jspecify.org. + * + *

Null-marked and null-unmarked code

+ * + *

{@link NullMarked} and this annotation work as a pair to include and exclude sections of code + * from null-marked status (respectively). Specifically, code is considered null-marked if the most + * narrowly enclosing element annotated with either of these two annotations exists and is annotated + * with {@code @NullMarked}. + * + *

Otherwise it is considered null-unmarked. This can happen in two ways: either it is more + * narrowly enclosed by a {@code @NullUnmarked}-annotated element than by any + * {@code @NullMarked}-annotated element, or neither annotation is present on any enclosing element. + * No distinction is made between these cases. + * + *

The effects of being null-marked are described in the Effects section of {@code NullMarked}. + * + *

Unspecified nullness

+ * + *

Within null-unmarked code, a type usage with no nullness annotation has unspecified + * nullness (Why?). This means that, while there is always + * some correct way to annotate it for nullness, that information is missing: we do not + * know whether it includes or excludes {@code null} as a value. In such a case, tools can vary + * widely in how strict or lenient their enforcement is, or might make it configurable. + * + *

For more, please see this more comprehensive + * discussion of unspecified nullness. + * + *

There is no way for an individual type usage within null-marked code to have unspecified + * nullness. (Why?) + * + *

Where it can be used

+ * + * The information in the Where it can be used section of {@code + * NullMarked} applies as well to this annotation. + */ +// TODO(kevinb9n): word the middle section better with good words +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({PACKAGE, TYPE, METHOD, CONSTRUCTOR}) +public @interface NullUnmarked {} diff --git a/src/java.base/share/classes/org/jspecify/annotations/Nullable.java b/src/java.base/share/classes/org/jspecify/annotations/Nullable.java new file mode 100644 index 00000000000..c20c3a55720 --- /dev/null +++ b/src/java.base/share/classes/org/jspecify/annotations/Nullable.java @@ -0,0 +1,141 @@ +/* + * Copyright 2018-2020 The JSpecify Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jspecify.annotations; + +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Indicates that the annotated type + * usage (commonly a parameter type or return type) is considered to include {@code null} as a + * value. + * + *

Example usages: + * + *

{@code
+ * @Nullable String field;
+ *
+ * @Nullable String getField() { return field; }
+ *
+ * void setField(@Nullable String value) { field = value; }
+ *
+ * List<@Nullable String> getList() { ... }
+ * }
+ * + *

For a comprehensive introduction to JSpecify, please see jspecify.org. + * + *

Meaning per each kind of type usage

+ * + *

The essential meaning of this annotation is always the same: the type it annotates is + * considered to include {@code null} as a value. But this may affect your code a little differently + * based on the kind of type usage involved. + * + *

    + *
  • On a parameter type: The {@code setField} method (at top) permissively accepts a + * "string-or-null", meaning that it is okay to pass an actual string, or to pass {@code + * null}. (This doesn't guarantee that passing {@code null} won't produce an exception at + * runtime, but it should be much less likely.) This also applies to the type of a lambda + * expression parameter, if that type is given explicitly (otherwise its nullness must be + * inferred from context). + *
  • On a method return type: The {@code getField} method returns a "string-or-null", so + * while the caller might get a string back, it should also address the possibility of getting + * {@code null} instead. (This doesn't guarantee there is any circumstance in which {@code + * null} will actually be returned.) + *
  • On a field type: The {@code field} field has the type "string-or-null", so at times + * it might hold a string, and at times it might hold {@code null}. (Of course, every field of + * a reference type originally holds {@code null}, but as long as the class ensures + * that its uninitialized states can't be observed, it's appropriate to overlook that fact.) + *
  • On a type argument: A type usage of "nullable string" appears within the + * compound type {@code List<@Nullable String>}. No matter how this type is used (return type, + * etc.), this means the same thing: every appearance of {@code E} in {@code List}'s member + * signatures will be considered nullable. For a list, this means it may contain null + * elements. If the list reference itself might be null as well, we can write + * {@code @Nullable List<@Nullable String>}, a "nullable list of nullable strings". + *
  • On the upper bound of a type parameter: For example, as seen in {@code class List}. This means that a type argument supplied for that type + * parameter is permitted to be nullable if desired: {@code List<@Nullable String>}. (A + * non-null type argument, as in {@code List}, is permitted either way.) + *
  • On a usage of a type variable: A type parameter, like the {@code E} in {@code + * interface List}, defines a "type variable" of the same name, usable only within + * the scope of the declaring API element. In any example using {@code String} above, a type + * variable like {@code E} might appear instead. {@code @Nullable} continues to mean "or null" + * as always, but notably, this works without regard to whether the type argument is + * already nullable. For example, suppose that {@code class Foo} has a method {@code @Nullable E eOrNull()}. Then, whether {@code foo} is of type + * {@code Foo} or {@code Foo<@Nullable String>}, the expression {@code foo.eOrNull()} + * is nullable either way. Using {@code @Nullable E} in this way is called "nullable + * projection" (non-null projection is likewise + * supported, but less commonly useful). + *
  • On a nested type: In most examples above, in place of {@code String} we might use a + * nested type such as {@code Map.Entry}. The Java syntax for annotating such a type as + * nullable looks like {@code Map.@Nullable Entry}. + *
  • On a record component: As expected, {@code @Nullable} here applies equally to the + * corresponding parameter type of the canonical constructor, and to the return type of a + * generated accessor method as well. If an explicit accessor method is provided for this + * record component, it must still be annotated explicitly. Any non-null components should be + * checked (for example using {@link java.util.Objects#requireNonNull}) in a compact + * constructor. + *
+ * + *

Where it is applicable

+ * + *

This annotation and {@link NonNull} are applicable to any type usage except the + * following cases, where they have no defined meaning: + * + *

    + *
  • On any intrinsically non-null type usage. Some type usages are incapable of + * including {@code null} by the rules of the Java language. Examples include any usage of a + * primitive type, the root type of the argument to {@code instanceof}, a method return type + * in an annotation interface, or the type following {@code throws} or {@code catch}. In such + * locations, a nullness annotation could only be contradictory ({@code @Nullable}) or + * redundant ({@code @NonNull}). + *
  • On the root type of a local variable declaration. The nullness of a local variable + * itself is not a fixed declarative property of its type. Rather it should be inferred + * from the nullness of each expression assigned to the variable, possibly changing over time. + * (Why?). Subcomponents of the type (type arguments, + * array component types) are annotatable as usual. + *
  • On the root type in a cast expression. To inform an analyzer that an expression it + * sees as nullable is truly non-null, use an assertion or a method like {@link + * java.util.Objects#requireNonNull}. (Why?) + * Subcomponents of the type (type arguments, array component types) are annotatable as usual. + *
  • On any part of the argument to {@code instanceof}. The root type is intrinsically + * non-null, as discussed above, and nothing else about nullness is checked at runtime. + *
  • On any part of a receiver parameter type (JLS 8.4). + *
  • If both {@code @Nullable} and {@code @NonNull} appear on the same type usage, + * neither one is recognized. + *
+ * + * Whether the code is {@link NullMarked} also has no consequence in the above locations. + * + *

Unannotated type usages

+ * + *

For a type usage where nullness annotations are applicable but + * not present, its nullness depends on whether it appears within {@linkplain NullMarked + * null-marked} code; see that class for details. Note in particular that nullness information from + * a superclass is never automatically "inherited". + */ +@Documented +@Target(TYPE_USE) +@Retention(RUNTIME) +public @interface Nullable {} diff --git a/src/java.base/share/classes/org/jspecify/annotations/package-info.java b/src/java.base/share/classes/org/jspecify/annotations/package-info.java new file mode 100644 index 00000000000..bcc0e4da7e2 --- /dev/null +++ b/src/java.base/share/classes/org/jspecify/annotations/package-info.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 The JSpecify Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * JSpecify annotations. See jspecify.org for general information. + * + *

What's here?

+ * + * This package will contain annotations supporting a variety of static analyses. For now it + * supports just nullness analysis. + * + *

Nullness

+ * + * The primary annotations of interest are {@link NullMarked} and {@link Nullable}. Together they + * provide declarative, use-site nullness for Java types. Less frequently, their negations + * may be useful: {@link NullUnmarked} and {@link NonNull}, respectively. + * + *

For a comprehensive introduction to JSpecify, please see jspecify.org. + * + *

Note on tool behavior

+ * + *

Each of these annotations defines a single meaning shared by all compatible tools (and + * libraries). JSpecify documentation aims to provide unambiguous, tool-independent answers for how + * to properly annotate your APIs in all circumstances. However, tools are permitted to + * respond to the information you provide however they see fit (or not at all). JSpecify + * compatibility does not require that any particular finding must or must not be issued to the + * user, let alone its message or severity. + * + *

In fact, it's important to remember that declarative annotations are merely one source + * of information an analyzer may consult in concluding an expression is safely non-null. Just like + * one analyzer might determine that an {@code int} expression can take on only positive values, + * another might likewise determine that a declaratively nullable expression can take on only + * non-null values. In both cases the declarative knowledge is correct, but the inferred + * knowledge is both correct and more specific. + * + *

On the other end, the tools might even enforce nothing at all. In particular, your + * annotated code (or other code dependent on its annotated APIs) might be compiled and run without + * any appropriate tool even in use. Therefore adopting JSpecify annotations is not a replacement + * for explicitly checking arguments at runtime. + */ +package org.jspecify.annotations; diff --git a/src/java.desktop/share/classes/java/awt/Dialog.java b/src/java.desktop/share/classes/java/awt/Dialog.java index 6d2e886b217..52fcefd9bc6 100644 --- a/src/java.desktop/share/classes/java/awt/Dialog.java +++ b/src/java.desktop/share/classes/java/awt/Dialog.java @@ -28,6 +28,10 @@ import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; +import java.awt.event.ComponentEvent; +import java.awt.event.HierarchyEvent; +import java.awt.event.InvocationEvent; +import java.awt.event.WindowEvent; import java.awt.peer.DialogPeer; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java new file mode 100644 index 00000000000..d4bae0d08ce --- /dev/null +++ b/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java @@ -0,0 +1,1528 @@ +/* + * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* ******************************************************************** + ********************************************************************** + ********************************************************************** + *** COPYRIGHT (c) Eastman Kodak Company, 1997 *** + *** As an unpublished work pursuant to Title 17 of the United *** + *** States Code. All rights reserved. *** + ********************************************************************** + ********************************************************************** + **********************************************************************/ + +package java.awt.color; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.Serial; +import java.io.Serializable; +import java.util.Objects; +import java.util.StringTokenizer; + +import sun.awt.AWTAccessor; +import sun.java2d.cmm.CMSManager; +import sun.java2d.cmm.PCMM; +import sun.java2d.cmm.Profile; +import sun.java2d.cmm.ProfileDataVerifier; +import sun.java2d.cmm.ProfileDeferralInfo; + +/** + * A representation of color profile data for device independent and device + * dependent color spaces based on the International Color Consortium + * Specification ICC.1:2001-12, File Format for Color Profiles, (see + * https://www.color.org). + *

+ * An {@code ICC_ColorSpace} object can be constructed from an appropriate + * {@code ICC_Profile}. Typically, an {@code ICC_ColorSpace} would be associated + * with an ICC Profile which is either an input, display, or output profile (see + * the ICC specification). There are also device link, abstract, color space + * conversion, and named color profiles. These are less useful for tagging a + * color or image, but are useful for other purposes (in particular device link + * profiles can provide improved performance for converting from one device's + * color space to another's). + *

+ * ICC Profiles represent transformations from the color space of the profile + * (e.g. a monitor) to a Profile Connection Space (PCS). Profiles of interest + * for tagging images or colors have a PCS which is one of the two specific + * device independent spaces (one CIEXYZ space and one CIELab space) defined in + * the ICC Profile Format Specification. Most profiles of interest either have + * invertible transformations or explicitly specify transformations going both + * directions. + * + * @see ICC_ColorSpace + */ +public sealed class ICC_Profile implements Serializable + permits ICC_ProfileGray, + ICC_ProfileRGB { + + /** + * Use serialVersionUID from JDK 1.2 for interoperability. + */ + @Serial + private static final long serialVersionUID = -3938515861990936766L; + + /** + * The implementation specific CMM profile, {@code null} if this + * {@code ICC_Profile} is not activated by the {@link #cmmProfile()} method. + * This field must not be used directly and only via {@link #cmmProfile()}. + */ + private transient volatile Profile cmmProfile; + + /** + * Stores some information about {@code ICC_Profile} without causing a + * deferred profile to be loaded. Note that we can defer the loading of + * standard profiles only. If this field is null, then {@link #cmmProfile} + * should be used to access profile information. + */ + private transient volatile ProfileDeferralInfo deferralInfo; + + /** + * The lazy registry of singleton profile objects for specific built-in + * color spaces defined in the ColorSpace class (e.g. CS_sRGB), + * see getInstance(int cspace) factory method. + */ + private interface BuiltInProfile { + /* + * Deferral is only used for standard profiles. Enabling the appropriate + * access privileges is handled at a lower level. + */ + ICC_Profile SRGB = new ICC_ProfileRGB(new ProfileDeferralInfo( + "sRGB.pf", ColorSpace.TYPE_RGB, 3, CLASS_DISPLAY)); + + ICC_Profile LRGB = new ICC_ProfileRGB(new ProfileDeferralInfo( + "LINEAR_RGB.pf", ColorSpace.TYPE_RGB, 3, CLASS_DISPLAY)); + + ICC_Profile XYZ = new ICC_Profile(new ProfileDeferralInfo( + "CIEXYZ.pf", ColorSpace.TYPE_XYZ, 3, CLASS_ABSTRACT)); + + ICC_Profile PYCC = new ICC_Profile(new ProfileDeferralInfo( + "PYCC.pf", ColorSpace.TYPE_3CLR, 3, CLASS_COLORSPACECONVERSION)); + + ICC_Profile GRAY = new ICC_ProfileGray(new ProfileDeferralInfo( + "GRAY.pf", ColorSpace.TYPE_GRAY, 1, CLASS_DISPLAY)); + } + + static { + AWTAccessor.setICC_ProfileAccessor(ICC_Profile::cmmProfile); + } + + /** + * Profile class is input. + */ + public static final int CLASS_INPUT = 0; + + /** + * Profile class is display. + */ + public static final int CLASS_DISPLAY = 1; + + /** + * Profile class is output. + */ + public static final int CLASS_OUTPUT = 2; + + /** + * Profile class is device link. + */ + public static final int CLASS_DEVICELINK = 3; + + /** + * Profile class is color space conversion. + */ + public static final int CLASS_COLORSPACECONVERSION = 4; + + /** + * Profile class is abstract. + */ + public static final int CLASS_ABSTRACT = 5; + + /** + * Profile class is named color. + */ + public static final int CLASS_NAMEDCOLOR = 6; + + + /** + * ICC Profile Color Space Type Signature: 'XYZ '. + */ + public static final int icSigXYZData = 0x58595A20; + + /** + * ICC Profile Color Space Type Signature: 'Lab '. + */ + public static final int icSigLabData = 0x4C616220; + + /** + * ICC Profile Color Space Type Signature: 'Luv '. + */ + public static final int icSigLuvData = 0x4C757620; + + /** + * ICC Profile Color Space Type Signature: 'YCbr'. + */ + public static final int icSigYCbCrData = 0x59436272; + + /** + * ICC Profile Color Space Type Signature: 'Yxy '. + */ + public static final int icSigYxyData = 0x59787920; + + /** + * ICC Profile Color Space Type Signature: 'RGB '. + */ + public static final int icSigRgbData = 0x52474220; + + /** + * ICC Profile Color Space Type Signature: 'GRAY'. + */ + public static final int icSigGrayData = 0x47524159; + + /** + * ICC Profile Color Space Type Signature: 'HSV'. + */ + public static final int icSigHsvData = 0x48535620; + + /** + * ICC Profile Color Space Type Signature: 'HLS'. + */ + public static final int icSigHlsData = 0x484C5320; + + /** + * ICC Profile Color Space Type Signature: 'CMYK'. + */ + public static final int icSigCmykData = 0x434D594B; + + /** + * ICC Profile Color Space Type Signature: 'CMY '. + */ + public static final int icSigCmyData = 0x434D5920; + + /** + * ICC Profile Color Space Type Signature: '2CLR'. + */ + public static final int icSigSpace2CLR = 0x32434C52; + + /** + * ICC Profile Color Space Type Signature: '3CLR'. + */ + public static final int icSigSpace3CLR = 0x33434C52; + + /** + * ICC Profile Color Space Type Signature: '4CLR'. + */ + public static final int icSigSpace4CLR = 0x34434C52; + + /** + * ICC Profile Color Space Type Signature: '5CLR'. + */ + public static final int icSigSpace5CLR = 0x35434C52; + + /** + * ICC Profile Color Space Type Signature: '6CLR'. + */ + public static final int icSigSpace6CLR = 0x36434C52; + + /** + * ICC Profile Color Space Type Signature: '7CLR'. + */ + public static final int icSigSpace7CLR = 0x37434C52; + + /** + * ICC Profile Color Space Type Signature: '8CLR'. + */ + public static final int icSigSpace8CLR = 0x38434C52; + + /** + * ICC Profile Color Space Type Signature: '9CLR'. + */ + public static final int icSigSpace9CLR = 0x39434C52; + + /** + * ICC Profile Color Space Type Signature: 'ACLR'. + */ + public static final int icSigSpaceACLR = 0x41434C52; + + /** + * ICC Profile Color Space Type Signature: 'BCLR'. + */ + public static final int icSigSpaceBCLR = 0x42434C52; + + /** + * ICC Profile Color Space Type Signature: 'CCLR'. + */ + public static final int icSigSpaceCCLR = 0x43434C52; + + /** + * ICC Profile Color Space Type Signature: 'DCLR'. + */ + public static final int icSigSpaceDCLR = 0x44434C52; + + /** + * ICC Profile Color Space Type Signature: 'ECLR'. + */ + public static final int icSigSpaceECLR = 0x45434C52; + + /** + * ICC Profile Color Space Type Signature: 'FCLR'. + */ + public static final int icSigSpaceFCLR = 0x46434C52; + + + /** + * ICC Profile Class Signature: 'scnr'. + */ + public static final int icSigInputClass = 0x73636E72; + + /** + * ICC Profile Class Signature: 'mntr'. + */ + public static final int icSigDisplayClass = 0x6D6E7472; + + /** + * ICC Profile Class Signature: 'prtr'. + */ + public static final int icSigOutputClass = 0x70727472; + + /** + * ICC Profile Class Signature: 'link'. + */ + public static final int icSigLinkClass = 0x6C696E6B; + + /** + * ICC Profile Class Signature: 'abst'. + */ + public static final int icSigAbstractClass = 0x61627374; + + /** + * ICC Profile Class Signature: 'spac'. + */ + public static final int icSigColorSpaceClass = 0x73706163; + + /** + * ICC Profile Class Signature: 'nmcl'. + */ + public static final int icSigNamedColorClass = 0x6e6d636c; + + + /** + * ICC Profile Rendering Intent: Perceptual. + */ + public static final int icPerceptual = 0; + + /** + * ICC Profile Rendering Intent: RelativeColorimetric. + */ + public static final int icRelativeColorimetric = 1; + + /** + * ICC Profile Rendering Intent: Media-RelativeColorimetric. + * + * @since 1.5 + */ + public static final int icMediaRelativeColorimetric = 1; + + /** + * ICC Profile Rendering Intent: Saturation. + */ + public static final int icSaturation = 2; + + /** + * ICC Profile Rendering Intent: AbsoluteColorimetric. + */ + public static final int icAbsoluteColorimetric = 3; + + /** + * ICC Profile Rendering Intent: ICC-AbsoluteColorimetric. + * + * @since 1.5 + */ + public static final int icICCAbsoluteColorimetric = 3; + + + /** + * ICC Profile Tag Signature: 'head' - special. + */ + public static final int icSigHead = 0x68656164; + + /** + * ICC Profile Tag Signature: 'A2B0'. + */ + public static final int icSigAToB0Tag = 0x41324230; + + /** + * ICC Profile Tag Signature: 'A2B1'. + */ + public static final int icSigAToB1Tag = 0x41324231; + + /** + * ICC Profile Tag Signature: 'A2B2'. + */ + public static final int icSigAToB2Tag = 0x41324232; + + /** + * ICC Profile Tag Signature: 'bXYZ'. + */ + public static final int icSigBlueColorantTag = 0x6258595A; + + /** + * ICC Profile Tag Signature: 'bXYZ'. + * + * @since 1.5 + */ + public static final int icSigBlueMatrixColumnTag = 0x6258595A; + + /** + * ICC Profile Tag Signature: 'bTRC'. + */ + public static final int icSigBlueTRCTag = 0x62545243; + + /** + * ICC Profile Tag Signature: 'B2A0'. + */ + public static final int icSigBToA0Tag = 0x42324130; + + /** + * ICC Profile Tag Signature: 'B2A1'. + */ + public static final int icSigBToA1Tag = 0x42324131; + + /** + * ICC Profile Tag Signature: 'B2A2'. + */ + public static final int icSigBToA2Tag = 0x42324132; + + /** + * ICC Profile Tag Signature: 'calt'. + */ + public static final int icSigCalibrationDateTimeTag = 0x63616C74; + + /** + * ICC Profile Tag Signature: 'targ'. + */ + public static final int icSigCharTargetTag = 0x74617267; + + /** + * ICC Profile Tag Signature: 'cprt'. + */ + public static final int icSigCopyrightTag = 0x63707274; + + /** + * ICC Profile Tag Signature: 'crdi'. + */ + public static final int icSigCrdInfoTag = 0x63726469; + + /** + * ICC Profile Tag Signature: 'dmnd'. + */ + public static final int icSigDeviceMfgDescTag = 0x646D6E64; + + /** + * ICC Profile Tag Signature: 'dmdd'. + */ + public static final int icSigDeviceModelDescTag = 0x646D6464; + + /** + * ICC Profile Tag Signature: 'devs'. + */ + public static final int icSigDeviceSettingsTag = 0x64657673; + + /** + * ICC Profile Tag Signature: 'gamt'. + */ + public static final int icSigGamutTag = 0x67616D74; + + /** + * ICC Profile Tag Signature: 'kTRC'. + */ + public static final int icSigGrayTRCTag = 0x6b545243; + + /** + * ICC Profile Tag Signature: 'gXYZ'. + */ + public static final int icSigGreenColorantTag = 0x6758595A; + + /** + * ICC Profile Tag Signature: 'gXYZ'. + * + * @since 1.5 + */ + public static final int icSigGreenMatrixColumnTag = 0x6758595A; + + /** + * ICC Profile Tag Signature: 'gTRC'. + */ + public static final int icSigGreenTRCTag = 0x67545243; + + /** + * ICC Profile Tag Signature: 'lumi'. + */ + public static final int icSigLuminanceTag = 0x6C756d69; + + /** + * ICC Profile Tag Signature: 'meas'. + */ + public static final int icSigMeasurementTag = 0x6D656173; + + /** + * ICC Profile Tag Signature: 'bkpt'. + */ + public static final int icSigMediaBlackPointTag = 0x626B7074; + + /** + * ICC Profile Tag Signature: 'wtpt'. + */ + public static final int icSigMediaWhitePointTag = 0x77747074; + + /** + * ICC Profile Tag Signature: 'ncl2'. + */ + public static final int icSigNamedColor2Tag = 0x6E636C32; + + /** + * ICC Profile Tag Signature: 'resp'. + */ + public static final int icSigOutputResponseTag = 0x72657370; + + /** + * ICC Profile Tag Signature: 'pre0'. + */ + public static final int icSigPreview0Tag = 0x70726530; + + /** + * ICC Profile Tag Signature: 'pre1'. + */ + public static final int icSigPreview1Tag = 0x70726531; + + /** + * ICC Profile Tag Signature: 'pre2'. + */ + public static final int icSigPreview2Tag = 0x70726532; + + /** + * ICC Profile Tag Signature: 'desc'. + */ + public static final int icSigProfileDescriptionTag = 0x64657363; + + /** + * ICC Profile Tag Signature: 'pseq'. + */ + public static final int icSigProfileSequenceDescTag = 0x70736571; + + /** + * ICC Profile Tag Signature: 'psd0'. + */ + public static final int icSigPs2CRD0Tag = 0x70736430; + + /** + * ICC Profile Tag Signature: 'psd1'. + */ + public static final int icSigPs2CRD1Tag = 0x70736431; + + /** + * ICC Profile Tag Signature: 'psd2'. + */ + public static final int icSigPs2CRD2Tag = 0x70736432; + + /** + * ICC Profile Tag Signature: 'psd3'. + */ + public static final int icSigPs2CRD3Tag = 0x70736433; + + /** + * ICC Profile Tag Signature: 'ps2s'. + */ + public static final int icSigPs2CSATag = 0x70733273; + + /** + * ICC Profile Tag Signature: 'ps2i'. + */ + public static final int icSigPs2RenderingIntentTag = 0x70733269; + + /** + * ICC Profile Tag Signature: 'rXYZ'. + */ + public static final int icSigRedColorantTag = 0x7258595A; + + /** + * ICC Profile Tag Signature: 'rXYZ'. + * + * @since 1.5 + */ + public static final int icSigRedMatrixColumnTag = 0x7258595A; + + /** + * ICC Profile Tag Signature: 'rTRC'. + */ + public static final int icSigRedTRCTag = 0x72545243; + + /** + * ICC Profile Tag Signature: 'scrd'. + */ + public static final int icSigScreeningDescTag = 0x73637264; + + /** + * ICC Profile Tag Signature: 'scrn'. + */ + public static final int icSigScreeningTag = 0x7363726E; + + /** + * ICC Profile Tag Signature: 'tech'. + */ + public static final int icSigTechnologyTag = 0x74656368; + + /** + * ICC Profile Tag Signature: 'bfd '. + */ + public static final int icSigUcrBgTag = 0x62666420; + + /** + * ICC Profile Tag Signature: 'vued'. + */ + public static final int icSigViewingCondDescTag = 0x76756564; + + /** + * ICC Profile Tag Signature: 'view'. + */ + public static final int icSigViewingConditionsTag = 0x76696577; + + /** + * ICC Profile Tag Signature: 'chrm'. + */ + public static final int icSigChromaticityTag = 0x6368726d; + + /** + * ICC Profile Tag Signature: 'chad'. + * + * @since 1.5 + */ + public static final int icSigChromaticAdaptationTag = 0x63686164; + + /** + * ICC Profile Tag Signature: 'clro'. + * + * @since 1.5 + */ + public static final int icSigColorantOrderTag = 0x636C726F; + + /** + * ICC Profile Tag Signature: 'clrt'. + * + * @since 1.5 + */ + public static final int icSigColorantTableTag = 0x636C7274; + + + /** + * ICC Profile Header Location: profile size in bytes. + */ + public static final int icHdrSize = 0; + + /** + * ICC Profile Header Location: CMM for this profile. + */ + public static final int icHdrCmmId = 4; + + /** + * ICC Profile Header Location: format version number. + */ + public static final int icHdrVersion = 8; + + /** + * ICC Profile Header Location: type of profile. + */ + public static final int icHdrDeviceClass = 12; + + /** + * ICC Profile Header Location: color space of data. + */ + public static final int icHdrColorSpace = 16; + + /** + * ICC Profile Header Location: PCS - XYZ or Lab only. + */ + public static final int icHdrPcs = 20; + + /** + * ICC Profile Header Location: date profile was created. + */ + public static final int icHdrDate = 24; + + /** + * ICC Profile Header Location: icMagicNumber. + */ + public static final int icHdrMagic = 36; + + /** + * ICC Profile Header Location: primary platform. + */ + public static final int icHdrPlatform = 40; + + /** + * ICC Profile Header Location: various bit settings. + */ + public static final int icHdrFlags = 44; + + /** + * ICC Profile Header Location: device manufacturer. + */ + public static final int icHdrManufacturer = 48; + + /** + * ICC Profile Header Location: device model number. + */ + public static final int icHdrModel = 52; + + /** + * ICC Profile Header Location: device attributes. + */ + public static final int icHdrAttributes = 56; + + /** + * ICC Profile Header Location: rendering intent. + */ + public static final int icHdrRenderingIntent = 64; + + /** + * ICC Profile Header Location: profile illuminant. + */ + public static final int icHdrIlluminant = 68; + + /** + * ICC Profile Header Location: profile creator. + */ + public static final int icHdrCreator = 80; + + /** + * ICC Profile Header Location: profile's ID. + * + * @since 1.5 + */ + public static final int icHdrProfileID = 84; + + + /** + * ICC Profile Constant: tag type signature. + */ + public static final int icTagType = 0; + + /** + * ICC Profile Constant: reserved. + */ + public static final int icTagReserved = 4; + + /** + * ICC Profile Constant: curveType count. + */ + public static final int icCurveCount = 8; + + /** + * ICC Profile Constant: curveType data. + */ + public static final int icCurveData = 12; + + /** + * ICC Profile Constant: XYZNumber X. + */ + public static final int icXYZNumberX = 8; + + + /** + * Constructs an {@code ICC_Profile} object with a given ID. + */ + ICC_Profile(Profile p) { + cmmProfile = p; + } + + /** + * Constructs an {@code ICC_Profile} object whose loading will be deferred. + * The ID will be 0 until the profile is loaded. + */ + ICC_Profile(ProfileDeferralInfo pdi) { + deferralInfo = pdi; + } + + /** + * Constructs an {@code ICC_Profile} object corresponding to the data in a + * byte array. + * + * @param data the specified ICC Profile data + * @return an {@code ICC_Profile} object corresponding to the data in the + * specified {@code data} array + * @throws IllegalArgumentException If the byte array does not contain valid + * ICC Profile data + */ + public static ICC_Profile getInstance(byte[] data) { + ProfileDataVerifier.verify(data); + Profile p; + try { + p = CMSManager.getModule().loadProfile(data); + } catch (CMMException c) { + throw new IllegalArgumentException("Invalid ICC Profile Data"); + } + try { + if (getColorSpaceType(p) == ColorSpace.TYPE_GRAY + && getData(p, icSigMediaWhitePointTag) != null + && getData(p, icSigGrayTRCTag) != null) { + return new ICC_ProfileGray(p); + } + if (getColorSpaceType(p) == ColorSpace.TYPE_RGB + && getData(p, icSigMediaWhitePointTag) != null + && getData(p, icSigRedColorantTag) != null + && getData(p, icSigGreenColorantTag) != null + && getData(p, icSigBlueColorantTag) != null + && getData(p, icSigRedTRCTag) != null + && getData(p, icSigGreenTRCTag) != null + && getData(p, icSigBlueTRCTag) != null) { + return new ICC_ProfileRGB(p); + } + } catch (CMMException c) { + // will try to create a general icc profile + } + return new ICC_Profile(p); + } + + /** + * Constructs an {@code ICC_Profile} corresponding to one of the specific + * color spaces defined by the {@code ColorSpace} class (for example + * {@code CS_sRGB}). + * + * @param cspace the type of color space to create a profile for. The + * specified type is one of the color space constants defined in the + * {@code ColorSpace} class. + * @return an {@code ICC_Profile} object corresponding to the specified + * {@code ColorSpace} type + * @throws IllegalArgumentException If {@code cspace} is not one of the + * predefined color space types + */ + public static ICC_Profile getInstance(int cspace) { + return switch (cspace) { + case ColorSpace.CS_sRGB -> BuiltInProfile.SRGB; + case ColorSpace.CS_LINEAR_RGB -> BuiltInProfile.LRGB; + case ColorSpace.CS_CIEXYZ -> BuiltInProfile.XYZ; + case ColorSpace.CS_PYCC -> BuiltInProfile.PYCC; + case ColorSpace.CS_GRAY -> BuiltInProfile.GRAY; + default -> { + throw new IllegalArgumentException("Unknown color space"); + } + }; + } + + /** + * Constructs an {@code ICC_Profile} corresponding to the data in a file. + * {@code fileName} may be an absolute or a relative file specification. + * Relative file names are looked for in several places: first, relative to + * any directories specified by the {@code java.iccprofile.path} property; + * second, relative to any directories specified by the + * {@code java.class.path} property; finally, in a directory used to store + * profiles always available, such as the profile for sRGB. Built-in + * profiles use {@code .pf} as the file name extension for profiles, e.g. + * {@code sRGB.pf}. + * + * @param fileName the file that contains the data for the profile + * @return an {@code ICC_Profile} object corresponding to the data in the + * specified file + * @throws IOException If the specified file cannot be opened or an I/O + * error occurs while reading the file + * @throws IllegalArgumentException If the file does not contain valid ICC + * Profile data + * @throws NullPointerException if {@code fileName} is {@code null} + */ + public static ICC_Profile getInstance(String fileName) throws IOException { + InputStream is; + File f = getProfileFile(fileName); + if (f != null) { + is = new FileInputStream(f); + } else { + is = getStandardProfileInputStream(fileName); + } + if (is == null) { + throw new IOException("Cannot open file " + fileName); + } + try (is) { + return getInstance(is); + } + } + + /** + * Constructs an {@code ICC_Profile} corresponding to the data in an + * {@code InputStream}. + * + * @param s the input stream from which to read the profile data + * @return an {@code ICC_Profile} object corresponding to the data in the + * specified {@code InputStream} + * @throws IOException If an I/O error occurs while reading the stream + * @throws IllegalArgumentException If the stream does not contain valid ICC + * Profile data + * @throws NullPointerException if {@code s} is {@code null} + */ + public static ICC_Profile getInstance(InputStream s) throws IOException { + Objects.requireNonNull(s); + return getInstance(getProfileDataFromStream(s)); + } + + static byte[] getProfileDataFromStream(InputStream s) throws IOException { + BufferedInputStream bis = new BufferedInputStream(s); + bis.mark(128); // 128 is the length of the ICC profile header + + byte[] header = bis.readNBytes(128); + if (header.length < 128 || header[36] != 0x61 || header[37] != 0x63 || + header[38] != 0x73 || header[39] != 0x70) { + return null; /* not a valid profile */ + } + int profileSize = intFromBigEndian(header, 0); + bis.reset(); + try { + return bis.readNBytes(profileSize); + } catch (OutOfMemoryError e) { + throw new IOException("Color profile is too big"); + } + } + + /** + * Activates and returns the deferred standard profiles. Implementation of + * this method mimics the old behaviour when the {@code CMMException} and + * {@code IOException} were wrapped by the {@code ProfileDataException}, and + * the {@code ProfileDataException} itself was ignored during activation. + * + * @return the implementation specific CMM profile, or {@code null} + */ + private Profile cmmProfile() { + Profile p = cmmProfile; + if (p != null) { + return p; // one volatile read on common path + } + synchronized (this) { + if (cmmProfile != null) { + return cmmProfile; + } + var is = getStandardProfileInputStream(deferralInfo.filename); + if (is == null) { + return null; + } + try (is) { + byte[] data = getProfileDataFromStream(is); + if (data != null) { + p = cmmProfile = CMSManager.getModule().loadProfile(data); + // from now we cannot use the deferred value, drop it + deferralInfo = null; + } + } catch (CMMException | IOException ignore) { + } + } + return p; + } + + /** + * Returns profile major version. + * + * @return the major version of the profile + */ + public int getMajorVersion() { + return getData(icSigHead)[8]; + } + + /** + * Returns profile minor version. + * + * @return the minor version of the profile + */ + public int getMinorVersion() { + return getData(icSigHead)[9]; + } + + /** + * Returns the profile class. + * + * @return one of the predefined profile class constants + */ + public int getProfileClass() { + ProfileDeferralInfo info = deferralInfo; + if (info != null) { + return info.profileClass; + } + byte[] theHeader = getData(icSigHead); + int theClassSig = intFromBigEndian(theHeader, icHdrDeviceClass); + return switch (theClassSig) { + case icSigInputClass -> CLASS_INPUT; + case icSigDisplayClass -> CLASS_DISPLAY; + case icSigOutputClass -> CLASS_OUTPUT; + case icSigLinkClass -> CLASS_DEVICELINK; + case icSigColorSpaceClass -> CLASS_COLORSPACECONVERSION; + case icSigAbstractClass -> CLASS_ABSTRACT; + case icSigNamedColorClass -> CLASS_NAMEDCOLOR; + default -> { + throw new IllegalArgumentException("Unknown profile class"); + } + }; + } + + /** + * Returns the color space type. Returns one of the color space type + * constants defined by the {@code ColorSpace} class. This is the "input" + * color space of the profile. The type defines the number of components of + * the color space and the interpretation, e.g. {@code TYPE_RGB} identifies + * a color space with three components - red, green, and blue. It does not + * define the particular color characteristics of the space, e.g. the + * chromaticities of the primaries. + * + * @return one of the color space type constants defined in the + * {@code ColorSpace} class + */ + public int getColorSpaceType() { + ProfileDeferralInfo info = deferralInfo; + if (info != null) { + return info.colorSpaceType; + } + return getColorSpaceType(cmmProfile()); + } + + private static int getColorSpaceType(Profile p) { + byte[] theHeader = getData(p, icSigHead); + int theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace); + return iccCStoJCS(theColorSpaceSig); + } + + /** + * Returns the color space type of the Profile Connection Space (PCS). + * Returns one of the color space type constants defined by the ColorSpace + * class. This is the "output" color space of the profile. For an input, + * display, or output profile useful for tagging colors or images, this will + * be either {@code TYPE_XYZ} or {@code TYPE_Lab} and should be interpreted + * as the corresponding specific color space defined in the ICC + * specification. For a device link profile, this could be any of the color + * space type constants. + * + * @return one of the color space type constants defined in the + * {@code ColorSpace} class + */ + public int getPCSType() { + byte[] theHeader = getData(icSigHead); + int thePCSSig = intFromBigEndian(theHeader, icHdrPcs); + return iccCStoJCS(thePCSSig); + } + + /** + * Write this {@code ICC_Profile} to a file. + * + * @param fileName the file to write the profile data to + * @throws IOException If the file cannot be opened for writing or an I/O + * error occurs while writing to the file + * @throws NullPointerException if {@code fileName} is {@code null} + */ + public void write(String fileName) throws IOException { + try (OutputStream out = new FileOutputStream(fileName)) { + write(out); + } + } + + /** + * Write this {@code ICC_Profile} to an {@code OutputStream}. + * + * @param s the stream to write the profile data to + * @throws IOException If an I/O error occurs while writing to the stream + * @throws NullPointerException if {@code s} is {@code null} + */ + public void write(OutputStream s) throws IOException { + s.write(getData()); + } + + /** + * Returns a byte array corresponding to the data of this + * {@code ICC_Profile}. + * + * @return a byte array that contains the profile data + * @see #setData(int, byte[]) + */ + public byte[] getData() { + return CMSManager.getModule().getProfileData(cmmProfile()); + } + + /** + * Returns a particular tagged data element from the profile as a byte + * array. Elements are identified by signatures as defined in the ICC + * specification. The signature icSigHead can be used to get the header. + * This method is useful for advanced applications which need to access + * profile data directly. + * + * @param tagSignature the ICC tag signature for the data element you want + * to get + * @return a byte array that contains the tagged data element. Returns + * {@code null} if the specified tag doesn't exist. + * @see #setData(int, byte[]) + */ + public byte[] getData(int tagSignature) { + byte[] t = getData(cmmProfile(), tagSignature); + return t != null ? t.clone() : null; + } + + private static byte[] getData(Profile p, int tagSignature) { + try { + return CMSManager.getModule().getTagData(p, tagSignature); + } catch (CMMException c) { + return null; + } + } + + /** + * Sets a particular tagged data element in the profile from a byte array. + * The array should contain data in a format, corresponded to the + * {@code tagSignature} as defined in the ICC specification, section 10. + * This method is useful for advanced applications which need to access + * profile data directly. + * + * @param tagSignature the ICC tag signature for the data element you want + * to set + * @param tagData the data to set for the specified tag signature + * @throws IllegalArgumentException if {@code tagSignature} is not a + * signature as defined in the ICC specification. + * @throws IllegalArgumentException if a content of the {@code tagData} + * array can not be interpreted as valid tag data, corresponding to + * the {@code tagSignature} + * @see #getData + */ + public void setData(int tagSignature, byte[] tagData) { + CMSManager.getModule().setTagData(cmmProfile(), tagSignature, tagData); + } + + /** + * Returns the number of color components in the "input" color space of this + * profile. For example if the color space type of this profile is + * {@code TYPE_RGB}, then this method will return 3. + * + * @return the number of color components in the profile's input color space + * @throws ProfileDataException if color space is in the profile is invalid + */ + public int getNumComponents() { + ProfileDeferralInfo info = deferralInfo; + if (info != null) { + return info.numComponents; + } + byte[] theHeader = getData(icSigHead); + int theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace); + return switch (theColorSpaceSig) { + case icSigGrayData -> 1; + case icSigSpace2CLR -> 2; + case icSigXYZData, icSigLabData, icSigLuvData, icSigYCbCrData, + icSigYxyData, icSigRgbData, icSigHsvData, icSigHlsData, + icSigCmyData, icSigSpace3CLR -> 3; + case icSigCmykData, icSigSpace4CLR -> 4; + case icSigSpace5CLR -> 5; + case icSigSpace6CLR -> 6; + case icSigSpace7CLR -> 7; + case icSigSpace8CLR -> 8; + case icSigSpace9CLR -> 9; + case icSigSpaceACLR -> 10; + case icSigSpaceBCLR -> 11; + case icSigSpaceCCLR -> 12; + case icSigSpaceDCLR -> 13; + case icSigSpaceECLR -> 14; + case icSigSpaceFCLR -> 15; + default -> { + throw new ProfileDataException("invalid ICC color space"); + } + }; + } + + /** + * Returns a float array of length 3 containing the X, Y, and Z components + * of the mediaWhitePointTag in the ICC profile. + */ + float[] getMediaWhitePoint() { + return getXYZTag(icSigMediaWhitePointTag); + } + + /** + * Returns a float array of length 3 containing the X, Y, and Z components + * encoded in an XYZType tag. + */ + final float[] getXYZTag(int tagSignature) { + byte[] theData = getData(tagSignature); + float[] theXYZNumber = new float[3]; /* array to return */ + + /* convert s15Fixed16Number to float */ + for (int i1 = 0, i2 = icXYZNumberX; i1 < 3; i1++, i2 += 4) { + int theS15Fixed16 = intFromBigEndian(theData, i2); + theXYZNumber[i1] = ((float) theS15Fixed16) / 65536.0f; + } + return theXYZNumber; + } + + /** + * Returns a gamma value representing a tone reproduction curve (TRC). If + * the profile represents the TRC as a table rather than a single gamma + * value, then an exception is thrown. In this case the actual table can be + * obtained via {@link #getTRC}. {@code tagSignature} should be one of + * {@code icSigGrayTRCTag}, {@code icSigRedTRCTag}, + * {@code icSigGreenTRCTag}, or {@code icSigBlueTRCTag}. + * + * @return the gamma value as a float + * @throws ProfileDataException if the profile does not specify the TRC as a + * single gamma value + */ + float getGamma(int tagSignature) { + byte[] theTRCData = getData(tagSignature); + if (intFromBigEndian(theTRCData, icCurveCount) != 1) { + throw new ProfileDataException("TRC is not a gamma"); + } + + /* convert u8Fixed8 to float */ + int theU8Fixed8 = shortFromBigEndian(theTRCData, icCurveData) & 0xffff; + return theU8Fixed8 / 256.0f; + } + + /** + * Returns the TRC as an array of shorts. If the profile has specified the + * TRC as linear (gamma = 1.0) or as a simple gamma value, this method + * throws an exception, and the {@link #getGamma} method should be used to + * get the gamma value. Otherwise the short array returned here represents a + * lookup table where the input Gray value is conceptually in the range + * [0.0, 1.0]. Value 0.0 maps to array index 0 and value 1.0 maps to array + * index length-1. Interpolation may be used to generate output values for + * input values which do not map exactly to an index in the array. Output + * values also map linearly to the range [0.0, 1.0]. Value 0.0 is + * represented by an array value of 0x0000 and value 1.0 by 0xFFFF, i.e. the + * values are really unsigned short values, although they are returned in a + * short array. {@code tagSignature} should be one of + * {@code icSigGrayTRCTag}, {@code icSigRedTRCTag}, + * {@code icSigGreenTRCTag}, or {@code icSigBlueTRCTag}. + * + * @return a short array representing the TRC + * @throws ProfileDataException if the profile does not specify the TRC as a + * table + */ + short[] getTRC(int tagSignature) { + byte[] theTRCData = getData(tagSignature); + int nElements = intFromBigEndian(theTRCData, icCurveCount); + if (nElements == 1) { + throw new ProfileDataException("TRC is not a table"); + } + + short[] theTRC = new short[nElements]; /* array to return */ + for (int i1 = 0, i2 = icCurveData; i1 < nElements; i1++, i2 += 2) { + theTRC[i1] = shortFromBigEndian(theTRCData, i2); + } + return theTRC; + } + + /** + * Convert an ICC color space signature into a Java color space type. + */ + private static int iccCStoJCS(int theColorSpaceSig) { + return switch (theColorSpaceSig) { + case icSigXYZData -> ColorSpace.TYPE_XYZ; + case icSigLabData -> ColorSpace.TYPE_Lab; + case icSigLuvData -> ColorSpace.TYPE_Luv; + case icSigYCbCrData -> ColorSpace.TYPE_YCbCr; + case icSigYxyData -> ColorSpace.TYPE_Yxy; + case icSigRgbData -> ColorSpace.TYPE_RGB; + case icSigGrayData -> ColorSpace.TYPE_GRAY; + case icSigHsvData -> ColorSpace.TYPE_HSV; + case icSigHlsData -> ColorSpace.TYPE_HLS; + case icSigCmykData -> ColorSpace.TYPE_CMYK; + case icSigCmyData -> ColorSpace.TYPE_CMY; + case icSigSpace2CLR -> ColorSpace.TYPE_2CLR; + case icSigSpace3CLR -> ColorSpace.TYPE_3CLR; + case icSigSpace4CLR -> ColorSpace.TYPE_4CLR; + case icSigSpace5CLR -> ColorSpace.TYPE_5CLR; + case icSigSpace6CLR -> ColorSpace.TYPE_6CLR; + case icSigSpace7CLR -> ColorSpace.TYPE_7CLR; + case icSigSpace8CLR -> ColorSpace.TYPE_8CLR; + case icSigSpace9CLR -> ColorSpace.TYPE_9CLR; + case icSigSpaceACLR -> ColorSpace.TYPE_ACLR; + case icSigSpaceBCLR -> ColorSpace.TYPE_BCLR; + case icSigSpaceCCLR -> ColorSpace.TYPE_CCLR; + case icSigSpaceDCLR -> ColorSpace.TYPE_DCLR; + case icSigSpaceECLR -> ColorSpace.TYPE_ECLR; + case icSigSpaceFCLR -> ColorSpace.TYPE_FCLR; + default -> { + throw new IllegalArgumentException("Unknown color space"); + } + }; + } + + private static int intFromBigEndian(byte[] array, int index) { + return (((array[index] & 0xff) << 24) | + ((array[index+1] & 0xff) << 16) | + ((array[index+2] & 0xff) << 8) | + (array[index+3] & 0xff)); + } + + private static short shortFromBigEndian(byte[] array, int index) { + return (short) (((array[index] & 0xff) << 8) | + (array[index+1] & 0xff)); + } + + /** + * {@code fileName} may be an absolute or a relative file specification. + * Relative file names are looked for in several places: first, relative to + * any directories specified by the {@code java.iccprofile.path} property; + * second, relative to any directories specified by the + * {@code java.class.path}. The built-in profile files are now loaded as + * resources, since they may not be individual disk files, and so this + * method will not find these and on a {@code null} return, the caller needs + * to try as resources. Built-in profiles use {@code .pf} as the file name + * extension for profiles, e.g. {@code sRGB.pf}. + */ + private static File getProfileFile(String fileName) { + File f = new File(fileName); /* try absolute file name */ + if (f.isAbsolute()) { + /* Rest of code has little sense for an absolute pathname, + so return here. */ + return f.isFile() ? f : null; + } + String path, dir, fullPath; + if (!f.isFile() && + (path = System.getProperty("java.iccprofile.path")) != null) { + /* try relative to java.iccprofile.path */ + StringTokenizer st = new StringTokenizer(path, File.pathSeparator); + while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { + dir = st.nextToken(); + fullPath = dir + File.separatorChar + fileName; + f = new File(fullPath); + if (!isChildOf(f, dir)) { + f = null; + } + } + } + + if ((f == null || !f.isFile()) + && (path = System.getProperty("java.class.path")) != null) { + /* try relative to java.class.path */ + StringTokenizer st = new StringTokenizer(path, File.pathSeparator); + while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { + dir = st.nextToken(); + fullPath = dir + File.separatorChar + fileName; + f = new File(fullPath); + } + } + + if (f != null && !f.isFile()) { + f = null; + } + return f; + } + + /** + * Returns a stream corresponding to a built-in profile specified by + * fileName. If there is no built-in profile with such name, then the method + * returns {@code null}. + */ + private static InputStream getStandardProfileInputStream(String fileName) { + return PCMM.class.getResourceAsStream("profiles/" + fileName); + } + + /** + * Checks whether given file resides inside give directory. + */ + private static boolean isChildOf(File f, String dirName) { + try { + File dir = new File(dirName); + String canonicalDirName = dir.getCanonicalPath(); + if (!canonicalDirName.endsWith(File.separator)) { + canonicalDirName += File.separator; + } + String canonicalFileName = f.getCanonicalPath(); + return canonicalFileName.startsWith(canonicalDirName); + } catch (IOException e) { + /* we do not expect the IOException here, because invocation + * of this function is always preceded by isFile() call. + */ + return false; + } + } + + /* + * Serialization support. + * + * Directly deserialized profiles are useless since they are not registered + * with CMM. We don't allow constructor to be called directly and instead + * have clients to call one of getInstance factory methods that will + * register the profile with CMM. For deserialization we implement + * readResolve method that will resolve the bogus deserialized profile + * object with one obtained with getInstance as well. + * + * There are two primary factory methods for construction of ICC profiles: + * getInstance(int cspace) and getInstance(byte[] data). This implementation + * of ICC_Profile uses the former to return a cached singleton profile + * object, other implementations will likely use this technique too. To + * preserve the singleton pattern across serialization we serialize cached + * singleton profiles in such a way that deserializing VM could call + * getInstance(int cspace) method that will resolve deserialized object into + * the corresponding singleton as well. + * + * Since the singletons are private to ICC_Profile the readResolve method + * have to be `protected' instead of `private' so that singletons that are + * instances of subclasses of ICC_Profile could be correctly deserialized. + */ + + /** + * Version of the format of additional serialized data in the stream. + * Version {@code 1} corresponds to Java 2 Platform, v1.3. + * + * @serial + * @since 1.3 + */ + private int iccProfileSerializedDataVersion = 1; + + /** + * Writes default serializable fields to the stream. Writes a string and an + * array of bytes to the stream as additional data. + * + * @param s stream used for serialization + * @throws IOException thrown by {@code ObjectInputStream} + * @throws NullPointerException if {@code s} is {@code null} + * @serialData the {@code String} is the name of one of + * CS_* constants defined in the + * {@link ColorSpace} class if the profile object is a profile for a + * predefined color space (for example {@code "CS_sRGB"}). The + * string is {@code null} otherwise. + *

+ * The {@code byte[]} array is the profile data for the profile. For + * predefined color spaces {@code null} is written instead of the + * profile data. If in the future versions of Java API new + * predefined color spaces will be added, future versions of this + * class may choose to write for new predefined color spaces not + * only the color space name, but the profile data as well so that + * older versions could still deserialize the object. + */ + @Serial + private void writeObject(ObjectOutputStream s) throws IOException { + s.defaultWriteObject(); + + String csName = null; + if (this == BuiltInProfile.SRGB) { + csName = "CS_sRGB"; + } else if (this == BuiltInProfile.XYZ) { + csName = "CS_CIEXYZ"; + } else if (this == BuiltInProfile.PYCC) { + csName = "CS_PYCC"; + } else if (this == BuiltInProfile.GRAY) { + csName = "CS_GRAY"; + } else if (this == BuiltInProfile.LRGB) { + csName = "CS_LINEAR_RGB"; + } + + // Future versions may choose to write profile data for new + // predefined color spaces as well, if any will be introduced, + // so that old versions that don't recognize the new CS name + // may fall back to constructing profile from the data. + byte[] data = null; + if (csName == null) { + // getData will activate deferred profile if necessary + data = getData(); + } + + s.writeObject(csName); + s.writeObject(data); + } + + // Temporary storage used by readObject to store resolved profile + // (obtained with getInstance) for readResolve to return. + private transient ICC_Profile resolvedDeserializedProfile; + + /** + * Reads default serializable fields from the stream. Reads from the stream + * a string and an array of bytes as additional data. + * + * @param s stream used for deserialization + * @throws IOException thrown by {@code ObjectInputStream} + * @throws ClassNotFoundException thrown by {@code ObjectInputStream} + * @throws NullPointerException if {@code s} is {@code null} + * @serialData the {@code String} is the name of one of + * CS_* constants defined in the + * {@link ColorSpace} class if the profile object is a profile for a + * predefined color space (for example {@code "CS_sRGB"}). The + * string is {@code null} otherwise. + *

+ * The {@code byte[]} array is the profile data for the profile. It + * will usually be {@code null} for the predefined profiles. + *

+ * If the string is recognized as a constant name for predefined + * color space the object will be resolved into profile obtained + * with + * getInstance(int cspace) and the profile data + * are ignored. Otherwise the object will be resolved into profile + * obtained with + * getInstance(byte[] data). + * @see #readResolve() + * @see #getInstance(int) + * @see #getInstance(byte[]) + */ + @Serial + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException { + s.defaultReadObject(); + + String csName = (String) s.readObject(); + byte[] data = (byte[]) s.readObject(); + + int cspace = 0; // ColorSpace.CS_* constant if known + boolean isKnownPredefinedCS = false; + if (csName != null) { + isKnownPredefinedCS = true; + if (csName.equals("CS_sRGB")) { + cspace = ColorSpace.CS_sRGB; + } else if (csName.equals("CS_CIEXYZ")) { + cspace = ColorSpace.CS_CIEXYZ; + } else if (csName.equals("CS_PYCC")) { + cspace = ColorSpace.CS_PYCC; + } else if (csName.equals("CS_GRAY")) { + cspace = ColorSpace.CS_GRAY; + } else if (csName.equals("CS_LINEAR_RGB")) { + cspace = ColorSpace.CS_LINEAR_RGB; + } else { + isKnownPredefinedCS = false; + } + } + + if (isKnownPredefinedCS) { + resolvedDeserializedProfile = getInstance(cspace); + } else { + resolvedDeserializedProfile = getInstance(data); + } + } + + /** + * Resolves instances being deserialized into instances registered with CMM. + * + * @return ICC_Profile object for profile registered with CMM + * @throws ObjectStreamException never thrown, but mandated by the + * serialization spec + * @since 1.3 + */ + @Serial + protected Object readResolve() throws ObjectStreamException { + return resolvedDeserializedProfile; + } +} diff --git a/src/java.logging/share/classes/java/util/logging/Handler.java b/src/java.logging/share/classes/java/util/logging/Handler.java index 225b113ddd0..921f36ea458 100644 --- a/src/java.logging/share/classes/java/util/logging/Handler.java +++ b/src/java.logging/share/classes/java/util/logging/Handler.java @@ -26,9 +26,6 @@ package java.util.logging; -import org.checkerframework.checker.interning.qual.UsesObjectEquals; -import org.checkerframework.framework.qual.AnnotatedFor; - import java.util.Objects; import java.io.UnsupportedEncodingException; import org.jspecify.annotations.NullMarked; @@ -52,9 +49,8 @@ * @since 1.4 */ -@AnnotatedFor({"interning"}) @NullMarked -public abstract @UsesObjectEquals class Handler { +public abstract class Handler { private static final int offValue = Level.OFF.intValue(); // ensure log manager is initialized