org.jruby.Ruby.newNameError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.jruby.Ruby.newNameError方法的一些代码示例,展示了Ruby.newNameError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newNameError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newNameError

Ruby.newNameError介绍

[英]Construct a NameError with a pre-formatted message and name. This is the same as calling #newNameError(String,String,Throwable) with a null originating exception.
[中]使用预先格式化的消息和名称构造NameError。这与调用#newNameError(String,String,Throwable)时出现空异常相同。

代码示例

代码示例来源:origin: bazelbuild/bazel

public static void checkNameAvailability(ThreadContext context, String name) {
  if (context.runtime.getObject().getConstantAt(name) != null)
    throw context.runtime.newNameError(name + " is already defined", name);
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
  public IRubyObject set(IRubyObject lastExitStatus) {
    throw runtime.newNameError("$? is a read-only variable", "$?");
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * @see Ruby#newNameError(String, IRubyObject, IRubyObject, boolean)
 */
public RaiseException newNameError(String message, IRubyObject recv, IRubyObject name) {
  return newNameError(message, recv, name, false);
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Construct a NameError that formats its message with an sprintf format string.
 *
 * This version just accepts a java.lang.String for the name.
 *
 * @see Ruby#newNameError(String, IRubyObject, IRubyObject)
 */
public RaiseException newNameError(String message, IRubyObject recv, String name) {
  return newNameError(message, recv, name, false);
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Construct a NameError that formats its message with an sprintf format string and has private_call? set to given.
 *
 * This version just accepts a java.lang.String for the name.
 *
 * @see Ruby#newNameError(String, IRubyObject, IRubyObject)
 */
public RaiseException newNameError(String message, IRubyObject recv, String name, boolean privateCall) {
  RubySymbol nameSym = newSymbol(name);
  return newNameError(message, recv, nameSym, privateCall);
}

代码示例来源:origin: org.jruby/jruby-core

/**
 * Checks if the name parameter represents a legal instance variable name, and otherwise throws a Ruby NameError
 */
@Deprecated
protected String validateInstanceVariable(String name) {
  if (IdUtil.isValidInstanceVariableName(name)) return name;
  throw getRuntime().newNameError("`%1$s' is not allowable as an instance variable name", this, name);
}

代码示例来源:origin: org.jruby/jruby-complete

protected final String validateClassVariable(IRubyObject nameObj, String name) {
  if (IdUtil.isValidClassVariableName(name)) {
    return name;
  }
  throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, nameObj);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 1, visibility = PRIVATE)
public IRubyObject initialize_copy(ThreadContext context, IRubyObject original) {
  if (this.isInited) {
    throw context.runtime.newNameError("`initialize' called twice", "initialize");
  }
  RubyRange other = (RubyRange) original;
  init(context, other.begin, other.end, other.isExclusive);
  return context.nil;
}

代码示例来源:origin: org.jruby/jruby-complete

protected final String validateClassVariable(String name) {
  if (IdUtil.isValidClassVariableName(name)) {
    return name;
  }
  throw getRuntime().newNameError("`%1$s' is not allowed as a class variable name", this, name);
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
  public IRubyObject set(IRubyObject value) {
    throw runtime.newNameError(name() + " is a read-only variable", name());
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@Deprecated // no-longer used
public static JavaMethod createDeclared(Ruby runtime, Class<?> javaClass, String methodName, Class<?>[] argumentTypes) {
  try {
    return create(runtime, javaClass.getDeclaredMethod(methodName, argumentTypes));
  }
  catch (NoSuchMethodException e) {
    throw runtime.newNameError(undefinedMethodMessage(runtime, ids(runtime, methodName), ids(runtime, javaClass.getName()), false), methodName);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@Override // skip constant name assert
public final IRubyObject fetchConstant(String name, boolean includePrivate) {
  ConstantEntry entry = constantEntryFetch(name);
  if (entry == null) return null;
  if (entry.hidden && !includePrivate) {
    throw getRuntime().newNameError("private constant " + getName() + "::" + name + " referenced", name);
  }
  return entry.value;
}

代码示例来源:origin: org.jruby/jruby-complete

/** rb_define_const
 *
 */
@Extension
public void defineConstant(String name, IRubyObject value) {
  assert value != null;
  if (!IdUtil.isValidConstantName(name)) {
    throw getRuntime().newNameError("bad constant name " + name, name);
  }
  setConstant(name, value);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 2, optional = 1, visibility = PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block unusedBlock) {
  if (this.isInited) {
    throw context.runtime.newNameError("`initialize' called twice", "initialize");
  }
  checkFrozen();
  init(context, args[0], args[1], args.length > 2 && args[2].isTrue());
  return context.nil;
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod
public IRubyObject local_variable_get(ThreadContext context, IRubyObject symbol) {
  String name = symbol.asJavaString().intern();
  DynamicScope evalScope = binding.getEvalScope(context.runtime);
  int slot = evalScope.getStaticScope().isDefined(name);
  if (slot == -1) throw context.runtime.newNameError("local variable `" + name +  "' not defined for " + inspect(), name);
  return evalScope.getValueOrNil(slot & 0xffff, slot >> 16, context.nil);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(name="read_object", alias="readObject")
public IRubyObject readObject() {
  try {
    return Java.getInstance(getRuntime(), impl.readObject());
  } catch (IOException ioe) {
    throw getRuntime().newIOErrorFromException(ioe);
  } catch (ClassNotFoundException cnfe) {
    throw getRuntime().newNameError(cnfe.getLocalizedMessage(), cnfe.getMessage(), cnfe);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

private RubyBoolean constantDefined(Ruby runtime, RubySymbol symbol, boolean inherit) {
  if (symbol.validConstantName()) {
    return runtime.newBoolean(getConstantSkipAutoload(symbol.idString(), inherit, inherit) != null);
  }
  throw runtime.newNameError(str(runtime, "wrong constant name", ids(runtime, symbol)), symbol.idString());
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 * Validates name is a valid constant name and returns its id string.
 * @param name object to verify as a valid constant.
 * @return the id for this valid constant name.
 */
protected final String validateConstant(IRubyObject name) {
  RubySymbol symbol = RubySymbol.retrieveIDSymbol(name);
  if (!symbol.validConstantName()) {
    throw getRuntime().newNameError(str(getRuntime(), "wrong constant name ", name), symbol.idString());
  }
  return symbol.idString();
}

代码示例来源:origin: org.jruby/jruby-complete

private DynamicMethod deepMethodSearch(String id, Ruby runtime) {
  DynamicMethod method = searchMethod(id);
  if (method.isUndefined() && isModule()) method = runtime.getObject().searchMethod(id);
  if (method.isUndefined()) {
    RubySymbol name = runtime.newSymbol(id);
    throw runtime.newNameError(undefinedMethodMessage(runtime, name, rubyName(), isModule()), id);
  }
  return method;
}

代码示例来源:origin: org.jruby/jruby-core

private DynamicMethod deepMethodSearch(String id, Ruby runtime) {
  DynamicMethod method = searchMethod(id);
  if (method.isUndefined() && isModule()) method = runtime.getObject().searchMethod(id);
  if (method.isUndefined()) {
    RubySymbol name = runtime.newSymbol(id);
    throw runtime.newNameError(undefinedMethodMessage(runtime, name, rubyName(), isModule()), id);
  }
  return method;
}

相关文章

微信公众号

最新文章

更多

Ruby类方法