-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/beta' into widget-guis
- Loading branch information
Showing
667 changed files
with
8,050 additions
and
5,416 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: check-style | ||
on: | ||
- pull_request | ||
jobs: | ||
ktlint: | ||
name: Check Style | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
name: Checkout code | ||
- name: ktlint | ||
uses: ScaCap/action-ktlint@master | ||
with: | ||
github_token: ${{ secrets.github_token }} | ||
reporter: github-pr-check |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,76 @@ | ||
import com.intellij.codeInspection.LocalQuickFix | ||
import com.intellij.codeInspection.ProblemDescriptor | ||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElementVisitor | ||
import liveplugin.registerInspection | ||
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName | ||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection | ||
import org.jetbrains.kotlin.idea.util.AnnotationModificationHelper | ||
import org.jetbrains.kotlin.name.FqName | ||
import org.jetbrains.kotlin.nj2k.postProcessing.type | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
import org.jetbrains.kotlin.psi.KtVisitorVoid | ||
import org.jetbrains.kotlin.psi.psiUtil.isPublic | ||
import org.jetbrains.kotlin.types.typeUtil.supertypes | ||
|
||
// depends-on-plugin org.jetbrains.kotlin | ||
|
||
val skyhanniEvent = "at.hannibal2.skyhanni.api.event.SkyHanniEvent" | ||
val handleEvent = "HandleEvent" | ||
|
||
registerInspection(HandleEventInspectionKotlin()) | ||
|
||
class HandleEventInspectionKotlin : AbstractKotlinInspection() { | ||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
|
||
val visitor = object : KtVisitorVoid() { | ||
override fun visitNamedFunction(function: KtNamedFunction) { | ||
val hasEventAnnotation = function.annotationEntries.any { it.shortName!!.asString() == handleEvent } | ||
val isEvent = function.valueParameters.firstOrNull()?.type()?.supertypes() | ||
?.any { it.fqName?.asString() == skyhanniEvent } ?: false | ||
|
||
if (isEvent && !hasEventAnnotation && function.valueParameters.size == 1 && function.isPublic) { | ||
holder.registerProblem( | ||
function, | ||
"Event handler function should be annotated with @HandleEvent", | ||
HandleEventQuickFix() | ||
) | ||
} else if (!isEvent && hasEventAnnotation) { | ||
holder.registerProblem( | ||
function, | ||
"Function should not be annotated with @HandleEvent if it does not take a SkyHanniEvent", | ||
ProblemHighlightType.GENERIC_ERROR | ||
) | ||
} | ||
} | ||
} | ||
|
||
return visitor | ||
} | ||
|
||
override fun getDisplayName() = "Event handler function should be annotated with @HandleEvent" | ||
override fun getShortName() = "HandleEventInspection" | ||
override fun getGroupDisplayName() = "SkyHanni" | ||
override fun isEnabledByDefault() = true | ||
} | ||
|
||
class HandleEventQuickFix : LocalQuickFix { | ||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) { | ||
val function = descriptor.psiElement as KtNamedFunction | ||
AnnotationModificationHelper.addAnnotation( | ||
function, | ||
FqName("at.hannibal2.skyhanni.api.event.HandleEvent"), | ||
null, | ||
null, | ||
{ null }, | ||
" ", | ||
null | ||
) | ||
} | ||
|
||
override fun getName() = "Annotate with @HandleEvent" | ||
|
||
override fun getFamilyName() = name | ||
} |
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,101 @@ | ||
import com.intellij.codeInspection.LocalQuickFix | ||
import com.intellij.codeInspection.ProblemDescriptor | ||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiElementVisitor | ||
import liveplugin.registerInspection | ||
import liveplugin.show | ||
import org.jetbrains.kotlin.idea.base.utils.fqname.fqName | ||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection | ||
import org.jetbrains.kotlin.idea.util.AnnotationModificationHelper | ||
import org.jetbrains.kotlin.name.FqName | ||
import org.jetbrains.kotlin.nj2k.postProcessing.type | ||
import org.jetbrains.kotlin.psi.* | ||
|
||
// depends-on-plugin org.jetbrains.kotlin | ||
|
||
val forgeEvent = "SubscribeEvent" | ||
val handleEvent = "HandleEvent" | ||
val skyHanniModule = "SkyHanniModule" | ||
|
||
val patternGroup = "at.hannibal2.skyhanni.utils.repopatterns.RepoPatternGroup" | ||
val pattern = "java.util.regex.Pattern" | ||
|
||
registerInspection(ModuleInspectionKotlin()) | ||
|
||
fun isEvent(function: KtNamedFunction): Boolean { | ||
return function.annotationEntries.any { | ||
it.shortName!!.asString() == handleEvent || it.shortName!!.asString() == forgeEvent | ||
} | ||
} | ||
|
||
fun isRepoPattern(property: KtProperty): Boolean { | ||
val type = property.type()?.fqName?.asString() ?: return false | ||
if (type == patternGroup) return true | ||
if (type == pattern && property.hasDelegate()) return true | ||
return false | ||
} | ||
|
||
class ModuleInspectionKotlin : AbstractKotlinInspection() { | ||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
|
||
val visitor = object : KtVisitorVoid() { | ||
|
||
override fun visitClass(klass: KtClass) { | ||
val hasAnnotation = klass.annotationEntries.any { it.shortName?.asString() == skyHanniModule } | ||
|
||
if (hasAnnotation) { | ||
holder.registerProblem( | ||
klass.nameIdentifier!!, | ||
"@SkyHanniModule can only be applied to objects", | ||
ProblemHighlightType.GENERIC_ERROR | ||
) | ||
} | ||
} | ||
|
||
override fun visitObjectDeclaration(declaration: KtObjectDeclaration) { | ||
if (declaration.isCompanion()) return | ||
val hasAnnotation = declaration.annotationEntries.any { it.shortName?.asString() == skyHanniModule } | ||
if (hasAnnotation) return | ||
|
||
val hasSkyHanniEvents = declaration.body!!.functions.any { function -> isEvent(function) } | ||
val hasRepoPatterns = declaration.body!!.properties.any { property -> isRepoPattern(property) } | ||
if (!hasSkyHanniEvents && !hasRepoPatterns) return | ||
|
||
holder.registerProblem( | ||
declaration, | ||
"Module should have a @SkyHanniModule annotation", | ||
ModuleQuickFix() | ||
) | ||
} | ||
} | ||
|
||
return visitor | ||
} | ||
|
||
override fun getDisplayName() = "Modules should have a @SkyHanniModule annotation" | ||
override fun getShortName() = "SkyHanniModuleInspection" | ||
override fun getGroupDisplayName() = "SkyHanni" | ||
override fun isEnabledByDefault() = true | ||
} | ||
|
||
class ModuleQuickFix : LocalQuickFix { | ||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) { | ||
val obj = descriptor.psiElement as KtObjectDeclaration | ||
AnnotationModificationHelper.addAnnotation( | ||
obj, | ||
FqName("at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule"), | ||
null, | ||
null, | ||
{ null }, | ||
" ", | ||
null | ||
) | ||
show("Annotation applied, make sure SkyHanniMod isn't still loading this module") | ||
} | ||
|
||
override fun getName() = "Annotate with @SkyHanniModule" | ||
|
||
override fun getFamilyName() = name | ||
} |
Oops, something went wrong.