mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[java-debugger] IDEA-367755 Stream trace debugging gives Internal Error in implicitly declared class
- set language level explicitly (cherry picked from commit 01b844c4f0d812c4505491121429af3cc7df24c5) IJ-CR-159083 GitOrigin-RevId: d6cca2ad6ad3a3717d27bba341419cb0c236833a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
206476236e
commit
0ff6bc9f98
@@ -8,6 +8,7 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
@@ -55,6 +56,11 @@ public final class ExtractLightMethodObjectHandler {
|
||||
final PsiFile copy = PsiFileFactory.getInstance(project)
|
||||
.createFileFromText(file.getName(), file.getFileType(), file.getText(), file.getModificationStamp(), false);
|
||||
|
||||
if (copy instanceof PsiJavaFile copyJavaFile && file instanceof PsiJavaFile originalJavaFile) {
|
||||
LanguageLevel level = PsiUtil.getLanguageLevel(originalJavaFile);
|
||||
PsiUtil.FILE_LANGUAGE_LEVEL_KEY.set(copyJavaFile, level);
|
||||
}
|
||||
|
||||
if (originalContext instanceof PsiKeyword && PsiModifier.PRIVATE.equals(originalContext.getText())) {
|
||||
final PsiNameIdentifierOwner identifierOwner = PsiTreeUtil.getParentOfType(originalContext, PsiNameIdentifierOwner.class);
|
||||
if (identifierOwner != null) {
|
||||
|
||||
@@ -32,13 +32,14 @@ public final class ImplicitlyImportedModule implements ImplicitlyImportedElement
|
||||
}
|
||||
|
||||
private static @NotNull PsiImportModuleStatement createImportStatementInner(@NotNull Project project, @NotNull String moduleName) {
|
||||
PsiElementFactory factory = PsiElementFactory.getInstance(project);
|
||||
if (PsiJavaModule.JAVA_BASE.equals(moduleName)) {
|
||||
return CachedValuesManager.getManager(project).getCachedValue(project, () -> {
|
||||
PsiElementFactory factory = PsiElementFactory.getInstance(project);
|
||||
return CachedValueProvider.Result.create(factory.createImportModuleStatementFromText(PsiJavaModule.JAVA_BASE),
|
||||
ProjectRootModificationTracker.getInstance(project));
|
||||
});
|
||||
}
|
||||
PsiElementFactory factory = PsiElementFactory.getInstance(project);
|
||||
return factory.createImportModuleStatementFromText(moduleName);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
List<String> strings = readNonEmptyLines();
|
||||
strings.forEach(System.out::println);
|
||||
}
|
||||
|
||||
private static List<String> readNonEmptyLines() throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("somePath"))) {
|
||||
<caret>
|
||||
return reader.lines().filter(l -> !l.isBlank()).filter(l -> !l.startsWith("a")).filter(l -> l.length() > 3).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
call text: BufferedReader result = new Test(reader).invoke();
|
||||
class:
|
||||
public class GeneratedEvaluationClass {
|
||||
private BufferedReader reader;
|
||||
|
||||
public GeneratedEvaluationClass(BufferedReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public BufferedReader invoke() {
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,15 @@
|
||||
package com.intellij.java.refactoring;
|
||||
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.JavaCodeFragment;
|
||||
import com.intellij.psi.JavaCodeFragmentFactory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.extractMethod.PrepareFailedException;
|
||||
import com.intellij.refactoring.extractMethodObject.ExtractLightMethodObjectHandler;
|
||||
import com.intellij.refactoring.extractMethodObject.LightMethodObjectExtractedData;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -15,6 +18,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author Vitaliy.Bibaev
|
||||
*/
|
||||
public class ExtractMethodObject4DebuggerReflectionTest extends LightRefactoringTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk21();
|
||||
}
|
||||
|
||||
public void testAccessField() throws PrepareFailedException {
|
||||
doTest("System.out.println(instance.field)");
|
||||
}
|
||||
@@ -51,15 +60,33 @@ public class ExtractMethodObject4DebuggerReflectionTest extends LightRefactoring
|
||||
doTest("new Inner()");
|
||||
}
|
||||
|
||||
public void testLanguageLevelImplicitClasses() {
|
||||
IdeaTestUtil.withLevel(getModule(), JavaFeature.PACKAGE_IMPORTS_SHADOW_MODULE_IMPORTS.getMinimumLevel(), () -> {
|
||||
String testName = getTestName(false);
|
||||
String pathToSource = "/" + testName + ".java";
|
||||
try {
|
||||
doTest("reader", pathToSource);
|
||||
}
|
||||
catch (PrepareFailedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/refactoring/extractMethodObject4Debugger";
|
||||
}
|
||||
|
||||
private void doTest(String evaluatedText) throws PrepareFailedException {
|
||||
private void doTest(@NotNull String evaluatedText) throws PrepareFailedException {
|
||||
String path = "/WithReflectionAccess.java";
|
||||
doTest(evaluatedText, path);
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String evaluatedText, @NotNull String pathToSource) throws PrepareFailedException {
|
||||
String testName = getTestName(true);
|
||||
configureByFile("/WithReflectionAccess.java");
|
||||
configureByFile(pathToSource);
|
||||
final int offset = getEditor().getCaretModel().getOffset();
|
||||
final PsiElement context = getFile().findElementAt(offset);
|
||||
final JavaCodeFragmentFactory fragmentFactory = JavaCodeFragmentFactory.getInstance(getProject());
|
||||
|
||||
Reference in New Issue
Block a user