importmatcher

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

README

importmatcher

Given source code, class names can be found in available .jar files, and import statements can be generated, for Java and for Kotlin.

Features and limitation
  • Searches directories of .jar files for class names.
  • Given the start of the class name, searches for the matching shortest class, and also returns the import path (like java.io.*).
  • Intended to be used for simple autocompletion of class names.
General info

Documentation

Overview

Package importmatcher tries to find which import should be used, given the start of a class name

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImportMatcher

type ImportMatcher struct {
	JARPaths []string // list of paths to examine for .jar files
	// contains filtered or unexported fields
}

ImportMatcher is a struct that contains a list of JAR file paths, and a lookup map from class names to class paths, which is populated when New or NewCustom is called.

func New

func New(onlyJava bool) (*ImportMatcher, error)

New creates a new ImportMatcher. If onlyJava is false, /usr/share/kotlin/lib will be added to the .jar file search path.

func NewCustom

func NewCustom(JARPaths []string, onlyJava bool) (*ImportMatcher, error)

NewCustom creates a new ImportMatcher, given a slice of paths to search for .jar files.

func (*ImportMatcher) ClassMap

func (impM *ImportMatcher) ClassMap() map[string]string

ClassMap returns the mapping from class names to class paths

func (*ImportMatcher) FindClassesInJAR

func (impM *ImportMatcher) FindClassesInJAR(JARPath string, found chan string) error

FindClassesInJAR will search the given JAR file for classes, and pass them as strings down the "found" chan.

func (*ImportMatcher) FindImports

func (impM *ImportMatcher) FindImports(sourceCode string) []string

FindImports can find words that looks like classes, and then look up appropriate import package paths. Ignores "java.lang." classes.

func (*ImportMatcher) ImportPathExact

func (impM *ImportMatcher) ImportPathExact(exactClassName string) string

ImportPathExact takes the exact class name and tries to return the shortest specific import path for the matching class, if found, like "java.io.File". Returns empty string if there are no matches.

func (*ImportMatcher) OrganizedImports

func (impM *ImportMatcher) OrganizedImports(sourceCode string, onlyJava bool) string

OrganizedImports generates import statements for packages that belongs to classes that are found in the given source code. If onlyJava is true, a semicolon is added after each line, and Kotlin jar files are not considered.

func (*ImportMatcher) StarPath

func (impM *ImportMatcher) StarPath(startOfClassName string) (string, string)

StarPath takes the start of the class name and tries to return the shortest found class name, and also the import path like "java.io.*" Returns empty strings if there are no matches.

func (*ImportMatcher) StarPathAll

func (impM *ImportMatcher) StarPathAll(startOfClassName string) ([]string, []string)

StarPathAll takes the start of the class name and tries to return all found class names, and also the import paths, like "java.io.*". Returns empty strings if there are no matches.

func (*ImportMatcher) StarPathAllExact

func (impM *ImportMatcher) StarPathAllExact(exactClassName string) ([]string, []string)

StarPathAllExact takes the exact class name and tries to return all matching class names, and also the import paths, like "java.io.*". Returns empty strings if there are no matches.

func (*ImportMatcher) StarPathExact

func (impM *ImportMatcher) StarPathExact(exactClassName string) string

StarPathExact takes the exact class name and tries to return the shortest import path for the matching class, if found, like "java.io.*". Returns empty string if there are no matches.

func (*ImportMatcher) String

func (impM *ImportMatcher) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL