Last active
August 29, 2015 14:19
-
-
Save lexruee/9fc2704c2997ad22e40f to your computer and use it in GitHub Desktop.
ugly code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Variable lookupVariable(String id) { | |
/* | |
* A variable lookup can only occur inside a method or a class. | |
* Everything else is invalid. | |
*/ | |
/* | |
* TODO: improve this hack! | |
*/ | |
Variable variable; | |
Scopeable currentScope = this.currentScope(); | |
Scopeable outerScope = this.currentScope().getOuterScope(); | |
if((variable = currentScope.lookupVariable(id)) != null){ // check local scope | |
return variable; | |
} else if(outerScope != null) { // check class scope / outer scope | |
Identifier classId; | |
if((variable = outerScope.lookupVariable(id)) != null) { | |
return variable; | |
} else if(outerScope.isClass() && (classId = outerScope.getId()) != null) { // check parent class scope | |
Klass klass = this.globalScope().lookupClass(classId.toString()); | |
Klass derivedClass; | |
if(klass.isDerived() && (derivedClass = this.globalScope().lookupClass(klass.getDerivedId())) != null) { | |
if((variable = derivedClass.lookupVariable(id)) != null) { | |
return variable; | |
} | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After refactoring the code above becomes: