mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: enable Flexibile Constructor Bodies in non-preview language level 25 (IDEA-372971)
GitOrigin-RevId: c0b12174a7dc60cfdf662d7d6d3bc576e734e4d4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0f7374f17e
commit
76a10e63e4
@@ -104,7 +104,11 @@ enum class JavaFeature {
|
||||
IMPLICIT_CLASS_NAME_OUT_OF_SCOPE(LanguageLevel.JDK_22_PREVIEW, "feature.implicit.class.name.out.of.scope"),
|
||||
CLASSFILE_API(LanguageLevel.JDK_22_PREVIEW, "feature.classfile.api"),
|
||||
STREAM_GATHERERS(LanguageLevel.JDK_22_PREVIEW, "feature.stream.gatherers"),
|
||||
STATEMENTS_BEFORE_SUPER(LanguageLevel.JDK_22_PREVIEW, "feature.statements.before.super"),
|
||||
STATEMENTS_BEFORE_SUPER(LanguageLevel.JDK_22_PREVIEW, "feature.statements.before.super") {
|
||||
override fun isSufficient(useSiteLevel: LanguageLevel): Boolean {
|
||||
return super.isSufficient(useSiteLevel) || useSiteLevel.isAtLeast(LanguageLevel.JDK_25)
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Was a preview feature in Java 20 Preview.
|
||||
* Keep the implementation, as it could reappear in the future.
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
class FlexibleConstructorBodiesNotAvailable {
|
||||
boolean sideEffect() {
|
||||
System.out.println("hello");
|
||||
return Math.random() > 0.5;
|
||||
}
|
||||
|
||||
class X {
|
||||
X(boolean b) {}
|
||||
}
|
||||
|
||||
class Y extends X {
|
||||
Y(int i) {
|
||||
// side-effect cannot be extracted from super call
|
||||
super(sideEffect() && false);
|
||||
}
|
||||
|
||||
Y(long l) {
|
||||
// side-effect cannot be extracted from super call
|
||||
super(false & sideEffect());
|
||||
}
|
||||
|
||||
Y(double d) {
|
||||
// no side-effect extraction necessary
|
||||
super(<warning descr="'sideEffect() && true' can be simplified to 'sideEffect()'">sideEffect() && true</warning>);
|
||||
}
|
||||
|
||||
Y(float f) {
|
||||
// no side-effect extraction necessary
|
||||
super(<warning descr="'false && sideEffect()' can be simplified to 'false'">false && sideEffect()</warning>);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -40,13 +40,13 @@ class PointlessBooleanExpression {
|
||||
|
||||
class Y extends X {
|
||||
Y(int i) {
|
||||
// side-effect cannot be extracted from super call
|
||||
super(sideEffect() && false);
|
||||
// side-effect can be extracted from super call with Flexible Constructor Bodies
|
||||
super(<warning descr="'sideEffect() && false' can be simplified to 'false'">sideEffect() && false</warning>);
|
||||
}
|
||||
|
||||
Y(long l) {
|
||||
// side-effect cannot be extracted from super call
|
||||
super(false & sideEffect());
|
||||
// side-effect can be extracted from super call with Flexible Constructor Bodies
|
||||
super(<warning descr="'false & sideEffect()' can be simplified to 'false'">false & sideEffect()</warning>);
|
||||
}
|
||||
|
||||
Y(double d) {
|
||||
|
||||
+8
-3
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
@@ -243,7 +243,12 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
public void testIgnoreImplicitThisReferenceBeforeSuperSinceJdk7() { doTest(false); }
|
||||
public void testStatementsBeforeSuper() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22_PREVIEW, () -> doTest(false)); }
|
||||
public void testFlexibleConstructorBodies() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_23_PREVIEW, () -> doTest(false)); }
|
||||
|
||||
public void testFlexibleConstructorBodies() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_23_PREVIEW, () -> doTest(false));
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_25, () -> doTest(false));
|
||||
}
|
||||
|
||||
public void testCastFromVoid() { doTest(false); }
|
||||
public void testCatchUnknownMethod() { doTest(false); }
|
||||
public void testIDEADEV8822() { doTest(false); }
|
||||
@@ -289,7 +294,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
public boolean isEntryPoint(@NotNull PsiElement psiElement) {
|
||||
return psiElement instanceof PsiMethod && ((PsiMethod)psiElement).getName().equals("myTestMethod");
|
||||
return psiElement instanceof PsiMethod m && m.getName().equals("myTestMethod");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.refactoring.inline;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
@@ -267,8 +267,9 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testInSuperCall() {
|
||||
doTestConflict("Inline cannot be applied to multiline method in constructor call");
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22_PREVIEW, () -> doTest());
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTestConflict("Inline cannot be applied to multiline method in constructor call"));
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22_PREVIEW, this::doTest);
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_25, this::doTest);
|
||||
}
|
||||
|
||||
public void testMethodReferenceInsideMethodCall() {
|
||||
@@ -394,7 +395,8 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testUnableToInlineCodeBlockToSuper() {
|
||||
doTestConflict("Inline cannot be applied to multiline method in constructor call");
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21,
|
||||
() -> doTestConflict("Inline cannot be applied to multiline method in constructor call"));
|
||||
}
|
||||
|
||||
public void testRedundantCastOnMethodReferenceToLambda() {
|
||||
|
||||
+7
-1
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -55,6 +57,10 @@ public class PointlessBooleanExpressionInspectionTest extends LightJavaInspectio
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFlexibleConstructorBodiesNotAvailable() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, this::doTest);
|
||||
}
|
||||
|
||||
public void testRegression() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user