Skip to content

Commit

Permalink
root file
Browse files Browse the repository at this point in the history
  • Loading branch information
kkkkkkkkkkkkkkeee committed Jan 6, 2020
1 parent 8a60f91 commit 748bf93
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/com/ruiyu/file/FileHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.*
import com.intellij.psi.impl.source.tree.CompositeElement
import com.intellij.psi.search.FilenameIndex
import com.jetbrains.lang.dart.DartLanguage
import com.jetbrains.lang.dart.DartTokenTypes
import com.ruiyu.jsontodart.AnnotationValue
import com.ruiyu.jsontodart.HelperClassGeneratorInfo
Expand All @@ -18,6 +17,7 @@ import io.flutter.utils.FlutterModuleUtils
//import org.jetbrains.kotlin.idea.refactoring.toPsiFile
import org.jetbrains.kotlin.psi.psiUtil.children
import org.yaml.snakeyaml.Yaml
import wu.seal.jsontokotlin.utils.showErrorMessage
import java.io.File
import java.io.FileInputStream

Expand Down Expand Up @@ -82,7 +82,7 @@ object FileHelpers {
* 获取generated/json自动生成目录
*/
private fun getGeneratedFile(project: Project): VirtualFile {
return PubRoot.forFile(project.projectFile)?.lib?.let { lib ->
return PubRoot.forFile(getProjectIdeaFile(project))?.lib?.let { lib ->
return@let (lib.findChild("generated")
?: lib.createChildDirectory(this, "generated")).run {
return@run (findChild("json")
Expand All @@ -91,6 +91,17 @@ object FileHelpers {
}!!
}

/**
* 获取项目.idea目录的一个文件
*/
private fun getProjectIdeaFile(project: Project): VirtualFile? {
val ideaFile = project.projectFile ?: project.workspaceFile
if (ideaFile == null) {
project.showErrorMessage("Missing .idea/misc.xml or .idea/workspace.xml file")
}
return ideaFile
}

/**
* 获取generated/json自动生成目录
*/
Expand Down Expand Up @@ -172,7 +183,7 @@ object FileHelpers {
@Suppress("DuplicatedCode")
@JvmStatic
fun getPubSpecConfig(project: Project): PubSpecConfig? {
PubRoot.forFile(project.projectFile)?.let { pubRoot ->
PubRoot.forFile(getProjectIdeaFile(project))?.let { pubRoot ->
FileInputStream(pubRoot.pubspec.path).use { inputStream ->
(Yaml().load(inputStream) as? Map<String, Any>)?.let { map ->
return PubSpecConfig(project, pubRoot, map)
Expand Down

0 comments on commit 748bf93

Please sign in to comment.