MCPcopy Index your code
hub / github.com/google/google-java-format / Level

Class Level

core/src/main/java/com/google/googlejavaformat/Doc.java:186–381  ·  view source on GitHub ↗

A Level inside a Doc.

Source from the content-addressed store, hash-verified

184
185 /** A {@code Level} inside a {@link Doc}. */
186 static final class Level extends Doc {
187 private final Indent plusIndent; // The extra indent following breaks.
188 private final List<Doc> docs = new ArrayList<>(); // The elements of the level.
189
190 private Level(Indent plusIndent) {
191 this.plusIndent = plusIndent;
192 }
193
194 /**
195 * Factory method for {@code Level}s.
196 *
197 * @param plusIndent the extra indent inside the {@code Level}
198 * @return the new {@code Level}
199 */
200 static Level make(Indent plusIndent) {
201 return new Level(plusIndent);
202 }
203
204 /**
205 * Add a {@link Doc} to the {@code Level}.
206 *
207 * @param doc the {@link Doc} to add
208 */
209 void add(Doc doc) {
210 docs.add(doc);
211 }
212
213 @Override
214 int computeWidth() {
215 return getWidth(docs);
216 }
217
218 @Override
219 String computeFlat() {
220 StringBuilder builder = new StringBuilder();
221 for (Doc doc : docs) {
222 builder.append(doc.getFlat());
223 }
224 return builder.toString();
225 }
226
227 @Override
228 Range<Integer> computeRange() {
229 Range<Integer> docRange = EMPTY_RANGE;
230 for (Doc doc : docs) {
231 docRange = union(docRange, doc.range());
232 }
233 return docRange;
234 }
235
236 // State that needs to be preserved between calculating breaks and
237 // writing output.
238 // TODO(cushon): represent phases as separate immutable data.
239
240 /** True if the entire {@link Level} fits on one line. */
241 boolean oneLine = false;
242
243 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…