-
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.
Merge pull request #26 from dblanovschi/add-explicit-type-intention
Add explicit type intention
- Loading branch information
Showing
42 changed files
with
614 additions
and
219 deletions.
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
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
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
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
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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/com/mdrobnak/lalrpop/intentions/AddExplicitTypeIntention.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,34 @@ | ||
package com.mdrobnak.lalrpop.intentions | ||
|
||
import com.intellij.codeInsight.intention.IntentionAction | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import com.intellij.psi.util.parentOfType | ||
import com.mdrobnak.lalrpop.LpLanguage | ||
import com.mdrobnak.lalrpop.psi.LpMacroArguments | ||
import com.mdrobnak.lalrpop.psi.LpNonterminal | ||
import com.mdrobnak.lalrpop.psi.ext.setType | ||
import com.mdrobnak.lalrpop.psi.getContextAndResolveType | ||
|
||
class AddExplicitTypeIntention : IntentionAction { | ||
override fun startInWriteAction(): Boolean = true | ||
|
||
override fun getText(): String = "Add explicit type" | ||
|
||
override fun getFamilyName(): String = "Add explicit type" | ||
|
||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean { | ||
if (editor == null || file == null || file.language != LpLanguage) return false | ||
|
||
return file.findElementAt(editor.caretModel.primaryCaret.offset)?.parentOfType<LpNonterminal>(withSelf = true) != null | ||
} | ||
|
||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { | ||
if (editor == null || file == null || file.language != LpLanguage) return | ||
|
||
file.findElementAt(editor.caretModel.primaryCaret.offset)?.parentOfType<LpNonterminal>(withSelf = true)?.apply { | ||
setType(getContextAndResolveType(LpMacroArguments.identity(nonterminalName.nonterminalParams))) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.