1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import java.util.*; 29 30 33 34 public class InterfaceDec extends TypeDec { 35 public String getKind() { return "interface"; } 36 37 public Type getSuperClassType() { 38 return getTypeManager().getObjectType(); 39 } 40 41 public boolean isAnonymous() { return false; } 42 43 public void checkSpec() { 44 if (isLocal()) { 45 showError("interface may not be defined in code body"); 46 } 47 super.checkSpec(); 48 } 49 50 51 protected void addFieldDec(FieldDec fieldDec) { 52 if (fieldDec.fromSource()) { 53 fieldDec.getModifiers().setPublic(true); 54 fieldDec.getModifiers().setStatic(true); 55 fieldDec.getModifiers().setFinal(true); 56 } 57 super.addFieldDec(fieldDec); 58 } 59 60 protected void addMethodDec(MethodDec methodDec) { 61 if (methodDec.fromSource()) { 62 methodDec.getModifiers().setPublic(true); 63 methodDec.getModifiers().setAbstract(true); 64 } 65 super.addMethodDec(methodDec); 66 } 67 68 protected void addTypeDec(TypeDec typeDec) { 69 if (typeDec.fromSource()) { 70 typeDec.getModifiers().setPublic(true); 71 typeDec.getModifiers().setStatic(true); 72 } 73 super.addTypeDec(typeDec); 74 } 75 76 77 protected void addInitializerDec(InitializerDec dec) { 78 if (dec.fromSource()) { 79 dec.showError("initializer not allowed in interface"); 80 } 81 super.addInitializerDec(dec); 82 } 83 84 88 public void addToHelperClass(Dec dec) { 89 ClassDec helper = getHelperClass(); 90 dec.setDeclaringType(helper.getType()); 91 helper.getBody().add(dec); 92 } 93 94 static final String HELPER_CLASS_NAME = "AJC_HELPER_CLASS"; 95 ClassDec getHelperClass() { 96 Decs body = getBody(); 97 for (int i = 0; i<body.size(); i++) { 98 if (isHelperClass(body.get(i))) return (ClassDec)body.get(i); 99 } 100 ClassDec helper = makeHelperClass(); 101 body.add(helper); 102 103 return helper; 104 } 105 106 public static boolean isHelperClass(Dec dec) { 107 return dec != null && dec instanceof ClassDec && dec.getName().equals(HELPER_CLASS_NAME); 108 } 109 110 ClassDec makeHelperClass() { 111 final AST ast = getAST(); 112 ClassDec ret = ast.makeClass(ast.makeModifiers(Modifiers.PUBLIC|Modifiers.STATIC), 113 HELPER_CLASS_NAME, getTypeManager().getObjectType().makeTypeD(), 114 ast.makeTypeDs()); 115 ret.setEnclosingTypeDec(this); 116 117 FieldDec ref1 = ast.makeField(ast.makeModifiers(Modifiers.PRIVATE|Modifiers.FINAL|Modifiers.STATIC), 120 getTypeManager().getObjectType(), "AJC_INNER_REF"); 121 FieldDec ref2 = ast.makeField(ast.makeModifiers(Modifiers.PUBLIC|Modifiers.FINAL|Modifiers.STATIC), 122 getTypeManager().getObjectType(), "AJC_OUTER_REF"); 123 ret.getBody().add(ref1); 124 getBody().add(ref2); 125 ref1.setInitializer(ast.makeGet(ref2.getField())); 126 ref2.setInitializer(ast.makeGet(ref1.getField())); 127 return ret; 128 } 129 130 public void unparse(CodeWriter writer) { 131 writer.write(modifiers); 132 writer.writeKeyword("interface"); 133 writer.requiredSpace(); 134 writer.write(id); 135 136 writeNames(writer, "extends", superInterfaces); 137 138 if (!writer.isOnlySignatures()) { 139 writer.optionalSpace(); 140 writer.openBlock(); 141 writer.write(body); 142 writer.closeBlock(); 143 } 144 } 145 146 public boolean isStatic() { 147 return true; 148 } 149 150 153 public ASTObject postCleanup(ByteCodeCleanupPass walker) { 154 final int len = getBody().size(); 155 for (int i = 0; i < len; i++ ) { 156 Dec dec = getBody().get(i); 157 Modifiers m = dec.getModifiers(); 158 if (dec instanceof FieldDec) { 159 m.setPublic(true); 160 m.setStatic(true); 161 m.setFinal(true); 162 } else if (dec instanceof MethodDec) { 163 m.setPublic(true); 164 m.setAbstract(true); 165 } 166 } 167 return this; 168 } 169 170 173 public ASTObject postAssignmentCheck(AssignmentCheckerPass walker) { 174 return this; 175 } 176 177 179 public InterfaceDec(SourceLocation location, Modifiers _modifiers, String _id, TypeDs _superInterfaces, Decs _body) { 180 super(location, _modifiers, _id, _superInterfaces, _body); 181 182 } 183 protected InterfaceDec(SourceLocation source) { 184 super(source); 185 } 186 187 public ASTObject copyWalk(CopyWalker walker) { 188 InterfaceDec ret = new InterfaceDec(getSourceLocation()); 189 ret.preCopy(walker, this); 190 if (modifiers != null) ret.setModifiers( (Modifiers)walker.process(modifiers) ); 191 ret.id = id; 192 if (superInterfaces != null) ret.setSuperInterfaces( (TypeDs)walker.process(superInterfaces) ); 193 if (body != null) ret.setBody( (Decs)walker.process(body) ); 194 return ret; 195 } 196 197 198 public String getDefaultDisplayName() { 199 return "InterfaceDec(id: "+id+")"; 200 } 201 202 } 204 | Popular Tags |