mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
encode qualifiers in method refs (IDEA-145512)
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -38,8 +39,10 @@ public class JavaTreeCopyHandler implements TreeCopyHandler {
|
||||
public TreeElement decodeInformation(TreeElement element, final Map<Object, Object> decodingState) {
|
||||
boolean shallDecodeEscapedTexts = shallEncodeEscapedTexts(element, decodingState);
|
||||
if (element instanceof CompositeElement) {
|
||||
if (element.getElementType() == JavaElementType.JAVA_CODE_REFERENCE ||
|
||||
element.getElementType() == JavaElementType.REFERENCE_EXPRESSION) {
|
||||
final IElementType elementType = element.getElementType();
|
||||
if (elementType == JavaElementType.JAVA_CODE_REFERENCE ||
|
||||
elementType == JavaElementType.REFERENCE_EXPRESSION ||
|
||||
elementType == JavaElementType.METHOD_REF_EXPRESSION) {
|
||||
PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(element);
|
||||
final PsiClass refClass = element.getCopyableUserData(JavaTreeGenerator.REFERENCED_CLASS_KEY);
|
||||
if (refClass != null) {
|
||||
@@ -190,7 +193,8 @@ public class JavaTreeCopyHandler implements TreeCopyHandler {
|
||||
final JavaResolveResult resolveResult = javaRefElement.advancedResolve(false);
|
||||
final PsiElement target = resolveResult.getElement();
|
||||
if (target instanceof PsiClass &&
|
||||
original.getTreeParent().getElementType() == JavaElementType.REFERENCE_EXPRESSION) {
|
||||
(original.getTreeParent().getElementType() == JavaElementType.REFERENCE_EXPRESSION ||
|
||||
original.getTreeParent().getElementType() == JavaElementType.METHOD_REF_EXPRESSION)) {
|
||||
ref.putCopyableUserData(JavaTreeGenerator.REFERENCED_CLASS_KEY, (PsiClass)target);
|
||||
}
|
||||
else if ((target instanceof PsiMethod || target instanceof PsiField) &&
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Bar {
|
||||
void bar() {
|
||||
Function<Map.Entry<Long, Set<Integer>>, Long> getKey = Map.Entry::getKey;
|
||||
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Foo {
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class Bar {
|
||||
void bar() {
|
||||
Foo.foo();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Foo {
|
||||
public static void foo() {
|
||||
|
||||
Function<Entry<Long, Set<Integer>>, Long> getKey = Entry::getKey;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,10 @@ public class InlineMethodMultifileTest extends RefactoringTestCase {
|
||||
doTest("Foo", "foo");
|
||||
}
|
||||
|
||||
public void testDecodeQualifierInMethodReference() throws Exception {
|
||||
doTest("Foo", "foo");
|
||||
}
|
||||
|
||||
private void doTest(String className, String methodName) throws Exception {
|
||||
String rootBefore = getRoot() + "/before";
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
|
||||
Reference in New Issue
Block a user