Skip to content

Add K2 support #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading