Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
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,37 @@
/*
* 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 {
val activeProject: Project?
get() {
val openProjects: Array<out Project> = ProjectManager.getInstance().openProjects
var activeProject: Project? = null

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

return activeProject
}
}
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
Loading