Example #1
0
 /**
  * Prints the node as a string.
  *
  * @return The printed representation.
  */
 public String build() {
   try {
     return (String) method_build.invoke(codePrinterBuilder);
   } catch (IllegalArgumentException e) {
     throw new MagicException(e);
   } catch (IllegalAccessException e) {
     throw new MagicException(e);
   } catch (InvocationTargetException e) {
     Magic.catchInvocationTargetException(e);
     return null;
   }
 }
Example #2
0
 private static void initialize() {
   if (constructor != null) return;
   Class<?> cls =
       Magic.getNestedClass(Magic.getClass("com.google.javascript.jscomp.CodePrinter"), "Builder");
   constructor = Magic.getDeclaredConstructor(cls, Node.class);
   method_build = Magic.getDeclaredMethod(cls, "build");
   field_prettyPrint = Magic.getDeclaredField(cls, "prettyPrint");
   field_outputTypes = Magic.getDeclaredField(cls, "outputTypes");
 }
Example #3
0
 /**
  * @param node The node to be printed.
  * @param prettyPrint Whether to pretty print.
  * @param outputTypes Whether to output types as JSDocStrings.
  */
 public MagicCodePrinterBuilder(Node node, boolean prettyPrint, boolean outputTypes) {
   initialize();
   try {
     codePrinterBuilder = constructor.newInstance(node);
     field_prettyPrint.setBoolean(codePrinterBuilder, prettyPrint);
     field_outputTypes.setBoolean(codePrinterBuilder, outputTypes);
   } catch (IllegalArgumentException e) {
     throw new MagicException(e);
   } catch (InstantiationException e) {
     throw new MagicException(e);
   } catch (IllegalAccessException e) {
     throw new MagicException(e);
   } catch (InvocationTargetException e) {
     Magic.catchInvocationTargetException(e);
   }
 }
Example #4
0
 private Magic(byte value) {
   intValue = value;
   Magic.getMappings().put(value, this);
 }