1- /* ************************************************************** *
2- * *
3- * Copyright (c) 2016-, Kota Mizushima, All rights reserved. *
4- * *
5- * *
6- * This software is distributed under the modified BSD License. *
7- * ************************************************************** */
81package onion .compiler
92
103import java .util .{HashMap => JHashMap }
11- import onion .compiler .environment .BcelRefs .BcelClassType
124import onion .compiler .environment .AsmRefs .AsmClassType
135import onion .compiler .environment .ClassFileTable
146import onion .compiler .environment .ReflectionRefs .ReflectClassType
157
16- /**
17- * @author Kota Mizushima
18- *
19- */
20- class ClassTable (classPath : String ) {
8+ class ClassTable (classPath : String ):
219 val classes = new OrderedTable [IRT .ClassDefinition ]
2210 private val classFiles = new JHashMap [String , IRT .ClassType ]
2311 private val arrayClasses = new JHashMap [String , IRT .ArrayType ]
2412 private val table = new ClassFileTable (classPath)
2513
26- def loadArray (component : IRT .Type , dimension : Int ): IRT .ArrayType = {
14+ def loadArray (component : IRT .Type , dimension : Int ): IRT .ArrayType =
2715 val arrayName = " [" * dimension + component.name
28- var array : IRT . ArrayType = arrayClasses.get(arrayName)
29- if ( array != null ) return array
30- array = new IRT .ArrayType (component, dimension, this )
16+ var array = arrayClasses.get(arrayName)
17+ if array != null then return array
18+ array = IRT .ArrayType (component, dimension, this )
3119 arrayClasses.put(arrayName, array)
3220 array
33- }
3421
35- def load (className : String ): IRT .ClassType = {
36- var clazz : IRT . ClassType = lookup(className)
37- if ( clazz == null ) {
38- val javaClass = table.load (className)
39- if (javaClass != null ) {
40- clazz = new BcelClassType (javaClass , this )
22+ def load (className : String ): IRT .ClassType =
23+ var clazz = lookup(className)
24+ if clazz == null then
25+ val bytes = table.loadBytes (className)
26+ if bytes != null then
27+ clazz = new AsmClassType (bytes , this )
4128 classFiles.put(clazz.name, clazz)
42- } else {
43- val bytes = table.loadBytes(className)
44- if (bytes != null ) {
45- clazz = new AsmClassType (bytes, this )
29+ else
30+ try
31+ clazz = new ReflectClassType (Class .forName(className, true , Thread .currentThread.getContextClassLoader), this )
4632 classFiles.put(clazz.name, clazz)
47- } else {
48- try {
49- clazz = new ReflectClassType (Class .forName(className, true , Thread .currentThread.getContextClassLoader), this )
50- classFiles.put(clazz.name, clazz)
51- }
52- catch {
53- case e : ClassNotFoundException => {}
54- }
55- }
56- }
57- }
33+ catch
34+ case _ : ClassNotFoundException => ()
5835 clazz
59- }
6036
6137 def rootClass : IRT .ClassType = load(" java.lang.Object" )
6238
63- def lookup (className : String ): IRT .ClassType = {
64- classes.get(className) match {
39+ def lookup (className : String ): IRT .ClassType =
40+ classes.get(className) match
6541 case Some (ref) => ref
6642 case None => classFiles.get(className)
67- }
68- }
6943
70- }
0 commit comments