当前位置: 首页>>代码示例>>Java>>正文


Java InvokerHelper类代码示例

本文整理汇总了Java中org.codehaus.groovy.runtime.InvokerHelper的典型用法代码示例。如果您正苦于以下问题:Java InvokerHelper类的具体用法?Java InvokerHelper怎么用?Java InvokerHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InvokerHelper类属于org.codehaus.groovy.runtime包,在下文中一共展示了InvokerHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bind

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
public void bind() {
    if (!bound) {
        bound = true;
        boundBean = bean;
        boundProperty = propertyName;
        try {
            InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{boundProperty, this});
            boundToProperty = true;
        } catch (MissingMethodException mme) {
            try {
                boundToProperty = false;
                InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                throw new RuntimeException("Properties in beans of type " + bean.getClass().getName() + " are not observable in any capacity (no PropertyChangeListener support).");
            }
        }
    }
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:19,代码来源:PropertyBinding.java

示例2: unbind

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
public void unbind() {
    if (bound) {
        if (boundToProperty) {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{boundProperty, this});
            } catch (MissingMethodException mme) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        } else {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        }
        boundBean = null;
        boundProperty = null;
        bound = false;
    }
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:21,代码来源:PropertyBinding.java

示例3: loadScript

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
/**
 * Loads a precompiled script with the supplied ID. The script class file must 
 * be stored in the pre-compiled scripts folder (see {@link Configuration#getFolderCompiledScripts()}.
 * 
 * The method will return null if such a folder does not exist or if it does not contain
 * the desired script.
 * @param id
 * @return
 */
public static Script loadScript(final String id) {
	String fileName = id+".class";
	Script cached = cache.get(fileName);
	if (cached != null) {
		return cached;
	}
	try {
		URLClassLoader cl = getURLClassLoader();
		if (cl != null) {
	    	Script script = InvokerHelper.createScript(cl.loadClass(fileName), new Binding());
	    	cache.put(fileName, script);
	    	return script;
		}
	} catch (ClassNotFoundException | RuntimeException | MalformedURLException e) {
		// do nothing and just build the class from the text
	}
	return null; 
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:28,代码来源:GroovyUtil.java

示例4: printNameAttributes

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
protected void printNameAttributes(Map attributes, NamespaceContext ctx) {
    if (attributes == null || attributes.isEmpty()) {
        return;
    }
    for (Object p : attributes.entrySet()) {
        Map.Entry entry = (Map.Entry) p;
        out.print(" ");
        out.print(getName(entry.getKey()));
        out.print("=");
        Object value = entry.getValue();
        out.print(quote);
        if (value instanceof String) {
            printEscaped((String) value, true);
        } else {
            printEscaped(InvokerHelper.toString(value), true);
        }
        out.print(quote);
        printNamespace(entry.getKey(), ctx);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:XmlNodePrinter.java

示例5: eval

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
/**
 * Evaluate an expression.
 */
public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
    try {
        Class scriptClass = evalScripts.get(script);
        if (scriptClass == null) {
            scriptClass = loader.parseClass(script.toString(), source);
            evalScripts.put(script, scriptClass);
        } else {
            LOG.fine("eval() - Using cached script...");
        }
        //can't cache the script because the context may be different.
        //but don't bother loading parsing the class again
        Script s = InvokerHelper.createScript(scriptClass, context);
        return s.run();
    } catch (Exception e) {
        throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:CachingGroovyEngine.java

示例6: invokeConstructor

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
private Object invokeConstructor(Class at, Object[] arguments) {
    checkInitalised();
    if (arguments == null) arguments = EMPTY_ARGUMENTS;
    Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
    MetaClassHelper.unwrap(arguments);
    CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
    if (constructor != null) {
        return constructor.doConstructorInvoke(arguments);
    }

    if (arguments.length == 1) {
        Object firstArgument = arguments[0];
        if (firstArgument instanceof Map) {
            constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
            if (constructor != null) {
                Object bean = constructor.doConstructorInvoke(MetaClassHelper.EMPTY_ARRAY);
                setProperties(bean, ((Map) firstArgument));
                return bean;
            }
        }
    }
    throw new GroovyRuntimeException(
            "Could not find matching constructor for: "
                    + theClass.getName()
                    + "(" + InvokerHelper.toTypeString(arguments) + ")");
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MetaClassImpl.java

示例7: run

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
public void run()
{
    final long id = Thread.currentThread().getId();

    // run the script numIter times
    for (int i = 0; i < numIter; i++)
    {
        Builder builder = new Builder();

        Binding binding = new Binding();
        binding.setVariable("builder", builder);

        script = InvokerHelper.createScript(scriptClass, binding);

        script.run();
    }

    latch.countDown();
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:ScriptLauncher.java

示例8: createPojoMetaClassGetPropertySite

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
private CallSite createPojoMetaClassGetPropertySite(Object receiver) {
    final MetaClass metaClass = InvokerHelper.getMetaClass(receiver);

    CallSite site;
    if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
        site = new PojoMetaClassGetPropertySite(this);
    } else {
        final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(receiver.getClass(), receiver, name, false);
        if (effective != null) {
            if (effective instanceof CachedField)
                site = new GetEffectivePojoFieldSite(this, (MetaClassImpl) metaClass, (CachedField) effective);
            else
                site = new GetEffectivePojoPropertySite(this, (MetaClassImpl) metaClass, effective);
        } else {
            site = new PojoMetaClassGetPropertySite(this);
        }
    }

    array.array[index] = site;
    return site;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:AbstractCallSite.java

示例9: realRunJUnit4Test

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
/**
 * Utility method to run a JUnit4 test.
 *
 * @param scriptClass the class we want to run as a test
 * @return the result of running the test
 */
static Object realRunJUnit4Test(Class scriptClass, GroovyClassLoader loader) {
    // invoke through reflection to eliminate mandatory JUnit 4 jar dependency

    try {
        Class junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
        Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
                "runClasses", new Object[]{scriptClass});
        System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
        System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
        System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
        List failures = (List) InvokerHelper.getProperty(result, "failures");
        for (int i = 0; i < failures.size(); i++) {
            Object f = failures.get(i);
            System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
            System.out.println(InvokerHelper.getProperty(f, "trace"));
        }
        return result;
    } catch (ClassNotFoundException e) {
        throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:JUnit4Utils.java

示例10: createCallStaticSite

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:CallSiteArray.java

示例11: valueToString

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
/**
 * Returns a string representation of the given value, or <tt>null</tt> if
 * the value should not be included (because it does not add any valuable
 * information).
 *
 * @param value a value
 * @return a string representation of the given value
 */
private static String valueToString(Object value) {
    String toString;

    try {
        toString = InvokerHelper.format(value, true, -1, false);
    } catch (Exception e) {
        return String.format("%s (toString() threw %s)",
                javaLangObjectToString(value), e.getClass().getName());
    }

    if (toString == null) {
        return String.format("%s (toString() == null)", javaLangObjectToString(value));
    }

    if (toString.equals("")) {
        if (hasStringLikeType(value)) return "\"\"";
        return String.format("%s (toString() == \"\")", javaLangObjectToString(value));
    }

    return toString;
}
 
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:AssertionRenderer.java

示例12: configureSourceSetDefaults

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) {
    final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
        @Override
        public void execute(final SourceSet sourceSet) {
            String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null);
            Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
            DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory);
            sourceSetConvention.getPlugins().put("scala", scalaSourceSet);
            final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala();
            scalaDirectorySet.srcDir(new Callable<File>() {
                @Override
                public File call() throws Exception {
                    return project.file("src/" + sourceSet.getName() + "/scala");
                }
            });
            sourceSet.getAllJava().source(scalaDirectorySet);
            sourceSet.getAllSource().source(scalaDirectorySet);
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {
                @Override
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return scalaDirectorySet.contains(element.getFile());
                }
            });

            configureScalaCompile(project, javaPlugin, sourceSet);
        }

    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:31,代码来源:ScalaBasePlugin.java

示例13: configureScalaCompile

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
private static void configureScalaCompile(final Project project, JavaBasePlugin javaPlugin, final SourceSet sourceSet) {
    String taskName = sourceSet.getCompileTaskName("scala");
    final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
    scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
    javaPlugin.configureForSourceSet(sourceSet, scalaCompile);
    Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
    ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
    scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
    scalaCompile.setSource(scalaSourceSet.getScala());
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);

    // cannot use convention mapping because the resulting object won't be serializable
    // cannot compute at task execution time because we need association with source set
    project.getGradle().addBuildListener(new BuildAdapter() {
        @Override
        public void projectsEvaluated(Gradle gradle) {
            IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
            if (incrementalOptions.getAnalysisFile() == null) {
                String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
                incrementalOptions.setAnalysisFile(new File(analysisFilePath));
            }

            if (incrementalOptions.getPublishedCode() == null) {
                Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
                incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
            }
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:30,代码来源:ScalaBasePlugin.java

示例14: invokeMethod

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
@Override
public Object invokeMethod(String name, Object args) {
    if (name.equals("dependency") || name.equals("dependencies") || name.equals("module")) {
        return InvokerHelper.invokeMethod(moduleFactoryDelegate, name, args);
    } else {
        return InvokerHelper.invokeMethod(clientModule, name, args);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:9,代码来源:ModuleFactoryDelegate.java

示例15: resultToString

import org.codehaus.groovy.runtime.InvokerHelper; //导入依赖的package包/类
public static String resultToString(Object obj) {
    if (obj instanceof Vertex) {
        return LazyVertex.toString((Vertex) obj);
    }
    if (obj instanceof Edge) {
        return LazyEdge.toString((Edge) obj);
    }
    if (obj instanceof Property) {
        return LazyProperty.toString((Property) obj, "property");
    }
    if (obj instanceof MemgraphCypherResult) {
        return memgraphCypherResultToString((MemgraphCypherResult) obj);
    }
    return InvokerHelper.toString(obj);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:16,代码来源:MemgraphScript.java


注:本文中的org.codehaus.groovy.runtime.InvokerHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。