Java 类org.mozilla.javascript.annotations.JSConstructor 实例源码

项目:code404    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:rhino-jscover    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:astor    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:Rhino-Prov-Mod    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:eggshell    文件:Egg.java   
/** Creates a Hadoop job with a default configuration of
 *  TextInputFormat and TextOutputFormat.  If invoked with no
 *  parameters, uses the initially created job as the parent to
 *  spawn a new job.  The name of the parent job is used as the name
 *  of the child job.  The object is used a the 'this' object of the
 *  eggshell function
 *  @param o    The Hadoop Job
 */
@JSConstructor
public Egg (Object o) 
  throws IOException
{
  Configuration cf = conf; // new Configuration(conf);
  job = new Job(cf, name);
  job.setJarByClass(this.getClass());               // set jar file
  job.setInputFormatClass(TextInputFormat.class);
  job.setOutputFormatClass(TextOutputFormat.class);
  job.setOutputKeyClass(Tuple.class);               // K2
  job.setOutputValueClass(Tuple.class);             // V2
  job.setMapperClass(Payload.TextMap.class);
  job.setReducerClass(Reducer.class);
  job.setCombinerClass(Reducer.class);
}
项目:closure-compiler-old    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:closure-compiler-copy    文件:File.java   
/**
 * The Java method defining the JavaScript File constructor.
 *
 * If the constructor has one or more arguments, and the
 * first argument is not undefined, the argument is converted
 * to a string as used as the filename.<p>
 *
 * Otherwise System.in or System.out is assumed as appropriate
 * to the use.
 */
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
                                       Function ctorObj,
                                       boolean inNewExpr)
{
    File result = new File();
    if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
        result.name = "";
        result.file = null;
    } else {
        result.name = Context.toString(args[0]);
        result.file = new java.io.File(result.name);
    }
    return result;
}
项目:openrasp    文件:JSRequestContext.java   
@JSConstructor
public JSRequestContext(Context cx, Object[] args,
                        Function ctorObj,
                        boolean inNewExpr) {
    this.cx = (JSContext) cx;
    this.scope = this.cx.getScope();
    this.javaContext = (AbstractRequest) args[0];
}
项目:lembos    文件:ConfigurationWrap.java   
/**
 * JavaScript constructor.
 *
 * @param ctx the JavaScript context
 * @param args the constructor arguments
 * @param ctorObj the constructor function
 * @param newExpr if a new expression caused the call
 *
 * @return the newly constructed configuration wrapper
 */
@JSConstructor
public static Object wrapConstructor(final Context ctx, final Object[] args, final Function ctorObj,
                                     final boolean newExpr) {
    Configuration conf;

    if (args.length == 0 || !JavaScriptUtils.isDefined(args[0])) {
        conf = new Configuration();
    } else if (args.length == 1) {
        final Object arg0 = args[0];

        if (arg0 instanceof Boolean) {
            conf = new Configuration((boolean)arg0);
        } else if (arg0 instanceof ConfigurationWrap) {
            conf = ((ConfigurationWrap)args[0]).conf;
        } else {
            throw Utils.makeError(ctx, ctorObj, LembosMessages.FIRST_ARG_MUST_BE_BOOL_OR_CONF);
        }
    } else {
        throw Utils.makeError(ctx, ctorObj, LembosMessages.ZERO_OR_ONE_ARG_EXPECTED);
    }

    ConfigurationWrap wrapper;

    if (newExpr) {
        wrapper = new ConfigurationWrap();
    } else {
        wrapper = (ConfigurationWrap)ctx.newObject(ctorObj, CLASS_NAME);
    }

    wrapper.conf = conf;

    return wrapper;
}
项目:MinecraftScripting    文件:Range.java   
/**
 * {@link org.mozilla.javascript.FunctionObject.FunctionObject}
 */
@JSConstructor
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
    if (!inNewExpr)
        throw ScriptRuntime.constructError("Range Error", "Call constructor using the \"new\" keyword.");
    if (args.length == 1)
        return new Range( (int)Context.toNumber(args[0]));
    if (args.length == 2) 
        return new Range( (int)Context.toNumber(args[0]), (int)Context.toNumber(args[1]));
    throw ScriptRuntime.constructError("Range Error", "Call constructor with one or two numbers.");
}
项目:MinecraftScripting    文件:TagItr.java   
@JSConstructor
public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
    if (!inNewExpr)
        throw ScriptRuntime.constructError("TagItr Error", "Call constructor using the \"new\" keyword.");
    if (args.length == 1)
        return new TagItr((TAG_List)Context.jsToJava(args[0], TAG_List.class));
    throw ScriptRuntime.constructError("TagItr Error", "Call constructor with a single TAG_List.");
}
项目:rhino-android    文件:DefineClassTest.java   
@JSConstructor
public void jsConstructorMethod() {
    put("initialized", this, Boolean.TRUE);
}
项目:code404    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }
项目:rhino-jscover    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }
项目:astor    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }
项目:Rhino-Prov-Mod    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }
项目:lembos    文件:JobWrap.java   
/**
 * JavaScript constructor.
 *
 * @param ctx the JavaScript context
 * @param args the constructor arguments
 * @param ctorObj the constructor function
 * @param newExpr if a new expression caused the call
 *
 * @return the newly constructed time wrapper
 */
@JSConstructor
public static Object wrapConstructor(final Context ctx, final Object[] args, final Function ctorObj,
                                     final boolean newExpr) {
    Job job;
    ConfigurationWrap jsConf = null;

    try {
        if (args.length == 0 || !JavaScriptUtils.isDefined(args[0])) {
            job = new Job();
        } else if (args.length >= 1) {
            if (args[0] instanceof ConfigurationWrap) {
                jsConf = (ConfigurationWrap)args[0];
                job = new Job(jsConf.getConf());
            } else {
                throw Utils.makeError(ctx, ctorObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
            }

            if (args.length >= 2 && JavaScriptUtils.isDefined(args[1])) {
                job = new Job(jsConf.getConf(), args[1].toString());
            }
        } else {
            throw Utils.makeError(ctx, ctorObj, LembosMessages.ZERO_ONE_OR_TWO_ARGS_EXPECTED);
        }
    } catch (IOException e) {
        throw Utils.makeError(ctx, ctorObj, e.getMessage());
    }

    if (!JavaScriptUtils.isDefined(jsConf)) {
        jsConf = ConfigurationWrap.getInstance((ScriptRunner)ctx.getThreadLocal(ScriptRunner.RUNNER),
                                               job.getConfiguration());
    }

    final JobWrap wrapper;

    if (newExpr) {
        wrapper = new JobWrap();
    } else {
        wrapper = (JobWrap)ctx.newObject(ctorObj, CLASS_NAME);
    }

    wrapper.job = job;
    wrapper.jsConf = jsConf;
    wrapper.runtime = (ScriptRunner)ctx.getThreadLocal(ScriptRunner.RUNNER);

    return wrapper;
}
项目:eggshell    文件:EggIterator.java   
/** Called when a new object is instantiated from this class.
 *  The new object encapsulates the passed Java iterator object.
 *  @param o    The Java Iterator
 *  @return     The new object
 */
@JSConstructor
public EggIterator (Object o)
{
  iterator = (Iterator) o;
}
项目:closure-compiler-old    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }
项目:closure-compiler-copy    文件:Counter.java   
@JSConstructor
public Counter(int a) { count = a; }