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.psi.search
18+
19+ import com.intellij.openapi.project.Project
20+ import com.intellij.util.Processor
21+ import com.tang.intellij.lua.psi.LuaClass
22+ import com.tang.intellij.lua.psi.LuaClassMember
23+ import com.tang.intellij.lua.psi.LuaTypeAlias
24+ import com.tang.intellij.lua.search.SearchContext
25+ import com.tang.intellij.lua.ty.ITyClass
26+
27+ class CompositeLuaShortNamesManager : LuaShortNamesManager () {
28+ private val list = EP_NAME .extensions
29+
30+ override fun findClass (name : String , context : SearchContext ): LuaClass ? {
31+ for (ep in list) {
32+ val c = ep.findClass(name, context)
33+ if (c != null )
34+ return c
35+ }
36+ return null
37+ }
38+
39+ override fun findMember (type : ITyClass , fieldName : String , context : SearchContext ): LuaClassMember ? {
40+ for (manager in list) {
41+ val ret = manager.findMember(type, fieldName, context)
42+ if (ret != null ) return ret
43+ }
44+ return null
45+ }
46+
47+ override fun processAllClassNames (project : Project , processor : Processor <String >): Boolean {
48+ for (ep in list) {
49+ if (! ep.processAllClassNames(project, processor))
50+ return false
51+ }
52+ return true
53+ }
54+
55+ override fun processClassesWithName (name : String , context : SearchContext , processor : Processor <LuaClass >): Boolean {
56+ for (ep in list) {
57+ if (! ep.processClassesWithName(name, context, processor))
58+ return false
59+ }
60+ return true
61+ }
62+
63+ override fun getClassMembers (clazzName : String , context : SearchContext ): Collection <LuaClassMember > {
64+ val collection = mutableListOf<LuaClassMember >()
65+ for (manager in list) {
66+ val col = manager.getClassMembers(clazzName, context)
67+ collection.addAll(col)
68+ }
69+ return collection
70+ }
71+
72+ override fun processAllMembers (type : ITyClass , fieldName : String , context : SearchContext , processor : Processor <LuaClassMember >): Boolean {
73+ for (manager in list) {
74+ if (! manager.processAllMembers(type, fieldName, context, processor))
75+ return false
76+ }
77+ return true
78+ }
79+
80+ override fun findAlias (name : String , context : SearchContext ): LuaTypeAlias ? {
81+ for (manager in list) {
82+ val alias = manager.findAlias(name, context)
83+ if (alias != null )
84+ return alias
85+ }
86+ return null
87+ }
88+
89+ override fun processAllAlias (project : Project , processor : Processor <String >): Boolean {
90+ for (manager in list) {
91+ if (! manager.processAllAlias(project, processor))
92+ return false
93+ }
94+ return true
95+ }
96+ }
0 commit comments