1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import org.aspectj.compiler.base.bcg.CodeBuilder; 30 31 35 36 37 public class QualifiedThisExpr extends ThisExpr { 39 public Type discoverType() { 40 return typeD.getType(); 41 } 42 43 public ASTObject postFixAST(final ASTFixerPass fixer) { 45 return this; 51 } 52 53 54 public void unparse(CodeWriter writer) { 55 if (getBytecodeType() == getType()) { 56 writer.write("this"); 57 } else { 58 writer.write(getType().getId()); 59 writer.write(".this"); 60 } 61 } 62 63 66 public ASTObject walkMemberMunger(MemberClassMunger w) { 67 final AST ast = getAST(); 68 NameType currentType = w.currentType(); 69 NameType targetType = (NameType) getTypeD().getType(); 70 if (currentType == targetType) { 71 return ast.makeThis(currentType); 72 } else { 73 CodeDec dec = getEnclosingCodeDec(); 74 if (dec instanceof ConstructorDec) { 75 ConstructorDec cdec = (ConstructorDec) dec; 76 Expr seed = ast.makeVar(cdec.getEnclosingInstanceFormal()); 77 return w.buildExprFromEnclosing(seed, targetType); 78 } else { 79 Expr seed = ast.makeThis(currentType); 80 return w.buildExprFromThis(seed, targetType); 81 } 82 } 83 } 84 85 protected void cgValue(CodeBuilder cb) { 88 throw new RuntimeException ("Invalid expression " + this); 89 } 90 91 protected TypeD typeD; 93 public TypeD getTypeD() { return typeD; } 94 public void setTypeD(TypeD _typeD) { 95 if (_typeD != null) _typeD.setParent(this); 96 typeD = _typeD; 97 } 98 99 public QualifiedThisExpr(SourceLocation location, TypeD _typeD) { 100 super(location); 101 setTypeD(_typeD); 102 } 103 protected QualifiedThisExpr(SourceLocation source) { 104 super(source); 105 } 106 107 public ASTObject copyWalk(CopyWalker walker) { 108 QualifiedThisExpr ret = new QualifiedThisExpr(getSourceLocation()); 109 ret.preCopy(walker, this); 110 if (typeD != null) ret.setTypeD( (TypeD)walker.process(typeD) ); 111 return ret; 112 } 113 114 public ASTObject getChildAt(int childIndex) { 115 switch(childIndex) { 116 case 0: return typeD; 117 default: return super.getChildAt(childIndex); 118 } 119 } 120 public String getChildNameAt(int childIndex) { 121 switch(childIndex) { 122 case 0: return "typeD"; 123 default: return super.getChildNameAt(childIndex); 124 } 125 } 126 public void setChildAt(int childIndex, ASTObject child) { 127 switch(childIndex) { 128 case 0: setTypeD((TypeD)child); return; 129 default: super.setChildAt(childIndex, child); return; 130 } 131 } 132 public int getChildCount() { 133 return 1; 134 } 135 136 public String getDefaultDisplayName() { 137 return "QualifiedThisExpr()"; 138 } 139 140 } 142 | Popular Tags |