mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8226585: Improve javac messages for using a preview API
Avoiding deprecation for removal for APIs associated with preview features, the features are marked with an annotation, and errors/warnings are produced for them based on the annotation. Co-authored-by: Joe Darcy <joe.darcy@oracle.com> Reviewed-by: erikj, mcimadamore, alanb
This commit is contained in:
parent
f771978f53
commit
a1894385b3
43 changed files with 794 additions and 166 deletions
|
@ -2888,6 +2888,15 @@ public final class String
|
|||
}
|
||||
|
||||
/**
|
||||
* {@preview Associated with text blocks, a preview feature of
|
||||
* the Java language.
|
||||
*
|
||||
* This method is associated with <i>text blocks</i>, a preview
|
||||
* feature of the Java language. Programs can only use this
|
||||
* method when preview features are enabled. Preview features
|
||||
* may be removed in a future release, or upgraded to permanent
|
||||
* features of the Java language.}
|
||||
*
|
||||
* Returns a string whose value is this string, with incidental
|
||||
* {@linkplain Character#isWhitespace(int) white space} removed from
|
||||
* the beginning and end of every line.
|
||||
|
@ -2963,10 +2972,9 @@ public final class String
|
|||
*
|
||||
* @since 13
|
||||
*
|
||||
* @deprecated This method is associated with text blocks, a preview language feature.
|
||||
* Text blocks and/or this method may be changed or removed in a future release.
|
||||
*/
|
||||
@Deprecated(forRemoval=true, since="13")
|
||||
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.TEXT_BLOCKS,
|
||||
essentialAPI=true)
|
||||
public String stripIndent() {
|
||||
int length = length();
|
||||
if (length == 0) {
|
||||
|
@ -3005,6 +3013,15 @@ public final class String
|
|||
}
|
||||
|
||||
/**
|
||||
* {@preview Associated with text blocks, a preview feature of
|
||||
* the Java language.
|
||||
*
|
||||
* This method is associated with <i>text blocks</i>, a preview
|
||||
* feature of the Java language. Programs can only use this
|
||||
* method when preview features are enabled. Preview features
|
||||
* may be removed in a future release, or upgraded to permanent
|
||||
* features of the Java language.}
|
||||
*
|
||||
* Returns a string whose value is this string, with escape sequences
|
||||
* translated as if in a string literal.
|
||||
* <p>
|
||||
|
@ -3079,11 +3096,9 @@ public final class String
|
|||
* @jls 3.10.7 Escape Sequences
|
||||
*
|
||||
* @since 13
|
||||
*
|
||||
* @deprecated This method is associated with text blocks, a preview language feature.
|
||||
* Text blocks and/or this method may be changed or removed in a future release.
|
||||
*/
|
||||
@Deprecated(forRemoval=true, since="13")
|
||||
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.TEXT_BLOCKS,
|
||||
essentialAPI=true)
|
||||
public String translateEscapes() {
|
||||
if (isEmpty()) {
|
||||
return "";
|
||||
|
@ -3309,6 +3324,15 @@ public final class String
|
|||
}
|
||||
|
||||
/**
|
||||
* {@preview Associated with text blocks, a preview feature of
|
||||
* the Java language.
|
||||
*
|
||||
* This method is associated with <i>text blocks</i>, a preview
|
||||
* feature of the Java language. Programs can only use this
|
||||
* method when preview features are enabled. Preview features
|
||||
* may be removed in a future release, or upgraded to permanent
|
||||
* features of the Java language.}
|
||||
*
|
||||
* Formats using this string as the format string, and the supplied
|
||||
* arguments.
|
||||
*
|
||||
|
@ -3324,10 +3348,9 @@ public final class String
|
|||
*
|
||||
* @since 13
|
||||
*
|
||||
* @deprecated This method is associated with text blocks, a preview language feature.
|
||||
* Text blocks and/or this method may be changed or removed in a future release.
|
||||
*/
|
||||
@Deprecated(forRemoval=true, since="13")
|
||||
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.TEXT_BLOCKS,
|
||||
essentialAPI=true)
|
||||
public String formatted(Object... args) {
|
||||
return new Formatter().format(this, args).toString();
|
||||
}
|
||||
|
|
60
src/java.base/share/classes/jdk/internal/PreviewFeature.java
Normal file
60
src/java.base/share/classes/jdk/internal/PreviewFeature.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 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.
|
||||
*/
|
||||
|
||||
package jdk.internal;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Indicates the API declaration in question is associated with a
|
||||
* <em>preview feature</em>. See JEP 12: "Preview Language and VM
|
||||
* Features" (http://openjdk.java.net/jeps/12).
|
||||
* @since 14
|
||||
*/
|
||||
// Match the meaningful targets of java.lang.Deprecated, omit local
|
||||
// variables and parameter declarations
|
||||
@Target({ElementType.METHOD,
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.FIELD,
|
||||
ElementType.PACKAGE,
|
||||
ElementType.MODULE,
|
||||
ElementType.TYPE})
|
||||
// CLASS retention will hopefully be sufficient for the purposes at hand
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
// *Not* @Documented
|
||||
public @interface PreviewFeature {
|
||||
/**
|
||||
* Name of the preview feature the annotated API is associated
|
||||
* with.
|
||||
*/
|
||||
public Feature feature();
|
||||
|
||||
public boolean essentialAPI() default false;
|
||||
|
||||
public enum Feature {
|
||||
SWITCH_EXPRESSIONS,
|
||||
TEXT_BLOCKS;
|
||||
}
|
||||
}
|
|
@ -135,7 +135,8 @@ module java.base {
|
|||
exports com.sun.security.ntlm to
|
||||
java.security.sasl;
|
||||
exports jdk.internal to
|
||||
jdk.jfr;
|
||||
jdk.jfr,
|
||||
jdk.compiler;
|
||||
exports jdk.internal.access to
|
||||
java.desktop,
|
||||
java.logging,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue