Skip to content

Commit

Permalink
feat(java): add method to find nearest target element
Browse files Browse the repository at this point in the history
Add a new method `findNearestTarget` to locate the nearest target element in the JavaElementStrategyBuilder class.
  • Loading branch information
phodal committed Jun 6, 2024
1 parent a4d571a commit 3cf769c
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.phodal.shirelang.java.impl

import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.*
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import com.phodal.shirecore.codemodel.model.ClassStructure
import com.phodal.shirecore.provider.PsiElementStrategyBuilder
import com.phodal.shirelang.java.codemodel.JavaClassStructureProvider
Expand All @@ -22,4 +20,17 @@ class JavaElementStrategyBuilder : PsiElementStrategyBuilder {
override fun relativeElement(project: Project, givenElement: PsiElement, type: PsiComment): PsiElement? {
TODO("Not yet implemented")
}

fun findNearestTarget(psiElement: PsiElement): PsiNameIdentifierOwner? {

Check warning on line 24 in languages/java/src/main/kotlin/com/phodal/shirelang/java/impl/JavaElementStrategyBuilder.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "findNearestTarget" is never used
if (psiElement is PsiMethod || psiElement is PsiClass) return psiElement as PsiNameIdentifierOwner

val closestIdentifierOwner = PsiTreeUtil.getParentOfType(psiElement, PsiNameIdentifierOwner::class.java)
if (closestIdentifierOwner !is PsiMethod) {
return PsiTreeUtil.getParentOfType(psiElement, PsiMethod::class.java) ?: closestIdentifierOwner
}

return closestIdentifierOwner
}

// fun findSampleDocument()
}

0 comments on commit 3cf769c

Please sign in to comment.