/** Returns true if equals. */
  public boolean equals(Object o) {
    if (o == this) return true;
    else if (o == null || getClass() != o.getClass()) return false;

    JClass jClass = (JClass) o;

    // note that the equality test doesn't include the class loader
    return getName().equals(jClass.getName());
  }
  /**
   * Create a new dependency with a given digest.
   *
   * @param cl the source class
   * @param digest the MD5 digest
   */
  public JClassDependency(JClass cl, String digest) {
    _className = cl.getName();

    String newDigest = getDigest();

    if (!newDigest.equals(digest)) {
      if (log.isLoggable(Level.FINE)) log.fine(_className + " digest is modified.");

      _isDigestModified = true;
    }
  }
Пример #3
0
  /**
   * Adds the given JMethodSignature to this JClass
   *
   * @param jMethodSig the JMethodSignature to add.
   * @throws java.lang.IllegalArgumentException when the given JMethodSignature conflicts with an
   *     existing method signature.
   */
  public void addMethod(JMethodSignature jMethodSig) throws IllegalArgumentException {
    if (jMethodSig == null) {
      String err = "The JMethodSignature cannot be null.";
      throw new IllegalArgumentException(err);
    }

    // -- check method name and signatures *add later*

    // -- keep method list sorted for esthetics when printing
    // -- START SORT :-)
    boolean added = false;
    //        short modifierVal = 0;
    JModifiers modifiers = jMethodSig.getModifiers();
    for (int i = 0; i < methods.size(); i++) {
      JMethodSignature tmp = (JMethodSignature) methods.elementAt(i);
      // -- first compare modifiers
      if (tmp.getModifiers().isProtected()) {
        if (!modifiers.isProtected()) {
          methods.insertElementAt(jMethodSig, i);
          added = true;
          break;
        }
      }
      // -- compare names
      if (jMethodSig.getName().compareTo(tmp.getName()) < 0) {
        methods.insertElementAt(jMethodSig, i);
        added = true;
        break;
      }
    }
    // -- END SORT
    if (!added) methods.addElement(jMethodSig);

    // -- check return type to make sure it's included in the
    // -- import list
    JType jType = jMethodSig.getReturnType();
    if (jType != null) {
      while (jType.isArray()) jType = jType.getComponentType();

      if (!jType.isPrimitive()) addImport(jType.getName());
    }
    // -- check exceptions
    JClass[] exceptions = jMethodSig.getExceptions();
    for (JClass exception : exceptions) {
      addImport(exception.getName());
    }
  } // -- addMethod
Пример #4
0
 /** Primitive type */
 @Test
 public void primitive() {
   JClass c = new JClass(Integer.TYPE);
   assertNull(c.getPackageName());
   assertEquals("int", c.getName());
 }
 /** Creates the class dependency. */
 public JClassDependency(JClass cl) {
   _className = cl.getName();
 }
 /** Returns the class name. */
 public String getName() {
   return "[" + _componentType.getName();
 }
 /** Returns true if the jClass is assignable to the class. */
 public boolean isAssignableFrom(JClass cl) {
   return getName().equals(cl.getName());
 }