github.com/galaxyobe/gen@v0.0.0-20220910125335-392fa8f0990f/pkg/util/types.go (about)

     1  /*
     2   Copyright 2022 Galaxyobe.
     3  
     4   Licensed under the Apache License, Version 2.0 (the "License");
     5   you may not use this file except in compliance with the License.
     6   You may obtain a copy of the License at
     7  
     8       http://www.apache.org/licenses/LICENSE-2.0
     9  
    10   Unless required by applicable law or agreed to in writing, software
    11   distributed under the License is distributed on an "AS IS" BASIS,
    12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   See the License for the specific language governing permissions and
    14   limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import (
    20  	"strings"
    21  
    22  	"k8s.io/gengo/types"
    23  )
    24  
    25  func UnderlyingType(t *types.Type) *types.Type {
    26  	for t.Kind == types.Alias {
    27  		t = t.Underlying
    28  	}
    29  	return t
    30  }
    31  
    32  // IsReference return true for pointer, maps, slices and aliases of those.
    33  func IsReference(t *types.Type) bool {
    34  	if t.Kind == types.Pointer || t.Kind == types.Map || t.Kind == types.Slice {
    35  		return true
    36  	}
    37  	return t.Kind == types.Alias && IsReference(UnderlyingType(t))
    38  }
    39  
    40  func IsLower(s string) bool {
    41  	if s == "" {
    42  		return false
    43  	}
    44  	return strings.ToLower(s[:1]) == s[:1]
    45  }