Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2003-2007 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.codehaus.groovy.runtime.callsite;
 
 
 import java.util.Map;
 
 public class ConstructorSite extends MetaClassSite {
     final CachedConstructor constructor;
     final Class [] params;
     private final int version;
 
     public ConstructorSite(CallSite siteMetaClassImpl metaClassCachedConstructor constructorClass params[]) {
         super(sitemetaClass);
         this. = constructor;
         this. = params;
         this. = metaClass.getVersion();
     }
 
     public Object callConstructor(Object receiverObject[] argsthrows Throwable {
         if (checkCall(receiverargs)) 
         {   
             MetaClassHelper.unwrap(args);
             try {
                 return .doConstructorInvoke(args);
             } catch (GroovyRuntimeException gre) {
                 throw ScriptBytecodeAdapter.unwrap(gre);
             }
         }
         else
           return CallSiteArray.defaultCallConstructor(thisreceiverargs);
     }
 
     protected final boolean checkCall(Object receiverObject[] args) {
     	return receiver == .getTheClass() // meta class match receiver
             && ((MetaClassImpl)).getVersion() ==  // metaClass still be valid
             && MetaClassHelper.sameClasses(args);
     }
 
     public static ConstructorSite createConstructorSite(CallSite siteMetaClassImpl metaClassCachedConstructor constructorClass[] paramsObject[] args) {
         if (constructor.correctArguments(args) == args) {
             if (noWrappers(args)) {
                 if (noCoerce(constructor,args))
                     return new ConstructorSiteNoUnwrap(sitemetaClassconstructorparams);
                 else
                     return new ConstructorSiteNoUnwrapNoCoerce(sitemetaClassconstructorparams);
             }
         }
         return new ConstructorSite(sitemetaClassconstructorparams);
     }


    
Call site where we know there is no need to unwrap arguments
 
     public static class ConstructorSiteNoUnwrap extends ConstructorSite {
 
         public ConstructorSiteNoUnwrap(CallSite siteMetaClassImpl metaClassCachedConstructor constructorClass params[]) {
             super(sitemetaClassconstructorparams);
         }
 
         public final Object callConstructor(Object receiverObject[] argsthrows Throwable {
             if (checkCall(receiverargs)) 
             {
                 try {
                     return .doConstructorInvoke(args);
                 } catch (GroovyRuntimeException gre) {
                     throw ScriptBytecodeAdapter.unwrap(gre);
                 }
             }
             else
               return CallSiteArray.defaultCallConstructor(thisreceiverargs);
         }
     }

    
Call site where we know there is no need neither unwrap nor coerce arguments
 
     public static class ConstructorSiteNoUnwrapNoCoerce extends ConstructorSite {
 
         public ConstructorSiteNoUnwrapNoCoerce(CallSite siteMetaClassImpl metaClassCachedConstructor constructorClass params[]) {
            super(sitemetaClassconstructorparams);
        }
        public Object callConstructor(Object receiverObject[] argsthrows Throwable {
            if (checkCall(receiverargs)) 
            {
                try {
                    return .invoke(args);
                } catch (GroovyRuntimeException gre) {
                    throw ScriptBytecodeAdapter.unwrap(gre);
                }
            }
            else
              return CallSiteArray.defaultCallConstructor(thisreceiverargs);
        }
    }
    public static class NoParamSite extends ConstructorSiteNoUnwrapNoCoerce {
        private static final Object[] NO_ARGS = new Object[0];
        public NoParamSite(CallSite siteMetaClassImpl metaClassCachedConstructor constructorClass[] params) {
            super(sitemetaClassconstructorparams);
        }
        public final Object callConstructor(Object receiverObject[] argsthrows Throwable {
            if (checkCall(receiverargs)) 
            {
                final Object bean = .invoke();
                try {
                    ((MetaClassImpl)).setProperties(bean, (Mapargs[0]);
                } catch (GroovyRuntimeException gre) {
                    throw ScriptBytecodeAdapter.unwrap(gre);
                }
                return bean;
            }
            else
              return CallSiteArray.defaultCallConstructor(thisreceiverargs);
        }
    }
New to GrepCode? Check out our FAQ X