mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 23:37:32 +00:00
Removed unused
This commit is contained in:
1 parent
fad17fa3bd
commit
4973203f72
1 file changed
+1
-89
@@ -54,95 +54,7 @@ public class JavaTextContainer extends TextContainer {
|
||||
super(text);
|
||||
this.text = text == null ? "" : text.replaceAll("\\r?\\n|\\r", "\n");
|
||||
}
|
||||
|
||||
public synchronized List<int[]> getBraceSpans() {
|
||||
if (braceSpansCache != null)
|
||||
return braceSpansCache;
|
||||
List<int[]> spans = new ArrayList<>();
|
||||
if (text == null || text.isEmpty() || lines == null || lines.isEmpty()) {
|
||||
braceSpansCache = spans;
|
||||
return spans;
|
||||
}
|
||||
|
||||
// Heuristics limits to avoid runaway spans when braces are unbalanced.
|
||||
final int MAX_SPAN_LINES = 200; // cap span length to this many lines
|
||||
final int MAX_STACK_DEPTH = 512; // avoid excessive stack growth
|
||||
|
||||
List<int[]> excluded = MethodBlock.getExcludedRanges(text);
|
||||
int exIdx = 0;
|
||||
java.util.ArrayList<Integer> openStack = new java.util.ArrayList<>();
|
||||
int len = text.length();
|
||||
for (int p = 0; p < len; p++) {
|
||||
while (exIdx < excluded.size() && p >= excluded.get(exIdx)[1])
|
||||
exIdx++;
|
||||
if (exIdx < excluded.size()) {
|
||||
int[] r = excluded.get(exIdx);
|
||||
if (p >= r[0] && p < r[1]) {
|
||||
p = r[1] - 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
char c = text.charAt(p);
|
||||
if (c == '{') {
|
||||
if (openStack.size() < MAX_STACK_DEPTH) {
|
||||
// Look ahead to see if this open has a plausible closing brace within limits.
|
||||
int openLine = getLineIndex(p);
|
||||
int lookaheadChars = Math.max(1000, MAX_SPAN_LINES * 120);
|
||||
int searchEnd = Math.min(len, p + lookaheadChars);
|
||||
boolean foundClose = false;
|
||||
int exIdx2 = exIdx; // local index for scanning ahead
|
||||
for (int q = p + 1; q < searchEnd; q++) {
|
||||
while (exIdx2 < excluded.size() && q >= excluded.get(exIdx2)[1]) exIdx2++;
|
||||
if (exIdx2 < excluded.size()) {
|
||||
int[] r2 = excluded.get(exIdx2);
|
||||
if (q >= r2[0] && q < r2[1]) { q = r2[1] - 1; continue; }
|
||||
}
|
||||
if (text.charAt(q) == '}') {
|
||||
int closeLineCandidate = getLineIndex(q);
|
||||
if (closeLineCandidate - openLine <= MAX_SPAN_LINES) {
|
||||
foundClose = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (foundClose) openStack.add(p);
|
||||
}
|
||||
} else if (c == '}') {
|
||||
if (!openStack.isEmpty()) {
|
||||
int openPos = openStack.remove(openStack.size() - 1);
|
||||
int level = openStack.size() + 1;
|
||||
int openLine = getLineIndex(openPos);
|
||||
int closeLine = getLineIndex(p);
|
||||
// Cap spans to avoid drawing across the whole document when syntax is broken
|
||||
if (closeLine - openLine > MAX_SPAN_LINES) {
|
||||
closeLine = Math.min(openLine + MAX_SPAN_LINES, lines.size() - 1);
|
||||
}
|
||||
// Only add spans where closeLine > openLine (multi-line blocks)
|
||||
if (closeLine > openLine) {
|
||||
spans.add(new int[]{level, openLine, closeLine});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
braceSpansCache = spans;
|
||||
return spans;
|
||||
}
|
||||
|
||||
private int getLineIndex(int pos) {
|
||||
if (lines == null || lines.isEmpty())
|
||||
return 0;
|
||||
int length = text == null ? 0 : text.length();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
LineData d = lines.get(i);
|
||||
int s = Math.max(0, Math.min(d.start, length));
|
||||
int e = Math.max(0, Math.min(d.end, length));
|
||||
if (pos >= s && pos <= e)
|
||||
return i;
|
||||
}
|
||||
return Math.max(0, lines.size() - 1);
|
||||
}
|
||||
|
||||
|
||||
public void init(int width, int height) {
|
||||
// lineHeight = ClientProxy.Font.height();
|
||||
// if (lineHeight == 0)
|
||||
|
||||
Reference in new issue
Block a user