Skip to content

Commit

Permalink
#207 Use UAST to be able to support both K1 and K2 in the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr authored Oct 20, 2024
1 parent 1b5cc39 commit 3978833
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
import com.intellij.patterns.PsiElementPattern;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
import org.jetbrains.uast.UAnnotation;
import org.jetbrains.uast.UastContextKt;

/**
* @author Filip Hrisafov
Expand All @@ -32,20 +29,12 @@ public KtAnnotationEntryPattern qName(ElementPattern<String> pattern) {
return with( new PatternCondition<KtAnnotationEntry>( "qName" ) {
@Override
public boolean accepts(@NotNull KtAnnotationEntry ktAnnotation, ProcessingContext context) {
AnnotationDescriptor descriptor = ResolutionUtils.analyze(
ktAnnotation,
BodyResolveMode.PARTIAL_FOR_COMPLETION
).get( BindingContext.ANNOTATION, ktAnnotation );

if ( descriptor == null ) {
return false;
}

FqName fqName = descriptor.getFqName();
if ( fqName == null ) {
UAnnotation uElement = UastContextKt.toUElement( ktAnnotation, UAnnotation.class );
if ( uElement == null ) {
return false;
}
return pattern.accepts( fqName.asString(), context );
String name = uElement.getQualifiedName();
return pattern.accepts( name, context );
}
} );
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
on how to target different products -->
<depends>com.intellij.modules.java</depends>
<depends optional="true" config-file="withKotlin.xml">org.jetbrains.kotlin</depends>
<extensions defaultExtensionNs="org.jetbrains.kotlin">
<supportsKotlinPluginMode supportsK2="true" />
</extensions>

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
Expand Down

0 comments on commit 3978833

Please sign in to comment.