|
7 | 7 |
|
8 | 8 | import com.intellij.openapi.util.TextRange; |
9 | 9 | import com.intellij.psi.PsiElement; |
10 | | -import com.intellij.psi.PsiLiteral; |
11 | 10 | import com.intellij.psi.PsiMethod; |
12 | 11 | import com.intellij.psi.PsiReferenceBase; |
13 | | -import com.intellij.psi.util.PsiTreeUtil; |
14 | 12 | import org.jetbrains.annotations.NotNull; |
15 | 13 | import org.jetbrains.annotations.Nullable; |
16 | | -import org.mapstruct.intellij.util.MapstructUtilKt; |
| 14 | +import org.jetbrains.uast.ULiteralExpression; |
| 15 | +import org.jetbrains.uast.UMethod; |
| 16 | +import org.jetbrains.uast.UastContextKt; |
| 17 | +import org.jetbrains.uast.UastUtils; |
17 | 18 |
|
18 | 19 | /** |
19 | 20 | * Base Reference for MapStruct. |
@@ -43,14 +44,13 @@ abstract class BaseReference extends PsiReferenceBase<PsiElement> { |
43 | 44 | @Nullable |
44 | 45 | PsiMethod getMappingMethod() { |
45 | 46 | PsiElement element = getElement(); |
46 | | - if ( element instanceof PsiLiteral ) { |
47 | | - return PsiTreeUtil.getParentOfType( element, PsiMethod.class ); |
| 47 | + ULiteralExpression expression = UastContextKt.toUElement( element, ULiteralExpression.class ); |
| 48 | + if ( expression != null ) { |
| 49 | + UMethod parent = UastUtils.getParentOfType( expression, UMethod.class ); |
| 50 | + if ( parent != null ) { |
| 51 | + return parent.getJavaPsi(); |
| 52 | + } |
48 | 53 | } |
49 | | - else if ( "KtStringTemplateExpression".equals( element.getClass().getSimpleName() ) ) { |
50 | | - // We cannot do an instanceOf check here because the kotlin class is optional |
51 | | - return MapstructUtilKt.getPsiMethod( element ); |
52 | | - } |
53 | | - |
54 | 54 | return null; |
55 | 55 | } |
56 | 56 | } |
0 commit comments