Skip to content

Commit 71af70a

Browse files
committed
I LOVE KOTLIN
1 parent bd52f5e commit 71af70a

File tree

2 files changed

+64
-74
lines changed

2 files changed

+64
-74
lines changed

src/main/java/com/tang/intellij/lua/search/SearchContext.java

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2017. tangzx([email protected])
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+
* http://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+
17+
package com.tang.intellij.lua.search
18+
19+
import com.intellij.openapi.project.DumbService
20+
import com.intellij.openapi.project.Project
21+
import com.intellij.psi.PsiFile
22+
import com.intellij.psi.search.GlobalSearchScope
23+
import com.intellij.psi.search.ProjectAndLibrariesScope
24+
import com.intellij.util.indexing.AdditionalIndexedRootsScope
25+
import com.tang.intellij.lua.lang.GuessTypeKind
26+
import com.tang.intellij.lua.project.LuaPredefinedLibraryProvider
27+
28+
/**
29+
30+
* Created by tangzx on 2017/1/14.
31+
*/
32+
class SearchContext(val project: Project) {
33+
34+
private var currentStubFile: PsiFile? = null
35+
private var scope: GlobalSearchScope? = null
36+
private var guessTypeKind = GuessTypeKind.Standard
37+
38+
fun setGuessTypeKind(value: Int) {
39+
guessTypeKind = value
40+
}
41+
42+
fun isGuessTypeKind(kind: Int): Boolean {
43+
return guessTypeKind and kind == kind
44+
}
45+
46+
fun setCurrentStubFile(currentStubFile: PsiFile): SearchContext {
47+
this.currentStubFile = currentStubFile
48+
return this
49+
}
50+
51+
fun getScope(): GlobalSearchScope {
52+
if (scope == null) {
53+
if (isDumb) {
54+
scope = GlobalSearchScope.EMPTY_SCOPE
55+
} else {
56+
scope = AdditionalIndexedRootsScope(ProjectAndLibrariesScope(project), LuaPredefinedLibraryProvider::class.java)
57+
}
58+
}
59+
return scope!!
60+
}
61+
62+
val isDumb: Boolean
63+
get() = DumbService.isDumb(project) || currentStubFile != null
64+
}

0 commit comments

Comments
 (0)