All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.extendj.ast.ElementConstantValue Maven / Gradle / Ivy

The newest version!
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.3.0 */
package org.extendj.ast;
import java.util.ArrayList;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.util.Set;
import beaver.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.LinkedHashSet;
import java.util.*;
import org.jastadd.util.PrettyPrintable;
import org.jastadd.util.PrettyPrinter;
import java.util.zip.*;
import java.io.*;
import org.jastadd.util.*;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
/**
 * @ast node
 * @declaredat /home/jesper/git/extendj/java5/grammar/Annotations.ast:11
 * @astdecl ElementConstantValue : ElementValue ::= Expr;
 * @production ElementConstantValue : {@link ElementValue} ::= {@link Expr};

 */
public class ElementConstantValue extends ElementValue implements Cloneable {
  /**
   * @aspect Java5PrettyPrint
   * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:99
   */
  public void prettyPrint(PrettyPrinter out) {
    out.print(getExpr());
  }
  /**
   * @aspect AnnotationsCodegen
   * @declaredat /home/jesper/git/extendj/java5/backend/AnnotationsCodegen.jrag:292
   */
  public void appendAsAttributeTo(Attribute buf) {
    if (getExpr().isConstant() && !getExpr().type().isEnumDecl()) {
      TypeDecl targetType = declType();
      char tag = targetType.isString() ? 's' : targetType.typeDescriptor().charAt(0);
      int const_value_index = targetType.addAnnotConstant(hostType().constantPool(),
          getExpr().constant());
      buf.u1(tag);
      buf.u2(const_value_index);
    } else if (getExpr().isClassAccess()) {
      int const_class_index = hostType().constantPool()
          .addUtf8(getExpr().classAccess().typeDescriptor());
      buf.u1('c');
      buf.u2(const_class_index);
    } else {
      Variable v = getExpr().varDecl();
      if (v == null) {
        throw new Error("Expected Enumeration constant");
      }

      int type_name_index = hostType().constantPool().addUtf8(v.type().typeDescriptor());
      int const_name_index = hostType().constantPool().addUtf8(v.name());
      buf.u1('e');
      buf.u2(type_name_index);
      buf.u2(const_name_index);
    }
  }
  /**
   * @declaredat ASTNode:1
   */
  public ElementConstantValue() {
    super();
  }
  /**
   * Initializes the child array to the correct size.
   * Initializes List and Opt nta children.
   * @apilevel internal
   * @ast method
   * @declaredat ASTNode:10
   */
  public void init$Children() {
    children = new ASTNode[1];
  }
  /**
   * @declaredat ASTNode:13
   */
  @ASTNodeAnnotation.Constructor(
    name = {"Expr"},
    type = {"Expr"},
    kind = {"Child"}
  )
  public ElementConstantValue(Expr p0) {
    setChild(p0, 0);
  }
  /** @apilevel low-level 
   * @declaredat ASTNode:22
   */
  protected int numChildren() {
    return 1;
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:28
   */
  public boolean mayHaveRewrite() {
    return false;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:32
   */
  public void flushAttrCache() {
    super.flushAttrCache();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:36
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /** @apilevel internal 
   * @declaredat ASTNode:40
   */
  public ElementConstantValue clone() throws CloneNotSupportedException {
    ElementConstantValue node = (ElementConstantValue) super.clone();
    return node;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:45
   */
  public ElementConstantValue copy() {
    try {
      ElementConstantValue node = (ElementConstantValue) clone();
      node.parent = null;
      if (children != null) {
        node.children = (ASTNode[]) children.clone();
      }
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " + getClass().getName());
    }
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @deprecated Please use treeCopy or treeCopyNoTransform instead
   * @declaredat ASTNode:64
   */
  @Deprecated
  public ElementConstantValue fullCopy() {
    return treeCopyNoTransform();
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:74
   */
  public ElementConstantValue treeCopyNoTransform() {
    ElementConstantValue tree = (ElementConstantValue) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if (child != null) {
          child = child.treeCopyNoTransform();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The subtree of this node is traversed to trigger rewrites before copy.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:94
   */
  public ElementConstantValue treeCopy() {
    ElementConstantValue tree = (ElementConstantValue) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) getChild(i);
        if (child != null) {
          child = child.treeCopy();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /** @apilevel internal 
   * @declaredat ASTNode:108
   */
  protected boolean is$Equal(ASTNode node) {
    return super.is$Equal(node);    
  }
  /**
   * Replaces the Expr child.
   * @param node The new node to replace the Expr child.
   * @apilevel high-level
   */
  public void setExpr(Expr node) {
    setChild(node, 0);
  }
  /**
   * Retrieves the Expr child.
   * @return The current node used as the Expr child.
   * @apilevel high-level
   */
  @ASTNodeAnnotation.Child(name="Expr")
  public Expr getExpr() {
    return (Expr) getChild(0);
  }
  /**
   * Retrieves the Expr child.
   * 

This method does not invoke AST transformations.

* @return The current node used as the Expr child. * @apilevel low-level */ public Expr getExprNoTransform() { return (Expr) getChildNoTransform(0); } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:111 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:111") public boolean validTarget(Annotation a) { { Variable v = getExpr().varDecl(); if (v == null) { return true; } return v.hostType().fullName().equals("java.lang.annotation.ElementType") && a.mayUseAnnotationTarget(v.name()); } } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:265 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:265") public Collection nameProblems() { { Collection problems = new LinkedList(); if (enclosingAnnotationDecl().fullName().equals("java.lang.annotation.Target")) { Variable v = getExpr().varDecl(); if (v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType")) { if (lookupElementTypeValue(v.name()) != this) { problems.add(error("repeated annotation target")); } } } return problems; } } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:285 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:285") public ElementValue definesElementTypeValue(String name) { { Variable v = getExpr().varDecl(); if (v != null && v.hostType().fullName().equals("java.lang.annotation.ElementType") && v.name().equals(name)) { return this; } return null; } } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:448 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:448") public boolean hasValue(String annot) { boolean hasValue_String_value = getExpr().type().isString() && getExpr().isConstant() && getExpr().constant().stringValue().equals(annot); return hasValue_String_value; } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:675 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:675") public boolean commensurateWithTypeDecl(TypeDecl type) { { Expr v = getExpr(); if (!v.type().assignConversionTo(type, v)) { return false; } if ((type.isPrimitive() || type.isString()) && !v.isConstant()) { return false; } if (v.type().isNull()) { return false; } if (type.fullName().equals("java.lang.Class") && !v.isClassAccess()) { return false; } if (type.isEnumDecl() && (v.varDecl() == null || !(v.varDecl() instanceof EnumConstant))) { return false; } return true; } } /** * @attribute syn * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:731 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.SYN) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:731") public TypeDecl type() { TypeDecl type_value = getExpr().type(); return type_value; } /** * @attribute inh * @aspect Annotations * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:278 */ @ASTNodeAnnotation.Attribute(kind=ASTNodeAnnotation.Kind.INH) @ASTNodeAnnotation.Source(aspect="Annotations", declaredAt="/home/jesper/git/extendj/java5/frontend/Annotations.jrag:278") public ElementValue lookupElementTypeValue(String name) { ElementValue lookupElementTypeValue_String_value = getParent().Define_lookupElementTypeValue(this, null, name); return lookupElementTypeValue_String_value; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 * @apilevel internal */ public NameType Define_nameType(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:778 return NameType.EXPRESSION_NAME; } else { return getParent().Define_nameType(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute nameType */ protected boolean canDefine_nameType(ASTNode _callerNode, ASTNode _childNode) { return true; } /** * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:33 * @apilevel internal */ public String Define_methodHost(ASTNode _callerNode, ASTNode _childNode) { if (getExprNoTransform() != null && _callerNode == getExpr()) { // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:783 return enclosingAnnotationDecl().typeName(); } else { return getParent().Define_methodHost(this, _callerNode); } } /** * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:33 * @apilevel internal * @return {@code true} if this node has an equation for the inherited attribute methodHost */ protected boolean canDefine_methodHost(ASTNode _callerNode, ASTNode _childNode) { return true; } /** @apilevel internal */ public ASTNode rewriteTo() { return super.rewriteTo(); } /** @apilevel internal */ public boolean canRewrite() { return false; } /** @apilevel internal */ protected void collect_contributors_CompilationUnit_problems(CompilationUnit _root, java.util.Map> _map) { // @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:263 { java.util.Set contributors = _map.get(_root); if (contributors == null) { contributors = new java.util.LinkedHashSet(); _map.put((ASTNode) _root, contributors); } contributors.add(this); } super.collect_contributors_CompilationUnit_problems(_root, _map); } /** @apilevel internal */ protected void contributeTo_CompilationUnit_problems(LinkedList collection) { super.contributeTo_CompilationUnit_problems(collection); for (Problem value : nameProblems()) { collection.add(value); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy