LCOV - code coverage report
Current view: top level - vala - valaerrortype.vala (source / functions) Coverage Total Hit
Test: vala 0.57.0.298-a8cae1 Lines: 97.5 % 40 39
Test Date: 2024-04-25 11:34:36 Functions: - 0 0

            Line data    Source code
       1              : /* valaerrortype.vala
       2              :  *
       3              :  * Copyright (C) 2008-2010  Jürg Billeter
       4              :  *
       5              :  * This library is free software; you can redistribute it and/or
       6              :  * modify it under the terms of the GNU Lesser General Public
       7              :  * License as published by the Free Software Foundation; either
       8              :  * version 2.1 of the License, or (at your option) any later version.
       9              : 
      10              :  * This library is distributed in the hope that it will be useful,
      11              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13              :  * Lesser General Public License for more details.
      14              : 
      15              :  * You should have received a copy of the GNU Lesser General Public
      16              :  * License along with this library; if not, write to the Free Software
      17              :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
      18              :  *
      19              :  * Author:
      20              :  *      Jürg Billeter <j@bitron.ch>
      21              :  *      Raffaele Sandrini <raffaele@sandrini.ch>
      22              :  */
      23              : 
      24              : using GLib;
      25              : 
      26              : /**
      27              :  * A class type.
      28              :  */
      29       957637 : public class Vala.ErrorType : ReferenceType {
      30              :         /**
      31              :          * The error domain or null for generic error.
      32              :          */
      33              :         public weak ErrorDomain? error_domain {
      34      1349207 :                 get {
      35      1349207 :                         return symbol as ErrorDomain;
      36              :                 }
      37              :         }
      38              : 
      39              :         /**
      40              :          * The error code or null for generic error.
      41              :          */
      42       958459 :         public weak ErrorCode? error_code { get; set; }
      43              : 
      44        41219 :         public bool dynamic_error { get; set; }
      45              : 
      46      1912432 :         public ErrorType (ErrorDomain? error_domain, ErrorCode? error_code, SourceReference? source_reference = null) {
      47      1561123 :                 base ((Symbol) error_domain ?? CodeContext.get ().root.scope.lookup ("GLib").scope.lookup ("Error"), source_reference);
      48       956216 :                 this.error_code = error_code;
      49              :         }
      50              : 
      51        12027 :         public override bool compatible (DataType target_type) {
      52              :                 /* temporarily ignore type parameters */
      53        12027 :                 if (target_type is GenericType) {
      54        11995 :                         return true;
      55              :                 }
      56              : 
      57        12027 :                 unowned ErrorType? et = target_type as ErrorType;
      58              : 
      59              :                 /* error types are only compatible to error types */
      60        12036 :                 if (et == null) {
      61           12 :                         return false;
      62              :                 }
      63              : 
      64              :                 /* every error type is compatible to the base error type */
      65        12024 :                 if (et.error_domain == null) {
      66        11995 :                         return true;
      67              :                 }
      68              : 
      69              :                 /* otherwise the error_domain has to be equal */
      70         6204 :                 if (et.error_domain != error_domain) {
      71           12 :                         return false;
      72              :                 }
      73              : 
      74         6195 :                 if (et.error_code == null) {
      75        11995 :                         return true;
      76              :                 }
      77              : 
      78           20 :                 return et.error_code == error_code;
      79              :         }
      80              : 
      81        40795 :         public override DataType copy () {
      82        40795 :                 var result = new ErrorType (error_domain, error_code, source_reference);
      83        40795 :                 result.value_owned = value_owned;
      84        40795 :                 result.nullable = nullable;
      85        40795 :                 result.dynamic_error = dynamic_error;
      86              : 
      87        40795 :                 return result;
      88              :         }
      89              : 
      90          395 :         public override bool equals (DataType type2) {
      91          395 :                 unowned ErrorType? et = type2 as ErrorType;
      92              : 
      93          395 :                 if (et == null) {
      94            0 :                         return false;
      95              :                 }
      96              : 
      97          395 :                 return error_domain == et.error_domain;
      98              :         }
      99              : 
     100           51 :         public override Symbol? get_member (string member_name) {
     101           51 :                 return CodeContext.get ().analyzer.gerror_type.scope.lookup (member_name);
     102              :         }
     103              : 
     104         2894 :         public override bool is_reference_type_or_type_parameter () {
     105         2894 :                 return true;
     106              :         }
     107              : 
     108       955689 :         public override bool check (CodeContext context) {
     109       955689 :                 if (error_domain != null) {
     110       321826 :                         return error_domain.check (context);
     111              :                 }
     112       955689 :                 return true;
     113              :         }
     114              : }
        

Generated by: LCOV version 2.0-1