Source file src/cmd/compile/internal/types2/importer_test.go

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file implements the (temporary) plumbing to get importing to work.
     6  
     7  package types2_test
     8  
     9  import (
    10  	gcimporter "cmd/compile/internal/importer"
    11  	"cmd/compile/internal/types2"
    12  	"io"
    13  )
    14  
    15  func defaultImporter() types2.Importer {
    16  	return &gcimports{
    17  		packages: make(map[string]*types2.Package),
    18  	}
    19  }
    20  
    21  type gcimports struct {
    22  	packages map[string]*types2.Package
    23  	lookup   func(path string) (io.ReadCloser, error)
    24  }
    25  
    26  func (m *gcimports) Import(path string) (*types2.Package, error) {
    27  	return m.ImportFrom(path, "" /* no vendoring */, 0)
    28  }
    29  
    30  func (m *gcimports) ImportFrom(path, srcDir string, mode types2.ImportMode) (*types2.Package, error) {
    31  	if mode != 0 {
    32  		panic("mode must be 0")
    33  	}
    34  	return gcimporter.Import(m.packages, path, srcDir, m.lookup)
    35  }
    36  

View as plain text