LCOV - code coverage report
Current view: top level - server/project - SectionMatcher.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 13 100.0 %
Date: 2022-11-19 15:00:39 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2011 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.project;
      16             : 
      17             : import com.google.gerrit.common.Nullable;
      18             : import com.google.gerrit.entities.AccessSection;
      19             : import com.google.gerrit.entities.Project;
      20             : import com.google.gerrit.server.CurrentUser;
      21             : 
      22             : /**
      23             :  * Matches an AccessSection against a reference name.
      24             :  *
      25             :  * <p>These matchers are "compiled" versions of the AccessSection name, supporting faster selection
      26             :  * of which sections are relevant to any given input reference.
      27             :  */
      28             : public class SectionMatcher extends RefPatternMatcher {
      29             :   @Nullable
      30             :   static SectionMatcher wrap(Project.NameKey project, AccessSection section) {
      31         145 :     String ref = section.getName();
      32         145 :     if (AccessSection.isValidRefSectionName(ref)) {
      33         145 :       return new SectionMatcher(project, section, getMatcher(section));
      34             :     }
      35         145 :     return null;
      36             :   }
      37             : 
      38             :   private final Project.NameKey project;
      39             :   private final AccessSection section;
      40             :   private final RefPatternMatcher matcher;
      41             : 
      42         145 :   public SectionMatcher(Project.NameKey project, AccessSection section, RefPatternMatcher matcher) {
      43         145 :     this.project = project;
      44         145 :     this.section = section;
      45         145 :     this.matcher = matcher;
      46         145 :   }
      47             : 
      48             :   @Override
      49             :   public boolean match(String ref, CurrentUser user) {
      50         145 :     return this.matcher.match(ref, user);
      51             :   }
      52             : 
      53             :   public AccessSection getSection() {
      54         145 :     return section;
      55             :   }
      56             : 
      57             :   public RefPatternMatcher getMatcher() {
      58         145 :     return matcher;
      59             :   }
      60             : 
      61             :   public Project.NameKey getProject() {
      62         145 :     return project;
      63             :   }
      64             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750