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
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public SqlElCommentExprImpl(@NotNull ASTNode node) {
super(node);
}

@Override
public @NotNull ASTNode getNode() {
return super.getNode();
}

@Override
public @NotNull IElementType getTokenType() {
return getNode().getElementType();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class JumpToDaoFromSQLAction : AnAction() {
val project = e.project ?: return
val daoFile = findDaoFile(project, file) ?: return

val nameWithoutExtension = file.virtualFile?.nameWithoutExtension ?: return
jumpToDaoMethod(project, nameWithoutExtension, daoFile)
val sqlFileName = file.virtualFile?.nameWithoutExtension ?: return
jumpToDaoMethod(project, sqlFileName, daoFile)
PluginLoggerUtil.countLoggingByAction(
this::class.java.simpleName,
"JumpToDao",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,96 @@
*/
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"
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.jps.model.java.JavaResourceRootType
import org.jetbrains.jps.model.java.JavaSourceRootType

val RESOURCES_PATH: String
get() = "resources"
val RESOURCES_META_INF_PATH: String
get() = "META-INF"

val RESOURCES_META_INF_PATH: String
get() = "META-INF"
class CommonPathParameter(
module: Module?,
) {
/**
* module base path ex)Absolute path of "/src/main"
*/
var moduleBasePath: VirtualFile? = null

/**
* module source directories ex) Absolute path of "/src/main/java","/src/main/kotlin"
*/
var moduleSourceDirectories: MutableList<VirtualFile> = mutableListOf()

/**
* module resource directory ex) Absolute path of "/src/main/resources"
*/
var moduleResourceDirectories: MutableList<VirtualFile> = mutableListOf()

var moduleTestSourceDirectories: MutableList<VirtualFile> = mutableListOf()
var moduleTestResourceDirectories: MutableList<VirtualFile> = mutableListOf()

init {
setModuleSourcesFiles(module)
}

private fun setModuleSourcesFiles(module: Module?) {
if (module == null) return

val modulemanager = ModuleRootManager.getInstance(module)

moduleSourceDirectories.clear()
modulemanager?.contentEntries?.firstOrNull()?.let { entry ->
moduleBasePath = entry.file
entry.sourceFolders.map { folder ->
val file = folder.file
if (file != null) {
when (folder.rootType) {
JavaSourceRootType.SOURCE -> {
moduleSourceDirectories.add(file)
}

JavaSourceRootType.TEST_SOURCE -> {
moduleTestSourceDirectories.add(file)
}

JavaResourceRootType.RESOURCE -> {
moduleResourceDirectories.add(file)
}

JavaResourceRootType.TEST_RESOURCE -> {
moduleTestResourceDirectories.add(file)
}
}
}
}
}
}

fun isTest(file: VirtualFile): Boolean {
val testSource =
moduleTestSourceDirectories.firstOrNull { testSource ->
file.path.contains(testSource.path)
}
if (testSource != null) return true

return moduleTestResourceDirectories.firstOrNull { testSource ->
file.path.contains(testSource.path)
} != null
}

fun getResources(file: VirtualFile): MutableList<VirtualFile> =
if (isTest(file)) {
moduleTestResourceDirectories
} else {
moduleResourceDirectories
}

fun getSources(file: VirtualFile): MutableList<VirtualFile> =
if (isTest(file)) {
moduleTestSourceDirectories
} else {
moduleSourceDirectories
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
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.CommonPathParameterHelper.SRC_MAIN_PATH

val sourceExtensionNames: List<String> = listOf("JAVA", "Kotlin", "CLASS")

/**
* Get extension by file type identifier
Expand Down Expand Up @@ -66,36 +66,3 @@ fun isInjectionSqlFile(file: PsiFile): Boolean {
} &&
!(filePath.endsWith(".sql") || filePath.endsWith(".script"))
}

/**
* Dao file search for SQL files
*/
fun searchDaoFile(
contentRoot: VirtualFile?,
originFilePath: String,
relativeDaoFilePath: String,
): VirtualFile? {
val projectRootPath = contentRoot?.path ?: return null
if (projectRootPath.endsWith(SRC_MAIN_PATH)) {
return contentRoot.findFileByRelativePath(relativeDaoFilePath)
}

if (projectRootPath.length > originFilePath.length) {
return null
}

// TODO Dynamically build the source directory path and retrieve subproject info
// by inspecting file metadata instead of using string manipulation.
val index = originFilePath.indexOf(SRC_MAIN_PATH)
val projectRootPathBefore = projectRootPath.substringBefore(SRC_MAIN_PATH)
if (index < 0 || projectRootPathBefore.length < index) return null
val subProjectName =
originFilePath.substring(projectRootPathBefore.length, index)

val daoFile =
contentRoot
.findFileByRelativePath(subProjectName)
?.findFileByRelativePath(relativeDaoFilePath)

return daoFile
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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.CommonPathParameterHelper.RESOURCES_META_INF_PATH

fun getJarRoot(
virtualFile: VirtualFile,
Expand Down
Loading