Skip to content

Commit

Permalink
Merge pull request #62 from bobi/dev
Browse files Browse the repository at this point in the history
- Improved code completion for copy, move, rename
  • Loading branch information
bobi authored Sep 24, 2022
2 parents 1136409 + ea6b8da commit 5bc9258
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# aem-groovyconsole-plugin Changelog

## [Unreleased]
### Changed
- Improved code completion for copy, move, rename

## [0.6.2]
### Changed
### Changed
- Improved code completion

## [0.6.1]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = com.github.bobi.aemgroovyconsoleplugin
pluginName = aem-groovyconsole-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.6.2
pluginVersion = 0.6.3

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.bobi.aemgroovyconsoleplugin.dsl

import com.icfolson.aem.groovy.extension.builders.NodeBuilder
import com.icfolson.aem.groovy.extension.builders.PageBuilder
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.ex.ApplicationManagerEx
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.JarFileSystem
Expand All @@ -18,9 +20,7 @@ import org.cid15.aem.groovy.console.table.Table
* Date/Time: 01.08.2022 19:24
*
*/
class AemScriptExtensionClassFinder(project: Project) : NonClasspathClassFinder(project) {

private val supportedPackages = classes.mapTo(HashSet<String>()) { it.`package`.name }
class AemScriptExtensionClassFinder(project: Project) : NonClasspathClassFinder(project, "groovy") {

override fun calcClassRoots(): List<VirtualFile> = roots

Expand All @@ -35,14 +35,30 @@ class AemScriptExtensionClassFinder(project: Project) : NonClasspathClassFinder(
}

companion object {
private val classes = listOf(NodeBuilder::class.java, Table::class.java)
private val thirdPartyClasses = listOf(
PageBuilder::class.java,
NodeBuilder::class.java,
Table::class.java,
)

private val supportedPackages = thirdPartyClasses.mapTo(HashSet<String>()) { it.`package`.name }
.also {
it.add("specs")
}

private val jarForClasses = listOf(
*thirdPartyClasses.toTypedArray(),
AemScriptExtensionClassFinder::class.java
)

private val roots = buildClassesRoots()

val searchScope = NonClasspathDirectoriesScope.compose(roots)

private fun buildClassesRoots(): List<VirtualFile> {
return classes.mapNotNull { clazz ->
val isInternal = java.lang.Boolean.getBoolean(ApplicationManagerEx.IS_INTERNAL_PROPERTY)

return jarForClasses.mapNotNullTo(LinkedHashSet()) { clazz ->
val jarForClass = PathManager.getJarForClass(clazz)

var classRoot: VirtualFile? = null
Expand All @@ -55,8 +71,13 @@ class AemScriptExtensionClassFinder(project: Project) : NonClasspathClassFinder(
}
}

return@mapNotNull classRoot
}
if (isInternal) {
// refresh changes during development
classRoot?.refresh(true, true)
}

return@mapNotNullTo classRoot
}.toList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.github.bobi.aemgroovyconsoleplugin.dsl
import com.intellij.openapi.diagnostic.Logger
import com.intellij.psi.CommonClassNames
import com.intellij.psi.PsiElement
import com.intellij.util.containers.ContainerUtil.immutableCopy
import groovy.lang.Closure
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames

Expand All @@ -30,7 +29,7 @@ data class VariableDescriptor(
data class GenericMethodDescriptor(
val name: String,
val genericTypes: List<String>,
val parameters: List<VariableDescriptor>, // doesn't include named parameters Map
val parameters: List<VariableDescriptor>,
val returnType: TypeDescriptor,
val throws: List<String>,
val containingClass: String?,
Expand Down Expand Up @@ -73,21 +72,21 @@ private fun params(args: Map<*, *>): List<VariableDescriptor> {
}
first = false
}
return immutableCopy(result)
return result.toList()
}

private fun throws(args: Map<*, *>): List<String> {
val throws = args["throws"]
return when {
throws is List<*> -> immutableCopy(throws.map(::stringifyType))
throws is List<*> -> throws.map(::stringifyType).toList()
throws != null -> listOf(stringifyType(throws))
else -> emptyList()
}
}

private fun genericTypes(args: Map<*, *>): List<String> {
return when (val genericTypes = args["genericTypes"]) {
is List<*> -> immutableCopy(genericTypes.filterIsInstance<String>())
is List<*> -> genericTypes.filterIsInstance<String>().toList()
is String -> listOf(genericTypes)
else -> emptyList()
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/specs/CopyTo.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//file:noinspection GrMethodMayBeStatic
//file:noinspection unused

package specs

interface CopyTo {
void to(String destinationAbsolutePath)
}
8 changes: 8 additions & 0 deletions src/main/resources/specs/MoveTo.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//file:noinspection GrMethodMayBeStatic
//file:noinspection unused

package specs

interface MoveTo {
void to(String destinationAbsolutePath)
}
8 changes: 8 additions & 0 deletions src/main/resources/specs/RenameTo.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//file:noinspection GrMethodMayBeStatic
//file:noinspection unused

package specs

interface RenameTo {
void to(String newName)
}
13 changes: 6 additions & 7 deletions src/main/resources/standardDsls/aem.gdsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ static String doc(final String doc) {
}

contributor(aemContext()) {

field name: 'log', type: 'org.slf4j.Logger'
field name: 'session', type: 'javax.jcr.Session'
field name: 'pageManager', type: 'com.day.cq.wcm.api.PageManager'
Expand Down Expand Up @@ -102,16 +101,16 @@ contributor(aemContext()) {
doc: doc('Get an instance of a Sling Model class for the Resource at the given path')

method name: 'copy',
params: [sourceAbsolutePath: String.name, destinationAbsolutePath: String.name],
type: void,
params: [sourceAbsolutePath: String.name],
type: 'specs.CopyTo',
doc: doc('Groovy DSL syntax for copying a node, equivalent to calling session.workspace.copy(sourceAbsolutePath, destinationAbsolutePath)')
method name: 'move',
params: [sourceAbsolutePath: String.name, destinationAbsolutePath: String.name],
type: void,
params: [sourceAbsolutePath: String.name],
type: 'specs.MoveTo',
doc: doc('Groovy DSL syntax for moving a node, equivalent to calling session.move(sourceAbsolutePath, destinationAbsolutePath), <b>except that the Session is saved automatically when the move is completed</b>')
method name: 'rename',
params: [node: 'javax.jcr.Node', newName: String.name],
type: void,
params: [node: 'javax.jcr.Node'],
type: 'specs.RenameTo',
doc: doc('Groovy DSL syntax for renaming a node, similar to calling session.move(sourceAbsolutePath, destinationAbsolutePath) with the new node name, <b>except that the renamed node will retain its order and the Session is saved automatically when the rename is completed.</b>')

method name: 'save',
Expand Down

0 comments on commit 5bc9258

Please sign in to comment.