Exemplo n.º 1
0
  /**
   * Returns whether a classNode has the specified property or not
   *
   * @param classNode The ClassNode
   * @param propertyName The name of the property
   * @return True if the property exists in the ClassNode
   */
  public static boolean hasProperty(ClassNode classNode, String propertyName) {
    if (classNode == null || StringUtils.isBlank(propertyName)) {
      return false;
    }

    final MethodNode method =
        classNode.getMethod(GrailsNameUtils.getGetterName(propertyName), Parameter.EMPTY_ARRAY);
    if (method != null) return true;

    for (PropertyNode pn : classNode.getProperties()) {
      if (pn.getName().equals(propertyName) && !pn.isPrivate()) {
        return true;
      }
    }

    return false;
  }