Example usage for jdk.nashorn.internal.runtime ScriptObject has

List of usage examples for jdk.nashorn.internal.runtime ScriptObject has

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ScriptObject has.

Prototype

@Override
    public boolean has(final int key) 

Source Link

Usage

From source file:com.asual.lesscss.compiler.NashornCompiler.java

License:Apache License

private Exception parseLessException(Exception root) {
    logger.debug("Parsing LESS Exception", root);
    if (root instanceof ECMAException) {
        ECMAException e = (ECMAException) root;
        Object thrown = e.getThrown();
        String type = null;/*  ww  w .ja v  a2s. c  o m*/
        String message = null;
        String filename = null;
        int line = -1;
        int column = -1;
        List<String> extractList = new ArrayList<String>();
        if (thrown instanceof ScriptObject) {
            ScriptObject so = (ScriptObject) e.getThrown();
            type = so.get("type").toString() + " Error";
            message = so.get("message").toString();
            filename = "";
            if (so.has("filename")) {
                filename = so.get("filename").toString();
            }
            if (so.has("line")) {
                line = ((Long) so.get("line")).intValue();
            }
            if (so.has("column")) {
                column = ((Double) so.get("column")).intValue();
            }
            if (so.has("extract")) {
                NativeArray extract = (NativeArray) so.get("extract");
                for (int i = 0; i < extract.size(); i++) {
                    if (extract.get(i) instanceof String) {
                        extractList.add(((String) extract.get(i)).replace("\t", " "));
                    }
                }
            }
        } else {
            type = thrown.getClass().getSimpleName() + " Error";
            message = e.getMessage().replaceFirst("[^:]+: ", "");
        }
        return new LessException(message, type, filename, line, column, extractList);
    }
    return root;
}

From source file:io.stallion.utils.json.ScriptObjectSerializer.java

License:Open Source License

@Override
public void serialize(ScriptObject value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    if (value.isArray()) {
        jgen.writeStartArray();// www.  j a  v  a2 s. c  om
        int i = -1;
        for (;;) {
            if (value.has(++i)) {
                jgen.writeObject(value.get(i));
            } else {
                break;
            }
        }
        jgen.writeEndArray();
    } else {
        jgen.writeStartObject();
        for (Object key : value.keySet()) {
            jgen.writeObjectField(key.toString(), value.get(key));
        }
        jgen.writeEndObject();
    }
}

From source file:org.jcruncher.less.LessProcessor.java

License:Apache License

private Exception parseLessException(Exception root) {
    //logger.debug("Parsing LESS Exception", root);
    if (root instanceof ECMAException) {
        ECMAException e = (ECMAException) root;
        Object thrown = e.getThrown();
        String type = null;// w w  w. j  a v a 2 s. c o  m
        String message = null;
        String filename = null;
        int line = -1;
        int column = -1;
        List<String> extractList = new ArrayList<String>();
        if (thrown instanceof ScriptObject) {
            ScriptObject so = (ScriptObject) e.getThrown();
            type = so.get("type").toString() + " Error";
            message = so.get("message").toString();
            filename = "";
            if (so.has("filename")) {
                filename = so.get("filename").toString();
            }
            if (so.has("line")) {
                line = ((Long) so.get("line")).intValue();
            }
            if (so.has("column")) {
                column = ((Double) so.get("column")).intValue();
            }
            if (so.has("extract")) {
                NativeArray extract = (NativeArray) so.get("extract");
                for (int i = 0; i < extract.size(); i++) {
                    if (extract.get(i) instanceof String) {
                        extractList.add(((String) extract.get(i)).replace("\t", " "));
                    }
                }
            }
        } else {
            type = thrown.getClass().getSimpleName() + " Error";
            message = e.getMessage().replaceFirst("[^:]+: ", "");
        }
        return new LessException(message, type, filename, line, column, extractList);
    }
    return root;
}