-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: workaround the Java Psi structure when errors are present
- Loading branch information
Showing
5 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
8 changes: 5 additions & 3 deletions
8
src/main/kotlin/com/github/lppedd/highlighter/java/JavaAlwaysHighlightStrategy.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.github.lppedd.highlighter.java | ||
|
||
import com.github.lppedd.highlighter.ReturnHighlightStrategy | ||
import com.intellij.psi.PsiReturnStatement | ||
import com.intellij.psi.PsiKeyword | ||
|
||
/** | ||
* @author Edoardo Luppi | ||
*/ | ||
object JavaAlwaysHighlightStrategy : ReturnHighlightStrategy<PsiReturnStatement> { | ||
override fun isValidContext(psiElement: PsiReturnStatement) = true | ||
object JavaAlwaysHighlightStrategy : ReturnHighlightStrategy<PsiKeyword> { | ||
// Note: it seems the Java Psi structure isn't quite right when errors are | ||
// present. Thus, we need to intercept a lower-level PsiElement | ||
override fun isValidContext(psiElement: PsiKeyword) = "$psiElement" == "PsiKeyword:return" | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/com/github/lppedd/highlighter/java/JavaReturnAnnotator.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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.github.lppedd.highlighter.java | ||
|
||
import com.intellij.psi.PsiReturnStatement | ||
import com.intellij.psi.PsiKeyword | ||
import com.github.lppedd.highlighter.AbstractReturnAnnotator as ARA | ||
|
||
/** | ||
* @author Edoardo Luppi | ||
*/ | ||
class JavaReturnAnnotator : ARA<PsiReturnStatement>(PsiReturnStatement::class.java) { | ||
class JavaReturnAnnotator : ARA<PsiKeyword>(PsiKeyword::class.java) { | ||
private val config = JavaReturnHighlighterConfig.INSTANCE | ||
|
||
override fun isValidContext(psiElement: PsiReturnStatement) = | ||
override fun isValidContext(psiElement: PsiKeyword) = | ||
config.getHighlightStrategy().isValidContext(psiElement) | ||
} |
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
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/com/github/lppedd/highlighter/java/JavaReturnLineMarkerProvider.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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package com.github.lppedd.highlighter.java | ||
|
||
import com.intellij.psi.PsiReturnStatement | ||
import com.intellij.psi.PsiKeyword | ||
import com.github.lppedd.highlighter.AbstractReturnLineMarkerProvider as ARLMP | ||
|
||
/** | ||
* @author Edoardo Luppi | ||
*/ | ||
class JavaReturnLineMarkerProvider : ARLMP<PsiReturnStatement>(PsiReturnStatement::class.java) { | ||
class JavaReturnLineMarkerProvider : ARLMP<PsiKeyword>(PsiKeyword::class.java) { | ||
private val config = JavaReturnHighlighterConfig.INSTANCE | ||
|
||
override fun getName() = "Java" | ||
override fun isValidContext(psiElement: PsiReturnStatement) = | ||
override fun isValidContext(psiElement: PsiKeyword) = | ||
config.getHighlightStrategy().isValidContext(psiElement) | ||
} |
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