Java Code Examples for org.codehaus.groovy.runtime.InvokerHelper#inspect()

The following examples show how to use org.codehaus.groovy.runtime.InvokerHelper#inspect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Inspector.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected String[] fieldInfo(Field field) {
    String[] result = new String[MEMBER_VALUE_IDX + 1];
    result[MEMBER_ORIGIN_IDX] = JAVA;
    result[MEMBER_MODIFIER_IDX] = Modifier.toString(field.getModifiers());
    result[MEMBER_DECLARER_IDX] = shortName(field.getDeclaringClass());
    result[MEMBER_TYPE_IDX] = shortName(field.getType());
    result[MEMBER_NAME_IDX] = field.getName();
    try {
        result[MEMBER_VALUE_IDX] = InvokerHelper.inspect(field.get(objectUnderInspection));
    } catch (IllegalAccessException e) {
        result[MEMBER_VALUE_IDX] = NOT_APPLICABLE;
    }
    return withoutNulls(result);
}
 
Example 2
Source File: Inspector.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected String[] fieldInfo(PropertyValue pv) {
    String[] result = new String[MEMBER_VALUE_IDX + 1];
    result[MEMBER_ORIGIN_IDX] = GROOVY;
    result[MEMBER_MODIFIER_IDX] = "public";
    result[MEMBER_DECLARER_IDX] = NOT_APPLICABLE;
    result[MEMBER_TYPE_IDX] = shortName(pv.getType());
    result[MEMBER_NAME_IDX] = pv.getName();
    try {
        result[MEMBER_VALUE_IDX] = InvokerHelper.inspect(pv.getValue());
    } catch (Exception e) {
        result[MEMBER_VALUE_IDX] = NOT_APPLICABLE;
    }
    return withoutNulls(result);
}
 
Example 3
Source File: ConfigObject.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void writeValue(String key, String space, String prefix, Object value, BufferedWriter out) throws IOException {
//        key = key.indexOf('.') > -1 ? InvokerHelper.inspect(key) : key;
        boolean isKeyword = KEYWORDS.contains(key);
        key = isKeyword ? InvokerHelper.inspect(key) : key;

        if (!StringGroovyMethods.asBoolean(prefix) && isKeyword) prefix = "this.";
        out.append(space).append(prefix).append(key).append('=').append(InvokerHelper.inspect(value));
        out.newLine();
    }
 
Example 4
Source File: ConfigObject.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void writeNode(String key, String space, int tab, ConfigObject value, BufferedWriter out) throws IOException {
    key = KEYWORDS.contains(key) ? InvokerHelper.inspect(key) : key;
    out.append(space).append(key).append(" {");
    out.newLine();
    writeConfig("", value, out, tab + 1, true);
    out.append(space).append('}');
    out.newLine();
}
 
Example 5
Source File: ObjectRange.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
public String inspect() {
    final String toText = InvokerHelper.inspect(to);
    final String fromText = InvokerHelper.inspect(from);
    return reverse ? "" + toText + ".." + fromText : "" + fromText + ".." + toText;
}
 
Example 6
Source File: EmptyRange.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String inspect() {
    return InvokerHelper.inspect(at) + "..<" + InvokerHelper.inspect(at);
}
 
Example 7
Source File: ConfigObject.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void writeConfig(String prefix, ConfigObject map, BufferedWriter out, int tab, boolean apply) throws IOException {
    String space = apply ? StringGroovyMethods.multiply(TAB_CHARACTER, tab) : "";

    for (Object o1 : map.keySet()) {
        String key = (String) o1;
        Object v = map.get(key);

        if (v instanceof ConfigObject) {
            ConfigObject value = (ConfigObject) v;

            if (!value.isEmpty()) {

                Object dotsInKeys = null;
                for (Object o : value.entrySet()) {
                    Entry e = (Entry) o;
                    String k = (String) e.getKey();
                    if (k.indexOf('.') > -1) {
                        dotsInKeys = e;
                        break;
                    }
                }

                int configSize = value.size();
                Object firstKey = value.keySet().iterator().next();
                Object firstValue = value.values().iterator().next();

                int firstSize;
                if (firstValue instanceof ConfigObject) {
                    firstSize = ((ConfigObject) firstValue).size();
                } else {
                    firstSize = 1;
                }

                if (configSize == 1 || DefaultGroovyMethods.asBoolean(dotsInKeys)) {
                    if (firstSize == 1 && firstValue instanceof ConfigObject) {
                        key = KEYWORDS.contains(key) ? InvokerHelper.inspect(key) : key;
                        String writePrefix = prefix + key + "." + firstKey + ".";
                        writeConfig(writePrefix, (ConfigObject) firstValue, out, tab, true);
                    } else if (!DefaultGroovyMethods.asBoolean(dotsInKeys) && firstValue instanceof ConfigObject) {
                        writeNode(key, space, tab, value, out);
                    } else {
                        for (Object j : value.keySet()) {
                            Object v2 = value.get(j);
                            Object k2 = ((String) j).indexOf('.') > -1 ? InvokerHelper.inspect(j) : j;
                            if (v2 instanceof ConfigObject) {
                                key = KEYWORDS.contains(key) ? InvokerHelper.inspect(key) : key;
                                writeConfig(prefix + key, (ConfigObject) v2, out, tab, false);
                            } else {
                                writeValue(key + "." + k2, space, prefix, v2, out);
                            }
                        }
                    }
                } else {
                    writeNode(key, space, tab, value, out);
                }
            }
        } else {
            writeValue(key, space, prefix, v, out);
        }
    }
}