cvs commit: jakarta-bcel/src/java/org/apache/bcel/generic FieldOrMethod.java ObjectType.java ReferenceType.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
mdahm       2004/08/31 01:04:00

  Modified:    src/java/org/apache/bcel/generic FieldOrMethod.java
                        ObjectType.java ReferenceType.java
  Log:
  Patches from [email protected]
  
  Revision  Changes    Path
  1.3       +24 -1     jakarta-bcel/src/java/org/apache/bcel/generic/FieldOrMethod.java
  
  Index: FieldOrMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/generic/FieldOrMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FieldOrMethod.java	23 May 2003 07:55:16 -0000	1.2
  +++ FieldOrMethod.java	31 Aug 2004 08:03:59 -0000	1.3
  @@ -104,9 +104,32 @@
     }
   
     /** @return type of the referenced class/interface
  +   * @deprecated If the instruction references an array class,
  +   *    the ObjectType returned will be invalid.  Use
  +   *    getReferenceType() instead.
      */
     public ObjectType getClassType(ConstantPoolGen cpg) {
       return new ObjectType(getClassName(cpg));
  +  }
  +
  +  /**
  +   * Return the reference type representing the class, interface,
  +   * or array class referenced by the instruction.
  +   * @param cpg the ConstantPoolGen used to create the instruction
  +   * @return an ObjectType (if the referenced class type is a class
  +   *   or interface), or an ArrayType (if the referenced class
  +   *   type is an array class)
  +   */
  +  public ReferenceType getReferenceType(ConstantPoolGen cpg) {
  +    ConstantPool cp  = cpg.getConstantPool();
  +    ConstantCP   cmr = (ConstantCP)cp.getConstant(index);
  +    String className = cp.getConstantString(cmr.getClassIndex(), org.apache.bcel.Constants.CONSTANT_Class);
  +    if (className.startsWith("[")) {
  +      return (ArrayType) Type.getType(className);
  +    } else {
  +      className = className.replace('/', '.');
  +      return new ObjectType(className);
  +    }
     }
   
     /** @return type of the referenced class/interface
  
  
  
  1.4       +33 -1     jakarta-bcel/src/java/org/apache/bcel/generic/ObjectType.java
  
  Index: ObjectType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/generic/ObjectType.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ObjectType.java	30 Apr 2004 06:51:33 -0000	1.3
  +++ ObjectType.java	31 Aug 2004 08:03:59 -0000	1.4
  @@ -92,6 +92,9 @@
     /**
      * If "this" doesn't reference a class, it references an interface
      * or a non-existant entity.
  +   * @deprecated this method returns an inaccurate result
  +   *   if the class or interface referenced cannot
  +   *   be found: use referencesClassExact() instead
      */
     public boolean referencesClass() {
       try {
  @@ -105,6 +108,9 @@
     /**
      * If "this" doesn't reference an interface, it references a class
      * or a non-existant entity.
  +   * @deprecated this method returns an inaccurate result
  +   *   if the class or interface referenced cannot
  +   *   be found: use referencesInterfaceExact() instead
      */
     public boolean referencesInterface(){
       try {
  @@ -113,6 +119,32 @@
       } catch (ClassNotFoundException e) {
         return false;
       }
  +  }
  +
  +  /**
  +   * Return true if this type references a class,
  +   * false if it references an interface.
  +   * @return true if the type references a class, false if
  +   *   it references an interface
  +   * @throws ClassNotFoundException if the class or interface
  +   *   referenced by this type can't be found
  +   */
  +  public boolean referencesClassExact() throws ClassNotFoundException {
  +    JavaClass jc = Repository.lookupClass(class_name);
  +    return jc.isClass();
  +  }
  +
  +  /**
  +   * Return true if this type references an interface,
  +   * false if it references a class.
  +   * @return true if the type references an interface, false if
  +   *   it references a class
  +   * @throws ClassNotFoundException if the class or interface
  +   *   referenced by this type can't be found
  +   */
  +  public boolean referencesInterfaceExact() throws ClassNotFoundException {
  +    JavaClass jc = Repository.lookupClass(class_name);
  +    return !jc.isClass();
     }
   
     /**
  
  
  
  1.8       +9 -9      jakarta-bcel/src/java/org/apache/bcel/generic/ReferenceType.java
  
  Index: ReferenceType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/generic/ReferenceType.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ReferenceType.java	12 Jun 2003 07:30:22 -0000	1.7
  +++ ReferenceType.java	31 Aug 2004 08:03:59 -0000	1.8
  @@ -116,11 +116,11 @@
   
       /* If this is a class type then
        */
  -    if ((this instanceof ObjectType) && (((ObjectType) this).referencesClass())) {
  +    if ((this instanceof ObjectType) && (((ObjectType) this).referencesClassExact())) {
         /* If T is a class type, then this must be the same class as T,
   	 or this must be a subclass of T;
         */
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) {
  +      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
   	if (this.equals(T))
   	  return true;
   
  @@ -131,7 +131,7 @@
   
         /* If T is an interface type, this must implement interface T.
          */
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) {
  +      if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
   	if (Repository.implementationOf(((ObjectType) this).getClassName(),
   					((ObjectType) T).getClassName()))
   	  return true;
  @@ -140,17 +140,17 @@
   
       /* If this is an interface type, then:
        */
  -    if ((this instanceof ObjectType) && (((ObjectType) this).referencesInterface())) {
  +    if ((this instanceof ObjectType) && (((ObjectType) this).referencesInterfaceExact())) {
         /* If T is a class type, then T must be Object (§2.4.7).
          */
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) {
  +      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
   	if (T.equals(Type.OBJECT)) return true;
         }
   
         /* If T is an interface type, then T must be the same interface
          * as this or a superinterface of this (§2.13.2).
          */
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) {
  +       if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
   	if (this.equals(T)) return true;
   	if (Repository.implementationOf(((ObjectType) this).getClassName(),
   					((ObjectType) T).getClassName()))
  @@ -164,7 +164,7 @@
       if (this instanceof ArrayType) {
         /* If T is a class type, then T must be Object (§2.4.7).
          */
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClass())) {
  +      if ((T instanceof ObjectType) && (((ObjectType) T).referencesClassExact())) {
   	if (T.equals(Type.OBJECT)) return true;
         }
   
  @@ -194,7 +194,7 @@
         // are at least two different pages where assignment compatibility is defined and
         // on one of them "interfaces implemented by arrays" is exchanged with "'Cloneable' or
         // 'java.io.Serializable'"
  -      if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterface())) {
  +      if ((T instanceof ObjectType) && (((ObjectType) T).referencesInterfaceExact())) {
   	for (int ii = 0; ii < Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS.length; ii++) {
   	  if (T.equals(new ObjectType(Constants.INTERFACES_IMPLEMENTED_BY_ARRAYS[ii]))) return true;
   	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.