本文整理汇总了Java中org.mozilla.javascript.RhinoException.lineNumber方法的典型用法代码示例。如果您正苦于以下问题:Java RhinoException.lineNumber方法的具体用法?Java RhinoException.lineNumber怎么用?Java RhinoException.lineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.RhinoException
的用法示例。
在下文中一共展示了RhinoException.lineNumber方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onException
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
@Override
public void onException(ScriptExecution execution, Exception e) {
RhinoException rhinoException = getRhinoException(e);
int line = -1, col = 0;
if (rhinoException != null) {
line = rhinoException.lineNumber();
col = rhinoException.columnNumber();
}
if (ScriptInterruptedException.causedByInterrupted(e)) {
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
} else {
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage())
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
}
}
示例2: throwWrappedScriptException
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* Wraps given exception and throws it as ScriptException.
*
* @param ex Exception to be wrapped.
* @throws ScriptException Thrown always by this method.
*/
public static void throwWrappedScriptException(Exception ex) throws ScriptException {
if ( ex instanceof RhinoException) {
RhinoException rhinoException = (RhinoException)ex;
int line = rhinoException.lineNumber();
int column = rhinoException.columnNumber();
String message;
if (ex instanceof JavaScriptException) {
message = String.valueOf(((JavaScriptException)ex).getValue());
} else {
message = ex.toString();
}
ScriptException scriptException = new ScriptException(message, rhinoException.sourceName(), line, column);
scriptException.initCause(ex);
throw scriptException;
} else {
throw new ScriptException(ex);
}
}
示例3: eval
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
public Object eval(Reader reader, ScriptContext ctxt) throws ScriptException {
Object ret;
Context cx = enterContext();
try {
Scriptable scope = getRuntimeScope(ctxt);
String filename = (String) get(ScriptEngine.FILENAME);
filename = filename == null ? "<Unknown source>" : filename;
ret = cx.evaluateReader(scope, reader, filename , 1, null);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} catch (IOException ee) {
throw new ScriptException(ee);
} finally {
Context.exit();
}
return unwrapReturnValue(ret);
}
示例4: invoke
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
private Object invoke(Object thiz, String name, Object... args)
throws ScriptException, NoSuchMethodException {
Context cx = enterContext();
try {
if (name == null) {
throw new NullPointerException("method name is null");
}
if (thiz != null && !(thiz instanceof Scriptable)) {
thiz = Context.toObject(thiz, topLevel);
}
Scriptable engineScope = getRuntimeScope(context);
Scriptable localScope = (thiz != null)? (Scriptable) thiz :
engineScope;
Object obj = ScriptableObject.getProperty(localScope, name);
if (! (obj instanceof Function)) {
throw new NoSuchMethodException("no such method: " + name);
}
Function func = (Function) obj;
Scriptable scope = func.getParentScope();
if (scope == null) {
scope = engineScope;
}
Object result = func.call(cx, scope, localScope,
wrapArguments(args));
return unwrapReturnValue(result);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
}
示例5: wrapRhinoException
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* Converts Rhino exception (a runtime exception) to BirtException
* @param e Rhino exception
* @param scriptText Javascript code which resulted in the exception (for error reporting purpose)
* @param source description of the source script. If null, get this info from Rhino exception
* @param lineNo lineNo of error location
* @throws
*/
public static BirtException wrapRhinoException( RhinoException e, String scriptText,
String source, int lineNo )
{
if ( source == null )
{
// Note that sourceName from RhinoException sometimes get truncated (need to find out why)
// Better some than nothing
source = e.sourceName();
lineNo = e.lineNumber();
}
if ( logger.isLoggable( Level.FINE ) )
logger.log( Level.FINE,
"Unexpected RhinoException. Source=" + source + ", line=" + lineNo+ ", Script=\n"
+ scriptText + "\n",
e );
return new CoreException( ResourceConstants.JAVASCRIPT_ERROR,
new Object[]{
e.getLocalizedMessage()
},
e);
}
示例6: eval
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
String msg;
if (re instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException)re).getValue());
} else {
msg = re.toString();
}
ScriptException se = new ScriptException(msg, re.sourceName(), line);
se.initCause(re);
throw se;
} finally {
Context.exit();
}
return result;
}
示例7: eval
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
public Object eval(Reader reader, ScriptContext ctxt)
throws ScriptException {
Object ret;
Context cx = enterContext();
try {
Scriptable scope = getRuntimeScope(ctxt);
String filename = (String) get(ScriptEngine.FILENAME);
filename = filename == null ? "<Unknown source>" : filename;
ret = cx.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException re) {
if (DEBUG) {
re.printStackTrace();
}
int line = (line = re.lineNumber()) == 0 ? -1 : line;
String msg;
if (re instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) re).getValue());
} else {
msg = re.toString();
}
ScriptException se = new ScriptException(msg, re.sourceName(), line);
se.initCause(re);
throw se;
} catch (IOException ee) {
throw new ScriptException(ee);
} finally {
cx.exit();
}
return unwrapReturnValue(ret);
}
示例8: invoke
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
private Object invoke(Object thiz, String name, Object... args)
throws ScriptException, NoSuchMethodException {
Context cx = enterContext();
try {
if (name == null) {
throw new NullPointerException("method name is null");
}
if (thiz != null && !(thiz instanceof Scriptable)) {
thiz = cx.toObject(thiz, topLevel);
}
Scriptable engineScope = getRuntimeScope(context);
Scriptable localScope = (thiz != null) ? (Scriptable) thiz
: engineScope;
Object obj = ScriptableObject.getProperty(localScope, name);
if (!(obj instanceof Function)) {
throw new NoSuchMethodException("no such method: " + name);
}
Function func = (Function) obj;
Scriptable scope = func.getParentScope();
if (scope == null) {
scope = engineScope;
}
Object result = func.call(cx, scope, localScope,
wrapArguments(args));
return unwrapReturnValue(result);
} catch (RhinoException re) {
if (DEBUG) {
re.printStackTrace();
}
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} finally {
cx.exit();
}
}
示例9: parse
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
astRoot = null;
result.clearNotices();
// Always spell check all lines, for now.
Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
result.setParsedLines(0, lineCount - 1);
DocumentReader r = new DocumentReader(doc);
ErrorCollector errorHandler = new ErrorCollector();
CompilerEnvirons env = createCompilerEnvironment(errorHandler, langSupport);
long start = System.currentTimeMillis();
try {
Parser parser = new Parser(env);
astRoot = parser.parse(r, null, 0);
long time = System.currentTimeMillis() - start;
result.setParseTime(time);
} catch (IOException ioe) { // Never happens
result.setError(ioe);
ioe.printStackTrace();
} catch (RhinoException re) {
// Shouldn't happen since we're passing an ErrorCollector in
int line = re.lineNumber();
// if (line>0) {
Element elem = root.getElement(line);
int offs = elem.getStartOffset();
int len = elem.getEndOffset() - offs - 1;
String msg = re.details();
result.addNotice(new DefaultParserNotice(this, msg, line, offs, len));
// }
} catch (Exception e) {
result.setError(e); // catch all
}
r.close();
// Get any parser errors.
switch (langSupport.getErrorParser()) {
default:
case RHINO:
gatherParserErrorsRhino(errorHandler, root);
break;
case JSHINT:
gatherParserErrorsJsHint(doc);
break;
}
// addNotices(doc);
support.firePropertyChange(PROPERTY_AST, null, astRoot);
return result;
}
示例10: execute
import org.mozilla.javascript.RhinoException; //导入方法依赖的package包/类
public Object execute(Object[] args) {
Context cx = RhinoUtil.enter();
Object ret = null;
try {
Scriptable scope = RhinoUtil.getScope();
Object jsRet;
if (_elStyle && args != null) {
Object host = getELStyleHost(cx, scope);
jsRet = functionExecute(cx, scope, host, args);
} else {
jsRet = normalExecute(cx, scope);
}
ret = RhinoUtil.convertResult(cx, getExpectedClass(), jsRet);
} catch (RhinoException e) {
if (e instanceof WrappedException) {
WrappedException we = (WrappedException) e;
Throwable wrapped = we.getWrappedException();
if (wrapped instanceof RenderingBrake) {
RhinoUtil.removeWrappedException(we);
}
}
// エラーとなったソース情報が微妙なので微調整。
// 行番号はスクリプト次第でずれてしまう。
int offsetLine;
String message;
String sourceName;
if (e instanceof JavaScriptException
&& ((JavaScriptException)e).getValue() instanceof IdScriptableObject) {
offsetLine = -1;
IdScriptableObject scriptable =
(IdScriptableObject) ((JavaScriptException) e).getValue();
Object messageProperty = scriptable.get("message", scriptable);
if (messageProperty != Scriptable.NOT_FOUND) {
message = messageProperty.toString();
} else {
message = scriptable.toString();
}
} else {
offsetLine = e.lineNumber() - _lineNumber + 1; // one "\n" is added
message = e.details() + " in script=\n" + getText();
}
if (e.lineSource() == null && message != null) {
String[] lines = message.split("\n");
offsetLine = (lines.length > offsetLine) ? offsetLine : _offsetLine;
if (offsetLine >= 0 && lines.length > offsetLine) {
e.initLineSource(lines[offsetLine]);
sourceName = _sourceName;
} else {
sourceName = e.sourceName();
}
} else {
sourceName = e.sourceName();
}
throw new OffsetLineRhinoException(
message,
sourceName, e.lineNumber(), e.lineSource(),
e.columnNumber(), offsetLine, e.getCause());
} finally {
Context.exit();
}
return ret;
}