Skip to content

Commit

Permalink
chore: prepare initial release (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell committed Jun 15, 2024
1 parent 297ef36 commit 5f40947
Show file tree
Hide file tree
Showing 37 changed files with 170 additions and 195 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![Build](https://github.com/SirYwell/HandleHints/workflows/Build/badge.svg)
[![Version](https://img.shields.io/jetbrains/plugin/v/PLUGIN_ID.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)
[![Downloads](https://img.shields.io/jetbrains/plugin/d/PLUGIN_ID.svg)](https://plugins.jetbrains.com/plugin/PLUGIN_ID)

<!--
## Template ToDo list
- [x] Create a new [IntelliJ Platform Plugin Template][template] project.
- [ ] Get familiar with the [template documentation][template].
Expand All @@ -13,9 +13,22 @@
- [ ] Set the Plugin ID in the above README badges.
- [ ] Set the [Deployment Token](https://plugins.jetbrains.com/docs/marketplace/plugin-upload.html).
- [ ] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.
-->

<!-- Plugin description -->
This IntelliJ plugin adds inspections and tools to make working with Java MethodHandles easier.

### Features

- Dataflow-sensitive type analysis
- Support for methods from the `MethodHandles` class
- Support for methods from the `MethodHandles.Lookup` class
- Support for methods from the `MethodType` class
- Support for methods from the `MethodHandle` class
- Precise type tracking for parameters and return types separately
- Inspections for supported creation/transformation/combination methods
- Inspections for `invoke` and `invokeExact` arguments and return type checks
- Inlay type hints
<!-- Plugin description end -->

## Installation
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html

pluginGroup = de.sirywell.methodhandleplugin
pluginGroup = de.sirywell.handlehints
pluginName = HandleHints
pluginRepositoryUrl = https://github.com/SirYwell/HandleHints
# SemVer format -> https://semver.org
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.sirywell.handlehints

import com.intellij.codeInsight.hints.declarative.InlayTreeSink
import com.intellij.codeInsight.hints.declarative.InlineInlayPosition
import com.intellij.codeInsight.hints.declarative.SharedBypassCollector
import com.intellij.psi.PsiDeclarationStatement
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiParameterList
import com.intellij.psi.PsiReferenceExpression
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import de.sirywell.handlehints.type.BotSignature
import de.sirywell.handlehints.type.TopSignature

class MethodTypeInlayHintsCollector : SharedBypassCollector {

override fun collectFromElement(element: PsiElement, sink: InlayTreeSink) {
val (pos, belongsToBefore) = when (element) {
is PsiDeclarationStatement -> (element.getVariable()?.nameIdentifier?.endOffset
?: element.endOffset) to true

is PsiReferenceExpression -> {
// TODO ????
if (element.parent is PsiParameterList) {
element.startOffset to false
} else {
element.endOffset to true
}
}

else -> element.endOffset to true
}
val typeData = TypeData.forFile(element.containingFile)
val type = typeData[element] ?: return
// don't print
if (type.signature is TopSignature || type.signature is BotSignature) {
return
}
sink.addPresentation(InlineInlayPosition(pos, belongsToBefore), hasBackground = true) {
text(type.toString())
}
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/de/sirywell/handlehints/MethodTypeInlayProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.sirywell.handlehints

import com.intellij.codeInsight.hints.declarative.InlayHintsProvider
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.DumbService
import com.intellij.psi.PsiFile

class MethodTypeInlayProvider : InlayHintsProvider {

override fun createCollector(
file: PsiFile,
editor: Editor
): com.intellij.codeInsight.hints.declarative.InlayHintsCollector? {
if (file.project.service<DumbService>().isDumb) return null
return MethodTypeInlayHintsCollector()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

enum class TriState {
YES,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.CachedValuesManager
import de.sirywell.methodhandleplugin.dfa.MhTypeProvider
import de.sirywell.methodhandleplugin.type.MethodHandleType
import de.sirywell.handlehints.dfa.MhTypeProvider
import de.sirywell.handlehints.type.MethodHandleType

class TypeData: ModificationTracker by ModificationTracker.NEVER_CHANGED {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

fun <T> List<T>.subList(start: Int) = this.subList(start, this.size)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.sirywell.methodhandleplugin.dfa
package de.sirywell.handlehints.dfa

import com.intellij.codeInsight.hints.ParameterHintsPassFactory
import com.intellij.lang.jvm.JvmModifier
import com.intellij.psi.*
import com.intellij.psi.controlFlow.*
import com.intellij.psi.util.PsiEditorUtil
import de.sirywell.methodhandleplugin.TypeData
import de.sirywell.handlehints.TypeData
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType.methodType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.sirywell.methodhandleplugin.dfa
package de.sirywell.handlehints.dfa

import com.intellij.openapi.util.RecursionManager.doPreventingRecursion
import com.intellij.psi.*
import com.intellij.psi.util.childrenOfType
import de.sirywell.methodhandleplugin.type.BotSignature
import de.sirywell.methodhandleplugin.type.MethodHandleType
import de.sirywell.handlehints.type.BotSignature
import de.sirywell.handlehints.type.MethodHandleType

class MethodHandleTypeResolver(private val ssaAnalyzer: SsaAnalyzer, private val block: SsaConstruction.Block) :
JavaRecursiveElementVisitor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.sirywell.methodhandleplugin.dfa
package de.sirywell.handlehints.dfa

import com.intellij.openapi.util.Key
import com.intellij.psi.PsiFile
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.ParameterizedCachedValue
import com.intellij.psi.util.ParameterizedCachedValueProvider
import com.intellij.psi.util.PsiModificationTracker
import de.sirywell.methodhandleplugin.TypeData
import de.sirywell.handlehints.TypeData

object MhTypeProvider : ParameterizedCachedValueProvider<TypeData, PsiFile> {
override fun compute(param: PsiFile): CachedValueProvider.Result<TypeData> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package de.sirywell.methodhandleplugin.dfa
package de.sirywell.handlehints.dfa

import com.intellij.openapi.diagnostic.Logger
import com.intellij.psi.*
import com.intellij.psi.controlFlow.ControlFlow
import com.intellij.psi.controlFlow.ReadVariableInstruction
import com.intellij.psi.controlFlow.WriteVariableInstruction
import de.sirywell.methodhandleplugin.*
import de.sirywell.methodhandleplugin.dfa.SsaConstruction.*
import de.sirywell.methodhandleplugin.mhtype.*
import de.sirywell.methodhandleplugin.type.BotSignature
import de.sirywell.methodhandleplugin.type.MethodHandleType
import de.sirywell.handlehints.*
import de.sirywell.handlehints.dfa.SsaConstruction.*
import de.sirywell.handlehints.mhtype.*
import de.sirywell.handlehints.type.BotSignature
import de.sirywell.handlehints.type.MethodHandleType

class SsaAnalyzer(private val controlFlow: ControlFlow, val typeData: TypeData) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:Suppress("UnstableApiUsage")

package de.sirywell.methodhandleplugin.dfa
package de.sirywell.handlehints.dfa

import com.google.common.graph.ElementOrder
import com.google.common.graph.GraphBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.sirywell.methodhandleplugin.inspection
package de.sirywell.handlehints.inspection

import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiReferenceExpression
import de.sirywell.methodhandleplugin.TypeData
import de.sirywell.handlehints.TypeData

class MethodHandleMergeInspection : LocalInspectionTool() {
class MethodHandleEditInspection : LocalInspectionTool() {

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return Visitor(holder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin.inspection
package de.sirywell.handlehints.inspection

import com.intellij.codeInsight.daemon.impl.quickfix.AddTypeCastFix
import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview
Expand All @@ -11,8 +11,8 @@ import com.intellij.psi.*
import com.intellij.psi.util.childrenOfType
import com.intellij.refactoring.introduceVariable.JavaIntroduceVariableHandlerBase
import de.sirywell.intellij.ReplaceMethodCallFix
import de.sirywell.methodhandleplugin.*
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.handlehints.*
import de.sirywell.handlehints.type.*
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

import com.intellij.openapi.diagnostic.Logger

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.sirywell.methodhandleplugin.mhtype
package de.sirywell.handlehints.mhtype

import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.psi.*
import com.intellij.psi.util.PsiTypesUtil
import de.sirywell.methodhandleplugin.*
import de.sirywell.methodhandleplugin.dfa.SsaAnalyzer
import de.sirywell.methodhandleplugin.dfa.SsaConstruction
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.methodhandleplugin.type.TopType
import de.sirywell.handlehints.*
import de.sirywell.handlehints.dfa.SsaAnalyzer
import de.sirywell.handlehints.dfa.SsaConstruction
import de.sirywell.handlehints.type.*
import de.sirywell.handlehints.type.TopType
import org.jetbrains.annotations.Nls

class LookupHelper(private val ssaAnalyzer: SsaAnalyzer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.sirywell.methodhandleplugin.mhtype
package de.sirywell.handlehints.mhtype

import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpression
import de.sirywell.methodhandleplugin.MethodHandleBundle.message
import de.sirywell.methodhandleplugin.TriState
import de.sirywell.methodhandleplugin.dfa.SsaAnalyzer
import de.sirywell.methodhandleplugin.dfa.SsaConstruction
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.handlehints.MethodHandleBundle.message
import de.sirywell.handlehints.TriState
import de.sirywell.handlehints.dfa.SsaAnalyzer
import de.sirywell.handlehints.dfa.SsaConstruction
import de.sirywell.handlehints.type.*
import org.jetbrains.annotations.Nls

class MethodHandleTransformer(private val ssaAnalyzer: SsaAnalyzer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.sirywell.methodhandleplugin.mhtype
package de.sirywell.handlehints.mhtype

import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.psi.*
import de.sirywell.methodhandleplugin.*
import de.sirywell.methodhandleplugin.MethodHandleBundle.message
import de.sirywell.methodhandleplugin.dfa.SsaAnalyzer
import de.sirywell.methodhandleplugin.dfa.SsaConstruction
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.methodhandleplugin.type.TopType
import de.sirywell.handlehints.*
import de.sirywell.handlehints.MethodHandleBundle.message
import de.sirywell.handlehints.dfa.SsaAnalyzer
import de.sirywell.handlehints.dfa.SsaConstruction
import de.sirywell.handlehints.type.*
import de.sirywell.handlehints.type.TopType
import org.jetbrains.annotations.Nls

private const val VAR_HANDLE_FQN = "java.lang.invoke.VarHandle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package de.sirywell.methodhandleplugin.mhtype
package de.sirywell.handlehints.mhtype

import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiTypes
import de.sirywell.methodhandleplugin.*
import de.sirywell.methodhandleplugin.MethodHandleBundle.message
import de.sirywell.methodhandleplugin.dfa.SsaAnalyzer
import de.sirywell.methodhandleplugin.dfa.SsaConstruction
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.methodhandleplugin.type.TopType
import de.sirywell.handlehints.*
import de.sirywell.handlehints.MethodHandleBundle.message
import de.sirywell.handlehints.dfa.SsaAnalyzer
import de.sirywell.handlehints.dfa.SsaConstruction
import de.sirywell.handlehints.type.*
import de.sirywell.handlehints.type.TopType
import org.jetbrains.annotations.Nls

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.sirywell.methodhandleplugin.mhtype
package de.sirywell.handlehints.mhtype

import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiPrimitiveType
import com.intellij.psi.PsiType
import de.sirywell.methodhandleplugin.TriState
import de.sirywell.methodhandleplugin.asType
import de.sirywell.methodhandleplugin.getConstantOfType
import de.sirywell.methodhandleplugin.mapToTypes
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.handlehints.TriState
import de.sirywell.handlehints.asType
import de.sirywell.handlehints.getConstantOfType
import de.sirywell.handlehints.mapToTypes
import de.sirywell.handlehints.type.*
import java.util.Collections.nCopies

object MethodTypeHelper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.sirywell.methodhandleplugin
package de.sirywell.handlehints

import com.intellij.codeInspection.dataFlow.CommonDataflow
import com.intellij.codeInspection.dataFlow.CommonDataflow.DataflowResult
import com.intellij.psi.*
import com.intellij.psi.impl.source.resolve.reference.impl.JavaReflectionReferenceUtil
import com.intellij.psi.search.GlobalSearchScope
import de.sirywell.methodhandleplugin.type.*
import de.sirywell.handlehints.type.*
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles
import java.lang.invoke.MethodType.methodType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin.type
package de.sirywell.handlehints.type

@JvmRecord
data class MethodHandleType(val signature: Signature) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.sirywell.methodhandleplugin.type
package de.sirywell.handlehints.type

import de.sirywell.methodhandleplugin.TriState
import de.sirywell.methodhandleplugin.toTriState
import de.sirywell.handlehints.TriState
import de.sirywell.handlehints.toTriState
import java.util.*
import java.util.stream.Collectors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.sirywell.methodhandleplugin.type
package de.sirywell.handlehints.type

enum class PartialOrder {
LT,
Expand Down
Loading

0 comments on commit 5f40947

Please sign in to comment.