generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
clion/src/main/kotlin/cc/unitmesh/clion/oc/context/OcClassContextBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cc.unitmesh.clion.oc.context | ||
|
||
import cc.unitmesh.devti.context.ClassContext | ||
import cc.unitmesh.devti.context.builder.ClassContextBuilder | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.util.PsiTreeUtil.getChildrenOfTypeAsList | ||
import com.jetbrains.cidr.lang.psi.OCDeclaration | ||
import com.jetbrains.cidr.lang.psi.OCFunctionDeclaration | ||
import com.jetbrains.cidr.lang.psi.OCStructLike | ||
|
||
class OcClassContextBuilder : ClassContextBuilder { | ||
override fun getClassContext(psiElement: PsiElement, gatherUsages: Boolean): ClassContext? { | ||
|
||
if (psiElement !is OCStructLike) return null | ||
|
||
val symbol = psiElement.symbol ?: return null | ||
val locateDefinition = symbol.locateDefinition(psiElement.project) ?: return null | ||
|
||
if (locateDefinition !is OCStructLike) return null | ||
|
||
val definitionSymbol = locateDefinition.symbol ?: return null | ||
val text = locateDefinition.text | ||
val name = locateDefinition.name!! | ||
|
||
val functionDecls: List<PsiElement> = | ||
getChildrenOfTypeAsList(locateDefinition, OCFunctionDeclaration::class.java) | ||
val decls: List<*> = getChildrenOfTypeAsList(locateDefinition, OCDeclaration::class.java) | ||
|
||
val fields: MutableList<PsiElement> = mutableListOf() | ||
for (decl in decls) { | ||
if ((decl as OCDeclaration).declarators.isNotEmpty()) { | ||
fields.add(decl) | ||
} | ||
} | ||
|
||
val superClasses: List<String> = definitionSymbol.getBaseCppClasses(locateDefinition).map { it.name } | ||
|
||
return ClassContext( | ||
locateDefinition, | ||
text, | ||
name, | ||
functionDecls, | ||
fields, | ||
superClasses, | ||
emptyList() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters