Merge
This commit is contained in:
commit
270fbcb3f5
make/langtools/src/classes/build/tools/symbolgenerator
src
hotspot/cpu/ppc
java.base/share/classes/jdk/internal
jdk.compiler/share/classes/com/sun/tools/javac
code
comp
jvm
parser
jdk.hotspot.agent/share/classes/sun/jvm/hotspot/types/basic
jdk.jpackage/linux/classes/jdk/jpackage/internal/resources
test
jdk
langtools
ProblemList.txt
tools/javac
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2021, 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
|
||||
@ -229,6 +229,7 @@ public class CreateSymbols {
|
||||
: null,
|
||||
Paths.get(ctDescriptionFile));
|
||||
|
||||
stripNonExistentAnnotations(data);
|
||||
splitHeaders(data.classes);
|
||||
|
||||
Map<String, Map<Character, String>> package2Version2Module = new HashMap<>();
|
||||
@ -301,6 +302,50 @@ public class CreateSymbols {
|
||||
}
|
||||
}
|
||||
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
|
||||
"Ljdk/internal/PreviewFeature;";
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
|
||||
"Ljdk/internal/javac/PreviewFeature;";
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
|
||||
"Ljdk/internal/PreviewFeature+Annotation;";
|
||||
private static final String VALUE_BASED_ANNOTATION =
|
||||
"Ljdk/internal/ValueBased;";
|
||||
private static final String VALUE_BASED_ANNOTATION_INTERNAL =
|
||||
"Ljdk/internal/ValueBased+Annotation;";
|
||||
public static final Set<String> HARDCODED_ANNOTATIONS = new HashSet<>(
|
||||
List.of("Ljdk/Profile+Annotation;",
|
||||
"Lsun/Proprietary+Annotation;",
|
||||
PREVIEW_FEATURE_ANNOTATION_OLD,
|
||||
PREVIEW_FEATURE_ANNOTATION_NEW,
|
||||
VALUE_BASED_ANNOTATION));
|
||||
|
||||
private void stripNonExistentAnnotations(LoadDescriptions data) {
|
||||
Set<String> allClasses = data.classes.name2Class.keySet();
|
||||
data.modules.values().forEach(mod -> {
|
||||
stripNonExistentAnnotations(allClasses, mod.header);
|
||||
});
|
||||
data.classes.classes.forEach(clazz -> {
|
||||
stripNonExistentAnnotations(allClasses, clazz.header);
|
||||
stripNonExistentAnnotations(allClasses, clazz.fields);
|
||||
stripNonExistentAnnotations(allClasses, clazz.methods);
|
||||
});
|
||||
}
|
||||
|
||||
private void stripNonExistentAnnotations(Set<String> allClasses, Iterable<? extends FeatureDescription> descs) {
|
||||
descs.forEach(d -> stripNonExistentAnnotations(allClasses, d));
|
||||
}
|
||||
|
||||
private void stripNonExistentAnnotations(Set<String> allClasses, FeatureDescription d) {
|
||||
stripNonExistentAnnotations(allClasses, d.classAnnotations);
|
||||
stripNonExistentAnnotations(allClasses, d.runtimeAnnotations);
|
||||
}
|
||||
|
||||
private void stripNonExistentAnnotations(Set<String> allClasses, List<AnnotationDescription> annotations) {
|
||||
if (annotations != null)
|
||||
annotations.removeIf(ann -> !HARDCODED_ANNOTATIONS.contains(ann.annotationType) &&
|
||||
!allClasses.contains(ann.annotationType.substring(1, ann.annotationType.length() - 1)));
|
||||
}
|
||||
|
||||
private ZipEntry createZipEntry(String name, long timestamp) {
|
||||
ZipEntry ze = new ZipEntry(name);
|
||||
|
||||
@ -1140,17 +1185,16 @@ public class CreateSymbols {
|
||||
values.put("reflective", essentialAPI != null && !essentialAPI);
|
||||
}
|
||||
|
||||
if (VALUE_BASED_ANNOTATION.equals(annotationType)) {
|
||||
//the non-public ValueBased annotation will not be available in ct.sym,
|
||||
//replace with purely synthetic javac-internal annotation:
|
||||
annotationType = VALUE_BASED_ANNOTATION_INTERNAL;
|
||||
}
|
||||
|
||||
return new Annotation(null,
|
||||
addString(constantPool, annotationType),
|
||||
createElementPairs(constantPool, values));
|
||||
}
|
||||
//where:
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_OLD =
|
||||
"Ljdk/internal/PreviewFeature;";
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_NEW =
|
||||
"Ljdk/internal/javac/PreviewFeature;";
|
||||
private static final String PREVIEW_FEATURE_ANNOTATION_INTERNAL =
|
||||
"Ljdk/internal/PreviewFeature+Annotation;";
|
||||
|
||||
private element_value_pair[] createElementPairs(List<CPInfo> constantPool, Map<String, Object> annotationAttributes) {
|
||||
element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()];
|
||||
|
@ -576,6 +576,7 @@ class Assembler : public AbstractAssembler {
|
||||
XVNMSUBASP_OPCODE=(60u<< OPCODE_SHIFT | 209u << 3),
|
||||
XVNMSUBADP_OPCODE=(60u<< OPCODE_SHIFT | 241u << 3),
|
||||
XVRDPI_OPCODE = (60u << OPCODE_SHIFT | 201u << 2),
|
||||
XVRDPIC_OPCODE = (60u << OPCODE_SHIFT | 235u << 2),
|
||||
XVRDPIM_OPCODE = (60u << OPCODE_SHIFT | 249u << 2),
|
||||
XVRDPIP_OPCODE = (60u << OPCODE_SHIFT | 233u << 2),
|
||||
|
||||
@ -2384,6 +2385,7 @@ class Assembler : public AbstractAssembler {
|
||||
inline void xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b);
|
||||
inline void xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b);
|
||||
inline void xvrdpi( VectorSRegister d, VectorSRegister b);
|
||||
inline void xvrdpic( VectorSRegister d, VectorSRegister b);
|
||||
inline void xvrdpim( VectorSRegister d, VectorSRegister b);
|
||||
inline void xvrdpip( VectorSRegister d, VectorSRegister b);
|
||||
|
||||
|
@ -848,6 +848,7 @@ inline void Assembler::xvmsubadp( VectorSRegister d, VectorSRegister a, VectorSR
|
||||
inline void Assembler::xvnmsubasp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBASP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
|
||||
inline void Assembler::xvnmsubadp(VectorSRegister d, VectorSRegister a, VectorSRegister b) { emit_int32( XVNMSUBADP_OPCODE | vsrt(d) | vsra(a) | vsrb(b)); }
|
||||
inline void Assembler::xvrdpi( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPI_OPCODE | vsrt(d) | vsrb(b)); }
|
||||
inline void Assembler::xvrdpic( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIC_OPCODE | vsrt(d) | vsrb(b)); }
|
||||
inline void Assembler::xvrdpim( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIM_OPCODE | vsrt(d) | vsrb(b)); }
|
||||
inline void Assembler::xvrdpip( VectorSRegister d, VectorSRegister b) { emit_int32( XVRDPIP_OPCODE | vsrt(d) | vsrb(b)); }
|
||||
|
||||
|
@ -2108,6 +2108,8 @@ const bool Matcher::match_rule_supported(int opcode) {
|
||||
switch (opcode) {
|
||||
case Op_SqrtD:
|
||||
return VM_Version::has_fsqrt();
|
||||
case Op_RoundDoubleMode:
|
||||
return VM_Version::has_vsx();
|
||||
case Op_CountLeadingZerosI:
|
||||
case Op_CountLeadingZerosL:
|
||||
return UseCountLeadingZerosInstructionsPPC64;
|
||||
@ -13964,7 +13966,7 @@ instruct roundD_reg(regD dst, regD src, immI8 rmode) %{
|
||||
ins_encode %{
|
||||
switch ($rmode$$constant) {
|
||||
case RoundDoubleModeNode::rmode_rint:
|
||||
__ frin($dst$$FloatRegister, $src$$FloatRegister);
|
||||
__ xvrdpic($dst$$FloatRegister->to_vsr(), $src$$FloatRegister->to_vsr());
|
||||
break;
|
||||
case RoundDoubleModeNode::rmode_floor:
|
||||
__ frim($dst$$FloatRegister, $src$$FloatRegister);
|
||||
@ -13988,7 +13990,7 @@ instruct vround2D_reg(vecX dst, vecX src, immI8 rmode) %{
|
||||
ins_encode %{
|
||||
switch ($rmode$$constant) {
|
||||
case RoundDoubleModeNode::rmode_rint:
|
||||
__ xvrdpi($dst$$VectorSRegister, $src$$VectorSRegister);
|
||||
__ xvrdpic($dst$$VectorSRegister, $src$$VectorSRegister);
|
||||
break;
|
||||
case RoundDoubleModeNode::rmode_floor:
|
||||
__ xvrdpim($dst$$VectorSRegister, $src$$VectorSRegister);
|
||||
|
@ -35,6 +35,11 @@ import static java.lang.annotation.ElementType.TYPE;
|
||||
* References to <a href="../lang/doc-files/ValueBased.html">value-based classes</a>
|
||||
* should produce warnings about behavior that is inconsistent with value based semantics.
|
||||
*
|
||||
* Note this internal annotation is handled specially by the javac compiler.
|
||||
* To work properly with {@code --release older-release}, it requires special
|
||||
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
|
||||
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
|
||||
*
|
||||
* @since 16
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -31,6 +31,12 @@ import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* The element annotated with this annotation should not be marked as a preview element.
|
||||
*
|
||||
* Note this internal annotation is handled specially by the javac compiler.
|
||||
* To work properly with {@code --release older-release}, it requires special
|
||||
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
|
||||
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
|
||||
*
|
||||
*/
|
||||
@Target({ElementType.METHOD,
|
||||
ElementType.CONSTRUCTOR,
|
||||
|
@ -31,6 +31,12 @@ 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).
|
||||
*
|
||||
* Note this internal annotation is handled specially by the javac compiler.
|
||||
* To work properly with {@code --release older-release}, it requires special
|
||||
* handling in {@code make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java}
|
||||
* and {@code src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java}.
|
||||
*
|
||||
* @since 14
|
||||
*/
|
||||
// Match the meaningful targets of java.lang.Deprecated, omit local
|
||||
|
@ -311,7 +311,12 @@ public class Flags {
|
||||
/**
|
||||
* Flag to indicate the given ModuleSymbol is a system module.
|
||||
*/
|
||||
public static final long SYSTEM_MODULE = 1L<<53;
|
||||
public static final long SYSTEM_MODULE = 1L<<53; //ModuleSymbols only
|
||||
|
||||
/**
|
||||
* Flag to indicate the given ClassSymbol is a value based.
|
||||
*/
|
||||
public static final long VALUE_BASED = 1L<<53; //ClassSymbols only
|
||||
|
||||
/**
|
||||
* Flag to indicate the given symbol has a @Deprecated annotation.
|
||||
|
@ -222,6 +222,7 @@ public class Symtab {
|
||||
public final Type recordType;
|
||||
public final Type switchBootstrapsType;
|
||||
public final Type valueBasedType;
|
||||
public final Type valueBasedInternalType;
|
||||
|
||||
/** The symbol representing the length field of an array.
|
||||
*/
|
||||
@ -588,6 +589,7 @@ public class Symtab {
|
||||
recordType = enterClass("java.lang.Record");
|
||||
switchBootstrapsType = enterClass("java.lang.runtime.SwitchBootstraps");
|
||||
valueBasedType = enterClass("jdk.internal.ValueBased");
|
||||
valueBasedInternalType = enterSyntheticAnnotation("jdk.internal.ValueBased+Annotation");
|
||||
|
||||
synthesizeEmptyInterfaceIfMissing(autoCloseableType);
|
||||
synthesizeEmptyInterfaceIfMissing(cloneableType);
|
||||
|
@ -53,6 +53,7 @@ import static com.sun.tools.javac.code.Flags.SYNTHETIC;
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.MDL;
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.MTH;
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.PCK;
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.TYP;
|
||||
import static com.sun.tools.javac.code.Kinds.Kind.VAR;
|
||||
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
|
||||
import static com.sun.tools.javac.code.TypeTag.ARRAY;
|
||||
@ -369,7 +370,6 @@ public class Annotate {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: @Deprecated has no effect on local variables and parameters
|
||||
if (!c.type.isErroneous()
|
||||
&& types.isSameType(c.type, syms.previewFeatureType)) {
|
||||
toAnnotate.flags_field |= Flags.PREVIEW_API;
|
||||
@ -377,6 +377,12 @@ public class Annotate {
|
||||
toAnnotate.flags_field |= Flags.PREVIEW_REFLECTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!c.type.isErroneous()
|
||||
&& toAnnotate.kind == TYP
|
||||
&& types.isSameType(c.type, syms.valueBasedType)) {
|
||||
toAnnotate.flags_field |= Flags.VALUE_BASED;
|
||||
}
|
||||
}
|
||||
|
||||
List<T> buf = List.nil();
|
||||
|
@ -1871,14 +1871,7 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
// where
|
||||
private boolean isValueBased(Type t) {
|
||||
if (t != null && t.tsym != null) {
|
||||
for (Attribute.Compound a: t.tsym.getDeclarationAttributes()) {
|
||||
if (a.type.tsym == syms.valueBasedType.tsym) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return t != null && t.tsym != null && (t.tsym.flags() & VALUE_BASED) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -386,6 +386,7 @@ public class TransPatterns extends TreeTranslator {
|
||||
hasNullCase = true;
|
||||
}
|
||||
}
|
||||
selector = translate(selector);
|
||||
statements.append(make.at(tree.pos).VarDef(temp, !hasNullCase ? attr.makeNullCheck(selector)
|
||||
: selector));
|
||||
VarSymbol index = new VarSymbol(Flags.SYNTHETIC,
|
||||
@ -469,6 +470,8 @@ public class TransPatterns extends TreeTranslator {
|
||||
currentValue = prevCurrentValue;
|
||||
bindingContext.pop();
|
||||
}
|
||||
} else {
|
||||
c.stats = translate(c.stats);
|
||||
}
|
||||
if (enumSwitch) {
|
||||
var labels = c.labels;
|
||||
|
@ -1446,6 +1446,9 @@ public class ClassReader {
|
||||
} else if (proxy.type.tsym.flatName() == syms.previewFeatureInternalType.tsym.flatName()) {
|
||||
sym.flags_field |= PREVIEW_API;
|
||||
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
|
||||
} else if (proxy.type.tsym.flatName() == syms.valueBasedInternalType.tsym.flatName()) {
|
||||
Assert.check(sym.kind == TYP);
|
||||
sym.flags_field |= VALUE_BASED;
|
||||
} else {
|
||||
if (proxy.type.tsym == syms.annotationTargetType.tsym) {
|
||||
target = proxy;
|
||||
@ -1457,6 +1460,8 @@ public class ClassReader {
|
||||
} else if (proxy.type.tsym == syms.previewFeatureType.tsym) {
|
||||
sym.flags_field |= PREVIEW_API;
|
||||
setFlagIfAttributeTrue(proxy, sym, names.reflective, PREVIEW_REFLECTIVE);
|
||||
} else if (proxy.type.tsym == syms.valueBasedType.tsym && sym.kind == TYP) {
|
||||
sym.flags_field |= VALUE_BASED;
|
||||
}
|
||||
proxies.append(proxy);
|
||||
}
|
||||
|
@ -772,8 +772,8 @@ public class JavacParser implements Parser {
|
||||
accept(RPAREN);
|
||||
pattern = toP(F.at(startPos).ParenthesizedPattern(p));
|
||||
} else {
|
||||
JCExpression e = parsedType == null ? term(EXPR | TYPE | NOLAMBDA) : parsedType;
|
||||
mods = mods != null ? mods : F.at(token.pos).Modifiers(0);
|
||||
mods = mods != null ? mods : optFinal(0);
|
||||
JCExpression e = parsedType == null ? term(TYPE | NOLAMBDA) : parsedType;
|
||||
JCVariableDecl var = toP(F.at(token.pos).VarDef(mods, ident(), e, null));
|
||||
pattern = toP(F.at(pos).BindingPattern(var));
|
||||
}
|
||||
@ -1694,16 +1694,12 @@ public class JavacParser implements Parser {
|
||||
* method reference or a binary expression. To disambiguate, look for a
|
||||
* matching '>' and see if the subsequent terminal is either '.' or '::'.
|
||||
*/
|
||||
ParensResult analyzeParens() {
|
||||
return analyzeParens(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
ParensResult analyzeParens(int startLookahead) {
|
||||
ParensResult analyzeParens() {
|
||||
int depth = 0;
|
||||
boolean type = false;
|
||||
ParensResult defaultResult = ParensResult.PARENS;
|
||||
outer: for (int lookahead = startLookahead; ; lookahead++) {
|
||||
outer: for (int lookahead = 0; ; lookahead++) {
|
||||
TokenKind tk = S.token(lookahead).kind;
|
||||
switch (tk) {
|
||||
case COMMA:
|
||||
@ -1729,7 +1725,7 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
break;
|
||||
case LPAREN:
|
||||
if (lookahead != startLookahead) {
|
||||
if (lookahead != 0) {
|
||||
// '(' in a non-starting position -> parens
|
||||
return ParensResult.PARENS;
|
||||
} else if (peekToken(lookahead, RPAREN)) {
|
||||
@ -1780,31 +1776,7 @@ public class JavacParser implements Parser {
|
||||
return ParensResult.EXPLICIT_LAMBDA;
|
||||
case MONKEYS_AT:
|
||||
type = true;
|
||||
lookahead += 1; //skip '@'
|
||||
while (peekToken(lookahead, DOT)) {
|
||||
lookahead += 2;
|
||||
}
|
||||
if (peekToken(lookahead, LPAREN)) {
|
||||
lookahead++;
|
||||
//skip annotation values
|
||||
int nesting = 0;
|
||||
for (; ; lookahead++) {
|
||||
TokenKind tk2 = S.token(lookahead).kind;
|
||||
switch (tk2) {
|
||||
case EOF:
|
||||
return ParensResult.PARENS;
|
||||
case LPAREN:
|
||||
nesting++;
|
||||
break;
|
||||
case RPAREN:
|
||||
nesting--;
|
||||
if (nesting == 0) {
|
||||
continue outer;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lookahead = skipAnnotation(lookahead);
|
||||
break;
|
||||
case LBRACKET:
|
||||
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
|
||||
@ -1861,6 +1833,35 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private int skipAnnotation(int lookahead) {
|
||||
lookahead += 1; //skip '@'
|
||||
while (peekToken(lookahead, DOT)) {
|
||||
lookahead += 2;
|
||||
}
|
||||
if (peekToken(lookahead, LPAREN)) {
|
||||
lookahead++;
|
||||
//skip annotation values
|
||||
int nesting = 0;
|
||||
for (; ; lookahead++) {
|
||||
TokenKind tk2 = S.token(lookahead).kind;
|
||||
switch (tk2) {
|
||||
case EOF:
|
||||
return lookahead;
|
||||
case LPAREN:
|
||||
nesting++;
|
||||
break;
|
||||
case RPAREN:
|
||||
nesting--;
|
||||
if (nesting == 0) {
|
||||
return lookahead;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookahead;
|
||||
}
|
||||
|
||||
/** Accepts all identifier-like tokens */
|
||||
protected Predicate<TokenKind> LAX_IDENTIFIER = t -> t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
|
||||
|
||||
@ -3067,34 +3068,69 @@ public class JavacParser implements Parser {
|
||||
nextToken();
|
||||
label = toP(F.at(patternPos).DefaultCaseLabel());
|
||||
} else {
|
||||
if (token.kind == LPAREN) {
|
||||
int lookahead = 0;
|
||||
while (S.token(lookahead + 1).kind == LPAREN) {
|
||||
lookahead++;
|
||||
}
|
||||
boolean pattern = analyzeParens(lookahead) == ParensResult.EXPLICIT_LAMBDA;
|
||||
if (pattern) {
|
||||
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
|
||||
return parsePattern(token.pos, null, null, false);
|
||||
} else {
|
||||
return term(EXPR | TYPE | NOLAMBDA);
|
||||
}
|
||||
int lookahead = 0;
|
||||
while (S.token(lookahead).kind == LPAREN) {
|
||||
lookahead++;
|
||||
}
|
||||
JCModifiers mods = optFinal(0);
|
||||
boolean pattern = mods.flags != 0 || mods.annotations.nonEmpty() ||
|
||||
analyzePattern(lookahead) == PatternResult.PATTERN;
|
||||
if (pattern) {
|
||||
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
|
||||
return parsePattern(patternPos, mods, null, false);
|
||||
} else {
|
||||
JCModifiers mods = optFinal(0);
|
||||
JCExpression e = term(EXPR | TYPE | NOLAMBDA);
|
||||
|
||||
if (token.kind == IDENTIFIER || mods.flags != 0 || mods.annotations.nonEmpty()) {
|
||||
checkSourceLevel(token.pos, Feature.PATTERN_SWITCH);
|
||||
return parsePattern(patternPos, null, e, false);
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
return term(EXPR | NOLAMBDA);
|
||||
}
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
PatternResult analyzePattern(int lookahead) {
|
||||
int depth = 0;
|
||||
while (true) {
|
||||
TokenKind token = S.token(lookahead).kind;
|
||||
switch (token) {
|
||||
case BYTE: case SHORT: case INT: case LONG: case FLOAT:
|
||||
case DOUBLE: case BOOLEAN: case CHAR: case VOID:
|
||||
case ASSERT, ENUM, IDENTIFIER, UNDERSCORE:
|
||||
if (depth == 0 && peekToken(lookahead, LAX_IDENTIFIER)) return PatternResult.PATTERN;
|
||||
break;
|
||||
case DOT, QUES, EXTENDS, SUPER, COMMA: break;
|
||||
case LT: depth++; break;
|
||||
case GTGTGT: depth--;
|
||||
case GTGT: depth--;
|
||||
case GT:
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
return peekToken(lookahead, LAX_IDENTIFIER) ? PatternResult.PATTERN
|
||||
: PatternResult.EXPRESSION;
|
||||
} else if (depth < 0) return PatternResult.EXPRESSION;
|
||||
break;
|
||||
case MONKEYS_AT:
|
||||
lookahead = skipAnnotation(lookahead);
|
||||
break;
|
||||
case LBRACKET:
|
||||
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
|
||||
return PatternResult.PATTERN;
|
||||
} else if (peekToken(lookahead, RBRACKET)) {
|
||||
lookahead++;
|
||||
break;
|
||||
} else {
|
||||
return PatternResult.EXPRESSION;
|
||||
}
|
||||
default: return PatternResult.EXPRESSION;
|
||||
}
|
||||
lookahead++;
|
||||
}
|
||||
}
|
||||
|
||||
private enum PatternResult {
|
||||
EXPRESSION,
|
||||
PATTERN;
|
||||
}
|
||||
|
||||
/** MoreStatementExpressions = { COMMA StatementExpression }
|
||||
*/
|
||||
<T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2021, 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
|
||||
@ -188,70 +188,21 @@ public class BasicTypeDataBase implements TypeDataBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The first implementation searched three locations for this vtbl
|
||||
// value; scanning through the entire object was considered, but
|
||||
// we thought we knew where we were looking, and looking only in
|
||||
// these specific locations should reduce the probability of
|
||||
// mistaking random bits as a pointer (although, realistically
|
||||
// speaking, the likelihood of finding a match between the bit
|
||||
// pattern of, for example, a double and the vtbl is vanishingly
|
||||
// small.)
|
||||
// 1. The first word of the object (should handle MSVC++ as
|
||||
// well as the solstudio compilers with compatibility set to
|
||||
// v5.0 or greater)
|
||||
// 2. and 3. The last two Address-aligned words of the part of
|
||||
// the object defined by its topmost polymorphic superclass.
|
||||
// This should handle the solstudio compilers, v4.2 or
|
||||
// earlier, as well as any other compilers which place the vptr
|
||||
// at the end of the user-defined fields of the first base
|
||||
// class with virtual functions.
|
||||
//
|
||||
// Unfortunately this algorithm did not work properly for the
|
||||
// specific case of the ThreadShadow/Thread inheritance situation,
|
||||
// because the Solaris compiler seems to cleverly eliminate the
|
||||
// vtbl for ThreadShadow since the only virtual is empty. (We
|
||||
// should get rid of the ThreadShadow and fix the include
|
||||
// databases, but need to postpone this for the present.) The
|
||||
// current solution performs the three-location check for this
|
||||
// class and all of its known superclasses rather than just the
|
||||
// topmost polymorphic one.
|
||||
|
||||
Type curType = type;
|
||||
|
||||
// See if the vtable at the first address of the object matches the vtable of the
|
||||
// specified type. Note this code used to be much more complex in order to support
|
||||
// Solaris. It included looking at the last 2 words of the object and also trying
|
||||
// to match on all supertypes of the specified type. This turned out to be buggy,
|
||||
// and was removed since Solaris is no longer supported. See JDK-8269830.
|
||||
try {
|
||||
while (curType != null) {
|
||||
// Using the size information we have for this type, check the
|
||||
// three locations described above.
|
||||
|
||||
// (1)
|
||||
if (vtblAddr.equals(addr.getAddressAt(0))) {
|
||||
return true;
|
||||
if (vtblAddr.equals(addr.getAddressAt(0))) {
|
||||
return true;
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " + type.getName());
|
||||
}
|
||||
|
||||
// (2)
|
||||
long offset = curType.getSize();
|
||||
// I don't think this should be misaligned under any
|
||||
// circumstances, but I'm not sure (FIXME: also not sure which
|
||||
// way to go here, up or down -- assuming down)
|
||||
offset -= (offset % getAddressSize());
|
||||
if (offset <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (vtblAddr.equals(addr.getAddressAt(offset))) {
|
||||
return true;
|
||||
}
|
||||
offset -= getAddressSize();
|
||||
if (offset <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (vtblAddr.equals(addr.getAddressAt(offset))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
curType = curType.getSuperclass();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
// Any UnmappedAddressExceptions, etc. are a good indication
|
||||
// that the pointer is not of the specified type
|
||||
if (DEBUG) {
|
||||
@ -261,13 +212,6 @@ public class BasicTypeDataBase implements TypeDataBase {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
|
||||
type.getName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type findDynamicTypeForAddress(Address addr, Type baseType) {
|
||||
|
@ -39,6 +39,8 @@ Requires: PACKAGE_DEFAULT_DEPENDENCIES PACKAGE_CUSTOM_DEPENDENCIES
|
||||
%description
|
||||
APPLICATION_DESCRIPTION
|
||||
|
||||
%global __os_install_post %{nil}
|
||||
|
||||
%prep
|
||||
|
||||
%build
|
||||
|
@ -28,7 +28,7 @@ java/rmi/Naming java/util/prefs sun/management/jmxremote \
|
||||
sun/tools/jstatd sun/tools/jcmd \
|
||||
sun/tools/jinfo sun/tools/jmap sun/tools/jps sun/tools/jstack sun/tools/jstat \
|
||||
com/sun/tools/attach sun/security/mscapi java/util/stream java/util/Arrays/largeMemory \
|
||||
java/util/BitSet/stream javax/rmi
|
||||
java/util/BitSet/stream javax/rmi java/net/httpclient/websocket
|
||||
|
||||
# Group definitions
|
||||
groups=TEST.groups
|
||||
|
@ -899,6 +899,7 @@ public class Basic {
|
||||
} catch (Throwable t) { unexpected(t); return ""; }
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
static void testIORedirection() throws Throwable {
|
||||
final File ifile = new File("ifile");
|
||||
final File ofile = new File("ofile");
|
||||
@ -1303,6 +1304,7 @@ public class Basic {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void realMain(String[] args) throws Throwable {
|
||||
if (Windows.is())
|
||||
System.out.println("This appears to be a Windows system.");
|
||||
@ -2184,7 +2186,9 @@ public class Basic {
|
||||
}
|
||||
if (r >= 0) {
|
||||
// The child sent unexpected output; print it to diagnose
|
||||
System.out.println("Unexpected child output:");
|
||||
System.out.println("Unexpected child output, to: " +
|
||||
((action & 0x1) == 0 ? "getInputStream" : "getErrorStream"));
|
||||
System.out.println("Child args: " + childArgs);
|
||||
if ((action & 0x2) == 0) {
|
||||
System.out.write(r); // Single character
|
||||
|
||||
@ -2205,7 +2209,7 @@ public class Basic {
|
||||
|
||||
thread.start();
|
||||
latch.await();
|
||||
Thread.sleep(10);
|
||||
Thread.sleep(30);
|
||||
|
||||
if (s instanceof BufferedInputStream) {
|
||||
// Wait until after the s.read occurs in "thread" by
|
||||
@ -2662,6 +2666,7 @@ public class Basic {
|
||||
//----------------------------------------------------------------
|
||||
// A Policy class designed to make permissions fiddling very easy.
|
||||
//----------------------------------------------------------------
|
||||
@SuppressWarnings("removal")
|
||||
private static class Policy extends java.security.Policy {
|
||||
static final java.security.Policy DEFAULT_POLICY = java.security.Policy.getPolicy();
|
||||
|
||||
|
@ -72,4 +72,3 @@ tools/sjavac/ClasspathDependencies.java
|
||||
#
|
||||
# jdeps
|
||||
|
||||
tools/jdeprscan/tests/jdk/jdeprscan/TestRelease.java 8258421 generic-all Deprecation vs JDK-private annotation class
|
||||
|
@ -1,10 +1,11 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8254274
|
||||
* @bug 8254274 8258421
|
||||
* @summary lint should warn when an instance of a value based class is synchronized upon
|
||||
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint ExternalAbuseOfVbc.java
|
||||
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:all ExternalAbuseOfVbc.java
|
||||
* @compile/fail/ref=ExternalAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
|
||||
* @compile/fail/ref=ExternalAbuseOfVbc.out --release 16 -XDrawDiagnostics -Werror -Xlint:synchronization ExternalAbuseOfVbc.java
|
||||
* @compile/ref=LintModeOffAbuseOfVbc.out -XDrawDiagnostics -Werror -Xlint:-synchronization ExternalAbuseOfVbc.java
|
||||
*/
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
ExternalAbuseOfVbc.java:18:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
|
||||
ExternalAbuseOfVbc.java:19:13: compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class
|
||||
- compiler.err.warnings.and.werror
|
||||
1 error
|
||||
1 warning
|
||||
|
@ -1,3 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @modules jdk.compiler/com.sun.tools.javac.file
|
||||
@ -5,8 +28,8 @@
|
||||
* jdk.compiler/com.sun.tools.javac.parser
|
||||
* jdk.compiler/com.sun.tools.javac.tree
|
||||
* jdk.compiler/com.sun.tools.javac.util
|
||||
* @compile --enable-preview -source ${jdk.version} DisambiguateParenthesizedPattern.java
|
||||
* @run main/othervm --enable-preview DisambiguateParenthesizedPattern
|
||||
* @compile --enable-preview -source ${jdk.version} DisambiguatePatterns.java
|
||||
* @run main/othervm --enable-preview DisambiguatePatterns
|
||||
*/
|
||||
|
||||
import com.sun.source.tree.CaseLabelTree;
|
||||
@ -24,16 +47,18 @@ import com.sun.tools.javac.main.Option;
|
||||
import com.sun.tools.javac.util.Options;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class DisambiguateParenthesizedPattern {
|
||||
public class DisambiguatePatterns {
|
||||
|
||||
public static void main(String... args) throws Throwable {
|
||||
DisambiguateParenthesizedPattern test = new DisambiguateParenthesizedPattern();
|
||||
DisambiguatePatterns test = new DisambiguatePatterns();
|
||||
test.disambiguationTest("String s",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("String s && s.isEmpty()",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("(String s)",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("(@Ann String s)",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("((String s))",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("(String) s",
|
||||
@ -56,11 +81,41 @@ public class DisambiguateParenthesizedPattern {
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("(a < c.d > b)",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<? extends c.d> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("@Ann a<? extends c.d> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<? extends @Ann c.d> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<? super c.d> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<? super @Ann c.d> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<b<c.d>> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<b<@Ann c.d>> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a<b<c<d>>> b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a[] b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a[][] b",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("int i",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("int[] i",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("a[a]",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("a[b][c]",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("a & b",
|
||||
ExpressionType.EXPRESSION);
|
||||
}
|
||||
|
||||
private final ParserFactory factory;
|
||||
|
||||
public DisambiguateParenthesizedPattern() {
|
||||
public DisambiguatePatterns() {
|
||||
Context context = new Context();
|
||||
JavacFileManager jfm = new JavacFileManager(context, true, Charset.defaultCharset());
|
||||
Options.instance(context).put(Option.PREVIEW, "");
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8268859
|
||||
* @summary Verify error recovery/disambiguation of case labels that mix expressions and patterns
|
||||
* @compile/fail/ref=PatternCaseErrorRecovery.out --enable-preview -source ${jdk.version} -XDrawDiagnostics PatternCaseErrorRecovery.java
|
||||
*/
|
||||
|
||||
public class PatternCaseErrorRecovery {
|
||||
Object expressionLikeType(Object o1, Object o2) {
|
||||
final int a = 1;
|
||||
final int b = 2;
|
||||
return switch (o1) {
|
||||
case true t -> o2;
|
||||
case 1 + 1 e -> o2;
|
||||
case a < b ? a : b e -> o2;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
PatternCaseErrorRecovery.java:13:22: compiler.err.expected2: :, ->
|
||||
PatternCaseErrorRecovery.java:13:23: compiler.err.not.stmt
|
||||
PatternCaseErrorRecovery.java:14:23: compiler.err.expected2: :, ->
|
||||
PatternCaseErrorRecovery.java:14:24: compiler.err.not.stmt
|
||||
PatternCaseErrorRecovery.java:15:31: compiler.err.expected2: :, ->
|
||||
PatternCaseErrorRecovery.java:15:32: compiler.err.not.stmt
|
||||
6 errors
|
@ -0,0 +1,3 @@
|
||||
PatternErrorRecovery.java:12:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)
|
||||
PatternErrorRecovery.java:11:18: compiler.err.const.expr.req
|
||||
2 errors
|
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8268320
|
||||
* @summary Verify user-friendly errors are reported for ill-formed pattern.
|
||||
* @compile/fail/ref=PatternErrorRecovery.out -XDrawDiagnostics -XDshould-stop.at=FLOW --enable-preview -source ${jdk.version} PatternErrorRecovery.java
|
||||
* @compile/fail/ref=PatternErrorRecovery-no-preview.out -XDrawDiagnostics -XDshould-stop.at=FLOW PatternErrorRecovery.java
|
||||
*/
|
||||
public class PatternErrorRecovery {
|
||||
void errorRecoveryNoPattern1(Object o) {
|
||||
switch (o) {
|
||||
case String: break;
|
||||
case Object obj: break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
PatternErrorRecovery.java:11:18: compiler.err.pattern.expected
|
||||
- compiler.note.preview.filename: PatternErrorRecovery.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
1 error
|
@ -76,7 +76,7 @@ public class SourceLevelChecks extends TestRunner {
|
||||
}
|
||||
}
|
||||
""",
|
||||
"Test.java:5:26: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
|
||||
"Test.java:5:18: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)",
|
||||
"1 error");
|
||||
}
|
||||
|
||||
|
@ -1,42 +0,0 @@
|
||||
SwitchErrors.java:35:31: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.pattern.switch)
|
||||
SwitchErrors.java:34:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
|
||||
SwitchErrors.java:40:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
|
||||
SwitchErrors.java:46:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:47:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
|
||||
SwitchErrors.java:52:18: compiler.err.preview.feature.disabled: (compiler.misc.feature.case.null)
|
||||
SwitchErrors.java:53:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
|
||||
SwitchErrors.java:54:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
|
||||
SwitchErrors.java:60:20: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:66:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:72:18: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:78:18: compiler.err.duplicate.total.pattern
|
||||
SwitchErrors.java:84:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:90:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:101:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:106:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:111:28: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:117:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:124:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:131:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:136:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:142:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
|
||||
SwitchErrors.java:148:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:155:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
|
||||
SwitchErrors.java:172:27: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:178:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:184:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:196:18: compiler.err.const.expr.req
|
||||
SwitchErrors.java:202:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:208:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:33:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:39:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:45:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:51:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:99:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:105:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:110:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:115:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:121:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:128:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:188:9: compiler.err.not.exhaustive.statement
|
||||
41 errors
|
@ -1,32 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8262891
|
||||
* @summary Verify errors related to pattern switches.
|
||||
* @compile/fail/ref=SwitchErrors.out --enable-preview -source ${jdk.version} -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
|
||||
* @compile/fail/ref=SwitchErrors-no-preview.out -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
|
||||
*/
|
||||
public class SwitchErrors {
|
||||
void incompatibleSelectorObjectString(Object o) {
|
||||
|
@ -1,47 +1,47 @@
|
||||
SwitchErrors.java:34:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
|
||||
SwitchErrors.java:40:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
|
||||
SwitchErrors.java:46:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:47:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
|
||||
SwitchErrors.java:52:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, int)
|
||||
SwitchErrors.java:53:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
|
||||
SwitchErrors.java:54:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
|
||||
SwitchErrors.java:60:20: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:66:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:66:24: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:72:18: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:78:18: compiler.err.duplicate.total.pattern
|
||||
SwitchErrors.java:84:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:90:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:95:27: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:101:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:106:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:111:28: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:117:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:124:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:131:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:136:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:142:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
|
||||
SwitchErrors.java:148:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:155:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
|
||||
SwitchErrors.java:161:28: compiler.err.flows.through.from.pattern
|
||||
SwitchErrors.java:167:18: compiler.err.flows.through.from.pattern
|
||||
SwitchErrors.java:172:27: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:178:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:184:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:196:18: compiler.err.pattern.expected
|
||||
SwitchErrors.java:202:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:208:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:33:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:39:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:45:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:51:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:99:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:105:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:110:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:115:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:121:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:128:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:188:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:10:18: compiler.err.constant.label.not.compatible: java.lang.String, java.lang.Object
|
||||
SwitchErrors.java:16:18: compiler.err.constant.label.not.compatible: int, java.lang.Object
|
||||
SwitchErrors.java:22:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:23:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.CharSequence)
|
||||
SwitchErrors.java:28:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.null, int)
|
||||
SwitchErrors.java:29:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, int)
|
||||
SwitchErrors.java:30:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.CharSequence)
|
||||
SwitchErrors.java:36:20: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:42:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:42:24: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:48:18: compiler.err.total.pattern.and.default
|
||||
SwitchErrors.java:54:18: compiler.err.duplicate.total.pattern
|
||||
SwitchErrors.java:60:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:66:20: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:71:27: compiler.err.duplicate.default.label
|
||||
SwitchErrors.java:77:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:82:13: compiler.err.duplicate.case.label
|
||||
SwitchErrors.java:87:28: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:93:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:100:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:107:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:112:18: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
|
||||
SwitchErrors.java:118:18: compiler.err.instanceof.reifiable.not.safe: java.util.List, java.util.List<java.lang.Integer>
|
||||
SwitchErrors.java:124:18: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:131:18: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
|
||||
SwitchErrors.java:137:28: compiler.err.flows.through.from.pattern
|
||||
SwitchErrors.java:143:18: compiler.err.flows.through.from.pattern
|
||||
SwitchErrors.java:148:27: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:154:18: compiler.err.flows.through.to.pattern
|
||||
SwitchErrors.java:160:13: compiler.err.pattern.dominated
|
||||
SwitchErrors.java:172:18: compiler.err.pattern.expected
|
||||
SwitchErrors.java:178:76: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:184:71: compiler.err.cant.resolve.location: kindname.variable, n, , , (compiler.misc.location: kindname.class, SwitchErrors, null)
|
||||
SwitchErrors.java:9:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:15:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:21:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:27:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:75:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:81:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:86:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:91:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:97:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:104:9: compiler.err.not.exhaustive.statement
|
||||
SwitchErrors.java:164:9: compiler.err.not.exhaustive.statement
|
||||
- compiler.note.preview.filename: SwitchErrors.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
44 errors
|
||||
|
@ -22,12 +22,13 @@
|
||||
*/
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8262891 8268333 8268896
|
||||
* @bug 8262891 8268333 8268896 8269802 8269808
|
||||
* @summary Check behavior of pattern switches.
|
||||
* @compile --enable-preview -source ${jdk.version} Switches.java
|
||||
* @run main/othervm --enable-preview Switches
|
||||
@ -66,6 +67,11 @@ public class Switches {
|
||||
npeTest(this::npeTestExpression);
|
||||
exhaustiveStatementSane("");
|
||||
exhaustiveStatementSane(null);
|
||||
switchNestingTest(this::switchNestingStatementStatement);
|
||||
switchNestingTest(this::switchNestingStatementExpression);
|
||||
switchNestingTest(this::switchNestingExpressionStatement);
|
||||
switchNestingTest(this::switchNestingExpressionExpression);
|
||||
switchNestingTest(this::switchNestingIfSwitch);
|
||||
}
|
||||
|
||||
void run(Function<Object, Integer> mapper) {
|
||||
@ -119,6 +125,13 @@ public class Switches {
|
||||
}
|
||||
}
|
||||
|
||||
void switchNestingTest(BiFunction<Object, Object, String> testCase) {
|
||||
assertEquals("string, string", testCase.apply("", ""));
|
||||
assertEquals("string, other", testCase.apply("", 1));
|
||||
assertEquals("other, string", testCase.apply(1, ""));
|
||||
assertEquals("other, other", testCase.apply(1, 1));
|
||||
}
|
||||
|
||||
int typeTestPatternSwitchTest(Object o) {
|
||||
switch (o) {
|
||||
case String s: return Integer.parseInt(s.toString());
|
||||
@ -366,6 +379,113 @@ public class Switches {
|
||||
}
|
||||
}
|
||||
|
||||
String switchNestingStatementStatement(Object o1, Object o2) {
|
||||
switch (o1) {
|
||||
case String s1 -> {
|
||||
switch (o2) {
|
||||
case String s2 -> {
|
||||
return "string, string";
|
||||
}
|
||||
default -> {
|
||||
return "string, other";
|
||||
}
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
switch (o2) {
|
||||
case String s2 -> {
|
||||
return "other, string";
|
||||
}
|
||||
default -> {
|
||||
return "other, other";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String switchNestingStatementExpression(Object o1, Object o2) {
|
||||
switch (o1) {
|
||||
case String s1 -> {
|
||||
return switch (o2) {
|
||||
case String s2 -> "string, string";
|
||||
default -> "string, other";
|
||||
};
|
||||
}
|
||||
default -> {
|
||||
return switch (o2) {
|
||||
case String s2 -> "other, string";
|
||||
default -> "other, other";
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String switchNestingExpressionStatement(Object o1, Object o2) {
|
||||
return switch (o1) {
|
||||
case String s1 -> {
|
||||
switch (o2) {
|
||||
case String s2 -> {
|
||||
yield "string, string";
|
||||
}
|
||||
default -> {
|
||||
yield "string, other";
|
||||
}
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
switch (o2) {
|
||||
case String s2 -> {
|
||||
yield "other, string";
|
||||
}
|
||||
default -> {
|
||||
yield "other, other";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
String switchNestingExpressionExpression(Object o1, Object o2) {
|
||||
return switch (o1) {
|
||||
case String s1 ->
|
||||
switch (o2) {
|
||||
case String s2 -> "string, string";
|
||||
default -> "string, other";
|
||||
};
|
||||
default ->
|
||||
switch (o2) {
|
||||
case String s2 -> "other, string";
|
||||
default -> "other, other";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
String switchNestingIfSwitch(Object o1, Object o2) {
|
||||
BiFunction<Object, Object, String> f = (n1, n2) -> {
|
||||
if (o1 instanceof CharSequence cs) {
|
||||
return switch (cs) {
|
||||
case String s1 ->
|
||||
switch (o2) {
|
||||
case String s2 -> "string, string";
|
||||
default -> "string, other";
|
||||
};
|
||||
default ->
|
||||
switch (o2) {
|
||||
case String s2 -> "other, string";
|
||||
default -> "other, other";
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return switch (o2) {
|
||||
case String s2 -> "other, string";
|
||||
default -> "other, other";
|
||||
};
|
||||
}
|
||||
};
|
||||
return f.apply(o1, o2);
|
||||
}
|
||||
|
||||
//verify that for cases like:
|
||||
//case ConstantClassClash ->
|
||||
//ConstantClassClash is interpreted as a field, not as a class
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8266036 8258421
|
||||
* @summary Verify no error is reported for extended ForkJoinPool with --release 8.
|
||||
* @modules jdk.compiler
|
||||
* @build NonPublicAnnotations
|
||||
* @compile -processor NonPublicAnnotations --release 8 NonPublicAnnotations.java
|
||||
*/
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
@SupportedAnnotationTypes("*")
|
||||
public class NonPublicAnnotations extends AbstractProcessor {
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> roots, RoundEnvironment roundEnv) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestForkJoinPool extends ForkJoinPool {}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2021, 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
|
||||
@ -215,82 +215,88 @@ public class CreateSymbolsTestImpl {
|
||||
|
||||
@Test
|
||||
void testAnnotations() throws Exception {
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public @Visible @Invisible class T { public void extra() { } }" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public @Visible @Invisible class T { }" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"@t.Invisible\n" +
|
||||
"@t.Visible\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void extra();\n" +
|
||||
"}\n",
|
||||
"t.Visible",
|
||||
"package t;\n\n" +
|
||||
"@java.lang.annotation.Retention(RUNTIME)\n" +
|
||||
"@interface Visible {\n" +
|
||||
"}\n");
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"import java.util.*;" +
|
||||
"public class T {" +
|
||||
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"import java.util.*;" +
|
||||
"public class T {" +
|
||||
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
|
||||
" public void extra() { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void test(int arg0,\n" +
|
||||
" @t.Invisible int arg1,\n" +
|
||||
" @t.Visible java.util.List<java.lang.String> arg2,\n" +
|
||||
" int arg3);\n" +
|
||||
"}\n",
|
||||
"t.Visible",
|
||||
"package t;\n\n" +
|
||||
"@java.lang.annotation.Retention(RUNTIME)\n" +
|
||||
"@interface Visible {\n" +
|
||||
"}\n");
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public class T {" +
|
||||
" public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
|
||||
" public String v();" +
|
||||
" public String dv();" +
|
||||
"}",
|
||||
"package t;" +
|
||||
"public class T { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" +
|
||||
"}\n",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n" +
|
||||
"}\n");
|
||||
Set<String> extraAnnotations = Set.of("Ljava/lang/annotation/Retention;");
|
||||
CreateSymbols.HARDCODED_ANNOTATIONS.addAll(extraAnnotations);
|
||||
try {
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public @Visible @Invisible class T { public void extra() { } }" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public @Visible @Invisible class T { }" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"@t.Invisible\n" +
|
||||
"@t.Visible\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void extra();\n" +
|
||||
"}\n",
|
||||
"t.Visible",
|
||||
"package t;\n\n" +
|
||||
"@java.lang.annotation.Retention(RUNTIME)\n" +
|
||||
"@interface Visible {\n" +
|
||||
"}\n");
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"import java.util.*;" +
|
||||
"public class T {" +
|
||||
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"import java.util.*;" +
|
||||
"public class T {" +
|
||||
" public void test(int h, @Invisible int i, @Visible List<String> j, int k) { }" +
|
||||
" public void extra() { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Visible { }" +
|
||||
"@Retention(RetentionPolicy.CLASS) @interface Invisible { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void test(int arg0,\n" +
|
||||
" @t.Invisible int arg1,\n" +
|
||||
" @t.Visible java.util.List<java.lang.String> arg2,\n" +
|
||||
" int arg3);\n" +
|
||||
"}\n",
|
||||
"t.Visible",
|
||||
"package t;\n\n" +
|
||||
"@java.lang.annotation.Retention(RUNTIME)\n" +
|
||||
"@interface Visible {\n" +
|
||||
"}\n");
|
||||
doPrintElementTest("package t;" +
|
||||
"import java.lang.annotation.*;" +
|
||||
"public class T {" +
|
||||
" public void test(@Ann(v=\"url\", dv=\"\\\"\\\"\") String str) { }" +
|
||||
"}" +
|
||||
"@Retention(RetentionPolicy.RUNTIME) @interface Ann {" +
|
||||
" public String v();" +
|
||||
" public String dv();" +
|
||||
"}",
|
||||
"package t;" +
|
||||
"public class T { }",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n\n" +
|
||||
" public void test(@t.Ann(dv=\"\\\"\\\"\", v=\"url\") java.lang.String arg0);\n" +
|
||||
"}\n",
|
||||
"t.T",
|
||||
"package t;\n\n" +
|
||||
"public class T {\n\n" +
|
||||
" public T();\n" +
|
||||
"}\n");
|
||||
} finally {
|
||||
CreateSymbols.HARDCODED_ANNOTATIONS.removeAll(extraAnnotations);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -360,11 +366,70 @@ public class CreateSymbolsTestImpl {
|
||||
Expect.SUCCESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClearMissingAnnotations() throws Exception {
|
||||
doPrintElementTest(new String[] {
|
||||
"""
|
||||
package t;
|
||||
import t.impl.HC;
|
||||
import t.impl.HR;
|
||||
@HC @HR public class T {
|
||||
@HC @HR public static final int i = 0;
|
||||
@HC @HR public void t() {}
|
||||
}
|
||||
""",
|
||||
"""
|
||||
package t.impl;
|
||||
import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface HC {
|
||||
}
|
||||
""",
|
||||
"""
|
||||
package t.impl;
|
||||
import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface HR {
|
||||
}
|
||||
"""
|
||||
},
|
||||
new String[] {
|
||||
"""
|
||||
package t;
|
||||
public class T {
|
||||
public static final int i = 0;
|
||||
}
|
||||
"""
|
||||
},
|
||||
"t.T",
|
||||
"""
|
||||
package t;
|
||||
|
||||
public class T {
|
||||
public static final int i = 0;
|
||||
|
||||
public T();
|
||||
|
||||
public void t();
|
||||
}
|
||||
""",
|
||||
"t.T",
|
||||
"""
|
||||
package t;
|
||||
|
||||
public class T {
|
||||
public static final int i = 0;
|
||||
|
||||
public T();
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
void doTest(String code7, String code8, String testCode, Expect result7, Expect result8) throws Exception {
|
||||
ToolBox tb = new ToolBox();
|
||||
Path classes = prepareVersionedCTSym(code7, code8);
|
||||
Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
|
||||
Path output = classes.getParent();
|
||||
Path scratch = output.resolve("scratch");
|
||||
|
||||
@ -392,6 +457,10 @@ public class CreateSymbolsTestImpl {
|
||||
}
|
||||
|
||||
void doPrintElementTest(String code7, String code8, String className7, String printed7, String className8, String printed8) throws Exception {
|
||||
doPrintElementTest(new String[] {code7}, new String[] {code8}, className7, printed7, className8, printed8);
|
||||
}
|
||||
|
||||
void doPrintElementTest(String[] code7, String[] code8, String className7, String printed7, String className8, String printed8) throws Exception {
|
||||
ToolBox tb = new ToolBox();
|
||||
Path classes = prepareVersionedCTSym(code7, code8);
|
||||
Path output = classes.getParent();
|
||||
@ -419,7 +488,7 @@ public class CreateSymbolsTestImpl {
|
||||
}
|
||||
|
||||
void doTestEquivalence(String code7, String code8, String testClass) throws Exception {
|
||||
Path classes = prepareVersionedCTSym(code7, code8);
|
||||
Path classes = prepareVersionedCTSym(new String[] {code7}, new String[] {code8});
|
||||
Path classfile = classes.resolve("78").resolve("java.base").resolve(testClass.replace('.', '/') + ".class");
|
||||
|
||||
if (!Files.isReadable(classfile)) {
|
||||
@ -576,7 +645,7 @@ public class CreateSymbolsTestImpl {
|
||||
boolean oldIncludeAll = includeAll;
|
||||
try {
|
||||
includeAll = false;
|
||||
Path classes = prepareVersionedCTSym(code, "package other; public class Other {}");
|
||||
Path classes = prepareVersionedCTSym(new String[] {code}, new String[] {"package other; public class Other {}"});
|
||||
Path root = classes.resolve("7").resolve("java.base");
|
||||
try (Stream<Path> classFiles = Files.walk(root)) {
|
||||
Set<String> names = classFiles.map(p -> root.relativize(p))
|
||||
@ -595,7 +664,7 @@ public class CreateSymbolsTestImpl {
|
||||
}
|
||||
}
|
||||
|
||||
Path prepareVersionedCTSym(String code7, String code8) throws Exception {
|
||||
Path prepareVersionedCTSym(String[] code7, String[] code8) throws Exception {
|
||||
String testClasses = System.getProperty("test.classes");
|
||||
Path output = Paths.get(testClasses, "test-data" + i++);
|
||||
deleteRecursively(output);
|
||||
@ -694,6 +763,7 @@ public class CreateSymbolsTestImpl {
|
||||
return files.filter(p -> Files.isRegularFile(p))
|
||||
.filter(p -> p.getFileName().toString().endsWith(".class"))
|
||||
.map(p -> root.relativize(p).toString())
|
||||
.filter(p -> !p.contains("impl"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -128,16 +128,16 @@ public class ElementStructureTest {
|
||||
(byte) 0xB7, (byte) 0x52, (byte) 0x0F, (byte) 0x68
|
||||
};
|
||||
static final byte[] hash7 = new byte[] {
|
||||
(byte) 0x3C, (byte) 0x03, (byte) 0xEA, (byte) 0x4A,
|
||||
(byte) 0x62, (byte) 0xD2, (byte) 0x18, (byte) 0xE5,
|
||||
(byte) 0xA5, (byte) 0xC2, (byte) 0xB7, (byte) 0x85,
|
||||
(byte) 0x90, (byte) 0xFA, (byte) 0x98, (byte) 0xCD
|
||||
(byte) 0x45, (byte) 0xCA, (byte) 0x83, (byte) 0xCD,
|
||||
(byte) 0x1A, (byte) 0x68, (byte) 0x57, (byte) 0x9C,
|
||||
(byte) 0x6F, (byte) 0x2D, (byte) 0xEB, (byte) 0x28,
|
||||
(byte) 0xAB, (byte) 0x05, (byte) 0x53, (byte) 0x6E
|
||||
};
|
||||
static final byte[] hash8 = new byte[] {
|
||||
(byte) 0x24, (byte) 0x38, (byte) 0x52, (byte) 0x1C,
|
||||
(byte) 0x5E, (byte) 0x83, (byte) 0x82, (byte) 0xE6,
|
||||
(byte) 0x41, (byte) 0xC2, (byte) 0xDD, (byte) 0x2A,
|
||||
(byte) 0xFD, (byte) 0xFF, (byte) 0x5E, (byte) 0x2F
|
||||
(byte) 0x26, (byte) 0x8C, (byte) 0xFD, (byte) 0x61,
|
||||
(byte) 0x53, (byte) 0x00, (byte) 0x57, (byte) 0x10,
|
||||
(byte) 0x36, (byte) 0x2B, (byte) 0x92, (byte) 0x0B,
|
||||
(byte) 0xE1, (byte) 0x6A, (byte) 0xB5, (byte) 0xFD
|
||||
};
|
||||
|
||||
final static Map<String, byte[]> version2Hash = new HashMap<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user