/*
  * @see ASTVisitor#visit(MethodDeclaration)
  */
 public boolean visit(MethodDeclaration node) {
   if (node.getJavadoc() != null) {
     node.getJavadoc().accept(this);
   }
   if (node.getAST().apiLevel() >= AST.JLS3) {
     printModifiers(node.modifiers());
     if (!node.typeParameters().isEmpty()) {
       this.fBuffer.append("<"); // $NON-NLS-1$
       for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) {
         TypeParameter t = (TypeParameter) it.next();
         t.accept(this);
         if (it.hasNext()) {
           this.fBuffer.append(", "); // $NON-NLS-1$
         }
       }
       this.fBuffer.append("> "); // $NON-NLS-1$
     }
   }
   if (!node.isConstructor()) {
     if (node.getReturnType2() != null) {
       node.getReturnType2().accept(this);
     } else {
       // methods really ought to have a return type
       this.fBuffer.append("void"); // $NON-NLS-1$
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   node.getName().accept(this);
   this.fBuffer.append("("); // $NON-NLS-1$
   for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
     SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
     v.accept(this);
     if (it.hasNext()) {
       this.fBuffer.append(", "); // $NON-NLS-1$
     }
   }
   this.fBuffer.append(")"); // $NON-NLS-1$
   for (int i = 0; i < node.getExtraDimensions(); i++) {
     this.fBuffer.append("[]"); // $NON-NLS-1$
   }
   if (!node.thrownExceptions().isEmpty()) {
     this.fBuffer.append(" throws "); // $NON-NLS-1$
     for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
       Name n = (Name) it.next();
       n.accept(this);
       if (it.hasNext()) {
         this.fBuffer.append(", "); // $NON-NLS-1$
       }
     }
     this.fBuffer.append(" "); // $NON-NLS-1$
   }
   if (node.getBody() == null) {
     this.fBuffer.append(";"); // $NON-NLS-1$
   } else {
     node.getBody().accept(this);
   }
   return false;
 }
Ejemplo n.º 2
0
  /**
   * generate checks accordingly.
   *
   * @param node
   * @param binding
   * @param declTypeBinding
   */
  private void handleInheritedAbstractMethodImplementation(
      MethodDeclaration node, IMethodBinding methodBinding, List<MethodPathItem> inhMethods) {

    // add check for method name
    checks.add(
        new MethodImplementationNameCheck(
            file, jdtTypingProvider, bridge(node), methodBinding, inhMethods));

    // add checks for parameters
    List parameterList = node.parameters();

    for (int j = 0; j < parameterList.size(); j++) {

      checks.add(
          new MethodImplementationParameterCheck(
              file,
              jdtTypingProvider,
              bridge((SingleVariableDeclaration) parameterList.get(j)),
              methodBinding,
              j,
              inhMethods));
    }

    // add checks for exceptions
    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 MethodImplementationExceptionCheck(
              file,
              jdtTypingProvider,
              bridge(curExcNode),
              methodBinding,
              curExcBinding.getKey(),
              inhMethods));
    }
  }
Ejemplo 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())));
    }
  }
 /**
  * @param decl method declaration
  * @return thrown exception names
  * @deprecated to avoid deprecation warnings
  */
 private static List<Name> getThrownExceptions(MethodDeclaration decl) {
   return decl.thrownExceptions();
 }
 /**
  * @param node node
  * @return thrown exception names
  * @deprecated to avoid deprecation warning
  */
 private static List<Name> getThrownExceptions(MethodDeclaration node) {
   return node.thrownExceptions();
 }