Java Code Examples for org.codehaus.groovy.ast.VariableScope#putDeclaredVariable()
The following examples show how to use
org.codehaus.groovy.ast.VariableScope#putDeclaredVariable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnknownElementsIndexerTest.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void should_add_to_unknonwn_variables_a_variable_not_declared_and_not_in_the_process_scope() throws Exception { final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS); final List<Statement> statements = new ArrayList<Statement>(); statements.add(new ReturnStatement(new VariableExpression("unkownVariable"))); final VariableScope variableScope = new VariableScope(); variableScope.putDeclaredVariable(new VariableExpression("unkownVariable")); final BlockStatement blockStatement = new BlockStatement(statements, variableScope); when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement); final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer( groovyCompilationUnit); unknownElementsIndexer.run(new NullProgressMonitor()); assertThat(unknownElementsIndexer.getUnknownVaraibles()).containsExactly("unkownVariable"); }
Example 2
Source File: UnknownElementsIndexerTest.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void should_not_add_to_unknonwn_variables_a_variable_declared_but_not_in_the_process_scope() throws Exception { final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS); final List<Statement> statements = new ArrayList<Statement>(); statements.add(new ExpressionStatement( new DeclarationExpression(new VariableExpression("declaredVar"), Token.NULL, new VariableExpression("something")))); statements.add(new ReturnStatement(new VariableExpression("declaredVar"))); final VariableScope variableScope = new VariableScope(); variableScope.putDeclaredVariable(new VariableExpression("declaredVar")); final BlockStatement blockStatement = new BlockStatement(statements, variableScope); when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement); final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer(groovyCompilationUnit); unknownElementsIndexer.run(new NullProgressMonitor()); assertThat(unknownElementsIndexer.getUnknownVaraibles()).isEmpty(); }
Example 3
Source File: UnknownElementsIndexerTest.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Test public void should_add_to_overriden_variables_a_variable_declared_and_already_in_the_process_scope() throws Exception { final BonitaScriptGroovyCompilationUnit groovyCompilationUnit = mock(BonitaScriptGroovyCompilationUnit.class, RETURNS_DEEP_STUBS); Map<String, ScriptVariable> context = new HashMap<String, ScriptVariable>(); context.put("declaredVar", null); when(groovyCompilationUnit.getContext()).thenReturn(context); final List<Statement> statements = new ArrayList<Statement>(); statements.add(new ExpressionStatement( new DeclarationExpression(new VariableExpression("declaredVar"), Token.NULL, new VariableExpression("something")))); statements.add(new ReturnStatement(new VariableExpression("declaredVar"))); final VariableScope variableScope = new VariableScope(); variableScope.putDeclaredVariable(new VariableExpression("declaredVar")); final BlockStatement blockStatement = new BlockStatement(statements, variableScope); when(groovyCompilationUnit.getModuleNode().getStatementBlock()).thenReturn(blockStatement); final UnknownElementsIndexer unknownElementsIndexer = new UnknownElementsIndexer(groovyCompilationUnit); unknownElementsIndexer.run(new NullProgressMonitor()); assertThat(unknownElementsIndexer.getOverridenVariables()).containsExactly(entry("declaredVar", new Position(0))); }
Example 4
Source File: VariablesVisitorTest.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Test public void should_add_a_variable_present_as_a_decalred_variable_in_the_scope() throws Exception { final VariableScope variableScope = new VariableScope(); variableScope.putDeclaredVariable(new VariableExpression("aData")); final VariablesVisitor variablesVisitor = new VariablesVisitor(variableScope); variablesVisitor.visitVariableExpression(new VariableExpression("aData")); assertThat(variablesVisitor.getVariableExpressions()).containsExactly("aData"); }
Example 5
Source File: VariablesVisitorTest.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Test public void should_not_add_a_variable_not_in_the_scope() throws Exception { final VariableScope variableScope = new VariableScope(); variableScope.putDeclaredVariable(new VariableExpression("aData")); final VariablesVisitor variablesVisitor = new VariablesVisitor(variableScope); variablesVisitor.visitVariableExpression(new VariableExpression("varaibleNotInScope")); assertThat(variablesVisitor.getVariableExpressions()).isEmpty(); }
Example 6
Source File: GroovyDocumentUtil.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static void addToVariableScope(GroovyCompilationUnit unit, List<FieldNode> nodes) { VariableScope scope = getVariableScope(unit); while (scope != null) { for (FieldNode f : nodes) { scope.putDeclaredVariable(f); } scope = scope.getParent(); } }