001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */ 002 package org.extendj.ast; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.Set; 007 import java.util.Collections; 008 import java.util.Collection; 009 import java.util.ArrayList; 010 import beaver.*; 011 import java.util.*; 012 import java.io.ByteArrayOutputStream; 013 import java.io.PrintStream; 014 import java.lang.reflect.InvocationTargetException; 015 import java.lang.reflect.Method; 016 import org.jastadd.util.*; 017 import java.util.zip.*; 018 import java.io.*; 019 import org.jastadd.util.PrettyPrintable; 020 import org.jastadd.util.PrettyPrinter; 021 import java.io.FileNotFoundException; 022 import java.io.BufferedInputStream; 023 import java.io.DataInputStream; 024 /** 025 * @ast node 026 * @declaredat /home/jesper/git/extendj/java5/grammar/Annotations.ast:11 027 * @production ElementConstantValue : {@link ElementValue} ::= <span class="component">{@link Expr}</span>; 028 029 */ 030 public class ElementConstantValue extends ElementValue implements Cloneable { 031 /** 032 * @aspect Annotations 033 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:214 034 */ 035 public void nameCheck() { 036 if (enclosingAnnotationDecl().fullName().equals("java.lang.annotation.Target")) { 037 Variable v = getExpr().varDecl(); 038 if (v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType")) { 039 if (lookupElementTypeValue(v.name()) != this) { 040 error("repeated annotation target"); 041 } 042 } 043 } 044 } 045 /** 046 * @aspect Java5PrettyPrint 047 * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:325 048 */ 049 public void prettyPrint(PrettyPrinter out) { 050 out.print(getExpr()); 051 } 052 /** 053 * @aspect AnnotationsCodegen 054 * @declaredat /home/jesper/git/extendj/java5/backend/AnnotationsCodegen.jrag:256 055 */ 056 public void appendAsAttributeTo(Attribute buf) { 057 if (getExpr().isConstant() && !getExpr().type().isEnumDecl()) { 058 TypeDecl targetType = declType(); 059 char tag = targetType.isString() ? 's' : targetType.typeDescriptor().charAt(0); 060 int const_value_index = targetType.addAnnotConstant(hostType().constantPool(), getExpr().constant()); 061 buf.u1(tag); 062 buf.u2(const_value_index); 063 } else if (getExpr().isClassAccess()) { 064 int const_class_index = hostType().constantPool().addUtf8(getExpr().classAccess().typeDescriptor()); 065 buf.u1('c'); 066 buf.u2(const_class_index); 067 } else { 068 Variable v = getExpr().varDecl(); 069 if (v == null) { 070 throw new Error("Expected Enumeration constant"); 071 } 072 073 int type_name_index = hostType().constantPool().addUtf8(v.type().typeDescriptor()); 074 int const_name_index = hostType().constantPool().addUtf8(v.name()); 075 buf.u1('e'); 076 buf.u2(type_name_index); 077 buf.u2(const_name_index); 078 } 079 } 080 /** 081 * @declaredat ASTNode:1 082 */ 083 public ElementConstantValue() { 084 super(); 085 } 086 /** 087 * Initializes the child array to the correct size. 088 * Initializes List and Opt nta children. 089 * @apilevel internal 090 * @ast method 091 * @declaredat ASTNode:10 092 */ 093 public void init$Children() { 094 children = new ASTNode[1]; 095 } 096 /** 097 * @declaredat ASTNode:13 098 */ 099 public ElementConstantValue(Expr p0) { 100 setChild(p0, 0); 101 } 102 /** 103 * @apilevel low-level 104 * @declaredat ASTNode:19 105 */ 106 protected int numChildren() { 107 return 1; 108 } 109 /** 110 * @apilevel internal 111 * @declaredat ASTNode:25 112 */ 113 public boolean mayHaveRewrite() { 114 return false; 115 } 116 /** 117 * @apilevel internal 118 * @declaredat ASTNode:31 119 */ 120 public void flushAttrCache() { 121 super.flushAttrCache(); 122 } 123 /** 124 * @apilevel internal 125 * @declaredat ASTNode:37 126 */ 127 public void flushCollectionCache() { 128 super.flushCollectionCache(); 129 } 130 /** 131 * @apilevel internal 132 * @declaredat ASTNode:43 133 */ 134 public void flushRewriteCache() { 135 super.flushRewriteCache(); 136 } 137 /** 138 * @apilevel internal 139 * @declaredat ASTNode:49 140 */ 141 public ElementConstantValue clone() throws CloneNotSupportedException { 142 ElementConstantValue node = (ElementConstantValue) super.clone(); 143 return node; 144 } 145 /** 146 * @apilevel internal 147 * @declaredat ASTNode:56 148 */ 149 public ElementConstantValue copy() { 150 try { 151 ElementConstantValue node = (ElementConstantValue) clone(); 152 node.parent = null; 153 if (children != null) { 154 node.children = (ASTNode[]) children.clone(); 155 } 156 return node; 157 } catch (CloneNotSupportedException e) { 158 throw new Error("Error: clone not supported for " + getClass().getName()); 159 } 160 } 161 /** 162 * Create a deep copy of the AST subtree at this node. 163 * The copy is dangling, i.e. has no parent. 164 * @return dangling copy of the subtree at this node 165 * @apilevel low-level 166 * @deprecated Please use treeCopy or treeCopyNoTransform instead 167 * @declaredat ASTNode:75 168 */ 169 @Deprecated 170 public ElementConstantValue fullCopy() { 171 return treeCopyNoTransform(); 172 } 173 /** 174 * Create a deep copy of the AST subtree at this node. 175 * The copy is dangling, i.e. has no parent. 176 * @return dangling copy of the subtree at this node 177 * @apilevel low-level 178 * @declaredat ASTNode:85 179 */ 180 public ElementConstantValue treeCopyNoTransform() { 181 ElementConstantValue tree = (ElementConstantValue) copy(); 182 if (children != null) { 183 for (int i = 0; i < children.length; ++i) { 184 ASTNode child = (ASTNode) children[i]; 185 if (child != null) { 186 child = child.treeCopyNoTransform(); 187 tree.setChild(child, i); 188 } 189 } 190 } 191 return tree; 192 } 193 /** 194 * Create a deep copy of the AST subtree at this node. 195 * The subtree of this node is traversed to trigger rewrites before copy. 196 * The copy is dangling, i.e. has no parent. 197 * @return dangling copy of the subtree at this node 198 * @apilevel low-level 199 * @declaredat ASTNode:105 200 */ 201 public ElementConstantValue treeCopy() { 202 doFullTraversal(); 203 return treeCopyNoTransform(); 204 } 205 /** 206 * @apilevel internal 207 * @declaredat ASTNode:112 208 */ 209 protected boolean is$Equal(ASTNode node) { 210 return super.is$Equal(node); 211 } 212 /** 213 * Replaces the Expr child. 214 * @param node The new node to replace the Expr child. 215 * @apilevel high-level 216 */ 217 public void setExpr(Expr node) { 218 setChild(node, 0); 219 } 220 /** 221 * Retrieves the Expr child. 222 * @return The current node used as the Expr child. 223 * @apilevel high-level 224 */ 225 @ASTNodeAnnotation.Child(name="Expr") 226 public Expr getExpr() { 227 return (Expr) getChild(0); 228 } 229 /** 230 * Retrieves the Expr child. 231 * <p><em>This method does not invoke AST transformations.</em></p> 232 * @return The current node used as the Expr child. 233 * @apilevel low-level 234 */ 235 public Expr getExprNoTransform() { 236 return (Expr) getChildNoTransform(0); 237 } 238 /** 239 * @attribute syn 240 * @aspect Annotations 241 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:80 242 */ 243 @ASTNodeAnnotation.Attribute 244 public boolean validTarget(Annotation a) { 245 { 246 Variable v = getExpr().varDecl(); 247 if (v == null) { 248 return true; 249 } 250 return v.hostType().fullName().equals("java.lang.annotation.ElementType") && a.mayUseAnnotationTarget(v.name()); 251 } 252 } 253 /** 254 * @attribute syn 255 * @aspect Annotations 256 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:228 257 */ 258 @ASTNodeAnnotation.Attribute 259 public ElementValue definesElementTypeValue(String name) { 260 { 261 Variable v = getExpr().varDecl(); 262 if (v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType") && v.name().equals(name)) { 263 return this; 264 } 265 return null; 266 } 267 } 268 /** 269 * @attribute syn 270 * @aspect Annotations 271 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:370 272 */ 273 @ASTNodeAnnotation.Attribute 274 public boolean hasValue(String annot) { 275 boolean hasValue_String_value = getExpr().type().isString() && getExpr().isConstant() 276 && getExpr().constant().stringValue().equals(annot); 277 278 return hasValue_String_value; 279 } 280 /** 281 * @attribute syn 282 * @aspect Annotations 283 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:558 284 */ 285 @ASTNodeAnnotation.Attribute 286 public boolean commensurateWithTypeDecl(TypeDecl type) { 287 { 288 Expr v = getExpr(); 289 if (!v.type().assignConversionTo(type, v)) { 290 return false; 291 } 292 if ((type.isPrimitive() || type.isString()) && !v.isConstant()) { 293 return false; 294 } 295 if (v.type().isNull()) { 296 return false; 297 } 298 if (type.fullName().equals("java.lang.Class") && !v.isClassAccess()) { 299 return false; 300 } 301 if (type.isEnumDecl() && (v.varDecl() == null || !(v.varDecl() instanceof EnumConstant))) { 302 return false; 303 } 304 return true; 305 } 306 } 307 /** 308 * @attribute syn 309 * @aspect Annotations 310 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:607 311 */ 312 @ASTNodeAnnotation.Attribute 313 public TypeDecl type() { 314 TypeDecl type_value = getExpr().type(); 315 316 return type_value; 317 } 318 /** 319 * @attribute inh 320 * @aspect Annotations 321 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:224 322 */ 323 /** 324 * @attribute inh 325 * @aspect Annotations 326 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:224 327 */ 328 @ASTNodeAnnotation.Attribute 329 public ElementValue lookupElementTypeValue(String name) { 330 ElementValue lookupElementTypeValue_String_value = getParent().Define_lookupElementTypeValue(this, null, name); 331 332 return lookupElementTypeValue_String_value; 333 } 334 /** 335 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 336 * @apilevel internal 337 */ 338 public NameType Define_nameType(ASTNode caller, ASTNode child) { 339 if (caller == getExprNoTransform()) { 340 // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:647 341 return NameType.EXPRESSION_NAME; 342 } 343 else { 344 return getParent().Define_nameType(this, caller); 345 } 346 } 347 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 348 return true; 349 } 350 /** 351 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:32 352 * @apilevel internal 353 */ 354 public String Define_methodHost(ASTNode caller, ASTNode child) { 355 if (caller == getExprNoTransform()) { 356 // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:652 357 return enclosingAnnotationDecl().typeName(); 358 } 359 else { 360 return getParent().Define_methodHost(this, caller); 361 } 362 } 363 protected boolean canDefine_methodHost(ASTNode caller, ASTNode child) { 364 return true; 365 } 366 /** 367 * @apilevel internal 368 */ 369 public ASTNode rewriteTo() { 370 return super.rewriteTo(); 371 } 372 }