Skip to content

Commit 2cf594d

Browse files
committed
Support Lombok
1 parent f8cd018 commit 2cf594d

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ intellij {
3737
pluginName = 'MapStruct-Intellij-Plugin'
3838
// The properties plugin is needed because Kotlin uses it
3939
// and for some reason plugins does not transitively pull itx
40-
plugins = ['java', 'Kotlin', 'properties']
40+
plugins = ['java', 'Kotlin', 'properties', 'Lombook Plugin:0.34-2020.1']
4141
}
4242

4343
compileKotlin {

src/main/java/org/mapstruct/intellij/codeinsight/references/MapstructTargetReference.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.intellij.psi.PsiType;
2121
import com.intellij.psi.PsiVariable;
2222
import com.intellij.psi.util.PsiUtil;
23+
import de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder;
2324
import org.jetbrains.annotations.NotNull;
2425
import org.jetbrains.annotations.Nullable;
2526
import org.mapstruct.intellij.util.MapStructVersion;
@@ -79,6 +80,12 @@ builderSupportPresent && isBuilderEnabled( getMappingMethod() )
7980
if ( constructor != null && constructor.hasParameters() ) {
8081
for ( PsiParameter parameter : constructor.getParameterList().getParameters() ) {
8182
if ( value.equals( parameter.getName() ) ) {
83+
if ( constructor instanceof LombokLightMethodBuilder ) {
84+
PsiField field = psiClass.findFieldByName( value, true );
85+
if ( field != null ) {
86+
return field;
87+
}
88+
}
8289
return parameter;
8390
}
8491
}

src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.intellij.psi.PsiClassObjectAccessExpression;
2828
import com.intellij.psi.PsiClassType;
2929
import com.intellij.psi.PsiElement;
30+
import com.intellij.psi.PsiField;
3031
import com.intellij.psi.PsiJavaCodeReferenceElement;
3132
import com.intellij.psi.PsiLanguageInjectionHost;
3233
import com.intellij.psi.PsiLiteralExpression;
@@ -181,6 +182,9 @@ public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull
181182
else if ( resolved instanceof PsiParameter ) {
182183
targetType = ( (PsiParameter) resolved ).getType();
183184
}
185+
else if ( resolved instanceof PsiField ) {
186+
targetType = ( (PsiField) resolved ).getType();
187+
}
184188
}
185189
}
186190
break;

src/main/java/org/mapstruct/intellij/util/TargetUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ public static PsiMethod resolveMappingConstructor(@NotNull PsiClass psiClass) {
210210
List<PsiMethod> accessibleConstructors = new ArrayList<>(constructors.length);
211211

212212
for ( PsiMethod constructor : constructors ) {
213-
if ( constructor.hasModifier( JvmModifier.PRIVATE ) ) {
214-
// private constructors are ignored
213+
if ( constructor.hasModifier( JvmModifier.PRIVATE ) || constructor.hasModifier( JvmModifier.PROTECTED ) ) {
214+
// private and protected constructors are ignored
215215
continue;
216216
}
217217
if ( !constructor.hasParameters() ) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
3+
Copyright MapStruct Authors.
4+
5+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
-->
8+
<idea-plugin>
9+
</idea-plugin>

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
3030
on how to target different products -->
3131
<depends>com.intellij.modules.java</depends>
32-
<depends optional="true" config-file="withKotlin.xml">org.jetbrains.kotlin</depends>
32+
<depends optional="true" config-file="org.mapstruct.intellij-withKotlin.xml">org.jetbrains.kotlin</depends>
33+
<depends optional="true" config-file="org.mapstruct.intellij-withLombok.xml">Lombook Plugin</depends>
3334

3435
<extensions defaultExtensionNs="com.intellij">
3536
<!-- Add your extensions here -->

0 commit comments

Comments
 (0)