use of groovy.lang.MetaClass in project groovy-core by groovy.
the class ResourceGroovyMethods method notFiltered.
private static boolean notFiltered(File file, Object filter, Object nameFilter, Object excludeFilter, Object excludeNameFilter) {
if (filter == null && nameFilter == null && excludeFilter == null && excludeNameFilter == null)
return true;
if (filter != null && nameFilter != null)
throw new IllegalArgumentException("Can't set both 'filter' and 'nameFilter'");
if (excludeFilter != null && excludeNameFilter != null)
throw new IllegalArgumentException("Can't set both 'excludeFilter' and 'excludeNameFilter'");
Object filterToUse = null;
Object filterParam = null;
if (filter != null) {
filterToUse = filter;
filterParam = file;
} else if (nameFilter != null) {
filterToUse = nameFilter;
filterParam = file.getName();
}
Object excludeFilterToUse = null;
Object excludeParam = null;
if (excludeFilter != null) {
excludeFilterToUse = excludeFilter;
excludeParam = file;
} else if (excludeNameFilter != null) {
excludeFilterToUse = excludeNameFilter;
excludeParam = file.getName();
}
final MetaClass filterMC = filterToUse == null ? null : InvokerHelper.getMetaClass(filterToUse);
final MetaClass excludeMC = excludeFilterToUse == null ? null : InvokerHelper.getMetaClass(excludeFilterToUse);
boolean included = filterToUse == null || DefaultTypeTransformation.castToBoolean(filterMC.invokeMethod(filterToUse, "isCase", filterParam));
boolean excluded = excludeFilterToUse != null && DefaultTypeTransformation.castToBoolean(excludeMC.invokeMethod(excludeFilterToUse, "isCase", excludeParam));
return included && !excluded;
}
use of groovy.lang.MetaClass in project groovy-core by groovy.
the class CallSiteArray method createPojoSite.
// for MetaClassImpl we try to pick meta method,
// otherwise or if method doesn't exist we make call via POJO meta class
private static CallSite createPojoSite(CallSite callSite, Object receiver, Object[] args) {
final Class klazz = receiver.getClass();
MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
if (!GroovyCategorySupport.hasCategoryInCurrentThread() && metaClass instanceof MetaClassImpl) {
final MetaClassImpl mci = (MetaClassImpl) metaClass;
final ClassInfo info = mci.getTheCachedClass().classInfo;
if (info.hasPerInstanceMetaClasses()) {
return new PerInstancePojoMetaClassSite(callSite, info);
} else {
return mci.createPojoCallSite(callSite, receiver, args);
}
}
ClassInfo info = ClassInfo.getClassInfo(klazz);
if (info.hasPerInstanceMetaClasses())
return new PerInstancePojoMetaClassSite(callSite, info);
else
return new PojoMetaClassSite(callSite, metaClass);
}
use of groovy.lang.MetaClass in project groovy-core by groovy.
the class CallSiteArray method createCallStaticSite.
private static CallSite createCallStaticSite(CallSite callSite, final Class receiver, Object[] args) {
CallSite site;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
try {
Class.forName(receiver.getName(), true, receiver.getClassLoader());
} catch (Exception e) {
// force <clinit>
}
return null;
}
});
MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
if (metaClass instanceof MetaClassImpl) {
site = ((MetaClassImpl) metaClass).createStaticSite(callSite, args);
} else
site = new StaticMetaClassSite(callSite, metaClass);
replaceCallSite(callSite, site);
return site;
}
use of groovy.lang.MetaClass in project groovy-core by groovy.
the class CallSiteArray method createCallCurrentSite.
private static CallSite createCallCurrentSite(CallSite callSite, GroovyObject receiver, Object[] args, Class sender) {
CallSite site;
if (receiver instanceof GroovyInterceptable)
site = new PogoInterceptableSite(callSite);
else {
MetaClass metaClass = receiver.getMetaClass();
if (receiver.getClass() != metaClass.getTheClass() && !metaClass.getTheClass().isInterface()) {
site = new PogoInterceptableSite(callSite);
} else if (metaClass instanceof MetaClassImpl) {
site = ((MetaClassImpl) metaClass).createPogoCallCurrentSite(callSite, sender, args);
} else
site = new PogoMetaClassSite(callSite, metaClass);
}
replaceCallSite(callSite, site);
return site;
}
use of groovy.lang.MetaClass in project groovy-core by groovy.
the class FactoryInterceptorMetaClass method build.
public Object build(Script script) {
// this used to be synchronized, but we also used to remove the
// metaclass. Since adding the metaclass is now a side effect, we
// don't need to ensure the meta-class won't be observed and don't
// need to hide the side effect.
MetaClass scriptMetaClass = script.getMetaClass();
script.setMetaClass(new FactoryInterceptorMetaClass(scriptMetaClass, this));
script.setBinding(this);
Object oldScriptName = getProxyBuilder().getVariables().get(SCRIPT_CLASS_NAME);
try {
getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, script.getClass().getName());
return script.run();
} finally {
if (oldScriptName != null) {
getProxyBuilder().setVariable(SCRIPT_CLASS_NAME, oldScriptName);
} else {
getProxyBuilder().getVariables().remove(SCRIPT_CLASS_NAME);
}
}
}
Aggregations