| 850 | } |
| 851 | |
| 852 | func (j *Importer) scanClassDecl(name string, decl string) (*Class, error) { |
| 853 | isRoot := name == "java.lang.Object" |
| 854 | cls := &Class{ |
| 855 | Name: name, |
| 856 | funcMap: make(map[string]*FuncSet), |
| 857 | methodMap: make(map[string]*FuncSet), |
| 858 | HasNoArgCon: isRoot, |
| 859 | } |
| 860 | const ( |
| 861 | stMod = iota |
| 862 | stName |
| 863 | stExt |
| 864 | stImpl |
| 865 | ) |
| 866 | superClsDecl := isRoot |
| 867 | st := stMod |
| 868 | var w []byte |
| 869 | // if > 0, we're inside a generics declaration |
| 870 | gennest := 0 |
| 871 | for i := 0; i < len(decl); i++ { |
| 872 | c := decl[i] |
| 873 | switch c { |
| 874 | default: |
| 875 | if gennest == 0 { |
| 876 | w = append(w, c) |
| 877 | } |
| 878 | case '>': |
| 879 | gennest-- |
| 880 | case '<': |
| 881 | gennest++ |
| 882 | case '{': |
| 883 | if !superClsDecl && !cls.Interface { |
| 884 | cls.Supers = append(cls.Supers, "java.lang.Object") |
| 885 | } |
| 886 | return cls, nil |
| 887 | case ' ', ',': |
| 888 | if gennest > 0 { |
| 889 | break |
| 890 | } |
| 891 | switch w := string(w); w { |
| 892 | default: |
| 893 | switch st { |
| 894 | case stName: |
| 895 | if strings.Replace(w, "$", ".", -1) != strings.Replace(name, "$", ".", -1) { |
| 896 | return nil, fmt.Errorf("unexpected name %q in class declaration: %q", w, decl) |
| 897 | } |
| 898 | cls.FindName = w |
| 899 | case stExt: |
| 900 | superClsDecl = true |
| 901 | cls.Supers = append(cls.Supers, w) |
| 902 | case stImpl: |
| 903 | if !cls.Interface { |
| 904 | cls.Supers = append(cls.Supers, w) |
| 905 | } |
| 906 | default: |
| 907 | return nil, fmt.Errorf("unexpected %q in class declaration: %q", w, decl) |
| 908 | } |
| 909 | case "": |