private void _populateLocalVariables( SNode statementList, SNode beforeStatement, List<SNode> result) { if (statementList == null) { return; } if (statementList != beforeStatement) { this._populateLocalVariablesFromList(statementList, beforeStatement, result); } SNode containingStatement = SNodeOperations.as( LocalVariablesScope.findThisOrParent( statementList, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.ILocalVariableElement")), "jetbrains.mps.baseLanguage.structure.ILocalVariableElement"); if (containingStatement != null) { statementList = SNodeOperations.getAncestor( containingStatement, "jetbrains.mps.baseLanguage.structure.ILocalVariableElementList", false, false); this._populateLocalVariables(statementList, containingStatement, result); } }
private void _populateLocalVariables(SNode loopStatement, List<SNode> result) { for (SNode child : SNodeOperations.getChildren(loopStatement)) { if (child.getRoleInParent().equals("body")) { continue; } if (SNodeOperations.isInstanceOf( child, "jetbrains.mps.baseLanguage.structure.LocalVariableDeclaration")) { result.add(child); } // <node> List<SNode> moreChildren = new ArrayList<SNode>(); if (SNodeOperations.isInstanceOf( loopStatement, "jetbrains.mps.lang.typesystem.structure.MultipleForeachLoop")) { ListSequence.fromList(moreChildren) .addSequence( ListSequence.fromList( SLinkOperations.getTargets( SNodeOperations.cast( loopStatement, "jetbrains.mps.lang.typesystem.structure.MultipleForeachLoop"), "loopVariable", true)) .where( new IWhereFilter<SNode>() { public boolean accept(SNode it) { return (SLinkOperations.getTarget(it, "variable", true) != null); } }) .select( new ISelector<SNode, SNode>() { public SNode select(SNode it) { return SLinkOperations.getTarget(it, "variable", true); } })); } for (SNode child_ : moreChildren) { result.add(child_); } } SNode containingLoop = SNodeOperations.as( LocalVariablesScope.findThisOrParent( SNodeOperations.getParent(loopStatement), SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement")), "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement"); if (containingLoop != null) { this._populateLocalVariables(containingLoop, result); } }
private void _populateLocalVariablesForCatch(SNode tryCatchStatement, List<SNode> result) { SNode throwable = SLinkOperations.getTarget(tryCatchStatement, "throwable", true); if (throwable != null) { result.add(throwable); } SNode containingCatchClause = SNodeOperations.as( LocalVariablesScope.findThisOrParent( SNodeOperations.getParent(tryCatchStatement), SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.CatchClause")), "jetbrains.mps.baseLanguage.structure.CatchClause"); if (containingCatchClause != null) { this._populateLocalVariablesForCatch(containingCatchClause, result); } }
@NotNull @Override public List<SNode> getNodes(Condition<SNode> condition) { if (this.myLocalVariables == null) { this.myLocalVariables = new ArrayList<SNode>(); SNode statementList = SNodeOperations.as( LocalVariablesScope.findThisOrParent( this.myContextNode, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.ILocalVariableElementList")), "jetbrains.mps.baseLanguage.structure.ILocalVariableElementList"); if (statementList != null) { SNode currentStatement = SNodeOperations.as( LocalVariablesScope.findThisOrParent( this.myContextNode, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.ILocalVariableElement")), "jetbrains.mps.baseLanguage.structure.ILocalVariableElement"); this._populateLocalVariables(statementList, currentStatement, this.myLocalVariables); } // specially process loop variables SNode loopStatement = SNodeOperations.as( LocalVariablesScope.findThisOrParent( this.myContextNode, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement")), "jetbrains.mps.baseLanguage.structure.AbstractLoopStatement"); if (loopStatement != null) { this._populateLocalVariables(loopStatement, this.myLocalVariables); } // specially process catch variables SNode catchClause = SNodeOperations.as( LocalVariablesScope.findThisOrParent( this.myContextNode, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.CatchClause")), "jetbrains.mps.baseLanguage.structure.CatchClause"); if (catchClause != null) { this._populateLocalVariablesForCatch(catchClause, this.myLocalVariables); } // specially process variables in switch cases before current SNode switchStatement = SNodeOperations.as( findThisOrParent( myContextNode, SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.SwitchStatement")), "jetbrains.mps.baseLanguage.structure.SwitchStatement"); while ((switchStatement != null)) { SNode caseStatement = getLastSourceNode(this.myContextNode, switchStatement); if (caseStatement != SLinkOperations.getTarget(switchStatement, "expression", true) && caseStatement != switchStatement) { for (SNode caseClause : ListSequence.fromList(SLinkOperations.getTargets(switchStatement, "case", true))) { if (caseClause == caseStatement) { break; } _populateLocalVariablesFromList( SLinkOperations.getTarget(caseClause, "body", true), null, myLocalVariables); } } switchStatement = SNodeOperations.as( findThisOrParent( SNodeOperations.getParent(switchStatement), SConceptOperations.findConceptDeclaration( "jetbrains.mps.baseLanguage.structure.SwitchStatement")), "jetbrains.mps.baseLanguage.structure.SwitchStatement"); } // filter nulls List<SNode> tmp = new ArrayList<SNode>(); for (SNode node : myLocalVariables) { if (node != null) { tmp.add(node); } } myLocalVariables = tmp; } if (condition == AbstractSearchScope.TRUE_CONDITION) { return this.myLocalVariables; } List<SNode> result = new ArrayList<SNode>(this.myLocalVariables.size()); for (SNode node : this.myLocalVariables) { if (condition.met(node)) { result.add(node); } } return result; }