View Javadoc

1   // jq_StaticMethod.java, created Mon Feb  5 23:23:20 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Class;
5   
6   //friend jq_ClassLoader;
7   
8   import joeq.Main.jq;
9   import joeq.UTF.Utf8;
10  import jwutil.util.Assert;
11  
12  /*
13   * @author  John Whaley <jwhaley@alum.mit.edu>
14   * @version $Id: jq_StaticMethod.java 1931 2004-09-22 22:17:47Z joewhaley $
15   */
16  public class jq_StaticMethod extends jq_Method {
17  
18      // clazz, name, desc, access_flags are inherited
19      protected jq_StaticMethod(jq_Class clazz, jq_NameAndDesc nd) {
20          super(clazz, nd);
21      }
22      // ONLY TO BE CALLED BY jq_ClassLoader!!!
23      static jq_StaticMethod newStaticMethod(jq_Class clazz, jq_NameAndDesc nd) {
24          return new jq_StaticMethod(clazz, nd);
25      }
26      protected void parseMethodSignature() {
27          Utf8.MethodDescriptorIterator i = nd.getDesc().getParamDescriptors();
28          // count them up
29          int num = 0, words = 0;
30          while (i.hasNext()) { i.nextUtf8(); ++num; }
31          // get them for real
32          param_types = new jq_Type[num];
33          i = nd.getDesc().getParamDescriptors();
34          for (int j=0; j<num; ++j) {
35              Utf8 pd = i.nextUtf8();
36              param_types[j] = PrimordialClassLoader.getOrCreateType(clazz.getClassLoader(), pd);
37              ++words;
38              if ((param_types[j] == jq_Primitive.LONG) ||
39                  (param_types[j] == jq_Primitive.DOUBLE)) ++words;
40          }
41          param_words = words;
42          Utf8 rd = i.getReturnDescriptor();
43          return_type = PrimordialClassLoader.getOrCreateType(clazz.getClassLoader(), rd);
44      }
45      
46      public final boolean needsDynamicLink(jq_Method method) {
47          if (getDeclaringClass().needsDynamicLink(method)) return true;
48          if (!jq.RunningNative) return false;
49          return (state < STATE_SFINITIALIZED);
50      }
51  
52      public final boolean isStatic() { return true; }
53      public boolean isClassInitializer() { return false; }
54  
55      public final jq_Member resolve() { return resolve1(); }
56      public jq_StaticMethod resolve1() {
57          this.clazz.load();
58          if (this.state >= STATE_LOADED) return this;
59          // this reference may be to a superclass or superinterface.
60          jq_StaticMethod m = this.clazz.getStaticMethod(nd);
61          if (m != null) return m;
62          throw new NoSuchMethodError(this.toString());
63      }
64      
65      public final void prepare() { Assert._assert(state == STATE_LOADED); state = STATE_PREPARED; }
66  
67      public final void unprepare() { Assert._assert(state == STATE_PREPARED); state = STATE_LOADED; }
68      
69      public void accept(jq_MethodVisitor mv) {
70          mv.visitStaticMethod(this);
71          super.accept(mv);
72      }
73      
74      public static final jq_Class _class;
75      static {
76          _class = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljoeq/Class/jq_StaticMethod;");
77      }
78  }