1 24 25 package org.aspectj.compiler.base.ast; 26 27 28 import java.util.*; 29 30 import org.aspectj.compiler.base.JavaCompiler; 31 import org.aspectj.compiler.base.*; 32 import org.aspectj.compiler.base.cst.*; 33 34 38 39 public class ClassDec extends TypeDec { 40 public String getKind() { return "class"; } 41 42 private boolean isAnonymousFlag = false; 43 public boolean isAnonymous() { return isAnonymousFlag || getId().equals("ANONYMOUS"); } 44 public void setIsAnonymous() { isAnonymousFlag = true; } 45 46 public ASTObject postCopy(CopyWalker walker, ASTObject oldObject) { 47 this.isAnonymousFlag = ((ClassDec)oldObject).isAnonymousFlag; 48 this.isInnerFlag = ((ClassDec)oldObject).isInnerFlag; 49 if (walker.isStatic) this.isInnerFlag = false; 52 return super.postCopy(walker, oldObject); 53 } 54 55 protected void walkExtendsAndImplements(ScopeWalker walker) { 56 if (superClass != null) { 57 setSuperClass((TypeD)walker.process(superClass)); 58 } 59 super.walkExtendsAndImplements(walker); 61 } 62 63 64 public Type getSuperClassType() { 65 Type superType; 66 if (superClass == null) superType = getTypeManager().getObjectType(); 67 else superType = superClass.getType(); 68 69 if (!type.isAspect() && superType.isAspect()) { 71 superClass.showError("class may not extend an aspect"); 72 } 73 74 if (superType.isClass()) return superType; 75 76 if (isAnonymous()) { 78 setSuperInterfaces(getAST().makeTypeDs(superClass)); 79 superType = getTypeManager().getObjectType(); 80 setSuperClass(superType.makeTypeD()); 81 } else { 82 superClass.showError(toShortString() + " must extend a class, not " + superType.toShortString()); 83 return getTypeManager().TYPE_NOT_FOUND; 84 } 85 return superType; 86 } 87 88 89 public void unparse(CodeWriter writer) { 90 writer.write(modifiers); 91 writer.writeKeyword("class"); 92 writer.requiredSpace(); 93 writer.write(id); 94 95 if (superClass != null) { 96 writer.requiredSpace(); 97 writer.write("extends"); 98 writer.requiredSpace(); 99 writer.write(superClass); 100 } 101 102 writeNames(writer, "implements", superInterfaces); 103 104 if (!writer.isOnlySignatures()) { 105 writer.optionalSpace(); 106 writer.openBlock(); 107 writer.write(body); 108 writer.newLine(); 109 writer.closeBlock(); 110 } 111 } 112 113 114 117 public void walkInnerInfo(InnerInfoPass w) { 118 setIsInner(! isStatic() && w.isInDynamicContext()); 119 super.walkInnerInfo(w); 120 } 121 122 125 127 private boolean isInnerFlag = false; 128 public void setIsInner(boolean b) { isInnerFlag = b; } 129 public boolean isInner() { return isInnerFlag; } 130 131 protected TypeD superClass; 133 public TypeD getSuperClass() { return superClass; } 134 public void setSuperClass(TypeD _superClass) { 135 if (_superClass != null) _superClass.setParent(this); 136 superClass = _superClass; 137 } 138 139 public ClassDec(SourceLocation location, Modifiers _modifiers, String _id, TypeD _superClass, TypeDs _superInterfaces, Decs _body) { 140 super(location, _modifiers, _id, _superInterfaces, _body); 141 setSuperClass(_superClass); 142 } 143 protected ClassDec(SourceLocation source) { 144 super(source); 145 } 146 147 public ASTObject copyWalk(CopyWalker walker) { 148 ClassDec ret = new ClassDec(getSourceLocation()); 149 ret.preCopy(walker, this); 150 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 151 ret.id = id; 152 if (superClass != null) ret.setSuperClass( (TypeD)walker.process(superClass) ); 153 if (superInterfaces != null) ret.setSuperInterfaces( (TypeDs)walker.process(superInterfaces) ); 154 if (body != null) ret.setBody( (Decs)walker.process(body) ); 155 return ret; 156 } 157 158 public ASTObject getChildAt(int childIndex) { 159 switch(childIndex) { 160 case 0: return modifiers; 161 case 1: return superClass; 162 case 2: return superInterfaces; 163 case 3: return body; 164 default: return super.getChildAt(childIndex); 165 } 166 } 167 public String getChildNameAt(int childIndex) { 168 switch(childIndex) { 169 case 0: return "modifiers"; 170 case 1: return "superClass"; 171 case 2: return "superInterfaces"; 172 case 3: return "body"; 173 default: return super.getChildNameAt(childIndex); 174 } 175 } 176 public void setChildAt(int childIndex, ASTObject child) { 177 switch(childIndex) { 178 case 0: setModifiers((Modifiers)child); return; 179 case 1: setSuperClass((TypeD)child); return; 180 case 2: setSuperInterfaces((TypeDs)child); return; 181 case 3: setBody((Decs)child); return; 182 default: super.setChildAt(childIndex, child); return; 183 } 184 } 185 public int getChildCount() { 186 return 4; 187 } 188 189 public String getDefaultDisplayName() { 190 return "ClassDec(id: "+id+")"; 191 } 192 193 } 195 | Popular Tags |