/* * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
private Consumer<String> assertDiagnostic(String expectedSource, ExpectedDiagnostic expectedDiagnostic) { int start = (int) expectedDiagnostic.getStartPosition(); int end = (int) expectedDiagnostic.getEndPosition();
String expectedMarkingLine = createMarkingLine(start, end); return s -> {
String[] lines = s.split("\n"); if (lines.length <= 3) { thrownew AssertionError("Not enough lines: " + s);
}
String kind = getKind(expectedDiagnostic.getKind());
assertEquals(lines[0], kind); boolean found = false; for (int i = 0; i < lines.length; i++) { if (lines[i].endsWith(expectedSource)) {
assertEquals(lines[i + 1], expectedMarkingLine, "Input: " + expectedSource + ", marking line: ");
found = true;
}
} if (!found) { thrownew AssertionError("Did not find: " + expectedSource + " in: " + s);
}
};
}
private String createMarkingLine(int start, int end) {
assertTrue(end >= start, String.format("End position %d is less than start position %d", end, start));
StringBuilder sb = new StringBuilder();
sb.append("| "); for (int i = 0; i < start; ++i) {
sb.append(' ');
}
sb.append('^'); for (int i = 1; i < end - start - 1; ++i) {
sb.append('-');
} if (start < end) {
sb.append('^');
} return sb.toString();
}
public String getKind(Diagnostic.Kind kind) { switch (kind) { case WARNING: return"| Warning:"; case ERROR: return"| Error:"; default: thrownew AssertionError("Unsupported kind: " + kind);
}
}
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.