|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "metadata": {}, |
| 5 | + "cell_type": "markdown", |
| 6 | + "source": [ |
| 7 | + "# Search Current Project Elements\n", |
| 8 | + "\n", |
| 9 | + "This simple notebook presents how to search through the current project to find out a list of methods annotated with some annotation." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "metadata": { |
| 15 | + "collapsed": true, |
| 16 | + "executionRelatedData": { |
| 17 | + "compiledClasses": [ |
| 18 | + "Line_3_jupyter", |
| 19 | + "Line_4_jupyter" |
| 20 | + ] |
| 21 | + }, |
| 22 | + "ExecuteTime": { |
| 23 | + "end_time": "2025-11-11T16:22:23.015190Z", |
| 24 | + "start_time": "2025-11-11T16:22:22.217954Z" |
| 25 | + } |
| 26 | + }, |
| 27 | + "source": "%use intellij-platform", |
| 28 | + "outputs": [ |
| 29 | + { |
| 30 | + "data": { |
| 31 | + "text/plain": [ |
| 32 | + "IntelliJ Platform integration is loaded" |
| 33 | + ] |
| 34 | + }, |
| 35 | + "metadata": {}, |
| 36 | + "output_type": "display_data", |
| 37 | + "jetTransient": { |
| 38 | + "display_id": null |
| 39 | + } |
| 40 | + } |
| 41 | + ], |
| 42 | + "execution_count": 1 |
| 43 | + }, |
| 44 | + { |
| 45 | + "metadata": { |
| 46 | + "executionRelatedData": { |
| 47 | + "compiledClasses": [ |
| 48 | + "Line_5_jupyter", |
| 49 | + "Line_6_jupyter" |
| 50 | + ] |
| 51 | + }, |
| 52 | + "ExecuteTime": { |
| 53 | + "end_time": "2025-11-11T16:22:27.601377Z", |
| 54 | + "start_time": "2025-11-11T16:22:23.015925Z" |
| 55 | + } |
| 56 | + }, |
| 57 | + "cell_type": "code", |
| 58 | + "source": "loadBundledPlugins(\"org.jetbrains.kotlin\", \"com.intellij.java\")", |
| 59 | + "outputs": [], |
| 60 | + "execution_count": 2 |
| 61 | + }, |
| 62 | + { |
| 63 | + "metadata": { |
| 64 | + "executionRelatedData": { |
| 65 | + "compiledClasses": [ |
| 66 | + "Line_7_jupyter", |
| 67 | + "Line_10_jupyter", |
| 68 | + "Line_8_jupyter" |
| 69 | + ] |
| 70 | + }, |
| 71 | + "ExecuteTime": { |
| 72 | + "end_time": "2025-11-11T16:22:28.577394Z", |
| 73 | + "start_time": "2025-11-11T16:22:27.603350Z" |
| 74 | + } |
| 75 | + }, |
| 76 | + "cell_type": "code", |
| 77 | + "source": [ |
| 78 | + "import com.intellij.openapi.application.runReadAction\n", |
| 79 | + "import com.intellij.openapi.project.Project\n", |
| 80 | + "import com.intellij.psi.PsiMethod\n", |
| 81 | + "import com.intellij.psi.PsiClass\n", |
| 82 | + "import com.intellij.psi.JavaPsiFacade\n", |
| 83 | + "import com.intellij.psi.search.GlobalSearchScope\n", |
| 84 | + "import com.intellij.psi.search.searches.AnnotatedElementsSearch\n", |
| 85 | + "import com.intellij.psi.util.PsiTreeUtil\n", |
| 86 | + "\n", |
| 87 | + "val project = currentProject()\n", |
| 88 | + "val scope = GlobalSearchScope.allScope(project)\n", |
| 89 | + "val annotationFqName = \"org.jetbrains.kotlinx.dataframe.annotations.Refine\"\n", |
| 90 | + "\n", |
| 91 | + "runReadAction {\n", |
| 92 | + " val annotationClass: PsiClass = JavaPsiFacade.getInstance(project)\n", |
| 93 | + " .findClass(annotationFqName, scope)!!\n", |
| 94 | + "\n", |
| 95 | + " AnnotatedElementsSearch.searchElements(\n", |
| 96 | + " annotationClass,\n", |
| 97 | + " scope,\n", |
| 98 | + " PsiMethod::class.java\n", |
| 99 | + " ).findAll().map { it as PsiMethod }\n", |
| 100 | + "}" |
| 101 | + ], |
| 102 | + "outputs": [ |
| 103 | + { |
| 104 | + "data": { |
| 105 | + "text/plain": [ |
| 106 | + "[KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:UngroupKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:InsertKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:InsertKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:UpdateKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:ConstructorsKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:MoveKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:RemoveKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:SelectKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:FlattenKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:GroupByKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:GroupKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:AddKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledDeclaration of PsiFile:GroupBy.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledDeclaration of PsiFile:GroupBy.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:AggregateKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:RenameKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:FlattenKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:InsertKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:JsonKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:MapKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:JsonKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:ValueCountsKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:InsertKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:AddIdKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:JoinKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:ExplodeKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:NullsKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledDeclaration of PsiFile:DataFrameBuilder.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledDeclaration of PsiFile:DataFrameBuilder.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:InsertKt.class, KtLightMethodForDecompiledDeclaration of KtLightClassForDecompiledFacade of PsiFile:CsvKt.class]" |
| 107 | + ] |
| 108 | + }, |
| 109 | + "execution_count": 3, |
| 110 | + "metadata": {}, |
| 111 | + "output_type": "execute_result" |
| 112 | + } |
| 113 | + ], |
| 114 | + "execution_count": 3 |
| 115 | + }, |
| 116 | + { |
| 117 | + "metadata": {}, |
| 118 | + "cell_type": "markdown", |
| 119 | + "source": "The `currentProject` function provided by the Kotlin Notebook IntelliJ Platform integration returns a [`Project`](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/project/Project.java) instance that refers to the currently open project." |
| 120 | + } |
| 121 | + ], |
| 122 | + "metadata": { |
| 123 | + "kernelspec": { |
| 124 | + "display_name": "Kotlin", |
| 125 | + "language": "kotlin", |
| 126 | + "name": "kotlin" |
| 127 | + }, |
| 128 | + "language_info": { |
| 129 | + "name": "kotlin", |
| 130 | + "version": "2.2.20-dev-4982", |
| 131 | + "mimetype": "text/x-kotlin", |
| 132 | + "file_extension": ".kt", |
| 133 | + "pygments_lexer": "kotlin", |
| 134 | + "codemirror_mode": "text/x-kotlin", |
| 135 | + "nbconvert_exporter": "" |
| 136 | + }, |
| 137 | + "ktnbPluginMetadata": { |
| 138 | + "sessionRunMode": "IDE_PROCESS" |
| 139 | + } |
| 140 | + }, |
| 141 | + "nbformat": 4, |
| 142 | + "nbformat_minor": 0 |
| 143 | +} |
0 commit comments