mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 07:10:51 +00:00
@@ -29,283 +29,283 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class Highlighting {
|
||||
|
||||
/**
|
||||
* Starting position
|
||||
*/
|
||||
public int startPos;
|
||||
/**
|
||||
* Length of highlighted text
|
||||
*/
|
||||
public int len;
|
||||
/**
|
||||
* Offset of instruction or trait
|
||||
*/
|
||||
public long offset;
|
||||
/**
|
||||
* Turn hignlighting on/off
|
||||
*/
|
||||
public static boolean doHighlight = true;
|
||||
/**
|
||||
* Starting position
|
||||
*/
|
||||
public int startPos;
|
||||
/**
|
||||
* Length of highlighted text
|
||||
*/
|
||||
public int len;
|
||||
/**
|
||||
* Offset of instruction or trait
|
||||
*/
|
||||
public long offset;
|
||||
/**
|
||||
* Turn hignlighting on/off
|
||||
*/
|
||||
public static boolean doHighlight = true;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + startPos + "-" + (startPos + len) + " ofs" + offset;
|
||||
}
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "" + startPos + "-" + (startPos + len) + " ofs" + offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param startPos Starting position
|
||||
* @param len Length of highlighted text
|
||||
* @param offset Offset of instruction or trait
|
||||
*/
|
||||
public Highlighting(int startPos, int len, long offset) {
|
||||
this.startPos = startPos;
|
||||
this.len = len;
|
||||
this.offset = offset;
|
||||
}
|
||||
private static final String OFSOPEN = "[OFS";
|
||||
private static final String OFSCLOSE = "]";
|
||||
private static final String OFSEND = "[/OFS]";
|
||||
private static final String TRAITOPEN = "[TRAIT";
|
||||
private static final String TRAITCLOSE = "]";
|
||||
private static final String TRAITEND = "[/TRAIT]";
|
||||
private static final String METHODOPEN = "[METHOD";
|
||||
private static final String METHODCLOSE = "]";
|
||||
private static final String METHODEND = "[/METHOD]";
|
||||
private static final String CLASSOPEN = "[CLASS";
|
||||
private static final String CLASSCLOSE = "]";
|
||||
private static final String CLASSEND = "[/CLASS]";
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param startPos Starting position
|
||||
* @param len Length of highlighted text
|
||||
* @param offset Offset of instruction or trait
|
||||
*/
|
||||
public Highlighting(int startPos, int len, long offset) {
|
||||
this.startPos = startPos;
|
||||
this.len = len;
|
||||
this.offset = offset;
|
||||
}
|
||||
private static final String OFSOPEN = "[OFS";
|
||||
private static final String OFSCLOSE = "]";
|
||||
private static final String OFSEND = "[/OFS]";
|
||||
private static final String TRAITOPEN = "[TRAIT";
|
||||
private static final String TRAITCLOSE = "]";
|
||||
private static final String TRAITEND = "[/TRAIT]";
|
||||
private static final String METHODOPEN = "[METHOD";
|
||||
private static final String METHODCLOSE = "]";
|
||||
private static final String METHODEND = "[/METHOD]";
|
||||
private static final String CLASSOPEN = "[CLASS";
|
||||
private static final String CLASSCLOSE = "]";
|
||||
private static final String CLASSEND = "[/CLASS]";
|
||||
|
||||
/**
|
||||
* Highlights specified text as instruction by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of instruction
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighOffset(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return OFSOPEN + offset + OFSCLOSE + text + OFSEND;
|
||||
}
|
||||
/**
|
||||
* Highlights specified text as instruction by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of instruction
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighOffset(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return OFSOPEN + offset + OFSCLOSE + text + OFSEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as method by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param index Methodinfo index
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighMethod(String text, long index) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return hilighMethodBegin(index) + text + hilighMethodEnd();
|
||||
}
|
||||
/**
|
||||
* Highlights specified text as method by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param index Methodinfo index
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighMethod(String text, long index) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return hilighMethodBegin(index) + text + hilighMethodEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Beggining of hilight of method
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public static String hilighMethodBegin(long index) {
|
||||
if (!doHighlight) {
|
||||
return "";
|
||||
}
|
||||
return METHODOPEN + index + METHODCLOSE;
|
||||
}
|
||||
/**
|
||||
* Beggining of hilight of method
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public static String hilighMethodBegin(long index) {
|
||||
if (!doHighlight) {
|
||||
return "";
|
||||
}
|
||||
return METHODOPEN + index + METHODCLOSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ending of hilight of method
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String hilighMethodEnd() {
|
||||
if (!doHighlight) {
|
||||
return "";
|
||||
}
|
||||
return METHODEND;
|
||||
}
|
||||
/**
|
||||
* Ending of hilight of method
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String hilighMethodEnd() {
|
||||
if (!doHighlight) {
|
||||
return "";
|
||||
}
|
||||
return METHODEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as trait by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of trait
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighTrait(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return TRAITOPEN + offset + TRAITCLOSE + text + TRAITEND;
|
||||
}
|
||||
/**
|
||||
* Highlights specified text as trait by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of trait
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighTrait(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return TRAITOPEN + offset + TRAITCLOSE + text + TRAITEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as class by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of trait
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighClass(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return CLASSOPEN + offset + CLASSCLOSE + text + CLASSEND;
|
||||
}
|
||||
/**
|
||||
* Highlights specified text as class by adding special tags
|
||||
*
|
||||
* @param text Text to highlight
|
||||
* @param offset Offset of trait
|
||||
* @return Highlighted text
|
||||
*/
|
||||
public static String hilighClass(String text, long offset) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
return CLASSOPEN + offset + CLASSCLOSE + text + CLASSEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips all highlights from the text
|
||||
*
|
||||
* @param text Text to strip highlights in
|
||||
* @return Text with no highlights
|
||||
*/
|
||||
public static String stripHilights(String text) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
text = stripInstrHilights(text);
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return text;
|
||||
}
|
||||
/**
|
||||
* Strips all highlights from the text
|
||||
*
|
||||
* @param text Text to strip highlights in
|
||||
* @return Text with no highlights
|
||||
*/
|
||||
public static String stripHilights(String text) {
|
||||
if (!doHighlight) {
|
||||
return text;
|
||||
}
|
||||
text = stripInstrHilights(text);
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips instruction highlights from the text
|
||||
*
|
||||
* @param text Text to strip instruction highlights in
|
||||
* @return Text with no instruction highlights
|
||||
*/
|
||||
public static String stripInstrHilights(String text) {
|
||||
return stripSpecificHilights(text, OFSOPEN, OFSCLOSE, OFSEND);
|
||||
}
|
||||
/**
|
||||
* Strips instruction highlights from the text
|
||||
*
|
||||
* @param text Text to strip instruction highlights in
|
||||
* @return Text with no instruction highlights
|
||||
*/
|
||||
public static String stripInstrHilights(String text) {
|
||||
return stripSpecificHilights(text, OFSOPEN, OFSCLOSE, OFSEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips method highlights from the text
|
||||
*
|
||||
* @param text Text to strip method highlights in
|
||||
* @return Text with no method highlights
|
||||
*/
|
||||
public static String stripMethodHilights(String text) {
|
||||
return stripSpecificHilights(text, METHODOPEN, METHODCLOSE, METHODEND);
|
||||
}
|
||||
/**
|
||||
* Strips method highlights from the text
|
||||
*
|
||||
* @param text Text to strip method highlights in
|
||||
* @return Text with no method highlights
|
||||
*/
|
||||
public static String stripMethodHilights(String text) {
|
||||
return stripSpecificHilights(text, METHODOPEN, METHODCLOSE, METHODEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips trait highlights from the text
|
||||
*
|
||||
* @param text Text to strip trait highlights in
|
||||
* @return Text with no trait highlights
|
||||
*/
|
||||
public static String stripTraitHilights(String text) {
|
||||
return stripSpecificHilights(text, TRAITOPEN, TRAITCLOSE, TRAITEND);
|
||||
}
|
||||
/**
|
||||
* Strips trait highlights from the text
|
||||
*
|
||||
* @param text Text to strip trait highlights in
|
||||
* @return Text with no trait highlights
|
||||
*/
|
||||
public static String stripTraitHilights(String text) {
|
||||
return stripSpecificHilights(text, TRAITOPEN, TRAITCLOSE, TRAITEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips class highlights from the text
|
||||
*
|
||||
* @param text Text to strip trait highlights in
|
||||
* @return Text with no class highlights
|
||||
*/
|
||||
public static String stripClassHilights(String text) {
|
||||
return stripSpecificHilights(text, CLASSOPEN, CLASSCLOSE, CLASSEND);
|
||||
}
|
||||
/**
|
||||
* Strips class highlights from the text
|
||||
*
|
||||
* @param text Text to strip trait highlights in
|
||||
* @return Text with no class highlights
|
||||
*/
|
||||
public static String stripClassHilights(String text) {
|
||||
return stripSpecificHilights(text, CLASSOPEN, CLASSCLOSE, CLASSEND);
|
||||
}
|
||||
|
||||
private static String stripSpecificHilights(String text, String txtOpen, String txtClose, String txtEnd) {
|
||||
text = text.replaceAll(Pattern.quote(txtOpen) + "[0-9]+" + Pattern.quote(txtClose), "");
|
||||
text = text.replace(txtEnd, "");
|
||||
return text;
|
||||
}
|
||||
private static String stripSpecificHilights(String text, String txtOpen, String txtClose, String txtEnd) {
|
||||
text = text.replaceAll(Pattern.quote(txtOpen) + "[0-9]+" + Pattern.quote(txtClose), "");
|
||||
text = text.replace(txtEnd, "");
|
||||
return text;
|
||||
}
|
||||
|
||||
private static List<Highlighting> getSpecificHighlights(String text, String txtOpen, String txtClose, String txtEnd) {
|
||||
List<Highlighting> ret = new ArrayList<Highlighting>();
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int openpos = text.indexOf(txtOpen);
|
||||
if (openpos == -1) {
|
||||
break;
|
||||
}
|
||||
int closepos = text.indexOf(txtClose, openpos);
|
||||
int enpos = text.indexOf(txtEnd, openpos);
|
||||
int textlen = enpos - closepos - txtClose.length();
|
||||
|
||||
int nextopenpos = text.indexOf(txtOpen, openpos + 1);
|
||||
if (nextopenpos != -1) {
|
||||
if (nextopenpos < enpos) {
|
||||
Logger.getLogger(Highlighting.class.getName()).log(Level.SEVERE, "Crossed highligh - str:{0}", text);
|
||||
enpos = nextopenpos;
|
||||
private static List<Highlighting> getSpecificHighlights(String text, String txtOpen, String txtClose, String txtEnd) {
|
||||
List<Highlighting> ret = new ArrayList<Highlighting>();
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
int openpos = text.indexOf(txtOpen);
|
||||
if (openpos == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
long offset = Long.parseLong(text.substring(openpos + txtOpen.length(), closepos));
|
||||
Highlighting hl = new Highlighting(pos + openpos, textlen, offset);
|
||||
pos += openpos + textlen;
|
||||
text = text.substring(enpos + txtEnd.length());
|
||||
ret.add(hl);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int closepos = text.indexOf(txtClose, openpos);
|
||||
int enpos = text.indexOf(txtEnd, openpos);
|
||||
int textlen = enpos - closepos - txtClose.length();
|
||||
|
||||
/**
|
||||
* Gets all trait highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of trait highlights
|
||||
*/
|
||||
public static List<Highlighting> getTraitHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripInstrHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, TRAITOPEN, TRAITCLOSE, TRAITEND);
|
||||
}
|
||||
int nextopenpos = text.indexOf(txtOpen, openpos + 1);
|
||||
if (nextopenpos != -1) {
|
||||
if (nextopenpos < enpos) {
|
||||
Logger.getLogger(Highlighting.class.getName()).log(Level.SEVERE, "Crossed highligh - str:{0}", text);
|
||||
enpos = nextopenpos;
|
||||
}
|
||||
}
|
||||
long offset = Long.parseLong(text.substring(openpos + txtOpen.length(), closepos));
|
||||
Highlighting hl = new Highlighting(pos + openpos, textlen, offset);
|
||||
pos += openpos + textlen;
|
||||
text = text.substring(enpos + txtEnd.length());
|
||||
ret.add(hl);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all method highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of method highlights
|
||||
*/
|
||||
public static List<Highlighting> getMethodHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripInstrHilights(text);
|
||||
text = stripTraitHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, METHODOPEN, METHODCLOSE, METHODEND);
|
||||
}
|
||||
/**
|
||||
* Gets all trait highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of trait highlights
|
||||
*/
|
||||
public static List<Highlighting> getTraitHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripInstrHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, TRAITOPEN, TRAITCLOSE, TRAITEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all instruction highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of instruction highlights
|
||||
*/
|
||||
public static List<Highlighting> getInstrHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, OFSOPEN, OFSCLOSE, OFSEND);
|
||||
}
|
||||
/**
|
||||
* Gets all method highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of method highlights
|
||||
*/
|
||||
public static List<Highlighting> getMethodHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripInstrHilights(text);
|
||||
text = stripTraitHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, METHODOPEN, METHODCLOSE, METHODEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all class highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of class highlights
|
||||
*/
|
||||
public static List<Highlighting> getClassHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripInstrHilights(text);
|
||||
return getSpecificHighlights(text, CLASSOPEN, CLASSCLOSE, CLASSEND);
|
||||
}
|
||||
/**
|
||||
* Gets all instruction highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of instruction highlights
|
||||
*/
|
||||
public static List<Highlighting> getInstrHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripClassHilights(text);
|
||||
return getSpecificHighlights(text, OFSOPEN, OFSCLOSE, OFSEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all class highlight objects from specified text
|
||||
*
|
||||
* @param text Text to get highlights from
|
||||
* @return List of class highlights
|
||||
*/
|
||||
public static List<Highlighting> getClassHighlights(String text) {
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = stripTraitHilights(text);
|
||||
text = stripMethodHilights(text);
|
||||
text = stripInstrHilights(text);
|
||||
return getSpecificHighlights(text, CLASSOPEN, CLASSCLOSE, CLASSEND);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user