diff --git a/parser/chunk.go b/parser/chunk.go index 60dffa9..750fd34 100644 --- a/parser/chunk.go +++ b/parser/chunk.go @@ -152,6 +152,14 @@ func buildClasses(metadata MetadataEvent) ClassMap { numConstants++ } } + + if typeFn, ok := types[class.Name]; ok { + class.typeFn = typeFn + } else { + class.typeFn = func() ParseResolvable { + return &UnsupportedType{} + } + } class.numConstants = numConstants classes[int(class.ID)] = class } diff --git a/parser/metadata.go b/parser/metadata.go index 37b0d38..6237ebc 100644 --- a/parser/metadata.go +++ b/parser/metadata.go @@ -91,6 +91,7 @@ type ClassMetadata struct { Settings []SettingMetadata Annotations []AnnotationMetadata numConstants int + typeFn func() ParseResolvable } func (c *ClassMetadata) SetAttribute(key, value string) (err error) { diff --git a/parser/types.go b/parser/types.go index 2634665..ad1b5a9 100644 --- a/parser/types.go +++ b/parser/types.go @@ -53,12 +53,7 @@ func ParseClass(r reader.Reader, classes ClassMap, cpools PoolMap, classID int64 if !ok { return nil, fmt.Errorf("unexpected class %d", classID) } - var v ParseResolvable - if typeFn, ok := types[class.Name]; ok { - v = typeFn() - } else { - v = new(UnsupportedType) - } + v := class.typeFn() if err := v.Parse(r, classes, cpools, class); err != nil { return nil, err }