Skip to content

Commit 15bf835

Browse files
committed
#207 Use Uast to be able to support both K1 and K2 in the same time
1 parent 1b5cc39 commit 15bf835

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

Diff for: src/main/java/org/mapstruct/intellij/util/patterns/KtAnnotationEntryPattern.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import com.intellij.patterns.PsiElementPattern;
1111
import com.intellij.util.ProcessingContext;
1212
import org.jetbrains.annotations.NotNull;
13-
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
14-
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
15-
import org.jetbrains.kotlin.name.FqName;
1613
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
17-
import org.jetbrains.kotlin.resolve.BindingContext;
18-
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
14+
import org.jetbrains.uast.UAnnotation;
15+
import org.jetbrains.uast.UastContextKt;
1916

2017
/**
2118
* @author Filip Hrisafov
@@ -32,20 +29,12 @@ public KtAnnotationEntryPattern qName(ElementPattern<String> pattern) {
3229
return with( new PatternCondition<KtAnnotationEntry>( "qName" ) {
3330
@Override
3431
public boolean accepts(@NotNull KtAnnotationEntry ktAnnotation, ProcessingContext context) {
35-
AnnotationDescriptor descriptor = ResolutionUtils.analyze(
36-
ktAnnotation,
37-
BodyResolveMode.PARTIAL_FOR_COMPLETION
38-
).get( BindingContext.ANNOTATION, ktAnnotation );
39-
40-
if ( descriptor == null ) {
41-
return false;
42-
}
43-
44-
FqName fqName = descriptor.getFqName();
45-
if ( fqName == null ) {
32+
UAnnotation uElement = UastContextKt.toUElement( ktAnnotation, UAnnotation.class );
33+
if ( uElement == null ) {
4634
return false;
4735
}
48-
return pattern.accepts( fqName.asString(), context );
36+
String name = uElement.getQualifiedName();
37+
return pattern.accepts( name, context );
4938
}
5039
} );
5140
}

Diff for: src/main/resources/META-INF/withKotlin.xml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
77
-->
88
<idea-plugin>
9+
<extensions defaultExtensionNs="org.jetbrains.kotlin">
10+
<supportsKotlinPluginMode supportsK2="true" />
11+
</extensions>
912
<extensions defaultExtensionNs="com.intellij">
1013
<psi.referenceContributor language="kotlin" implementation="org.mapstruct.intellij.codeinsight.references.MapstructKotlinReferenceContributor" />
1114
</extensions>

0 commit comments

Comments
 (0)