@@ -25,7 +25,7 @@ package de.halirutan.mathematica.lang.resolve.processors
2525
2626import com.intellij.psi.PsiElement
2727import com.intellij.psi.ResolveState
28- import com.intellij.psi.scope.BaseScopeProcessor
28+ import com.intellij.psi.scope.PsiScopeProcessor
2929import com.intellij.psi.util.PsiTreeUtil
3030import de.halirutan.mathematica.lang.psi.LocalizationConstruct
3131import de.halirutan.mathematica.lang.psi.LocalizationConstruct.MScope
@@ -80,73 +80,73 @@ import de.halirutan.mathematica.lang.resolve.resolvers.TableLikeResolver
8080 *
8181 * @author patrick (5/22/13)
8282 */
83- class LocalDefinitionResolveProcessor (private val myStartElement : Symbol ) : BaseScopeProcessor() {
84- /* *
85- * Returns the list of all symbols collected during a run. Before returning
86- * the list, it removes duplicates, so that no entry appears more than once in the auto-completion window.
87- *
88- * @return Sorted and cleaned list of collected symbols.
89- */
90- var resolveResult: SymbolResolveResult ? = null
83+ class LocalDefinitionResolveProcessor (private val myStartElement : Symbol ) : PsiScopeProcessor {
84+ /* *
85+ * Returns the list of all symbols collected during a run. Before returning
86+ * the list, it removes duplicates, so that no entry appears more than once in the auto-completion window.
87+ *
88+ * @return Sorted and cleaned list of collected symbols.
89+ */
90+ var resolveResult: SymbolResolveResult ? = null
9191
92- /* *
93- * There are several places where a local variable can be "defined". First I check all localization constructs which
94- * are always function call like `Module[{var},...]`. The complete list of localization constructs can be
95- * found in [MScope].
96- *
97- *
98- * Secondly I check the patterns in e.g. ```f[var_]:=...!``` for `SetDelayed` and `TagSetDelayed`.
99- *
100- *
101- * Finally, `RuleDelayed` constructs are checked.
102- *
103- * @param element
104- * Element to check for defining the [.myStartElement].
105- * @param state State of the resolving.
106- * @return `false` if the search can be stopped, `true` otherwise
107- */
108- override fun execute (element : PsiElement , state : ResolveState ): Boolean {
109- if (element is FunctionCall ) {
92+ /* *
93+ * There are several places where a local variable can be "defined". First I check all localization constructs which
94+ * are always function call like `Module[{var},...]`. The complete list of localization constructs can be
95+ * found in [MScope].
96+ *
97+ *
98+ * Secondly I check the patterns in e.g. ```f[var_]:=...!``` for `SetDelayed` and `TagSetDelayed`.
99+ *
100+ *
101+ * Finally, `RuleDelayed` constructs are checked.
102+ *
103+ * @param element
104+ * Element to check for defining the [.myStartElement].
105+ * @param state State of the resolving.
106+ * @return `false` if the search can be stopped, `true` otherwise
107+ */
108+ override fun execute (element : PsiElement , state : ResolveState ): Boolean {
109+ if (element is FunctionCall ) {
110110
111- if (element.isScopingConstruct) {
112- val scopingConstruct = element.scopingConstruct
111+ if (element.isScopingConstruct) {
112+ val scopingConstruct = element.scopingConstruct
113113
114- when {
115- LocalizationConstruct .isModuleLike(scopingConstruct) -> resolveResult = ModuleLikeResolver ().resolve(myStartElement, element, state)
116- LocalizationConstruct .isFunctionLike(scopingConstruct) -> resolveResult = FunctionLikeResolver ().resolve(myStartElement, element, state)
117- LocalizationConstruct .isCompileLike(scopingConstruct) -> resolveResult = CompileLikeResolver ().resolve(myStartElement, element, state)
118- LocalizationConstruct .isTableLike(scopingConstruct) -> resolveResult = TableLikeResolver ().resolve(myStartElement, element, state)
119- LocalizationConstruct .isManipulateLike(scopingConstruct) -> resolveResult = TableLikeResolver ().resolve(myStartElement, element, state)
120- }
121- resolveResult?.let { return false }
122- }
123- } else if (element is SetDelayed || element is TagSetDelayed || element is Set ) {
114+ when {
115+ LocalizationConstruct .isModuleLike(scopingConstruct) -> resolveResult = ModuleLikeResolver ().resolve(myStartElement, element, state)
116+ LocalizationConstruct .isFunctionLike(scopingConstruct) -> resolveResult = FunctionLikeResolver ().resolve(myStartElement, element, state)
117+ LocalizationConstruct .isCompileLike(scopingConstruct) -> resolveResult = CompileLikeResolver ().resolve(myStartElement, element, state)
118+ LocalizationConstruct .isTableLike(scopingConstruct) -> resolveResult = TableLikeResolver ().resolve(myStartElement, element, state)
119+ LocalizationConstruct .isManipulateLike(scopingConstruct) -> resolveResult = TableLikeResolver ().resolve(myStartElement, element, state)
120+ }
121+ resolveResult?.let { return false }
122+ }
123+ } else if (element is SetDelayed || element is TagSetDelayed || element is Set ) {
124124
125- val p2 = MathematicaPatternVisitor2 ()
126- element.accept(p2)
125+ val p2 = MathematicaPatternVisitor2 ()
126+ element.accept(p2)
127127
128- val patternVisitor = MathematicaPatternVisitor ()
129- element.accept(patternVisitor)
130- for (p in patternVisitor.patternSymbols) {
131- if (p.fullSymbolName == myStartElement.fullSymbolName) {
132- if (element is Set && myStartElement != = p) {
133- continue
134- }
135- resolveResult = SymbolResolveResult (p, MScope .SETDELAYED_SCOPE , element, true )
136- return false
137- }
138- }
139- } else if (element is RuleDelayed ) {
140- val patternExtractor = PatternSymbolExtractor ()
141- element.accept(patternExtractor)
128+ val patternVisitor = MathematicaPatternVisitor ()
129+ element.accept(patternVisitor)
130+ for (p in patternVisitor.patternSymbols) {
131+ if (p.fullSymbolName == myStartElement.fullSymbolName) {
132+ if (element is Set && myStartElement != = p) {
133+ continue
134+ }
135+ resolveResult = SymbolResolveResult (p, MScope .SETDELAYED_SCOPE , element, true )
136+ return false
137+ }
138+ }
139+ } else if (element is RuleDelayed ) {
140+ val patternExtractor = PatternSymbolExtractor ()
141+ element.accept(patternExtractor)
142142
143- for (symbol in patternExtractor.patternSymbols) {
144- if (symbol.fullSymbolName == myStartElement.fullSymbolName) {
145- resolveResult = SymbolResolveResult (symbol, MScope .RULEDELAYED_SCOPE , element, true )
146- return false
147- }
148- }
143+ for (symbol in patternExtractor.patternSymbols) {
144+ if (symbol.fullSymbolName == myStartElement.fullSymbolName) {
145+ resolveResult = SymbolResolveResult (symbol, MScope .RULEDELAYED_SCOPE , element, true )
146+ return false
149147 }
150- return true
148+ }
151149 }
150+ return true
151+ }
152152}
0 commit comments