Example #1
0
File: Macro.java Project: bramk/bnd
 private String doCommand(Object target, String method, String[] args) {
   if (target == null) ; // System.err.println("Huh? Target should never be null " +
   // domain);
   else {
     String cname = "_" + method.replaceAll("-", "_");
     try {
       Method m = target.getClass().getMethod(cname, new Class[] {String[].class});
       return (String) m.invoke(target, new Object[] {args});
     } catch (NoSuchMethodException e) {
       // Ignore
     } catch (InvocationTargetException e) {
       if (e.getCause() instanceof IllegalArgumentException) {
         domain.error(
             "%s, for cmd: %s, arguments; %s",
             e.getCause().getMessage(), method, Arrays.toString(args));
       } else {
         domain.warning("Exception in replace: %s", e.getCause());
         e.getCause().printStackTrace();
       }
     } catch (Exception e) {
       domain.warning("Exception in replace: " + e + " method=" + method);
       e.printStackTrace();
     }
   }
   return null;
 }
 public static void main(String[] args) {
   if (args.length < 1) {
     print(usage);
     System.exit(0);
   }
   int lines = 0;
   try {
     Class<?> c = Class.forName(args[0]);
     Method[] methods = c.getMethods();
     Constructor[] ctors = c.getConstructors();
     if (args.length == 1) {
       for (Method method : methods) print(p.matcher(method.toString()).replaceAll(""));
       for (Constructor ctor : ctors) print(p.matcher(ctor.toString()).replaceAll(""));
       lines = methods.length + ctors.length;
     } else {
       for (Method method : methods)
         if (method.toString().indexOf(args[1]) != -1) {
           print(p.matcher(method.toString()).replaceAll(""));
           lines++;
         }
       for (Constructor ctor : ctors)
         if (ctor.toString().indexOf(args[1]) != -1) {
           print(p.matcher(ctor.toString()).replaceAll(""));
           lines++;
         }
     }
   } catch (ClassNotFoundException e) {
     print("No such class: " + e);
   }
 }
Example #3
0
  static <T> T set(Class<T> interf, Object value) {
    Properties p = new Properties();
    Method ms[] = interf.getMethods();

    for (Method m : ms) {
      p.put(m.getName(), value);
    }
    return Configurable.createConfigurable(interf, (Map<Object, Object>) p);
  }
 public void close() {
   if (jusl) {
     try {
       // Call java.util.ServiceLoader.reload
       Method reloadMethod = loaderClass.getMethod("reload");
       reloadMethod.invoke(loader);
     } catch (Exception e) {; // Ignore problems during a call to reload.
     }
   }
 }
    ServiceIterator(ClassLoader classLoader, Log log) {
      String loadMethodName;

      this.log = log;
      try {
        try {
          loaderClass = Class.forName("java.util.ServiceLoader");
          loadMethodName = "load";
          jusl = true;
        } catch (ClassNotFoundException cnfe) {
          try {
            loaderClass = Class.forName("sun.misc.Service");
            loadMethodName = "providers";
            jusl = false;
          } catch (ClassNotFoundException cnfe2) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
            return;
          }
        }

        // java.util.ServiceLoader.load or sun.misc.Service.providers
        Method loadMethod = loaderClass.getMethod(loadMethodName, Class.class, ClassLoader.class);

        Object result = loadMethod.invoke(null, Processor.class, classLoader);

        // For java.util.ServiceLoader, we have to call another
        // method to get the iterator.
        if (jusl) {
          loader = result; // Store ServiceLoader to call reload later
          Method m = loaderClass.getMethod("iterator");
          result = m.invoke(result); // serviceLoader.iterator();
        }

        // The result should now be an iterator.
        this.iterator = (Iterator<?>) result;
      } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
      }
    }
Example #6
0
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine().trim());
    Object o;

    // Solution starts here
    if (num < 1 || num > Math.pow(2, 30)) throw new Exception();
    Solution ob = new Solution();
    Class<?> c = Class.forName("Solution$Private");
    Constructor<?> constructor = c.getDeclaredConstructor(Solution.class);
    constructor.setAccessible(true);
    o = constructor.newInstance(ob);
    Method m = c.getDeclaredMethod("powerof2", new Class[] {int.class});
    m.setAccessible(true);
    String ans = (String) m.invoke(o, num);
    System.out.println(num + " is " + ans);
    // ends here

    System.out.println(
        "An instance of class: " + o.getClass().getSimpleName() + " has been created");
  } // end of main