home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / tools / java / FieldDefinition.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  9.2 KB  |  437 lines

  1. package sun.tools.java;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Vector;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.tree.Context;
  7. import sun.tools.tree.Expression;
  8. import sun.tools.tree.Node;
  9. import sun.tools.tree.Statement;
  10. import sun.tools.tree.Vset;
  11.  
  12. public class FieldDefinition implements Constants {
  13.    protected int where;
  14.    protected int modifiers;
  15.    protected Type type;
  16.    protected String documentation;
  17.    protected IdentifierToken[] expIds;
  18.    protected ClassDeclaration[] exp;
  19.    protected Node value;
  20.    protected ClassDefinition clazz;
  21.    protected Identifier name;
  22.    protected ClassDefinition innerClass;
  23.    protected FieldDefinition nextField;
  24.    protected FieldDefinition nextMatch;
  25.    protected FieldDefinition accessPeer;
  26.  
  27.    public FieldDefinition(int var1, ClassDefinition var2, int var3, Type var4, Identifier var5, IdentifierToken[] var6, Node var7) {
  28.       if (var6 == null) {
  29.          var6 = new IdentifierToken[0];
  30.       }
  31.  
  32.       this.where = var1;
  33.       this.clazz = var2;
  34.       this.modifiers = var3;
  35.       this.type = var4;
  36.       this.name = var5;
  37.       this.expIds = var6;
  38.       this.value = var7;
  39.    }
  40.  
  41.    public FieldDefinition(ClassDefinition var1) {
  42.       this(var1.getWhere(), var1.getOuterClass(), var1.getModifiers(), var1.getType(), var1.getName().getFlatName().getName(), (IdentifierToken[])null, (Node)null);
  43.       this.innerClass = var1;
  44.    }
  45.  
  46.    public final int getWhere() {
  47.       return this.where;
  48.    }
  49.  
  50.    public final ClassDeclaration getClassDeclaration() {
  51.       return this.clazz.getClassDeclaration();
  52.    }
  53.  
  54.    public void resolveTypeStructure(Environment var1) {
  55.    }
  56.  
  57.    public ClassDeclaration getDefiningClassDeclaration() {
  58.       return this.getClassDeclaration();
  59.    }
  60.  
  61.    public final ClassDefinition getClassDefinition() {
  62.       return this.clazz;
  63.    }
  64.  
  65.    public final ClassDefinition getTopClass() {
  66.       return this.clazz.getTopClass();
  67.    }
  68.  
  69.    public final int getModifiers() {
  70.       return this.modifiers;
  71.    }
  72.  
  73.    public final void subModifiers(int var1) {
  74.       this.modifiers &= ~var1;
  75.    }
  76.  
  77.    public final void addModifiers(int var1) {
  78.       this.modifiers |= var1;
  79.    }
  80.  
  81.    public final Type getType() {
  82.       return this.type;
  83.    }
  84.  
  85.    public final Identifier getName() {
  86.       return this.name;
  87.    }
  88.  
  89.    public Vector getArguments() {
  90.       return this.isMethod() ? new Vector() : null;
  91.    }
  92.  
  93.    public ClassDeclaration[] getExceptions(Environment var1) {
  94.       if (this.expIds != null && this.exp == null) {
  95.          if (this.expIds.length != 0) {
  96.             throw new CompilerError("getExceptions " + this);
  97.          }
  98.  
  99.          this.exp = new ClassDeclaration[0];
  100.       }
  101.  
  102.       return this.exp;
  103.    }
  104.  
  105.    public final IdentifierToken[] getExceptionIds() {
  106.       return this.expIds;
  107.    }
  108.  
  109.    public ClassDefinition getInnerClass() {
  110.       return this.innerClass;
  111.    }
  112.  
  113.    public boolean isUplevelValue() {
  114.       if (this.isSynthetic() && this.isVariable() && !this.isStatic()) {
  115.          String var1 = this.name.toString();
  116.          return var1.startsWith("val$") || var1.toString().startsWith("loc$") || var1.toString().startsWith("this$");
  117.       } else {
  118.          return false;
  119.       }
  120.    }
  121.  
  122.    public boolean isAccessMethod() {
  123.       return this.isSynthetic() && this.isMethod() && this.name.toString().startsWith("access$");
  124.    }
  125.  
  126.    public FieldDefinition getAccessMethodTarget() {
  127.       if (this.isAccessMethod()) {
  128.          for(FieldDefinition var1 = this.accessPeer; var1 != null; var1 = var1.accessPeer) {
  129.             if (!var1.isAccessMethod()) {
  130.                return var1;
  131.             }
  132.          }
  133.       }
  134.  
  135.       return null;
  136.    }
  137.  
  138.    public void setAccessMethodTarget(FieldDefinition var1) {
  139.       if (this.getAccessMethodTarget() != var1) {
  140.          if (!this.isAccessMethod() || this.accessPeer != null || var1.accessPeer != null) {
  141.             throw new CompilerError("accessPeer");
  142.          }
  143.  
  144.          this.accessPeer = var1;
  145.       }
  146.  
  147.    }
  148.  
  149.    public FieldDefinition getAccessUpdateField() {
  150.       if (this.isAccessMethod()) {
  151.          for(FieldDefinition var1 = this.accessPeer; var1 != null; var1 = var1.accessPeer) {
  152.             if (var1.isAccessMethod()) {
  153.                return var1;
  154.             }
  155.          }
  156.       }
  157.  
  158.       return null;
  159.    }
  160.  
  161.    public void setAccessUpdateField(FieldDefinition var1) {
  162.       if (this.getAccessUpdateField() != var1) {
  163.          if (!this.isAccessMethod() || var1.getAccessMethodTarget() != this.getAccessMethodTarget()) {
  164.             throw new CompilerError("accessPeer");
  165.          }
  166.  
  167.          var1.accessPeer = this.accessPeer;
  168.          this.accessPeer = var1;
  169.       }
  170.  
  171.    }
  172.  
  173.    public final boolean isBlankFinal() {
  174.       return this.isFinal() && !this.isSynthetic() && this.getValue() == null;
  175.    }
  176.  
  177.    public boolean isNeverNull() {
  178.       if (this.isUplevelValue()) {
  179.          return !this.name.toString().startsWith("val$");
  180.       } else {
  181.          return false;
  182.       }
  183.    }
  184.  
  185.    public Node getValue(Environment var1) throws ClassNotFound {
  186.       return this.value;
  187.    }
  188.  
  189.    public final Node getValue() {
  190.       return this.value;
  191.    }
  192.  
  193.    public final void setValue(Node var1) {
  194.       this.value = var1;
  195.    }
  196.  
  197.    public Object getInitialValue() {
  198.       return null;
  199.    }
  200.  
  201.    public final FieldDefinition getNextField() {
  202.       return this.nextField;
  203.    }
  204.  
  205.    public final FieldDefinition getNextMatch() {
  206.       return this.nextMatch;
  207.    }
  208.  
  209.    public String getDocumentation() {
  210.       return this.documentation;
  211.    }
  212.  
  213.    public void check(Environment var1) throws ClassNotFound {
  214.    }
  215.  
  216.    public Vset check(Environment var1, Context var2, Vset var3) throws ClassNotFound {
  217.       return var3;
  218.    }
  219.  
  220.    public void code(Environment var1, Assembler var2) throws ClassNotFound {
  221.       throw new CompilerError("code");
  222.    }
  223.  
  224.    public void codeInit(Environment var1, Context var2, Assembler var3) throws ClassNotFound {
  225.       throw new CompilerError("codeInit");
  226.    }
  227.  
  228.    public boolean reportDeprecated(Environment var1) {
  229.       return this.isDeprecated() || this.clazz.reportDeprecated(var1);
  230.    }
  231.  
  232.    public final boolean canReach(Environment var1, FieldDefinition var2) {
  233.       if (!var2.isLocal() && var2.isVariable() && (this.isVariable() || this.isInitializer())) {
  234.          if (this.getClassDeclaration().equals(var2.getClassDeclaration()) && this.isStatic() == var2.isStatic()) {
  235.             while((var2 = var2.getNextField()) != null && var2 != this) {
  236.             }
  237.  
  238.             return var2 != null;
  239.          } else {
  240.             return true;
  241.          }
  242.       } else {
  243.          return true;
  244.       }
  245.    }
  246.  
  247.    public final boolean isPublic() {
  248.       return (this.modifiers & 1) != 0;
  249.    }
  250.  
  251.    public final boolean isPrivate() {
  252.       return (this.modifiers & 2) != 0;
  253.    }
  254.  
  255.    public final boolean isProtected() {
  256.       return (this.modifiers & 4) != 0;
  257.    }
  258.  
  259.    public final boolean isFinal() {
  260.       return (this.modifiers & 16) != 0;
  261.    }
  262.  
  263.    public final boolean isStatic() {
  264.       return (this.modifiers & 8) != 0;
  265.    }
  266.  
  267.    public final boolean isSynchronized() {
  268.       return (this.modifiers & 32) != 0;
  269.    }
  270.  
  271.    public final boolean isAbstract() {
  272.       return (this.modifiers & 1024) != 0;
  273.    }
  274.  
  275.    public final boolean isNative() {
  276.       return (this.modifiers & 256) != 0;
  277.    }
  278.  
  279.    public final boolean isVolatile() {
  280.       return (this.modifiers & 64) != 0;
  281.    }
  282.  
  283.    public final boolean isTransient() {
  284.       return (this.modifiers & 128) != 0;
  285.    }
  286.  
  287.    public final boolean isMethod() {
  288.       return this.type.isType(12);
  289.    }
  290.  
  291.    public final boolean isVariable() {
  292.       return !this.type.isType(12) && this.innerClass == null;
  293.    }
  294.  
  295.    public final boolean isSynthetic() {
  296.       return (this.modifiers & 524288) != 0;
  297.    }
  298.  
  299.    public final boolean isDeprecated() {
  300.       return (this.modifiers & 262144) != 0;
  301.    }
  302.  
  303.    public final boolean isInnerClass() {
  304.       return this.innerClass != null;
  305.    }
  306.  
  307.    public final boolean isInitializer() {
  308.       return this.getName().equals(Constants.idClassInit);
  309.    }
  310.  
  311.    public final boolean isConstructor() {
  312.       return this.getName().equals(Constants.idInit);
  313.    }
  314.  
  315.    public boolean isLocal() {
  316.       return false;
  317.    }
  318.  
  319.    public boolean isInlineable(Environment var1, boolean var2) throws ClassNotFound {
  320.       return (this.isStatic() || this.isPrivate() || this.isFinal() || this.isConstructor() || var2) && !this.isSynchronized() && !this.isNative();
  321.    }
  322.  
  323.    public boolean isConstant() {
  324.       if (this.isFinal() && this.isVariable() && this.value != null) {
  325.          boolean var1;
  326.          try {
  327.             this.modifiers &= -17;
  328.             var1 = ((Expression)this.value).isConstant();
  329.          } finally {
  330.             this.modifiers |= 16;
  331.          }
  332.  
  333.          return var1;
  334.       } else {
  335.          return false;
  336.       }
  337.    }
  338.  
  339.    public String toString() {
  340.       Identifier var1 = this.getClassDefinition().getName();
  341.       if (this.isInitializer()) {
  342.          return this.isStatic() ? "static {}" : "instance {}";
  343.       } else if (this.isConstructor()) {
  344.          StringBuffer var2 = new StringBuffer();
  345.          var2.append(var1);
  346.          var2.append('(');
  347.          Type[] var3 = this.getType().getArgumentTypes();
  348.  
  349.          for(int var4 = 0; var4 < var3.length; ++var4) {
  350.             if (var4 > 0) {
  351.                var2.append(',');
  352.             }
  353.  
  354.             var2.append(var3[var4].toString());
  355.          }
  356.  
  357.          var2.append(')');
  358.          return var2.toString();
  359.       } else {
  360.          return this.isInnerClass() ? this.getInnerClass().toString() : this.type.typeString(this.getName().toString());
  361.       }
  362.    }
  363.  
  364.    public void print(PrintStream var1) {
  365.       if (this.isPublic()) {
  366.          var1.print("public ");
  367.       }
  368.  
  369.       if (this.isPrivate()) {
  370.          var1.print("private ");
  371.       }
  372.  
  373.       if (this.isProtected()) {
  374.          var1.print("protected ");
  375.       }
  376.  
  377.       if (this.isFinal()) {
  378.          var1.print("final ");
  379.       }
  380.  
  381.       if (this.isStatic()) {
  382.          var1.print("static ");
  383.       }
  384.  
  385.       if (this.isSynchronized()) {
  386.          var1.print("synchronized ");
  387.       }
  388.  
  389.       if (this.isAbstract()) {
  390.          var1.print("abstract ");
  391.       }
  392.  
  393.       if (this.isNative()) {
  394.          var1.print("native ");
  395.       }
  396.  
  397.       if (this.isVolatile()) {
  398.          var1.print("volatile ");
  399.       }
  400.  
  401.       if (this.isTransient()) {
  402.          var1.print("transient ");
  403.       }
  404.  
  405.       var1.println(this.toString() + ";");
  406.    }
  407.  
  408.    public void cleanup(Environment var1) {
  409.       this.documentation = null;
  410.       if (this.isMethod() && this.value != null) {
  411.          int var2 = 0;
  412.          if (!this.isPrivate() && !this.isInitializer()) {
  413.             if ((var2 = ((Statement)this.value).costInline(30, (Environment)null, (Context)null)) >= 30) {
  414.                this.value = Statement.empty;
  415.             } else {
  416.                try {
  417.                   if (!this.isInlineable((Environment)null, true)) {
  418.                      this.value = Statement.empty;
  419.                   }
  420.                } catch (ClassNotFound var3) {
  421.                }
  422.             }
  423.          } else {
  424.             this.value = Statement.empty;
  425.          }
  426.  
  427.          if (this.value != Statement.empty && var1.dump()) {
  428.             var1.output("[after cleanup of " + this.getName() + ", " + var2 + " expression cost units remain]");
  429.             return;
  430.          }
  431.       } else if (this.isVariable() && (this.isPrivate() || !this.isFinal() || this.type.isType(9))) {
  432.          this.value = null;
  433.       }
  434.  
  435.    }
  436. }
  437.