-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathLombokUtil.java
More file actions
56 lines (47 loc) · 1.6 KB
/
LombokUtil.java
File metadata and controls
56 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.intellij.util;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
/**
* @author Filip Hrisafov
*/
public final class LombokUtil {
private static final Class<?> LOMBOK_LIGHT_METHOD;
static {
Class<?> lombokLightMethod;
try {
lombokLightMethod = Class.forName( "de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder" );
}
catch ( ClassNotFoundException e ) {
lombokLightMethod = null;
}
LOMBOK_LIGHT_METHOD = lombokLightMethod;
}
private LombokUtil() {
}
public static boolean isLombokLightMethod(PsiMethod method) {
if ( LOMBOK_LIGHT_METHOD != null ) {
return LOMBOK_LIGHT_METHOD.isInstance( method );
}
return false;
}
public static PsiElement resolvePsiElementForMethod(PsiMethod method, String value, PsiClass psiClass) {
return resolvePsiElement( method, method, value, psiClass );
}
public static PsiElement resolvePsiElement(PsiMethod method, PsiElement currentResolved, String value,
PsiClass psiClass) {
if ( isLombokLightMethod( method ) ) {
PsiField field = psiClass.findFieldByName( value, true );
if ( field != null ) {
return field;
}
}
return currentResolved;
}
}