1 24 25 package org.aspectj.compiler.base; 26 27 import org.aspectj.compiler.base.ast.*; 28 29 import java.util.*; 30 31 55 56 public class MemberClassMunger extends WalkerPass { 57 58 public MemberClassMunger(JavaCompiler compiler) { 59 super(compiler); 60 } 61 62 public String getDisplayName() { 63 return "munging inner classes"; 64 } 65 66 private Stack types = new Stack(); 67 public void enterType(NameType t) { 68 types.push(t); 69 } 70 public void leaveType() { 71 types.pop(); 72 } 73 public NameType currentType() { 74 return (NameType) types.peek(); 75 } 76 77 private List fields = new ArrayList(); 78 public void pushField(FieldDec dec) { 79 fields.add(dec); 80 } 81 public void popField() { 82 fields.remove(fields.size() - 1); 83 } 84 public FieldDec currentField() { 85 return (FieldDec) fields.get(fields.size() - 1); 86 } 87 public List saveFields() { 89 List fields = this.fields; 90 this.fields = new ArrayList(); 91 return fields; 92 } 93 public void restoreFields(List fields) { 94 this.fields = fields; 95 } 96 97 public Expr buildExprFromEnclosing(Expr seed, NameType targetType) { 98 return buildExpr(seed, targetType, fields.size() - 2); 99 } 100 public Expr buildExprFromThis(Expr seed, NameType targetType) { 101 return buildExpr(seed, targetType, fields.size() - 1); 102 } 103 104 private Expr buildExpr(Expr seed, NameType targetType, int i) { 105 final AST ast = getAST(); 106 while (true) { 107 Type currType = seed.getType(); 108 if (currType == targetType) { 109 return seed; 110 } else { 111 if (i < 0) { 112 throw new RuntimeException ("Can't get to " + targetType 113 + " from " + seed); 114 } 115 seed = ast.makeGet(seed, (FieldDec) fields.get(i--)); 116 } 117 } 118 } 119 120 public ASTObject process(ASTObject object) { 121 return object.walkMemberMunger(this); 122 } 123 } 124 125 | Popular Tags |