in uimaj-core/src/main/java/org/apache/uima/cas/impl/FeatureStructureImplC.java [1353:1534]
private void prettyPrint(int indent, // the current indent position
int incr, // the delta to indent this FS printing
final StringBuilder buf, boolean useShortNames, String s, // carries the "#123" id refs
// for others to use, labels
// this fs with that.
PrintReferences printRefs, boolean isShortForm_arg) { // short form only prints type:_id
// for refs
final boolean isShortForm =
// isShortForm_arg;
// debug
// (this._id == 2512)
// ? false
// :
isShortForm_arg;
try {
indent += incr;
if (!IS_V2_PRETTY_PRINT && indent > 20 * incr) {
buf.append(" ... past indent limit ... ");
return;
}
final int printInfo = printRefs.printInfo(this);
if (printInfo != PrintReferences.NO_LABEL) {
String label = printRefs.getLabel(this);
if (!label.equals("seen once")) {
buf.append(printRefs.getLabel(this));
}
if (printInfo == PrintReferences.JUST_LABEL) {
buf.append(IS_V2_PRETTY_PRINT ? ' ' : '\n');
return;
}
buf.append(' ');
}
if (_typeImpl == null) {
buf.append((_id == 0) ? " Special REMOVED marker "
: _isJCasHashMapReserve() ? (" Special JCasHashMap Reserve, id = " + _id)
: " Special Search Key, id = " + _id);
} else {
if (useShortNames) {
buf.append(getType().getShortName());
} else {
buf.append(getType().getName());
}
if (!IS_V2_PRETTY_PRINT) {
buf.append(':').append(_id);
}
if (s != null) {
buf.append(" \"" + s + "\"");
}
}
buf.append('\n');
// final int typeClass = this._casView.ll_getTypeClass(this.getType());
if (_typeImpl == null) { // happens for special version which is REMOVED marker
return;
}
switch (_getTypeCode()) {
case TypeSystemConstants.stringArrayTypeCode: {
StringArray a = (StringArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, a.get(i)), indent, incr, buf);
return;
}
case TypeSystemConstants.intArrayTypeCode: {
IntegerArray a = (IntegerArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Integer.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.floatArrayTypeCode: {
FloatArray a = (FloatArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Float.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.booleanArrayTypeCode: {
BooleanArray a = (BooleanArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Boolean.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.byteArrayTypeCode: {
ByteArray a = (ByteArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Byte.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.shortArrayTypeCode: {
ShortArray a = (ShortArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Short.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.longArrayTypeCode: {
LongArray a = (LongArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Long.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.doubleArrayTypeCode: {
DoubleArray a = (DoubleArray) this;
printArrayElements(a.size(), i -> appendOrNull(buf, Double.toString(a.get(i))), indent,
incr, buf);
return;
}
case TypeSystemConstants.fsArrayTypeCode: {
if (IS_V2_PRETTY_PRINT) {
break; // v2 did not descend to print FSArray contents
}
FSArray a = (FSArray) this;
printFSArrayElements(a, indent, incr, buf, useShortNames, printRefs, isShortForm);
return;
} // end of case
} // end of switch
// if get here, non of the cases in the above switch fit
if (this instanceof FSArray) { // catches instance of FSArrays which are "typed" to hold
// specific element types
if (IS_V2_PRETTY_PRINT) {
return; // v2 did not descend to print fs array contents
}
FSArray a = (FSArray) this;
printFSArrayElements(a, indent, incr, buf, useShortNames, printRefs, isShortForm);
return;
}
for (FeatureImpl fi : _typeImpl.getFeatureImpls()) {
Misc.indent(buf, indent);
buf.append(fi.getShortName() + ": ");
TypeImpl range = (TypeImpl) fi.getRange();
if (range.isPrimitive()) { // Strings and string subtypes are primitive
addStringOrPrimitive(buf, fi);
continue;
}
// not primitive
FeatureStructureImplC val = null;
boolean hadException = false;
try {
val = getFeatureValue(fi);
} catch (Exception e) {
buf.append("<exception ").append(e.getMessage()).append(">\n");
hadException = true;
}
if (!hadException) {
if (isShortForm) {
if (null == val) {
buf.append("<null>");
} else {
buf.append(val._getTypeImpl().getShortName()).append(':').append(val._id);
}
} else {
// treat sofa refs special, since they're pervasive
if (val instanceof Sofa) {
buf.append(((Sofa) val).getSofaID());
} else {
ppval(val, indent, incr, buf, useShortNames, printRefs, false);
}
}
// if (val != null && !val._typeImpl.getName().equals(CAS.TYPE_NAME_SOFA)) {
// val.prettyPrint(indent, incr, buf, useShortNames, null, printRefs);
// } else {
// buf.append((val == null) ? "<null>\n" : ((SofaFS) val).getSofaID() + '\n');
// }
}
}
} catch (Exception e) {
buf.append("**Caught exception: ").append(e);
// StringWriter sw = new StringWriter();
// e.printStackTrace(new PrintWriter(sw, true));
// buf.append(sw.toString());
}
}