1 24 25 package org.aspectj.compiler.crosscuts.ast; 26 27 import org.aspectj.compiler.crosscuts.joinpoints.TypeDecPlanner; 28 import org.aspectj.compiler.crosscuts.*; 29 30 import org.aspectj.compiler.base.ast.*; 31 import org.aspectj.compiler.base.cst.*; 32 33 import org.aspectj.compiler.base.JavaCompiler; 34 import org.aspectj.compiler.base.bcg.ClassfileBuilder; 35 36 import java.util.*; 37 38 43 44 public class IntroducedDec extends Dec implements TypeDecPlanner { 45 private List introducedDecs = new LinkedList(); 46 47 48 public Modifiers getModifiers() { return dec.getModifiers(); } 49 50 Scope myLexicalScope = null; 51 public void walkScope(ScopeWalker walker) { 52 walker.process(targets); 53 boolean saveWalkBodies = walker.walkBodies(); 54 walker.setWalkBodies(false); 55 walker.process(dec); 56 walker.setWalkBodies(saveWalkBodies); 57 58 59 myLexicalScope = walker.getScope(); 60 dec.setParent(this); 61 getWorld().addTypeDecPlanner(this); 62 } 63 64 65 73 74 78 public boolean isStatic() { return true; } 79 80 public String getUniqueIdString(Type onType) { 81 String ret = null; 82 83 if (isPrivate()) { 84 ret = getLexicalType().getPrivateCookieType().getPrettyString(); 85 } else if (isProtected()) { 86 showError("protected introduction not allowed"); 87 ret = ""; 88 } else if (isPublic()) { 89 ret = ""; 90 } else { ret = getLexicalType().getPackageName(); 92 } 93 94 if (onType.isInterface() && dec instanceof FieldDec) { 95 ret += "_" + onType.getPrettyString(); 96 } 97 98 return ret; 99 } 100 101 public void plan(TypeDec typeDec, int phase) { 102 if (phase != TypeDecPlanner.SIGNATURE) return; 103 104 Type toType = typeDec.getType(); 105 106 if (!getTargets().matches(toType)) return; 107 108 117 120 Dec newDec = (Dec)CopyWalker.rawCopy(dec, toType); 121 newDec.setSourceLocation(getAST().getSourceLocation()); 122 newDec.setLanguageVisible(); 123 124 if (isPublic()) { 127 newDec.setExplicitlyNonSynthetic(); 128 } 129 newDec.setDeclaringType(toType); 130 newDec.setLexicalType(getLexicalType()); 131 newDec.setFromLexicalScope(myLexicalScope); 132 133 134 if (!isPublic() || (newDec instanceof FieldDec && typeDec instanceof InterfaceDec)) { 135 String newId = getAST().makeGeneratedName(newDec.getBytecodeId() + '_' + 136 getUniqueIdString(typeDec.getType())); 137 newDec.setBytecodeId(newId); 138 } 139 140 typeDec.addIntroducedDec(newDec); 142 typeDec.addExtraWithinType(this.getLexicalType()); 143 144 ((AspectJCompiler)getCompiler()).getCorrespondences().addPointsTo(this, typeDec); 145 getCompiler().showMessage(" introduced " + newDec.toShortString() + " on " + 146 typeDec.getType().toShortString()); 147 } 148 149 public String getKind() { 150 return "introduction"; 151 } 152 153 public String getId() { return dec.getId(); } 154 155 public String toShortString() { 156 return targets.toShortString()+"."+dec.getId(); 157 } 158 159 162 protected void cgMember(ClassfileBuilder maker) {} 165 166 protected GenTypeName targets; 168 public GenTypeName getTargets() { return targets; } 169 public void setTargets(GenTypeName _targets) { 170 if (_targets != null) _targets.setParent(this); 171 targets = _targets; 172 } 173 174 protected Dec dec; 175 public Dec getDec() { return dec; } 176 public void setDec(Dec _dec) { dec = _dec; } 177 178 public IntroducedDec(SourceLocation location, GenTypeName _targets, Dec _dec) { 179 super(location); 180 setTargets(_targets); 181 setDec(_dec); 182 } 183 protected IntroducedDec(SourceLocation source) { 184 super(source); 185 } 186 187 public ASTObject copyWalk(CopyWalker walker) { 188 IntroducedDec ret = new IntroducedDec(getSourceLocation()); 189 ret.preCopy(walker, this); 190 if (targets != null) ret.setTargets( (GenTypeName)walker.process(targets) ); 191 ret.dec = dec; 192 return ret; 193 } 194 195 public ASTObject getChildAt(int childIndex) { 196 switch(childIndex) { 197 case 0: return targets; 198 default: return super.getChildAt(childIndex); 199 } 200 } 201 public String getChildNameAt(int childIndex) { 202 switch(childIndex) { 203 case 0: return "targets"; 204 default: return super.getChildNameAt(childIndex); 205 } 206 } 207 public void setChildAt(int childIndex, ASTObject child) { 208 switch(childIndex) { 209 case 0: setTargets((GenTypeName)child); return; 210 default: super.setChildAt(childIndex, child); return; 211 } 212 } 213 public int getChildCount() { 214 return 1; 215 } 216 217 public String getDefaultDisplayName() { 218 return "IntroducedDec(dec: "+dec+")"; 219 } 220 221 } 223 224 225 226 | Popular Tags |