From: Shigeru Chiba Date: Tue, 10 May 2022 16:54:28 +0000 (+0900) Subject: Merge branch 'master' into master X-Git-Tag: rel_3_29_0_ga~11^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=da39aa805002d3b090d7f93410adce36f1e97d84;p=javassist.git Merge branch 'master' into master --- da39aa805002d3b090d7f93410adce36f1e97d84 diff --cc src/main/javassist/bytecode/SignatureAttribute.java index 15dbd56c,6a483057..c17b3f29 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@@ -122,72 -121,30 +122,73 @@@ public class SignatureAttribute extend if (j < 0) break; - int k = desc.indexOf(';', j); - if (k < 0) - break; - - int l = desc.indexOf('<', j); - int classEndIndex; - char classEndChar; - if (l < 0 || k < l) { - classEndIndex = k; - classEndChar = ';'; - } else { - classEndIndex = l; - classEndChar = '<'; + StringBuilder nameBuf = new StringBuilder(); + StringBuilder genericParamBuf = new StringBuilder(); + final ArrayList nameBufs = new ArrayList<>(); + final ArrayList genericParamBufs = new ArrayList<>(); + int k = j; + char c; + try { + while ((c = desc.charAt(++k)) != ';') { + if (c == '<') { + genericParamBuf.append(c); + int level = 1; + while (level > 0) { + c = desc.charAt(++k); + genericParamBuf.append(c); + if (c == '<') ++level; + else if (c == '>') --level; + } + } else if (c == '.') { + nameBufs.add(nameBuf); + genericParamBufs.add(genericParamBuf); + nameBuf = new StringBuilder(); + genericParamBuf = new StringBuilder(); + } else { + nameBuf.append(c); + } + } } - i = classEndIndex + 1; - - String name = desc.substring(j + 1, classEndIndex); - String name2 = map.get(name); - if (name2 != null) { - newdesc.append(desc.substring(head, j)); - newdesc.append('L'); - newdesc.append(name2); - newdesc.append(classEndChar); - head = i; + catch (IndexOutOfBoundsException e) { break; } - nameBufs.add(nameBuf); - genericParamBufs.add(genericParamBuf); ++ ++ nameBufs.add(nameBuf); ++ genericParamBufs.add(genericParamBuf); + i = k + 1; + + String name = String.join("$", nameBufs.toArray(new StringBuilder[0])); + String newname = map.get(name); + if (newname != null) { + final String[] nameSplit = name.split("\\$"); + final String[] newnameSplit = newname.split("\\$"); + if (nameSplit.length == newnameSplit.length) { + final String[] newnames = new String[nameBufs.size()]; + for (int start = 0, z = 0; z < nameBufs.size(); ++z) { + final int toAggregate = (int) nameBufs.get(z).chars().filter(ch -> ch == '$').count() + 1; + String s = String.join("$", Arrays.copyOfRange(newnameSplit, start, start + toAggregate)); + start += toAggregate; + newnames[z] = s; + } + + + newdesc.append(desc.substring(head, j)); + newdesc.append('L'); + for (int z = 0; z < newnames.length; ++z) { + if (z > 0) { + newdesc.append('.'); + } + newdesc.append(newnames[z]); + final String newgenericParam; + final StringBuilder genericParamBufCurrent = genericParamBufs.get(z); + if (genericParamBufCurrent.length() > 0) { + newgenericParam = "<" + renameClass(genericParamBufCurrent.substring(1, genericParamBufCurrent.length() - 1), map) + ">"; + } else { + newgenericParam = genericParamBufCurrent.toString(); //empty string + } + newdesc.append(newgenericParam); + } + newdesc.append(c); //the final semicolon + head = i; + } } }