当前位置: 首页>>代码示例>>Java>>正文


Java CompilerConstants类代码示例

本文整理汇总了Java中jdk.nashorn.internal.codegen.CompilerConstants的典型用法代码示例。如果您正苦于以下问题:Java CompilerConstants类的具体用法?Java CompilerConstants怎么用?Java CompilerConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompilerConstants类属于jdk.nashorn.internal.codegen包,在下文中一共展示了CompilerConstants类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getScriptFrames

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            }

            if (methodName.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName())) {
                methodName = "<anonymous>";
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:NashornException.java

示例2: getScriptFrames

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[0]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:NashornException.java

示例3: getScriptFrames

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.PROGRAM.symbolName())) {
                methodName = "<program>";
            } else {
                methodName = stripMethodName(methodName);
            }

            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:26,代码来源:NashornException.java

示例4: getScriptFrames

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Returns array javascript stack frames from the given exception object.
 *
 * @param exception exception from which stack frames are retrieved and filtered
 * @return array of javascript stack frames
 */
public static StackTraceElement[] getScriptFrames(final Throwable exception) {
    final StackTraceElement[] frames = exception.getStackTrace();
    final List<StackTraceElement> filtered = new ArrayList<>();
    for (final StackTraceElement st : frames) {
        if (ECMAErrors.isScriptFrame(st)) {
            final String className = "<" + st.getFileName() + ">";
            String methodName = st.getMethodName();
            if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
                methodName = "<program>";
            }
            filtered.add(new StackTraceElement(className, methodName,
                    st.getFileName(), st.getLineNumber()));
        }
    }
    return filtered.toArray(new StackTraceElement[filtered.size()]);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:23,代码来源:NashornException.java

示例5: TYPEOF

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * ECMA 11.4.3 The typeof Operator - generic implementation
 *
 * @param object   the object from which to retrieve property to type check
 * @param property property in object to check
 *
 * @return type name
 */
public static Object TYPEOF(final Object object, final Object property) {
    Object obj = object;

    if (property != null) {
        if (obj instanceof ScriptObject) {
            obj = ((ScriptObject)obj).get(property);
            if(Global.isLocationPropertyPlaceholder(obj)) {
                if(CompilerConstants.__LINE__.name().equals(property)) {
                    obj = Integer.valueOf(0);
                } else {
                    obj = "";
                }
            }
        } else if (object instanceof Undefined) {
            obj = ((Undefined)obj).get(property);
        } else if (object == null) {
            throw typeError("cant.get.property", safeToString(property), "null");
        } else if (JSType.isPrimitive(obj)) {
            obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
        } else if (obj instanceof JSObject) {
            obj = ((JSObject)obj).getMember(property.toString());
        } else {
            obj = UNDEFINED;
        }
    }

    return JSType.of(obj).typeName();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:ScriptRuntime.java

示例6: reparse

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
FunctionNode reparse() {
    if (isSerialized()) {
        return deserialize();
    }

    final int descPosition = Token.descPosition(token);
    final Context context = Context.getContextTrusted();
    final Parser parser = new Parser(
        context.getEnv(),
        source,
        new Context.ThrowErrorManager(),
        isStrict(),
        // source starts at line 0, so even though lineNumber is the correct declaration line, back off
        // one to make it exclusive
        lineNumber - 1,
        context.getLogger(Parser.class));

    if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) {
        parser.setFunctionName(functionName);
    }
    parser.setReparsedFunction(this);

    final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition,
            Token.descLength(token), true);
    // Parser generates a program AST even if we're recompiling a single function, so when we are only
    // recompiling a single function, extract it from the program.
    return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:RecompilableScriptFunctionData.java

示例7: allocate

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(allocatorClassName),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:AllocationStrategy.java

示例8: isScriptFrame

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Check if a stack trace element is in JavaScript
 *
 * @param frame frame
 *
 * @return true if frame is in the script
 */
public static boolean isScriptFrame(final StackTraceElement frame) {
    final String className = frame.getClassName();

    // Look for script package in class name (into which compiler puts generated code)
    if (className.startsWith(scriptPackage) && !CompilerConstants.isInternalMethodName(frame.getMethodName())) {
        final String source = frame.getFileName();
        // Make sure that it is not some Java code that Nashorn has in that package!
        return source != null && !source.endsWith(".java");
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:ECMAErrors.java

示例9: toString

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
@Override
public void toString(final StringBuilder sb, final boolean printType) {
    if (printType) {
        sb.append("{I}");
    }
    sb.append(CompilerConstants.SCOPE.symbolName()).append('.').append(Scope.GET_SPLIT_STATE.name()).append("()");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:GetSplitState.java

示例10: stripMethodName

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
private static String stripMethodName(final String methodName) {
    String name = methodName;

    final int nestedSeparator = name.lastIndexOf(CompilerConstants.NESTED_FUNCTION_SEPARATOR.symbolName());
    if (nestedSeparator >= 0) {
        name = name.substring(nestedSeparator + 1);
    }

    final int idSeparator = name.indexOf(CompilerConstants.ID_FUNCTION_SEPARATOR.symbolName());
    if (idSeparator >= 0) {
        name = name.substring(0, idSeparator);
    }

    return name.contains(CompilerConstants.ANON_FUNCTION_PREFIX.symbolName()) ? "<anonymous>" : name;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:NashornException.java

示例11: allocate

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * Allocate an object with the given property map
 * @param map the property map
 * @return the allocated object
 */
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AllocationStrategy.java

示例12: TYPEOF

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
/**
 * ECMA 11.4.3 The typeof Operator - generic implementation
 *
 * @param object   the object from which to retrieve property to type check
 * @param property property in object to check
 *
 * @return type name
 */
public static Object TYPEOF(final Object object, final Object property) {
    Object obj = object;

    if (property != null) {
        if (obj instanceof ScriptObject) {
            obj = ((ScriptObject)obj).get(property);
            if(Global.isLocationPropertyPlaceholder(obj)) {
                if(CompilerConstants.__LINE__.name().equals(property)) {
                    obj = 0;
                } else {
                    obj = "";
                }
            }
        } else if (object instanceof Undefined) {
            obj = ((Undefined)obj).get(property);
        } else if (object == null) {
            throw typeError("cant.get.property", safeToString(property), "null");
        } else if (JSType.isPrimitive(obj)) {
            obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
        } else if (obj instanceof JSObject) {
            obj = ((JSObject)obj).getMember(property.toString());
        } else {
            obj = UNDEFINED;
        }
    }

    return JSType.of(obj).typeName();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:37,代码来源:ScriptRuntime.java

示例13: reparse

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
FunctionNode reparse() {
    if (isSerialized()) {
        return deserialize();
    }

    final int descPosition = Token.descPosition(token);
    final Context context = Context.getContextTrusted();
    final Parser parser = new Parser(
        context.getEnv(),
        source,
        new Context.ThrowErrorManager(),
        isStrict(),
        // source starts at line 0, so even though lineNumber is the correct declaration line, back off
        // one to make it exclusive
        lineNumber - 1,
        context.getLogger(Parser.class));

    if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) {
        parser.setFunctionName(functionName);
    }
    parser.setReparsedFunction(this);

    final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition,
            Token.descLength(token), isPropertyAccessor());
    // Parser generates a program AST even if we're recompiling a single function, so when we are only
    // recompiling a single function, extract it from the program.
    return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:29,代码来源:RecompilableScriptFunctionData.java

示例14: allocate

import jdk.nashorn.internal.codegen.CompilerConstants; //导入依赖的package包/类
ScriptObject allocate(final PropertyMap map) {
    try {
        if (allocator == null) {
            allocator = MH.findStatic(LOOKUP, Context.forStructureClass(getAllocatorClassName()),
                    CompilerConstants.ALLOCATE.symbolName(), MH.type(ScriptObject.class, PropertyMap.class));
        }
        return (ScriptObject)allocator.invokeExact(map);
    } catch (final RuntimeException | Error e) {
        throw e;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
 
开发者ID:malaporte,项目名称:kaziranga,代码行数:14,代码来源:AllocationStrategy.java


注:本文中的jdk.nashorn.internal.codegen.CompilerConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。