Package dtool.ast.expressions

Source Code of dtool.ast.expressions.ExpThis

package dtool.ast.expressions;

import java.util.Collection;
import java.util.Collections;

import dtool.ast.ASTCodePrinter;
import dtool.ast.ASTNode;
import dtool.ast.ASTNodeTypes;
import dtool.ast.IASTVisitor;
import dtool.ast.definitions.DefinitionClass;
import dtool.ast.definitions.INamedElement;
import dtool.engine.modules.IModuleResolver;

public class ExpThis extends Expression {
 
  public ExpThis() {
  }
 
  @Override
  public ASTNodeTypes getNodeType() {
    return ASTNodeTypes.EXP_THIS;
  }
 
  @Override
  public void visitChildren(IASTVisitor visitor) {
  }
 
  @Override
  public void toStringAsCode(ASTCodePrinter cp) {
    cp.append("this");
  }
 
  @Override
  public Collection<INamedElement> findTargetDefElements(IModuleResolver moduleResolver, boolean findFirstOnly) {
    DefinitionClass definitionClass = getClassNodeParent(this);
    if(definitionClass == null) {
      return null;
    }
    return Collections.<INamedElement>singleton(definitionClass);
  }
 
  public static DefinitionClass getClassNodeParent(ASTNode node) {
    do {
      node = node.getParent();
      if(node instanceof DefinitionClass) {
        DefinitionClass definitionClass = (DefinitionClass) node;
        return definitionClass;
      }
    } while(node != null);
    return null;
  }
 
}
TOP

Related Classes of dtool.ast.expressions.ExpThis

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.