示例#1
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy n_18) {
   ITermFactory termFactory = context.getFactory();
   context.push("Overlays_1_0");
   Fail56:
   {
     IStrategoTerm u_109 = null;
     IStrategoTerm t_109 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || extraction._consOverlays_1 != ((IStrategoAppl) term).getConstructor()) break Fail56;
     t_109 = term.getSubterm(0);
     IStrategoList annos32 = term.getAnnotations();
     u_109 = annos32;
     term = n_18.invoke(context, t_109);
     if (term == null) break Fail56;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(extraction._consOverlays_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, u_109));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#2
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy q_23) {
   ITermFactory termFactory = context.getFactory();
   context.push("OpDeclInj_1_0");
   Fail144:
   {
     IStrategoTerm s_124 = null;
     IStrategoTerm q_124 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || ext_out._consOpDeclInj_1 != ((IStrategoAppl) term).getConstructor()) break Fail144;
     q_124 = term.getSubterm(0);
     IStrategoList annos114 = term.getAnnotations();
     s_124 = annos114;
     term = q_23.invoke(context, q_124);
     if (term == null) break Fail144;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(ext_out._consOpDeclInj_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, s_124));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#3
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy t_27, Strategy u_27) {
   ITermFactory termFactory = context.getFactory();
   context.push("strategy_2_0");
   Fail231:
   {
     IStrategoTerm k_141 = null;
     IStrategoTerm f_141 = null;
     IStrategoTerm g_141 = null;
     IStrategoTerm l_141 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || ext_out._consstrategy_2 != ((IStrategoAppl) term).getConstructor()) break Fail231;
     f_141 = term.getSubterm(0);
     g_141 = term.getSubterm(1);
     IStrategoList annos189 = term.getAnnotations();
     k_141 = annos189;
     term = t_27.invoke(context, f_141);
     if (term == null) break Fail231;
     l_141 = term;
     term = u_27.invoke(context, g_141);
     if (term == null) break Fail231;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(ext_out._consstrategy_2, new IStrategoTerm[] {l_141, term}),
             checkListAnnos(termFactory, k_141));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#4
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy p_17, Strategy q_17) {
   ITermFactory termFactory = context.getFactory();
   context.push("SortListTl_2_0");
   Fail121:
   {
     IStrategoTerm l_111 = null;
     IStrategoTerm j_111 = null;
     IStrategoTerm k_111 = null;
     IStrategoTerm m_111 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consSortListTl_2 != ((IStrategoAppl) term).getConstructor()) break Fail121;
     j_111 = term.getSubterm(0);
     k_111 = term.getSubterm(1);
     IStrategoList annos109 = term.getAnnotations();
     l_111 = annos109;
     term = p_17.invoke(context, j_111);
     if (term == null) break Fail121;
     m_111 = term;
     term = q_17.invoke(context, k_111);
     if (term == null) break Fail121;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(out._consSortListTl_2, new IStrategoTerm[] {m_111, term}),
             checkListAnnos(termFactory, l_111));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#5
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy m_23, Strategy n_23) {
   ITermFactory termFactory = context.getFactory();
   context.push("ExtOpDeclQ_2_0");
   Fail142:
   {
     IStrategoTerm c_124 = null;
     IStrategoTerm z_123 = null;
     IStrategoTerm b_124 = null;
     IStrategoTerm d_124 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || ext_out._consExtOpDeclQ_2 != ((IStrategoAppl) term).getConstructor()) break Fail142;
     z_123 = term.getSubterm(0);
     b_124 = term.getSubterm(1);
     IStrategoList annos112 = term.getAnnotations();
     c_124 = annos112;
     term = m_23.invoke(context, z_123);
     if (term == null) break Fail142;
     d_124 = term;
     term = n_23.invoke(context, b_124);
     if (term == null) break Fail142;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(ext_out._consExtOpDeclQ_2, new IStrategoTerm[] {d_124, term}),
             checkListAnnos(termFactory, c_124));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#6
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy w_48, Strategy x_48) {
   ITermFactory termFactory = context.getFactory();
   context.push("OpQ_2_0");
   Fail375:
   {
     IStrategoTerm k_198 = null;
     IStrategoTerm i_198 = null;
     IStrategoTerm j_198 = null;
     IStrategoTerm l_198 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consOpQ_2 != ((IStrategoAppl) term).getConstructor()) break Fail375;
     i_198 = term.getSubterm(0);
     j_198 = term.getSubterm(1);
     IStrategoList annos318 = term.getAnnotations();
     k_198 = annos318;
     term = w_48.invoke(context, i_198);
     if (term == null) break Fail375;
     l_198 = term;
     term = x_48.invoke(context, j_198);
     if (term == null) break Fail375;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(out._consOpQ_2, new IStrategoTerm[] {l_198, term}),
             checkListAnnos(termFactory, k_198));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#7
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy e_26, Strategy f_26) {
   ITermFactory termFactory = context.getFactory();
   context.push("range_2_0");
   Fail193:
   {
     IStrategoTerm q_134 = null;
     IStrategoTerm u_133 = null;
     IStrategoTerm x_133 = null;
     IStrategoTerm r_134 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || ext_out._consrange_2 != ((IStrategoAppl) term).getConstructor()) break Fail193;
     u_133 = term.getSubterm(0);
     x_133 = term.getSubterm(1);
     IStrategoList annos161 = term.getAnnotations();
     q_134 = annos161;
     term = e_26.invoke(context, u_133);
     if (term == null) break Fail193;
     r_134 = term;
     term = f_26.invoke(context, x_133);
     if (term == null) break Fail193;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(ext_out._consrange_2, new IStrategoTerm[] {r_134, term}),
             checkListAnnos(termFactory, q_134));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#8
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy d_28) {
   ITermFactory termFactory = context.getFactory();
   context.push("iter_1_0");
   Fail225:
   {
     IStrategoTerm z_142 = null;
     IStrategoTerm y_142 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || extraction._consiter_1 != ((IStrategoAppl) term).getConstructor()) break Fail225;
     y_142 = term.getSubterm(0);
     IStrategoList annos186 = term.getAnnotations();
     z_142 = annos186;
     term = d_28.invoke(context, y_142);
     if (term == null) break Fail225;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(extraction._consiter_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, z_142));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy x_29) {
   ITermFactory termFactory = context.getFactory();
   context.push("ExtendsInterfaces_1_0");
   Fail76:
   {
     IStrategoTerm x_136 = null;
     IStrategoTerm w_136 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consExtendsInterfaces_1 != ((IStrategoAppl) term).getConstructor()) break Fail76;
     w_136 = term.getSubterm(0);
     IStrategoList annos52 = term.getAnnotations();
     x_136 = annos52;
     term = x_29.invoke(context, w_136);
     if (term == null) break Fail76;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(out._consExtendsInterfaces_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, x_136));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#10
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy p_18) {
   ITermFactory termFactory = context.getFactory();
   context.push("Signature_1_0");
   Fail58:
   {
     IStrategoTerm a_110 = null;
     IStrategoTerm z_109 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || extraction._consSignature_1 != ((IStrategoAppl) term).getConstructor()) break Fail58;
     z_109 = term.getSubterm(0);
     IStrategoList annos34 = term.getAnnotations();
     a_110 = annos34;
     term = p_18.invoke(context, z_109);
     if (term == null) break Fail58;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(extraction._consSignature_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, a_110));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#11
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy c_21) {
   ITermFactory termFactory = context.getFactory();
   context.push("LRule_1_0");
   Fail88:
   {
     IStrategoTerm v_116 = null;
     IStrategoTerm u_116 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || extraction._consLRule_1 != ((IStrategoAppl) term).getConstructor()) break Fail88;
     u_116 = term.getSubterm(0);
     IStrategoList annos64 = term.getAnnotations();
     v_116 = annos64;
     term = c_21.invoke(context, u_116);
     if (term == null) break Fail88;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(extraction._consLRule_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, v_116));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#12
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy m_18) {
   ITermFactory termFactory = context.getFactory();
   context.push("BuildDefaultPT_1_0");
   Fail139:
   {
     IStrategoTerm a_114 = null;
     IStrategoTerm z_113 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consBuildDefaultPT_1 != ((IStrategoAppl) term).getConstructor()) break Fail139;
     z_113 = term.getSubterm(0);
     IStrategoList annos126 = term.getAnnotations();
     a_114 = annos126;
     term = m_18.invoke(context, z_113);
     if (term == null) break Fail139;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(out._consBuildDefaultPT_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, a_114));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#13
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy s_19) {
   ITermFactory termFactory = context.getFactory();
   context.push("Block_1_0");
   Fail72:
   {
     IStrategoTerm q_112 = null;
     IStrategoTerm p_112 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || renaming._consBlock_1 != ((IStrategoAppl) term).getConstructor()) break Fail72;
     p_112 = term.getSubterm(0);
     IStrategoList annos56 = term.getAnnotations();
     q_112 = annos56;
     term = s_19.invoke(context, p_112);
     if (term == null) break Fail72;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(renaming._consBlock_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, q_112));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#14
0
 @Override
 public IStrategoTerm invoke(Context context, IStrategoTerm term, Strategy a_15) {
   ITermFactory termFactory = context.getFactory();
   context.push("ElemValArrayInit_1_0");
   Fail20:
   {
     IStrategoTerm j_100 = null;
     IStrategoTerm i_100 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || renaming._consElemValArrayInit_1 != ((IStrategoAppl) term).getConstructor())
       break Fail20;
     i_100 = term.getSubterm(0);
     IStrategoList annos6 = term.getAnnotations();
     j_100 = annos6;
     term = a_15.invoke(context, i_100);
     if (term == null) break Fail20;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(renaming._consElemValArrayInit_1, new IStrategoTerm[] {term}),
             checkListAnnos(termFactory, j_100));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
 public boolean isTransactionInProgress(
     JDBCContext jdbcContext, Context transactionContext, Transaction transaction) {
   try {
     return JTAHelper.isTransactionInProgress(
         transactionContext.getFactory().getTransactionManager().getTransaction());
   } catch (SystemException se) {
     throw new TransactionException("Unable to check transaction status", se);
   }
 }
示例#16
0
 @Override
 public IStrategoTerm invoke(
     Context context,
     IStrategoTerm term,
     Strategy p_29,
     Strategy q_29,
     Strategy r_29,
     Strategy s_29,
     Strategy t_29) {
   ITermFactory termFactory = context.getFactory();
   context.push("ClassDecHead_5_0");
   Fail73:
   {
     IStrategoTerm f_136 = null;
     IStrategoTerm r_135 = null;
     IStrategoTerm u_135 = null;
     IStrategoTerm y_135 = null;
     IStrategoTerm b_136 = null;
     IStrategoTerm d_136 = null;
     IStrategoTerm h_136 = null;
     IStrategoTerm j_136 = null;
     IStrategoTerm k_136 = null;
     IStrategoTerm l_136 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consClassDecHead_5 != ((IStrategoAppl) term).getConstructor()) break Fail73;
     r_135 = term.getSubterm(0);
     u_135 = term.getSubterm(1);
     y_135 = term.getSubterm(2);
     b_136 = term.getSubterm(3);
     d_136 = term.getSubterm(4);
     IStrategoList annos49 = term.getAnnotations();
     f_136 = annos49;
     term = p_29.invoke(context, r_135);
     if (term == null) break Fail73;
     h_136 = term;
     term = q_29.invoke(context, u_135);
     if (term == null) break Fail73;
     j_136 = term;
     term = r_29.invoke(context, y_135);
     if (term == null) break Fail73;
     k_136 = term;
     term = s_29.invoke(context, b_136);
     if (term == null) break Fail73;
     l_136 = term;
     term = t_29.invoke(context, d_136);
     if (term == null) break Fail73;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(
                 out._consClassDecHead_5, new IStrategoTerm[] {h_136, j_136, k_136, l_136, term}),
             checkListAnnos(termFactory, f_136));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#17
0
 /** Close the generator if it is still open. */
 @Override
 protected void finalize() throws Throwable {
   if (savedState != null) {
     // This is a little tricky since we are most likely running in
     // a different thread. We need to get a Context to run this, and
     // we must call "doTopCall" since this will likely be the outermost
     // JavaScript frame on this thread.
     Context cx = Context.getCurrentContext();
     ContextFactory factory = cx != null ? cx.getFactory() : ContextFactory.getGlobal();
     factory.call(new CloseGeneratorAction(this));
   }
 }
示例#18
0
  /**
   * Make glue object implementing interface cl that will call the supplied JS function when called.
   * Only interfaces were all methods have the same signature is supported.
   *
   * @return The glue object or null if <tt>cl</tt> is not interface or has methods with different
   *     signatures.
   */
  static Object create(Context cx, Class<?> cl, Callable function) {
    if (!cl.isInterface()) throw new IllegalArgumentException();

    Scriptable topScope = ScriptRuntime.getTopCallScope(cx);
    ClassCache cache = ClassCache.get(topScope);
    InterfaceAdapter adapter;
    adapter = (InterfaceAdapter) cache.getInterfaceAdapter(cl);
    ContextFactory cf = cx.getFactory();
    if (adapter == null) {
      Method[] methods = cl.getMethods();
      if (methods.length == 0) {
        throw Context.reportRuntimeError2(
            "msg.no.empty.interface.conversion", String.valueOf(function), cl.getClass().getName());
      }
      boolean canCallFunction = false;
      canCallFunctionChecks:
      {
        Class<?>[] argTypes = methods[0].getParameterTypes();
        // check that the rest of methods has the same signature
        for (int i = 1; i != methods.length; ++i) {
          Class<?>[] types2 = methods[i].getParameterTypes();
          if (types2.length != argTypes.length) {
            break canCallFunctionChecks;
          }
          for (int j = 0; j != argTypes.length; ++j) {
            if (types2[j] != argTypes[j]) {
              break canCallFunctionChecks;
            }
          }
        }
        canCallFunction = true;
      }
      if (!canCallFunction) {
        throw Context.reportRuntimeError2(
            "msg.no.function.interface.conversion",
            String.valueOf(function),
            cl.getClass().getName());
      }
      adapter = new InterfaceAdapter(cf, cl);
      cache.cacheInterfaceAdapter(cl, adapter);
    }
    return VMBridge.instance.newInterfaceProxy(
        adapter.proxyHelper, cf, adapter, function, topScope);
  }
示例#19
0
  static Object js_createAdpter(Context cx, Scriptable scope, Object[] args) {
    int N = args.length;
    if (N == 0) {
      throw ScriptRuntime.typeError0("msg.adapter.zero.args");
    }

    Class superClass = null;
    Class[] intfs = new Class[N - 1];
    int interfaceCount = 0;
    for (int i = 0; i != N - 1; ++i) {
      Object arg = args[i];
      if (!(arg instanceof NativeJavaClass)) {
        throw ScriptRuntime.typeError2(
            "msg.not.java.class.arg", String.valueOf(i), ScriptRuntime.toString(arg));
      }
      Class c = ((NativeJavaClass) arg).getClassObject();
      if (!c.isInterface()) {
        if (superClass != null) {
          throw ScriptRuntime.typeError2("msg.only.one.super", superClass.getName(), c.getName());
        }
        superClass = c;
      } else {
        intfs[interfaceCount++] = c;
      }
    }

    if (superClass == null) superClass = ScriptRuntime.ObjectClass;

    Class[] interfaces = new Class[interfaceCount];
    System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
    Scriptable obj = ScriptRuntime.toObject(cx, scope, args[N - 1]);

    Class adapterClass = getAdapterClass(scope, superClass, interfaces, obj);

    Class[] ctorParms = {ScriptRuntime.ContextFactoryClass, ScriptRuntime.ScriptableClass};
    Object[] ctorArgs = {cx.getFactory(), obj};
    try {
      Object adapter = adapterClass.getConstructor(ctorParms).newInstance(ctorArgs);
      return getAdapterSelf(adapterClass, adapter);
    } catch (Exception ex) {
      throw Context.throwAsScriptRuntimeEx(ex);
    }
  }
示例#20
0
 @Override
 public IStrategoTerm invoke(
     Context context, IStrategoTerm term, Strategy x_19, Strategy y_19, Strategy z_19) {
   ITermFactory termFactory = context.getFactory();
   context.push("DynRuleIntersect_3_0");
   Fail85:
   {
     IStrategoTerm y_113 = null;
     IStrategoTerm v_113 = null;
     IStrategoTerm w_113 = null;
     IStrategoTerm x_113 = null;
     IStrategoTerm z_113 = null;
     IStrategoTerm a_114 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || ext_out._consDynRuleIntersect_3 != ((IStrategoAppl) term).getConstructor())
       break Fail85;
     v_113 = term.getSubterm(0);
     w_113 = term.getSubterm(1);
     x_113 = term.getSubterm(2);
     IStrategoList annos58 = term.getAnnotations();
     y_113 = annos58;
     term = x_19.invoke(context, v_113);
     if (term == null) break Fail85;
     z_113 = term;
     term = y_19.invoke(context, w_113);
     if (term == null) break Fail85;
     a_114 = term;
     term = z_19.invoke(context, x_113);
     if (term == null) break Fail85;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(
                 ext_out._consDynRuleIntersect_3, new IStrategoTerm[] {z_113, a_114, term}),
             checkListAnnos(termFactory, y_113));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#21
0
 @Override
 public IStrategoTerm invoke(
     Context context, IStrategoTerm term, Strategy j_16, Strategy k_16, Strategy l_16) {
   ITermFactory termFactory = context.getFactory();
   context.push("GuardedLChoice_3_0");
   Fail101:
   {
     IStrategoTerm z_107 = null;
     IStrategoTerm w_107 = null;
     IStrategoTerm x_107 = null;
     IStrategoTerm y_107 = null;
     IStrategoTerm a_108 = null;
     IStrategoTerm b_108 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || out._consGuardedLChoice_3 != ((IStrategoAppl) term).getConstructor()) break Fail101;
     w_107 = term.getSubterm(0);
     x_107 = term.getSubterm(1);
     y_107 = term.getSubterm(2);
     IStrategoList annos91 = term.getAnnotations();
     z_107 = annos91;
     term = j_16.invoke(context, w_107);
     if (term == null) break Fail101;
     a_108 = term;
     term = k_16.invoke(context, x_107);
     if (term == null) break Fail101;
     b_108 = term;
     term = l_16.invoke(context, y_107);
     if (term == null) break Fail101;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(
                 out._consGuardedLChoice_3, new IStrategoTerm[] {a_108, b_108, term}),
             checkListAnnos(termFactory, z_107));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#22
0
 @Override
 public IStrategoTerm invoke(
     Context context, IStrategoTerm term, Strategy z_18, Strategy a_19, Strategy b_19) {
   ITermFactory termFactory = context.getFactory();
   context.push("Param_3_0");
   Fail66:
   {
     IStrategoTerm s_110 = null;
     IStrategoTerm p_110 = null;
     IStrategoTerm q_110 = null;
     IStrategoTerm r_110 = null;
     IStrategoTerm t_110 = null;
     IStrategoTerm u_110 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || renaming._consParam_3 != ((IStrategoAppl) term).getConstructor()) break Fail66;
     p_110 = term.getSubterm(0);
     q_110 = term.getSubterm(1);
     r_110 = term.getSubterm(2);
     IStrategoList annos51 = term.getAnnotations();
     s_110 = annos51;
     term = z_18.invoke(context, p_110);
     if (term == null) break Fail66;
     t_110 = term;
     term = a_19.invoke(context, q_110);
     if (term == null) break Fail66;
     u_110 = term;
     term = b_19.invoke(context, r_110);
     if (term == null) break Fail66;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(renaming._consParam_3, new IStrategoTerm[] {t_110, u_110, term}),
             checkListAnnos(termFactory, s_110));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }
示例#23
0
  // Needed by NativeJavaObject de-serializer
  public static Object readAdapterObject(Scriptable self, ObjectInputStream in)
      throws IOException, ClassNotFoundException {
    ContextFactory factory;
    Context cx = Context.getCurrentContext();
    if (cx != null) {
      factory = cx.getFactory();
    } else {
      factory = null;
    }

    Class<?> superClass = Class.forName((String) in.readObject());

    String[] interfaceNames = (String[]) in.readObject();
    Class<?>[] interfaces = new Class[interfaceNames.length];

    for (int i = 0; i < interfaceNames.length; i++)
      interfaces[i] = Class.forName(interfaceNames[i]);

    Scriptable delegee = (Scriptable) in.readObject();

    Class<?> adapterClass = getAdapterClass(self, superClass, interfaces, delegee);

    Class<?>[] ctorParms = {
      ScriptRuntime.ContextFactoryClass,
      ScriptRuntime.ScriptableClass,
      ScriptRuntime.ScriptableClass
    };
    Object[] ctorArgs = {factory, delegee, self};
    try {
      return adapterClass.getConstructor(ctorParms).newInstance(ctorArgs);
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    } catch (NoSuchMethodException e) {
    }

    throw new ClassNotFoundException("adapter");
  }
示例#24
0
  static Object js_createAdapter(Context cx, Scriptable scope, Object[] args) {
    int N = args.length;
    if (N == 0) {
      throw ScriptRuntime.typeError0("msg.adapter.zero.args");
    }

    // Expected arguments:
    // Any number of NativeJavaClass objects representing the super-class
    // and/or interfaces to implement, followed by one NativeObject
    // providing
    // the implementation, followed by any number of arguments to pass on
    // to the (super-class) constructor.

    int classCount;
    for (classCount = 0; classCount < N - 1; classCount++) {
      Object arg = args[classCount];
      // We explicitly test for NativeObject here since checking for
      // instanceof ScriptableObject or !(instanceof NativeJavaClass)
      // would fail for a Java class that isn't found in the class path
      // as NativeJavaPackage extends ScriptableObject.
      if (arg instanceof NativeObject) {
        break;
      }
      if (!(arg instanceof NativeJavaClass)) {
        throw ScriptRuntime.typeError2(
            "msg.not.java.class.arg", String.valueOf(classCount), ScriptRuntime.toString(arg));
      }
    }
    Class<?> superClass = null;
    Class<?>[] intfs = new Class[classCount];
    int interfaceCount = 0;
    for (int i = 0; i < classCount; ++i) {
      Class<?> c = ((NativeJavaClass) args[i]).getClassObject();
      if (!c.isInterface()) {
        if (superClass != null) {
          throw ScriptRuntime.typeError2("msg.only.one.super", superClass.getName(), c.getName());
        }
        superClass = c;
      } else {
        intfs[interfaceCount++] = c;
      }
    }

    if (superClass == null) {
      superClass = ScriptRuntime.ObjectClass;
    }

    Class<?>[] interfaces = new Class[interfaceCount];
    System.arraycopy(intfs, 0, interfaces, 0, interfaceCount);
    // next argument is implementation, must be scriptable
    Scriptable obj = ScriptableObject.ensureScriptable(args[classCount]);

    Class<?> adapterClass = getAdapterClass(scope, superClass, interfaces, obj);
    Object adapter;

    int argsCount = N - classCount - 1;
    try {
      if (argsCount > 0) {
        // Arguments contain parameters for super-class constructor.
        // We use the generic Java method lookup logic to find and
        // invoke the right constructor.
        Object[] ctorArgs = new Object[argsCount + 2];
        ctorArgs[0] = obj;
        ctorArgs[1] = cx.getFactory();
        System.arraycopy(args, classCount + 1, ctorArgs, 2, argsCount);
        // TODO: cache class wrapper?
        NativeJavaClass classWrapper = new NativeJavaClass(scope, adapterClass, true);
        NativeJavaMethod ctors = classWrapper.members.ctors;
        int index = ctors.findCachedFunction(cx, ctorArgs);
        if (index < 0) {
          String sig = NativeJavaMethod.scriptSignature(args);
          throw Context.reportRuntimeError2("msg.no.java.ctor", adapterClass.getName(), sig);
        }

        // Found the constructor, so try invoking it.
        adapter = NativeJavaClass.constructInternal(ctorArgs, ctors.methods[index]);
      } else {
        Class<?>[] ctorParms = {ScriptRuntime.ScriptableClass, ScriptRuntime.ContextFactoryClass};
        Object[] ctorArgs = {obj, cx.getFactory()};
        adapter = adapterClass.getConstructor(ctorParms).newInstance(ctorArgs);
      }

      Object self = getAdapterSelf(adapterClass, adapter);
      // Return unwrapped JavaAdapter if it implements Scriptable
      if (self instanceof Wrapper) {
        Object unwrapped = ((Wrapper) self).unwrap();
        if (unwrapped instanceof Scriptable) {
          if (unwrapped instanceof ScriptableObject) {
            ScriptRuntime.setObjectProtoAndParent((ScriptableObject) unwrapped, scope);
          }
          return unwrapped;
        }
      }
      return self;
    } catch (Exception ex) {
      throw Context.throwAsScriptRuntimeEx(ex);
    }
  }
 public IStrategoTerm invoke(
     Context context,
     IStrategoTerm term,
     Strategy c_17,
     Strategy d_17,
     Strategy e_17,
     Strategy f_17,
     Strategy g_17,
     Strategy h_17,
     Strategy i_17) {
   ITermFactory termFactory = context.getFactory();
   context.push("DeprAbstractMethodDec_7_0");
   Fail47:
   {
     IStrategoTerm b_106 = null;
     IStrategoTerm t_105 = null;
     IStrategoTerm u_105 = null;
     IStrategoTerm v_105 = null;
     IStrategoTerm w_105 = null;
     IStrategoTerm x_105 = null;
     IStrategoTerm y_105 = null;
     IStrategoTerm z_105 = null;
     IStrategoTerm c_106 = null;
     IStrategoTerm d_106 = null;
     IStrategoTerm e_106 = null;
     IStrategoTerm f_106 = null;
     IStrategoTerm g_106 = null;
     IStrategoTerm h_106 = null;
     if (term.getTermType() != IStrategoTerm.APPL
         || renaming._consDeprAbstractMethodDec_7 != ((IStrategoAppl) term).getConstructor())
       break Fail47;
     t_105 = term.getSubterm(0);
     u_105 = term.getSubterm(1);
     v_105 = term.getSubterm(2);
     w_105 = term.getSubterm(3);
     x_105 = term.getSubterm(4);
     y_105 = term.getSubterm(5);
     z_105 = term.getSubterm(6);
     IStrategoList annos33 = term.getAnnotations();
     b_106 = annos33;
     term = c_17.invoke(context, t_105);
     if (term == null) break Fail47;
     c_106 = term;
     term = d_17.invoke(context, u_105);
     if (term == null) break Fail47;
     d_106 = term;
     term = e_17.invoke(context, v_105);
     if (term == null) break Fail47;
     e_106 = term;
     term = f_17.invoke(context, w_105);
     if (term == null) break Fail47;
     f_106 = term;
     term = g_17.invoke(context, x_105);
     if (term == null) break Fail47;
     g_106 = term;
     term = h_17.invoke(context, y_105);
     if (term == null) break Fail47;
     h_106 = term;
     term = i_17.invoke(context, z_105);
     if (term == null) break Fail47;
     term =
         termFactory.annotateTerm(
             termFactory.makeAppl(
                 renaming._consDeprAbstractMethodDec_7,
                 new IStrategoTerm[] {c_106, d_106, e_106, f_106, g_106, h_106, term}),
             checkListAnnos(termFactory, b_106));
     context.popOnSuccess();
     if (true) return term;
   }
   context.popOnFailure();
   return null;
 }