Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2003-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.codehaus.groovy.ast;
 
 import java.util.Map;

Represents a variable scope. This is primarily used to determine variable sharing across method and closure boundaries.

Author(s):
James Strachan
Jochen Theodorou
Version:
$Revision: 14564 $
 
 public class VariableScope  {
     private Map declaredVariables = .;
  
     private boolean inStaticContext = false;
     private boolean resolvesDynamic = false
     // Non-null iff this scope corresponds to a class, as opposed to a method, "if" statement,
     // block statement, etc.
     private ClassNode clazzScope;
     private VariableScope parent;
 
     public VariableScope() {
     }
     public VariableScope(VariableScope parent) {
         this. = parent;
     }
 
     public Variable getDeclaredVariable(String name) {
         return (Variable.get(name);
     }
 
     public boolean isReferencedLocalVariable(String name) {
         return .containsKey(name);
     }
     
     public boolean isReferencedClassVariable(String name) {
         return .containsKey(name);
     }
     public VariableScope getParent() {
         return ;
     }
 
     public boolean isInStaticContext() {
         return ;
     }
 
     public void setInStaticContext(boolean inStaticContext) {
         this. = inStaticContext;
     }
 
     public boolean isResolvingDynamic() {
         return ;
     }
 
     public void setDynamicResolving(boolean resolvesDynamic) {
         this. = resolvesDynamic;
     }
 
     public void setClassScope(ClassNode node) {
         this. = node;
     }
    
    
Non-null iff this scope corresponds to a class; as opposed to a method, "if" statement, block statement, etc.
 
     public ClassNode getClassScope(){
         return ;
     }
    
    
Returns true iff this scope corresponds to a class; as opposed to a method, "if" statement, block statement, etc.
 
     public boolean isClassScope(){
         return !=null;
     }
     
    public boolean isRoot() {
        return ==null;
    }
    
    public VariableScope copy() {
        VariableScope copy = new VariableScope();
        copy.clazzScope = ;
        if (.size() > 0) {
          copy.declaredVariables = new HashMap();
          copy.declaredVariables.putAll();
        }
        copy.inStaticContext = ;
        copy.parent = ;
        if (.size() > 0) {
            copy.referencedClassVariables = new HashMap();
            copy.referencedClassVariables.putAll();
        }
        if (.size() > 0) {
            copy.referencedLocalVariables = new HashMap();
            copy.referencedLocalVariables.putAll();
        }
        copy.resolvesDynamic = ;
        return copy;
    }
    public void putDeclaredVariable(Variable var) {
        if ( == .)
           = new HashMap();
        .put(var.getName(), var);
    }
        return .values().iterator();
    }
    public int getReferencedLocalVariablesCount() {
        return .size();
    }
    public Variable getReferencedLocalVariable(String name) {
        return (Variable.get(name);
    }
    public void putReferencedLocalVariable(Variable var) {
           = new HashMap();
        .put(var.getName(), var);
    }
    public void putReferencedClassVariable(Variable var) {
           = new HashMap();
        .put(var.getName(), var);
    }
    public Variable getReferencedClassVariable(String name) {
        return (Variable.get(name); 
    }
          return null;
        else
          return .remove(name);
    }
    
    
Gets a map containing the class variables referenced by this scope. This not can not be modified.

Returns:
a map containing the class variable references
    public Map getReferencedClassVariables() {
        if ( == .) {
            return .;
        } else {
            return Collections.unmodifiableMap();
        }
    }
    
    
Gets an iterator for the referenced class variables. The remove operation is not supported.

Returns:
an iterator for the referenced class variables
        return getReferencedClassVariables().values().iterator();
    }
New to GrepCode? Check out our FAQ X