MCPcopy Create free account
hub / github.com/golang/mobile / importClasses

Method importClasses

internal/importers/java/java.go:597–647  ·  view source on GitHub ↗

importClasses imports the named classes from the classpaths of the Importer.

(names []string, allowMissingClasses bool)

Source from the content-addressed store, hash-verified

595
596// importClasses imports the named classes from the classpaths of the Importer.
597func (j *Importer) importClasses(names []string, allowMissingClasses bool) ([]*Class, error) {
598 if len(names) == 0 {
599 return nil, nil
600 }
601 args := []string{"-J-Duser.language=en", "-s", "-protected", "-constants"}
602 args = append(args, "-classpath", j.Classpath)
603 if j.Bootclasspath != "" {
604 args = append(args, "-bootclasspath", j.Bootclasspath)
605 }
606 args = append(args, names...)
607 javapPath, err := javapPath()
608 if err != nil {
609 return nil, err
610 }
611 javap := exec.Command(javapPath, args...)
612 out, err := javap.CombinedOutput()
613 if err != nil {
614 if _, ok := err.(*exec.ExitError); !ok {
615 return nil, fmt.Errorf("javap failed: %v", err)
616 }
617 // Not every name is a Java class so an exit error from javap is not
618 // fatal.
619 }
620 s := bufio.NewScanner(bytes.NewBuffer(out))
621 var classes []*Class
622 for _, name := range names {
623 cls, err := j.scanClass(s, name)
624 if err != nil {
625 _, notfound := err.(*errClsNotFound)
626 if notfound && allowMissingClasses {
627 continue
628 }
629 if notfound && name != "android.databinding.DataBindingComponent" {
630 return nil, err
631 }
632 // The Android Databinding library generates android.databinding.DataBindingComponent
633 // too late in the build process for the gobind plugin to import it. Synthesize a class
634 // for it instead.
635 cls = &Class{
636 Name: name,
637 FindName: name,
638 Interface: true,
639 PkgName: "databinding",
640 JNIName: JNIMangle(name),
641 }
642 }
643 classes = append(classes, cls)
644 j.clsMap[name] = cls
645 }
646 return classes, nil
647}
648
649// importReferencedClasses imports all implicit classes (super types, parameter and
650// return types) for the given classes not already imported.

Callers 2

ImportMethod · 0.95

Calls 3

scanClassMethod · 0.95
javapPathFunction · 0.85
JNIMangleFunction · 0.85

Tested by

no test coverage detected