Skip to content

Commit db2aec6

Browse files
committed
Add support for custom functions and refactor related settings
1 parent 5955785 commit db2aec6

23 files changed

+365
-73
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.common
17+
18+
// TODO Dynamically build the source directory path and retrieve subproject info
19+
// by inspecting file metadata instead of using string manipulation.
20+
object CommonPathParameterHelper {
21+
val SRC_MAIN_PATH: String
22+
get() = "/src/main"
23+
24+
val RESOURCES_PATH: String
25+
get() = "resources"
26+
27+
val RESOURCES_META_INF_PATH: String
28+
get() = "META-INF"
29+
}

src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.domaframework.doma.intellij.common
1818
import com.intellij.openapi.fileTypes.FileTypeManager
1919
import com.intellij.openapi.vfs.VirtualFile
2020
import com.intellij.psi.PsiFile
21-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.SRC_MAIN_PATH
21+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.SRC_MAIN_PATH
2222

2323
/**
2424
* Get extension by file type identifier
@@ -46,14 +46,6 @@ fun isJavaOrKotlinFileType(daoFile: PsiFile): Boolean {
4646
}
4747
}
4848

49-
fun isJavaOrKotlinFileType(file: VirtualFile): Boolean {
50-
val fileType = file.fileType
51-
return when (fileType.name) {
52-
"JAVA", "Kotlin", "CLASS" -> true
53-
else -> false
54-
}
55-
}
56-
5749
/*
5850
* Determine whether the open file is an SQL template file extension
5951
*/

src/main/kotlin/org/domaframework/doma/intellij/common/JarFileSearch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.domaframework.doma.intellij.common
1818
import com.intellij.openapi.vfs.StandardFileSystems
1919
import com.intellij.openapi.vfs.VirtualFile
2020
import com.intellij.psi.PsiFile
21-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
21+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
2222

2323
fun getJarRoot(
2424
virtualFile: VirtualFile,

src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import com.intellij.psi.PsiManager
2727
import com.intellij.psi.PsiMethod
2828
import com.intellij.psi.search.GlobalSearchScope
2929
import com.intellij.psi.util.PsiTreeUtil
30-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
31-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
30+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
31+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
3232
import org.domaframework.doma.intellij.common.getExtension
3333
import org.domaframework.doma.intellij.common.getJarRoot
3434
import org.domaframework.doma.intellij.common.getMethodDaoFilePath
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.common.helper
17+
18+
import com.intellij.openapi.project.Project
19+
import com.intellij.openapi.project.ProjectManager
20+
import com.intellij.openapi.wm.IdeFocusManager
21+
22+
object ActiveProjectHelper {
23+
val activeProject: Project?
24+
get() {
25+
val openProjects: Array<out Project> = ProjectManager.getInstance().openProjects
26+
var activeProject: Project? = null
27+
28+
for (project in openProjects) {
29+
if (IdeFocusManager.getInstance(project).focusOwner != null) {
30+
activeProject = project
31+
break
32+
}
33+
}
34+
35+
return activeProject
36+
}
37+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.common.helper
17+
18+
import com.intellij.openapi.project.Project
19+
import com.intellij.psi.PsiClass
20+
import org.domaframework.doma.intellij.extension.getJavaClazz
21+
import org.domaframework.doma.intellij.extension.psi.psiClassType
22+
23+
class ExpressionFunctionsHelper {
24+
companion object {
25+
var expressionFunction: PsiClass? = null
26+
27+
fun setExpressionFunctionsInterface(project: Project): PsiClass? {
28+
val expressionFunctionsClass =
29+
project.getJavaClazz("org.seasar.doma.expr.ExpressionFunctions")
30+
if (expressionFunctionsClass != null) {
31+
expressionFunction = expressionFunctionsClass
32+
}
33+
return expressionFunction
34+
}
35+
36+
fun isInheritor(expressionClazz: PsiClass?): Boolean {
37+
val project = expressionClazz?.project
38+
39+
expressionFunction?.let { functionInterface ->
40+
expressionClazz?.let {
41+
if (expressionClazz.isInheritor(functionInterface, true)) return true
42+
43+
val parentType =
44+
expressionClazz.superTypes.firstOrNull()?.canonicalText
45+
?: expressionClazz.psiClassType.canonicalText
46+
return project?.let {
47+
expressionClazz.psiClassType.canonicalText
48+
project
49+
.getJavaClazz(parentType)
50+
?.isInheritor(functionInterface, true) == true
51+
} == true
52+
}
53+
}
54+
return false
55+
}
56+
}
57+
}

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.intellij.psi.PsiManager
3232
import com.intellij.psi.PsiMethod
3333
import com.intellij.psi.PsiNameValuePair
3434
import com.intellij.util.IncorrectOperationException
35-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
35+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
3636
import org.domaframework.doma.intellij.common.dao.formatSqlPathFromDaoPath
3737
import org.domaframework.doma.intellij.common.getExtension
3838
import org.domaframework.doma.intellij.extension.findFile

src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import com.intellij.openapi.vfs.VirtualFile
2121
import com.intellij.psi.JavaPsiFacade
2222
import com.intellij.psi.PsiClass
2323
import com.intellij.psi.search.GlobalSearchScope
24-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
24+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
2525
import org.domaframework.doma.intellij.common.dao.formatSqlPathFromDaoPath
2626
import org.jetbrains.kotlin.idea.util.sourceRoots
2727

src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ fun Project.getJavaClazz(fqdn: String): PsiClass? {
4545
.getInstance(this)
4646
.findClasses(fqdn, scope)
4747
.firstOrNull()
48+
?: JavaPsiFacade.getInstance(this).findClass(
49+
fqdn,
50+
GlobalSearchScope.allScope(this),
51+
)
4852
}

src/main/kotlin/org/domaframework/doma/intellij/extension/psi/PsiMethodExtension.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.domaframework.doma.intellij.extension.psi
1717

18-
import com.intellij.codeInsight.AnnotationUtil
1918
import com.intellij.psi.PsiMethod
2019
import com.intellij.psi.PsiParameter
2120

@@ -25,13 +24,3 @@ val PsiMethod.methodParameters: List<PsiParameter>
2524
get() = this.parameterList.parameters.toList()
2625

2726
fun PsiMethod.searchParameter(searchName: String): List<PsiParameter> = this.methodParameters.filter { it.name.startsWith(searchName) }
28-
29-
@OptIn(ExperimentalStdlibApi::class)
30-
fun PsiMethod.getDomaAnnotationType(): DomaAnnotationType {
31-
DomaAnnotationType.entries.forEach {
32-
if (AnnotationUtil.findAnnotation(this, it.fqdn) != null) {
33-
return it
34-
}
35-
}
36-
return DomaAnnotationType.Unknown
37-
}

0 commit comments

Comments
 (0)