Beispiel #1
0
  protected void checkReturn(Stmt.Return ret) {
    JavaMethod method = (JavaMethod) getEnclosingScope(JavaMethod.class);

    if (method instanceof JavaConstructor) {
      return; // could do better than this.
    }

    Type retType = method.returnType().attribute(Type.class);

    if (ret.expr() != null) {
      checkExpression(ret.expr());

      Type ret_t = ret.expr().attribute(Type.class);
      try {
        if (ret_t.equals(new Type.Void())) {
          syntax_error("cannot return a value from method whose result type is void", ret);
        } else if (!types.subtype(retType, ret_t, loader)) {
          syntax_error("required return type " + retType + ",  found type " + ret_t, ret);
        }

      } catch (ClassNotFoundException ex) {
        syntax_error(ex.getMessage(), ret);
      }
    } else if (!(retType instanceof Type.Void)) {
      syntax_error("missing return value", ret);
    }
  }
Beispiel #2
0
 private void doExposePageLoadMethod(JavaClass jc) {
   boolean hitOne = false;
   for (Iterator itr = jc.findMethodsByName("Page_Load").iterator(); itr.hasNext(); ) {
     JavaMethod jm = (JavaMethod) itr.next();
     jm.addModifier(JavaKeywords.J_PUBLIC);
     hitOne = true;
   }
   if (!hitOne) {
     throw new RuntimeException(jc + " is a form class, but has no Page_Load method...");
   }
 }
Beispiel #3
0
  protected void checkMethod(JavaMethod d) {
    enclosingScopes.push(d);

    checkStatement(d.body());

    enclosingScopes.pop();
  }
  /**
   * @return true if {@code method} is a static method of enum class, which is to be put into its
   *     class object (and not into the corresponding package). This applies to values() and
   *     valueOf(String) methods
   */
  public static boolean shouldBeInEnumClassObject(@NotNull JavaMethod method) {
    if (!method.getContainingClass().isEnum()) return false;

    String signature = JavaSignatureFormatter.getInstance().formatMethod(method);

    return "values()".equals(signature) || "valueOf(java.lang.String)".equals(signature);
  }
Beispiel #5
0
 public int indexOf(JavaMethod method) {
   if (method != null) {
     String signature = method.getSignature();
     for (int i = 0; i < methods.size(); i++) {
       if (signature.equals(methods.get(i).getSignature())) {
         return i;
       }
     }
   }
   return -1;
 }
Beispiel #6
0
 public boolean hasMethod(JavaMethod method) {
   if (method != null) {
     String signature = method.getSignature();
     for (int i = 0; i < methods.size(); i++) {
       if (signature.equals(methods.get(i).getSignature())) {
         return true;
       }
     }
   }
   return false;
 }
  private static boolean hasStaticMembers(@NotNull JavaClass javaClass) {
    for (JavaMethod method : javaClass.getMethods()) {
      if (method.isStatic() && !shouldBeInEnumClassObject(method)) {
        return true;
      }
    }

    for (JavaField field : javaClass.getFields()) {
      if (field.isStatic() && !field.isEnumEntry()) {
        return true;
      }
    }

    for (JavaClass nestedClass : javaClass.getInnerClasses()) {
      if (SingleAbstractMethodUtils.isSamInterface(nestedClass)) {
        return true;
      }
      if (nestedClass.isStatic() && hasStaticMembers(nestedClass)) {
        return true;
      }
    }

    return false;
  }