加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

GroovyShell的初始化过程

发布时间:2020-12-14 16:48:37 所属栏目:大数据 来源:网络整理
导读:GroovyShell的初始化 public GroovyShell(CompilerConfiguration config) { this(new Binding(),config); }class Binding is subclass of GroovyObjectSupportpublic GroovyObjectSupport() { this.metaClass = InvokerHelper.getMetaClass(this.getClass())
GroovyShell的初始化

    public GroovyShell(CompilerConfiguration config) {
        this(new Binding(),config);
    }
	
	class Binding is subclass of GroovyObjectSupport

	public GroovyObjectSupport() {
        this.metaClass = InvokerHelper.getMetaClass(this.getClass());
    }
	
	while the InvokerHelper has static members 
	
	public static final MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry();
	
	So the GroovySystem will be loaded,and its static members
	
	static {
        USE_REFLECTION = true;
        META_CLASS_REGISTRY = new MetaClassRegistryImpl();
    }
	
	public MetaClassRegistryImpl() {
        this(LOAD_DEFAULT,true);
    }
	
	it will call MetaClassRegistryImpl.registerMethods,-> GeneratedMetaMethod.DgmMethodRecord.loadDgmInfo();
	the function will analysis groovy-2.4.0.jar$META-INF/dgminfo
	这是一个二进制流的文件,她定义了很多基本的函数的参数个数,类型,返回值的类型等等
	这个函数最后返回一个列表,记录了所欧的基本函数
	
	registerMethods(null,true,map);返回后, map是一个CachedClass为key (如java.util.Calendar)
		list<MetaMethod>  为value的map 如[org.codehaus.groovy.reflection.GeneratedMetaMethod$Proxy@a5852[name: clearTime params: [] returns: class java.util.Calendar owner: class java.util.Calendar],..]
		
	接着和DefaultGroovyMethods.additionals 合并, 不断填充map
	接着和class org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods 合并 (所有函数为 [
	public static java.lang.StringBuilder org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.leftShift(java.lang.StringBuilder,java.lang.Object),public static java.lang.Object org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.next(java.lang.Enum),public static java.lang.String org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.plus(java.lang.StringBuilder,java.lang.String),public static java.lang.Object org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.previous(java.lang.Enum),public static void org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.putAt(java.lang.StringBuilder,groovy.lang.EmptyRange,groovy.lang.IntRange,public static int org.codehaus.groovy.vmplugin.v5.PluginDefaultGroovyMethods.size(java.lang.StringBuilder)])
	
	注意leftShift
	
	接着DefaultGroovyStaticMethods
	接着     ExtensionModuleScanner scanner = new ExtensionModuleScanner(new DefaultModuleListener(map),this.getClass().getClassLoader());
            scanner.scanClasspathModules();
			从所有META-INF/services/org.codehaus.groovy.runtime.ExtensionModule 中找出properties, 
			处理   ---------具体略以后分析
			从 groovy-jsr223-<version>.jar中,找出
			[public static java.lang.Object org.codehaus.groovy.jsr223.ScriptExtensions.eval(javax.script.ScriptEngine,java.io.Reader,groovy.lang.Binding) throws javax.script.ScriptException,public static java.lang.Object org.codehaus.groovy.jsr223.ScriptExtensions.eval(javax.script.ScriptEngine,java.lang.String,public static javax.script.ScriptEngine org.codehaus.groovy.jsr223.ScriptStaticExtensions.$static_propertyMissing(javax.script.ScriptEngineManager,java.lang.String)]
	
	以上过程也在同时不断写MetaClassRegistryImpl类的
	private FastArray instanceMethods = new FastArray();
    private FastArray staticMethods = new FastArray();
	


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读