MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / call

Method call

ij/src/main/java/ij/macro/Functions.java:4767–4857  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4765 // of String parameters, returning a String.
4766 // Contributed by Johannes Schindelin
4767 @AstroImageJ(reason = "Allow invoking nonpublic members", modified = true)
4768 String call() {
4769 // get class and method name
4770 String fullName = getFirstString();
4771 int dot = fullName.lastIndexOf('.');
4772 if(dot<0) {
4773 interp.error("'classname.methodname' expected");
4774 return null;
4775 }
4776 String className = fullName.substring(0,dot);
4777 String methodName = fullName.substring(dot+1);
4778
4779 // get optional string arguments
4780 Object[] args = null;
4781 if (interp.nextToken()==',') {
4782 Vector vargs = new Vector();
4783 do
4784 vargs.add(getNextString());
4785 while (interp.nextToken()==',');
4786 args = vargs.toArray();
4787 }
4788 interp.getRightParen();
4789 if (args==null) args = new Object[0];
4790
4791 // get the class
4792 Class c;
4793 try {
4794 c = IJ.getClassLoader().loadClass(className);
4795 } catch(Exception ex) {
4796 interp.error("Could not load class "+className);
4797 return null;
4798 }
4799
4800 // get method
4801 Method m;
4802 try {
4803 Class[] argClasses = null;
4804 if (args.length>0) {
4805 argClasses = new Class[args.length];
4806 for(int i=0;i<args.length;i++)
4807 argClasses[i] = args[i].getClass();
4808 }
4809 m = c.getDeclaredMethod(methodName,argClasses);
4810 if (c.getPackageName().startsWith("Astronomy.")) {
4811 m.trySetAccessible();
4812 }
4813 } catch(Exception ex) {
4814 m = null;
4815 }
4816 if (m==null && args.length>0) {
4817 try {
4818 Class[] argClasses = new Class[args.length];
4819 for(int i=0;i<args.length;i++) {
4820 double value = Tools.parseDouble((String)args[i]);
4821 if (!Double.isNaN(value)) {
4822 args[i] = Integer.valueOf((int)value);
4823 argClasses[i] = int.class;
4824 } else

Callers 1

getStringFunctionMethod · 0.95

Calls 15

getFirstStringMethod · 0.95
getNextStringMethod · 0.95
getClassLoaderMethod · 0.95
parseDoubleMethod · 0.95
getInstanceMethod · 0.95
logMethod · 0.95
substringMethod · 0.80
getRightParenMethod · 0.80
startsWithMethod · 0.80
valueOfMethod · 0.80
invokeMethod · 0.80
addMethod · 0.65

Tested by

no test coverage detected