Esempio n. 1
0
  private boolean initializeAndCollectInhData(
      IMethodBinding binding, List<MethodPathItem> inhMethods) {
    if (binding == null) return false;

    // check if method is abstract
    if (Modifier.isAbstract(binding.getModifiers())) return false;

    ITypeBinding declTypeBinding = binding.getDeclaringClass();

    // check only for classes
    if (declTypeBinding == null || !declTypeBinding.isClass()) return false;

    Set<String> checkedInterfaces = new HashSet<String>();

    // (recursively) collects all keys of methods in abstract classes which
    // belongs to this declaration
    OverridingRelationUtils.collectSimilarMethodKeysInSuperClasses(
        binding, declTypeBinding.getSuperclass(), inhMethods, checkedInterfaces);

    // (recursively) collects all keys of methods in interfaces which
    // belongs to this declaration
    OverridingRelationUtils.collectSimilarMethodKeysInInterfaces(
        binding, declTypeBinding.getInterfaces(), inhMethods, checkedInterfaces);

    // the set should contain at least one inherited method
    if (inhMethods.size() == 0) return false;

    return true;
  }
Esempio n. 2
0
  private void handleMethodCall(ASTNode node, IMethodBinding methodBinding, List arguments) {
    if (methodBinding == null) return;

    // name check
    checks.add(
        new MethodInvocationCheck(
            file,
            jdtTypingProvider,
            bridge(node),
            OverridingRelationUtils.getIASTNodeList(arguments),
            methodBinding));
  }
Esempio n. 3
0
  private void handleOverridingRelationshipViolation(
      MethodDeclaration node, IMethodBinding methodBinding, List<MethodPathItem> inhMethods) {

    // get first overridden item
    MethodPathItem superItem = OverridingRelationUtils.getFirstNonAbstractItem(inhMethods);

    if (superItem == null) return;

    // add check for method name and params
    checks.add(
        new InheritedMethodCheck(
            file,
            jdtTypingProvider,
            bridge(node),
            OverridingRelationUtils.getIASTNodeList(node.parameters()),
            methodBinding.getName(),
            superItem));

    // get all keys of method exceptions in super classes which are cast
    // compatible to exceptions of "node"
    // the list should contain at least one overridden exception key
    List exceptionList = node.thrownExceptions();
    Name curExcNode;
    for (int i = 0; i < exceptionList.size(); i++) {

      curExcNode = (Name) exceptionList.get(i);
      ITypeBinding curExcBinding = curExcNode.resolveTypeBinding();

      if (curExcBinding == null) continue;

      checks.add(
          new InheritedMethodExceptionCheck(
              file,
              jdtTypingProvider,
              bridge(curExcNode),
              curExcBinding.getName(),
              superItem.getInheritedExceptionKeys(methodBinding).get(curExcBinding.getKey())));
    }
  }