Skip to content

Commit

Permalink
Revert "master to beta java 22 merge (#1837)"
Browse files Browse the repository at this point in the history
This reverts commit 220c841.
  • Loading branch information
mpalat committed Jan 11, 2024
1 parent 220c841 commit 34b5d93
Show file tree
Hide file tree
Showing 26 changed files with 3,510 additions and 3,726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,17 @@ public TypeBinding resolveType(BlockScope scope) {
}

collectPatternVariablesToScope(null, scope);
LocalVariableBinding[] patternVariablesInTrueScope = this.condition.getPatternVariablesWhenTrue();
LocalVariableBinding[] patternVariablesInFalseScope = this.condition.getPatternVariablesWhenFalse();

if (this.constant != Constant.NotAConstant) {
this.constant = Constant.NotAConstant;
TypeBinding conditionType = this.condition.resolveTypeExpecting(scope, TypeBinding.BOOLEAN);
this.condition.computeConversion(scope, TypeBinding.BOOLEAN, conditionType);

if (this.valueIfTrue instanceof CastExpression) this.valueIfTrue.bits |= DisableUnnecessaryCastCheck; // will check later on
this.originalValueIfTrueType = this.valueIfTrue.resolveTypeWithPatternVariablesInScope(patternVariablesInTrueScope, scope);
this.originalValueIfTrueType = this.valueIfTrue.resolveType(scope);

if (this.valueIfFalse instanceof CastExpression) this.valueIfFalse.bits |= DisableUnnecessaryCastCheck; // will check later on
this.originalValueIfFalseType = this.valueIfFalse.resolveTypeWithPatternVariablesInScope(patternVariablesInFalseScope, scope);
this.originalValueIfFalseType = this.valueIfFalse.resolveType(scope);

if (conditionType == null || this.originalValueIfTrueType == null || this.originalValueIfFalseType == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.eclipse.jdt.internal.compiler.lookup.InferenceContext18;
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
Expand Down Expand Up @@ -1163,21 +1162,6 @@ public TypeBinding resolveExpressionType(BlockScope scope) {
return resolveType(scope);
}

public TypeBinding resolveTypeWithPatternVariablesInScope(LocalVariableBinding[] patternVariablesInScope, BlockScope scope) {
if (patternVariablesInScope != null) {
for (LocalVariableBinding binding : patternVariablesInScope) {
binding.modifiers &= ~ExtraCompilerModifiers.AccPatternVariable;
}
}
TypeBinding retVal = this.resolveType(scope);
if (patternVariablesInScope != null) {
for (LocalVariableBinding binding : patternVariablesInScope) {
binding.modifiers |= ExtraCompilerModifiers.AccPatternVariable;
}
}
return retVal;
}

/**
* Resolve the type of this expression in the context of a blockScope
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4902,9 +4902,8 @@ private VanguardScanner getNewVanguardScanner() {
return vs;
}
protected final boolean mayBeAtCasePattern(int token) {
return ((token == TokenNamecase || this.multiCaseLabelComma)
&& JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(this.complianceLevel, this.previewEnabled))
&& !isInModuleDeclaration();
return (!isInModuleDeclaration() && JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(this.complianceLevel, this.previewEnabled))
&& (token == TokenNamecase || this.multiCaseLabelComma);
}
protected final boolean maybeAtLambdaOrCast() { // Could the '(' we saw just now herald a lambda parameter list or a cast expression ? (the possible locations for both are identical.)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public X() {
String address;
String doc = STR.\"""\n{\\n \\\"name\\\": \\\"\\{STR.\"\\{<SelectOnName:name>}\"}\\\",\\n \\\"phone\\\": \\\"\\{phone}\\\",\\n \\\"address\\\": \\\"\\{address}\\\"\\n};\""";
}
}
}
""";
String expectedReplacedSource = "name";
String testName = "X.java";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10566,7 +10566,7 @@ public static void main(String[] args) {
.collect(Collectors.toCollection(() -> new ArrayList<>(strings.size())));
System.out.println(collectedStrings);
}
}
}
"""
},
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4230,7 +4230,7 @@ public static void main(String [] args) {
return switch (a) {
^
A switch expression should have a default case
----------
----------
""",
false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9702,7 +9702,7 @@ public static void main(String[] args) {
}
}
}
"""
},
"true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6474,7 +6474,7 @@ public String demo(String input) {
}
};
}
}
}
"""
},
"");
Expand Down Expand Up @@ -6602,159 +6602,4 @@ public static void main(String[] args) {
},
"");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1820
// [switch] Switch expression fails with instanceof + ternary operator combo
public void testGHI1820() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public class X {
static String method(Object element, int columnIndex) {
return element instanceof String data ?
switch (columnIndex) {
case 0 -> data;
case 1 -> data.toUpperCase();
default -> "Done";
} : "";
}
public static void main(String[] args) {
System.out.println(method("Blah", 0));
System.out.println(method("Blah", 1));
System.out.println(method("Blah", 10));
}
}
"""
},
"Blah\n"
+ "BLAH\n"
+ "Done");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1820
// [switch] Switch expression fails with instanceof + ternary operator combo
public void testGHI1820_2() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runNegativeTest(
new String[] {
"X.java",
"""
public class X {
static String method(Object element, int columnIndex) {
return element instanceof String data ? "" :
switch (columnIndex) {
case 0 -> data;
case 1 -> data.toUpperCase();
default -> "";
};
}
public static void main(String[] args) {
System.out.println(method("Blah", 1));
}
}
"""
},
"----------\n"
+ "1. ERROR in X.java (at line 5)\n"
+ " case 0 -> data;\n"
+ " ^^^^\n"
+ "data cannot be resolved to a variable\n"
+ "----------\n"
+ "2. ERROR in X.java (at line 6)\n"
+ " case 1 -> data.toUpperCase();\n"
+ " ^^^^\n"
+ "data cannot be resolved\n"
+ "----------\n");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1820
// [switch] Switch expression fails with instanceof + ternary operator combo
public void testGHI1820_3() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public class X {
static String method(Object element, int columnIndex) {
return element instanceof String data ?
switch (columnIndex) {
case 0 -> { yield data; }
case 1 -> data.toUpperCase();
default -> "";
} : "";
}
public static void main(String[] args) {
System.out.println(method("Blah", 1));
}
}
"""
},
"BLAH");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1820
// [switch] Switch expression fails with instanceof + ternary operator combo
public void testGHI1820_4() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public class X {
static String method(Object element, int columnIndex) {
return !(element instanceof String data) ? "" :
switch (columnIndex) {
case 0 -> data;
case 1 -> data.toUpperCase();
default -> "Done";
};
}
public static void main(String[] args) {
System.out.println(method("Blah", 0));
System.out.println(method("Blah", 1));
System.out.println(method("Blah", 10));
}
}
"""
},
"Blah\n"
+ "BLAH\n"
+ "Done");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1820
// [switch] Switch expression fails with instanceof + ternary operator combo
public void testGHI1820_5() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public class X {
static String method(Object element, int columnIndex) {
if (element instanceof String string) {
return element instanceof String data ?
switch (columnIndex) {
case 0 -> data;
case 1 -> string.toUpperCase();
default -> "Done";
} : "";
}
return null;
}
public static void main(String[] args) {
System.out.println(method("Blah", 0));
System.out.println(method("Blah", 1));
System.out.println(method("Blah", 10));
}
}
"""
},
"Blah\n"
+ "BLAH\n"
+ "Done");
}
}
3 changes: 1 addition & 2 deletions org.eclipse.jdt.core.tests.model/forceQualifierUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# To force a version qualifier update, add the bug here
Bug 489604 - should not override <timestampProvider>
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1184
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1659
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1704
https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1659
Original file line number Diff line number Diff line change
Expand Up @@ -9575,19 +9575,5 @@ public void testASTLevels() throws Exception {
AST a = new AST(options);
assertEquals("Incorrect ast mapping", a.apiLevel(), AST.getJLSLatest());
}

@SuppressWarnings("deprecation")
public void testDimension() {
// Introduced with JSL8
if (this.ast.apiLevel() < AST.JLS8) {
return;
}
Dimension dimension = this.ast.newDimension();
dimension.setSourceRange(1, 2);

Dimension copy = (Dimension) ASTNode.copySubtree(this.ast, dimension);
assertEquals(copy.getStartPosition(), 1);
assertEquals(copy.getLength(), 2);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13378,7 +13378,7 @@ private void foo(String a) {
// foo
// bar
}
}
}
""";
formatSource(source,
"""
Expand All @@ -13391,7 +13391,7 @@ private void foo(String a) {
// foo
// bar
}
}
}
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1411,13 +1411,13 @@ public void testJoinLineComment01() {
class A {
int a = 5; // one two
// three
}
}
""";
formatSource(source,
"""
class A {
int a = 5; // one two three
}
}
""");
}
public void testJoinLineComment02() {
Expand All @@ -1427,14 +1427,14 @@ public void testJoinLineComment02() {
class A {
int a = 5; // one two
// three
}
}
""";
formatSource(source,
"""
class A {
int a = 5; // one two
// three
}
}
""");
}
public void testJoinLineComment03() {
Expand All @@ -1444,14 +1444,14 @@ public void testJoinLineComment03() {
class A {
int a = 5; // one two
// three
}
}
""";
formatSource(source,
"""
class A {
int a = 5; // one two
// three
}
}
""");
}
public void testJoinLineComment04() {
Expand All @@ -1466,7 +1466,7 @@ class A {
// seventeen eighteen nineteen
// one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen
// one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen
}
}
""";
formatSource(source,
"""
Expand All @@ -1478,7 +1478,7 @@ class A {
// eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen
// one two three four five six seven eight nine ten eleven twelve thirteen
// fourteen fifteen sixteen seventeen eighteen nineteen
}
}
""");
}
}

0 comments on commit 34b5d93

Please sign in to comment.