com.reprezen.genflow.openapi3.doc.Indentation Maven / Gradle / Ivy
package com.reprezen.genflow.openapi3.doc;
/**
* Surprisingly, indentation was one of the hardest things to get right in this module! Here's how it works.
*
* There are two sorts of indented texts used in the tables:
*
* - code items: blank indentation followed by shaded indentation followed by shaded monospaced text. Blank
* indentation is in a "samp" element to produce monospaced text. Second indentation and text are joined within
* a "code" element, which provides monospacing and shading.
*
- text item: blank indentation followed by text. Indentation is in a "samp" block for monospacing, text is
* left as-is.
*
* The Indentation class maintains two indentation levels, called n1 and n2, which control the width of the
* plain and shaded indentations. For a new table, both start out at zero.
*
* Certain structures call for advancing these indentation levels. In all cases, this results in a new
* Indentation object which is passsed in nested calls, so when those calls unwind the prevailing indentation
* object is unchanged.
*
* The tricky part turned out to be knowing whether to ignore indentation changes. The answer is keeping
* track of whether anything's actually been output using the current indentation levels. If so, the advance
* is performed, and either way, a new Indentation object is created. So, for example, the properties of a
* top-level ObjectProperty will be at indentation level (0,0) even though its rendering method calls for
* advancing the n2 value for the nested properties.
*
* Advancing the n1 value really means setting n1 to n1+n2 and n2 to zero. The n1 value is only used when
* outputing the names of schemas that contribut to an allOf schema.
*/
@SuppressWarnings("all")
class Indentation {
private final int n1;
private final int n2;
private boolean used1 = false;
private boolean used2 = false;
public Indentation() {
this(0, 0);
}
public Indentation(final int n1, final int n2) {
this.n1 = n1;
this.n2 = n2;
}
public Indentation(final Indentation ind) {
this.n1 = ind.n1;
this.n2 = ind.n2;
this.used1 = ind.used1;
this.used2 = ind.used2;
}
public Indentation copy() {
return new Indentation(this);
}
public Indentation advance1() {
Indentation _xifexpression = null;
if ((this.used1 || this.used2)) {
_xifexpression = new Indentation(((this.n1 + this.n2) + 1), 0);
} else {
_xifexpression = new Indentation(this);
}
return _xifexpression;
}
public Indentation advance2() {
Indentation _xifexpression = null;
if (this.used2) {
Indentation _xblockexpression = null;
{
final Indentation adv = new Indentation(this.n1, (this.n2 + 1));
if (this.used1) {
adv.use1();
}
_xblockexpression = adv;
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = this.copy();
}
return _xifexpression;
}
public int getN1() {
return this.n1;
}
public int getN2() {
return this.n2;
}
public boolean use1() {
return this.used1 = true;
}
public boolean use2() {
return this.used2 = true;
}
}