Skip to content

Commit 3978833

Browse files
authored
#207 Use UAST to be able to support both K1 and K2 in the same time
1 parent 1b5cc39 commit 3978833

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/plugin.xml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
on how to target different products -->
3131
<depends>com.intellij.modules.java</depends>
3232
<depends optional="true" config-file="withKotlin.xml">org.jetbrains.kotlin</depends>
33+
<extensions defaultExtensionNs="org.jetbrains.kotlin">
34+
<supportsKotlinPluginMode supportsK2="true" />
35+
</extensions>
3336

3437
<extensions defaultExtensionNs="com.intellij">
3538
<!-- Add your extensions here -->

0 commit comments

Comments
 (0)