Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The plugin also provides quick fixes for Dao methods where the required SQL file
- Check the class name and package name for static property calls
![inspectionPackageName.png](images/inspectionPackageName.png)
- Optional types are recognized as their element type (e.g. Optional<String> is treated as String).
- Checks calls to custom functions and error-highlights any methods that aren’t defined in the classes registered via the settings.

## Completion
Adds code completion functionality to support indexing of Doma directives and bind variables
Expand All @@ -54,6 +55,7 @@ Adds code completion functionality to support indexing of Doma directives and bi
- Directives such as Condition, Loop, Population are suggested after “%”
- Suggest built-in functions after “@”
- Optional types are recognized as their element type (e.g. Optional<String> is treated as String).
- Suggest functions during code completion from the ExpressionFunctions implementation classes registered in the settings.

## Refactoring
Along with the Dao name change, we will refactor the SQL file directory and file name.
Expand Down Expand Up @@ -81,6 +83,7 @@ This feature works in source JARs as well, but in binary JARs, if the DAO method
- The DAO method’s argument parameter definition
- The field and method definitions on that parameter’s type
- The class definition referenced by @ClassName@
- Resolve references for custom functions using the ExpressionFunctions implementation class in which they are defined.
- You can also jump using the **Go To > Declaration Usage** menu.

![reference.png](images/reference.png)
Expand All @@ -92,3 +95,6 @@ Some functions of "Doma Tools" can be customized from the settings screen.
- Highlight color settings for SQL elements
![setting_highlight.png](images/setting_highlight.png)
- Customize action shortcut keys
- Toggle the SQL formatting feature on or off
- Specify the class names that define custom functions.
![setting.png](images/setting.png)
Binary file added images/setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.common

// TODO Dynamically build the source directory path and retrieve subproject info
// by inspecting file metadata instead of using string manipulation.
object CommonPathParameterHelper {
val SRC_MAIN_PATH: String
get() = "/src/main"

val RESOURCES_PATH: String
get() = "resources"

val RESOURCES_META_INF_PATH: String
get() = "META-INF"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.domaframework.doma.intellij.common
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.SRC_MAIN_PATH
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.SRC_MAIN_PATH

/**
* Get extension by file type identifier
Expand Down Expand Up @@ -46,14 +46,6 @@ fun isJavaOrKotlinFileType(daoFile: PsiFile): Boolean {
}
}

fun isJavaOrKotlinFileType(file: VirtualFile): Boolean {
val fileType = file.fileType
return when (fileType.name) {
"JAVA", "Kotlin", "CLASS" -> true
else -> false
}
}

/*
* Determine whether the open file is an SQL template file extension
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.domaframework.doma.intellij.common
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH

fun getJarRoot(
virtualFile: VirtualFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.intellij.psi.PsiManager
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
import org.domaframework.doma.intellij.common.getExtension
import org.domaframework.doma.intellij.common.getJarRoot
import org.domaframework.doma.intellij.common.getMethodDaoFilePath
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.common.helper

import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.wm.IdeFocusManager

object ActiveProjectHelper {
private var activeProject: Project? = null

fun setCurrentActiveProject(value: Project?) {
activeProject = value
}

fun getCurrentActiveProject(): Project? {
val initProject = activeProject
val active = getActiveUIProject()
return active ?: initProject
}

private fun getActiveUIProject(): Project? {
val openProjects: Array<out Project> = ProjectManager.getInstance().openProjects
var active: Project? = null

for (project in openProjects) {
if (IdeFocusManager.getInstance(project).focusOwner != null) {
active = project
break
}
}

return active
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.common.helper

import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.psiClassType

class ExpressionFunctionsHelper {
companion object {
var expressionFunction: PsiClass? = null

fun setExpressionFunctionsInterface(project: Project): PsiClass? {
val expressionFunctionsClass =
project.getJavaClazz("org.seasar.doma.expr.ExpressionFunctions")
if (expressionFunctionsClass != null) {
expressionFunction = expressionFunctionsClass
}
return expressionFunction
}

fun isInheritor(expressionClazz: PsiClass?): Boolean {
val project = expressionClazz?.project

expressionFunction?.let { functionInterface ->
expressionClazz?.let {
if (expressionClazz.isInheritor(functionInterface, true)) return true

val parentType =
expressionClazz.superTypes.firstOrNull()?.canonicalText
?: expressionClazz.psiClassType.canonicalText
return project?.let {
expressionClazz.psiClassType.canonicalText
project
.getJavaClazz(parentType)
?.isInheritor(functionInterface, true) == true
} == true
}
}
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.intellij.psi.PsiManager
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiNameValuePair
import com.intellij.util.IncorrectOperationException
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
import org.domaframework.doma.intellij.common.dao.formatSqlPathFromDaoPath
import org.domaframework.doma.intellij.common.getExtension
import org.domaframework.doma.intellij.extension.findFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
package org.domaframework.doma.intellij.common.sql.directive

import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile

class DirectiveCompletion(
private val originalFile: PsiFile,
private val bindText: String,
private val element: PsiElement,
private val project: Project,
private val result: CompletionResultSet,
) {
fun directiveHandle(symbol: String): Boolean {
Expand Down Expand Up @@ -56,7 +54,6 @@ class DirectiveCompletion(
element = element,
result = result,
bindText = bindText,
project = project,
).directiveHandle()

else -> return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package org.domaframework.doma.intellij.common.sql.directive

import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.elementType
Expand All @@ -34,7 +33,6 @@ class StaticDirectiveHandler(
private val element: PsiElement,
private val result: CompletionResultSet,
private val bindText: String,
private val project: Project,
) : DirectiveHandler(originalFile) {
override fun directiveHandle(): Boolean {
var handleResult = false
Expand Down Expand Up @@ -95,7 +93,7 @@ class StaticDirectiveHandler(
): Boolean {
if (BindDirectiveUtil.getDirectiveType(element) == DirectiveType.BUILT_IN) {
val prefix = getBindSearchWord(element, bindText)
val collector = StaticBuildFunctionCollector(project, prefix)
val collector = StaticBuildFunctionCollector(element.project, prefix)
val candidates = collector.collect()
candidates?.let { it1 -> result.addAllElements(it1) }
return true
Expand Down
Loading