Advertisement
Guest User

Untitled

a guest
May 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public Variable lookupVariable(String id) {
  2. /*
  3. * A variable lookup can only occur inside a method or a class.
  4. * Everything else is invalid.
  5. */
  6. /*
  7. * TODO: improve this hack!
  8. */
  9. Variable variable;
  10. Scopeable currentScope = this.currentScope();
  11. Scopeable outerScope = this.currentScope().getOuterScope();
  12.  
  13. if((variable = currentScope.lookupVariable(id)) != null){ // check local scope
  14. return variable;
  15. } else if(outerScope != null) { // check class scope / outer scope
  16. Identifier classId;
  17. if((variable = outerScope.lookupVariable(id)) != null) {
  18. return variable;
  19. } else if(outerScope.isClass() && (classId = outerScope.getId()) != null) { // check parent class scope
  20. Klass klass = this.globalScope().lookupClass(classId.toString());
  21. Klass derivedClass;
  22. if(klass.isDerived() && (derivedClass = this.globalScope().lookupClass(klass.getDerivedId())) != null) {
  23. if((variable = derivedClass.lookupVariable(id)) != null) {
  24. return variable;
  25. }
  26. }
  27. }
  28. }
  29. return null;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement