Skip to content

Commit

Permalink
entity: mark getters/setters as implicitly used [closes #12]
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Jan 9, 2022
1 parent ce99336 commit a2395c3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]
### Changed
- Added support for marking entity getters/setters as implicitly used; closes #12

## [0.8.3]
### Changed
- Removed upper bound of compatibility constraint for latest PhpStorm. (Second try)
- Updated build dependencies.

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pluginGroup = org.nextras.orm.intellij
pluginName = Nextras Orm Plugin
pluginVersion = 0.8.3
pluginVersion = 0.9.0

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions = PS-2020.3.3, PS-2021.1, PS-2021.2
pluginVerifierIdeVersions = PS-2021.3

platformType = IU
platformVersion = 2021.2
platformVersion = 2021.3.1
platformDownloadSources = true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = com.jetbrains.php:212.4746.100
platformPlugins = com.jetbrains.php:213.6461.83
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.nextras.orm.intellij.usageProvider

import com.intellij.codeInsight.daemon.ImplicitUsageProvider
import com.intellij.psi.PsiElement
import com.jetbrains.php.PhpIndex
import com.jetbrains.php.lang.psi.elements.Method
import org.nextras.orm.intellij.utils.OrmUtils

class EntityUsageProvider : ImplicitUsageProvider {
override fun isImplicitUsage(element: PsiElement): Boolean {
val method = element as? Method ?: return false
if (!method.name.startsWith("getter") && !method.name.startsWith("setter")) return false

val clazz = method.containingClass ?: return false
val phpIndex = PhpIndex.getInstance(element.project)
if (!OrmUtils.OrmClass.ENTITY.`is`(clazz, phpIndex)) return false

val propertyName = method.name.substring(6)
val tags = clazz.docComment?.propertyTags ?: return false
return tags.any { it.property?.text?.substring(1).equals(propertyName, ignoreCase = true) }
}

override fun isImplicitRead(element: PsiElement): Boolean = false

override fun isImplicitWrite(element: PsiElement): Boolean = false
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

<referencesSearch implementation="org.nextras.orm.intellij.reference.ReferenceSearcher"/>

<implicitUsageProvider implementation="org.nextras.orm.intellij.usageProvider.EntityUsageProvider"/>

<localInspection
language="PHP"
implementationClass="org.nextras.orm.intellij.inspection.ReadOnlyPropertyInspection"
Expand Down

0 comments on commit a2395c3

Please sign in to comment.