Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
adevone committed Jan 11, 2020
1 parent aeb03a0 commit 01c09c4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 89 deletions.
9 changes: 3 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.8'
id 'org.jetbrains.kotlin.jvm' version '1.3.40'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
}

group 'ru.napoleonit'
version '0.4.20'
version '0.8.12'

sourceCompatibility = 1.8

Expand All @@ -14,17 +14,14 @@ repositories {
}

dependencies {
// implementation fileTree(dir: new File(project.rootDir, "ideaSDK/plugins/Kotlin/lib"), include: ['kotlin-plugin.jar'])
// implementation fileTree(dir: new File(project.rootDir, "ideaSDK/plugins/Kotlin/lib"), include: ['kotlin-compiler.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"
// implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable"
testCompile group: 'junit', name: 'junit', version: '4.12'
}

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2018.3.4'
version '2019.1'
// plugins 'org.jetbrains.kotlin'
plugins = ["kotlin"]
// plugins 'org.jetbrains.kotlin:1.3.31-release-IJ2019.1-1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,10 @@ class AddMissingStoreByOwnersObjectIntention : PsiElementBaseIntentionAction(),

private val logger = Logger.getInstance("StoreByOwnerPropertyIntention")

/**
* If this action is applicable, returns the text to be shown in the list of
* intention actions available.
*/
override fun getText(): String {
return "storeByOwner missing properties"
}

/**
* Returns text for name of this family of intentions. It is used to externalize
* "auto-show" state of intentions.
* It is also the directory name for the descriptions.
*
* @see com.intellij.codeInsight.intention.IntentionManager.registerIntentionAndMetaData
* @return the intention family name.
*/
override fun getFamilyName(): String {
return "intentionDescriptions/AddMissingStoreByOwnersObjectIntention"
}
Expand All @@ -50,23 +38,10 @@ class AddMissingStoreByOwnersObjectIntention : PsiElementBaseIntentionAction(),
val leafElement = element as? LeafPsiElement ?: return false
val objectDeclaration = leafElement.parent as? KtObjectDeclaration ?: return false
val objectLiteral = objectDeclaration.parent as? KtObjectLiteralExpression ?: return false
val parentFunction = objectLiteral.parent as? KtFunction ?: return false
return parentFunction.name == "createViewStateProxy"
val parentProp = objectLiteral.parent as? KtProperty ?: return false
return parentProp.name == "viewStateProxy"
}

/**
* Modifies the Psi to change a ternary expression to an if-then-else statement.
* If the ternary is part of a declaration, the declaration is separated and
* moved above the if-then-else statement. Called when user selects this intention action
* from the available intentions list.
*
* @param project a reference to the Project object being edited.
* @param editor a reference to the object editing the project source
* @param element a reference to the PSI element currently under the caret
* @throws IncorrectOperationException Thrown by underlying (Psi model) write action context
* when manipulation of the psi tree fails.
* @see AddMissingStoreByOwnersObjectIntention.startInWriteAction
*/
@Throws(IncorrectOperationException::class)
override fun invoke(project: Project, editor: Editor, element: PsiElement) {

Expand Down Expand Up @@ -103,15 +78,6 @@ class AddMissingStoreByOwnersObjectIntention : PsiElementBaseIntentionAction(),
}
}

/**
* Indicates this intention action expects the Psi framework to provide the write action
* context for any changes.
*
* @return
* * true if the intention requires a write action context to be provided
* * false if this intention action will start a write action
*
*/
override fun startInWriteAction(): Boolean = true

override fun getPriority(): PriorityAction.Priority = PriorityAction.Priority.TOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,10 @@ class AddMissingViewStateImplementationsIntention : PsiElementBaseIntentionActio

private val logger = Logger.getInstance("StoreByOwnerPropertyIntention")

/**
* If this action is applicable, returns the text to be shown in the list of
* intention actions available.
*/
override fun getText(): String {
return "storeByOwner missing properties"
}

/**
* Returns text for name of this family of intentions. It is used to externalize
* "auto-show" state of intentions.
* It is also the directory name for the descriptions.
*
* @see com.intellij.codeInsight.intention.IntentionManager.registerIntentionAndMetaData
* @return the intention family name.
*/
override fun getFamilyName(): String {
return "intentionDescriptions/AddMissingStoreByOwnersObjectIntention"
}
Expand All @@ -54,19 +42,6 @@ class AddMissingViewStateImplementationsIntention : PsiElementBaseIntentionActio
return parentFunction.name == "createViewState"
}

/**
* Modifies the Psi to change a ternary expression to an if-then-else statement.
* If the ternary is part of a declaration, the declaration is separated and
* moved above the if-then-else statement. Called when user selects this intention action
* from the available intentions list.
*
* @param project a reference to the Project object being edited.
* @param editor a reference to the object editing the project source
* @param element a reference to the PSI element currently under the caret
* @throws IncorrectOperationException Thrown by underlying (Psi model) write action context
* when manipulation of the psi tree fails.
* @see AddMissingViewStateImplementationsIntention.startInWriteAction
*/
@Throws(IncorrectOperationException::class)
override fun invoke(project: Project, editor: Editor, element: PsiElement) {

Expand Down Expand Up @@ -103,15 +78,6 @@ class AddMissingViewStateImplementationsIntention : PsiElementBaseIntentionActio
}
}

/**
* Indicates this intention action expects the Psi framework to provide the write action
* context for any changes.
*
* @return
* * true if the intention requires a write action context to be provided
* * false if this intention action will start a write action
*
*/
override fun startInWriteAction(): Boolean = true

override fun getPriority(): PriorityAction.Priority = PriorityAction.Priority.TOP
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/napoleonit/summerPlugin/StoreByOwner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType

fun KtPsiFactory.createStoreByOwnerProperty(name: String) =
createProperty("override var $name by store(vs::$name, initialValue = null)")
createProperty("override var $name by store({ it::$name }, initial = null)")

fun KtClassBody.containsPropertyWithName(name: String) =
children.any { it is KtProperty && it.name == name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ class StoreByOwnerPropertyIntention : PsiElementBaseIntentionAction(), Intention
} as KtClass

val presenterClassBody = presenterClass.body
val createViewStateProxyFun = presenterClassBody!!.children
.find {
(it as? KtFunction)?.name == "createViewStateProxy"
} as KtFunction
val viewStateProxyProp = presenterClassBody!!.children
.filterIsInstance<KtProperty>()
.find { property ->
property.name == "viewStateProxy"
} ?: return

val viewStateProxyObject = createViewStateProxyFun.children
val viewStateProxyObject = viewStateProxyProp.children
.find {
(it is KtObjectLiteralExpression)
} as KtObjectLiteralExpression
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,4 @@

<depends>org.jetbrains.kotlin</depends>

<actions>
<!-- Add your actions here -->
<!-- <action id="ru.napoleonit.summerPlugin.CreateFeatureAction"-->
<!-- class="ru.napoleonit.summerPlugin.CreateFeatureAction" text="New Summer presentation">-->
<!-- <add-to-group group-id="NewGroup" anchor="first" />-->
<!-- </action>-->
</actions>
</idea-plugin>

0 comments on commit 01c09c4

Please sign in to comment.