mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
compiling debugger: shift original context if on private, so 'make public' won't invalidate anchor (IDEA-132525)
This commit is contained in:
+12
-1
@@ -85,10 +85,21 @@ public class ExtractLightMethodObjectHandler {
|
||||
final PsiFile copy = PsiFileFactory.getInstance(project)
|
||||
.createFileFromText(file.getName(), file.getFileType(), file.getText(), file.getModificationStamp(), false);
|
||||
|
||||
final PsiElement originalContext = fragment.getContext();
|
||||
PsiElement originalContext = fragment.getContext();
|
||||
if (originalContext == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (originalContext instanceof PsiKeyword && PsiModifier.PRIVATE.equals(originalContext.getText())) {
|
||||
final PsiNameIdentifierOwner identifierOwner = PsiTreeUtil.getParentOfType(originalContext, PsiNameIdentifierOwner.class);
|
||||
if (identifierOwner != null) {
|
||||
final PsiElement identifier = identifierOwner.getNameIdentifier();
|
||||
if (identifier != null) {
|
||||
originalContext = identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final TextRange range = originalContext.getTextRange();
|
||||
final PsiElement originalAnchor =
|
||||
CodeInsightUtil.findElementInRange(copy, range.getStartOffset(), range.getEndOffset(), originalContext.getClass());
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Sample {
|
||||
pri<caret>vate int field;
|
||||
|
||||
int foo() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+10
@@ -264,6 +264,16 @@ public class ExtractMethodObject4DebuggerTest extends LightRefactoringTestCase {
|
||||
" }");
|
||||
}
|
||||
|
||||
public void testOnPrivateField() throws Exception {
|
||||
doTest(" foo()", "int result = new Test().invoke();",
|
||||
|
||||
"public class Test {\n" +
|
||||
" public int invoke() {\n" +
|
||||
" return foo();\n" +
|
||||
" }\n" +
|
||||
" }");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
|
||||
Reference in New Issue
Block a user