mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 17:40:43 +00:00
trunk contents moved to root
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class CodeFormatting {
|
||||
|
||||
public String newLineChars = "\r\n";
|
||||
public String indentString = " ";
|
||||
public boolean beginBlockOnNewLine = true;
|
||||
|
||||
// spaces
|
||||
// before parentheses
|
||||
public boolean spaceBeforeParenthesesMethodCallParentheses = false;
|
||||
public boolean spaceBeforeParenthesesMethodCallEmptyParentheses = false;
|
||||
public boolean spaceBeforeArrayAccessBrackets = false;
|
||||
public boolean spaceBeforeParenthesesMethodDeclarationParentheses = false;
|
||||
public boolean spaceBeforeParenthesesMethodDeclarationEmptyParentheses = false;
|
||||
public boolean spaceBeforeParenthesesIfParentheses = false;
|
||||
public boolean spaceBeforeParenthesesWithParentheses = false;
|
||||
public boolean spaceBeforeParenthesesWhileParentheses = false;
|
||||
public boolean spaceBeforeParenthesesCatchParentheses = false;
|
||||
public boolean spaceBeforeParenthesesSwitchParentheses = false;
|
||||
public boolean spaceBeforeParenthesesForParentheses = false;
|
||||
public boolean spaceBeforeParenthesesForEachParentheses = false;
|
||||
|
||||
// around operators
|
||||
public boolean spaceAroundOperatorsAssignmentOperators = false; // =, +=,...
|
||||
public boolean spaceAroundOperatorsLogicalOperators = false; // &&, ||
|
||||
public boolean spaceAroundOperatorsEqualityOperators = false; // ==, !=
|
||||
public boolean spaceAroundOperatorsRelationalOperator = false; // <, >, <=, >=
|
||||
public boolean spaceAroundOperatorsBitwiseOperator = false; // &, |, ^
|
||||
public boolean spaceAroundOperatorsAdditiveOperator = false; // +, -
|
||||
public boolean spaceAroundOperatorsMultiplicativeOperator = false; // *, /, %
|
||||
public boolean spaceAroundOperatorsShiftOperator = false; // <<, >>
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
|
||||
|
||||
private final Writer writer;
|
||||
private boolean newLine = true;
|
||||
private int indent;
|
||||
private int writtenBytes;
|
||||
|
||||
public FileTextWriter(CodeFormatting formatting, FileOutputStream fos) {
|
||||
super(formatting);
|
||||
this.writer = new BufferedWriter(new Utf8OutputStreamWriter(fos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter hilightSpecial(String text, String type) {
|
||||
writeToFile(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter hilightSpecial(String text, String type, int index) {
|
||||
writeToFile(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter append(String str) {
|
||||
writeToFile(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter append(String str, long offset) {
|
||||
writeToFile(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter appendNoHilight(int i) {
|
||||
writeToFile(Integer.toString(i));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter appendNoHilight(String str) {
|
||||
writeToFile(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter indent() {
|
||||
indent++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter unindent() {
|
||||
indent--;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter newLine() {
|
||||
writeToFile(formatting.newLineChars);
|
||||
newLine = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return writtenBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndent() {
|
||||
return indent;
|
||||
}
|
||||
|
||||
private void writeToFile(String str) {
|
||||
if (newLine) {
|
||||
newLine = false;
|
||||
appendIndent();
|
||||
}
|
||||
try {
|
||||
writer.write(str);
|
||||
writtenBytes += str.length();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(FileTextWriter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendIndent() {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
writeToFile(formatting.indentString);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class FontHelper {
|
||||
|
||||
public static String[] getInstalledFontFamilyNames() {
|
||||
// todo: cannot load newly installed fonts, so this feature is disabled until i find a solution for font loading problem
|
||||
if (Platform.isWindows()) {
|
||||
try {
|
||||
Class<?> clW32Fm = Class.forName("sun.awt.Win32FontManager");
|
||||
Class<?> clSunFm = Class.forName("sun.font.SunFontManager");
|
||||
Object fm = clW32Fm.newInstance();
|
||||
return (String[]) clSunFm.getDeclaredMethod("getInstalledFontFamilyNames", Locale.class).invoke(fm, Locale.getDefault());
|
||||
} catch (Throwable ex) {
|
||||
// catch everything to avoid class not found problems, because Win32FontManager is an internal proprietary API
|
||||
Logger.getLogger(FontHelper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface Freed {
|
||||
|
||||
public boolean isFreeing();
|
||||
|
||||
public void free();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class GraphSourceItemPosition {
|
||||
|
||||
public GraphSourceItem graphSourceItem;
|
||||
public int position;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public abstract class GraphTextWriter {
|
||||
|
||||
protected long startTime;
|
||||
protected long suspendTime;
|
||||
protected CodeFormatting formatting;
|
||||
|
||||
public CodeFormatting getFormatting() {
|
||||
return formatting;
|
||||
}
|
||||
|
||||
public GraphTextWriter(CodeFormatting formatting) {
|
||||
startTime = System.currentTimeMillis();
|
||||
this.formatting = formatting;
|
||||
}
|
||||
|
||||
public boolean getIsHighlighted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as instruction
|
||||
*
|
||||
* @param src
|
||||
* @param pos Offset of instruction
|
||||
* @return GraphTextWriter
|
||||
*/
|
||||
public GraphTextWriter startOffset(GraphSourceItem src, int pos) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter endOffset() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as method
|
||||
*
|
||||
* @param index MethodInfo index
|
||||
* @return GraphTextWriter
|
||||
*/
|
||||
public GraphTextWriter startMethod(long index) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter endMethod() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as class
|
||||
*
|
||||
* @param index Class index
|
||||
* @return GraphTextWriter
|
||||
*/
|
||||
public GraphTextWriter startClass(long index) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter endClass() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as trait
|
||||
*
|
||||
* @param index Trait index
|
||||
* @return GraphTextWriter
|
||||
*/
|
||||
public GraphTextWriter startTrait(long index) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter endTrait() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, int index) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static String hilighOffset(String text, long offset) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public abstract GraphTextWriter append(String str);
|
||||
|
||||
public abstract GraphTextWriter append(String str, long offset);
|
||||
|
||||
public abstract GraphTextWriter appendNoHilight(int i);
|
||||
|
||||
public abstract GraphTextWriter appendNoHilight(String str);
|
||||
|
||||
public GraphTextWriter indent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter unindent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GraphTextWriter newLine() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getIndent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void suspendMeasure() {
|
||||
suspendTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void continueMeasure() {
|
||||
long time = System.currentTimeMillis();
|
||||
startTime += time - suspendTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public GraphTextWriter startBlock(String opening) {
|
||||
if (formatting.beginBlockOnNewLine) {
|
||||
newLine();
|
||||
} else {
|
||||
append(" ");
|
||||
}
|
||||
return append(opening).newLine().indent();
|
||||
}
|
||||
|
||||
public GraphTextWriter startBlock() {
|
||||
return startBlock("{");
|
||||
}
|
||||
|
||||
public GraphTextWriter endBlock(String closing) {
|
||||
return unindent().append(closing);
|
||||
}
|
||||
|
||||
public GraphTextWriter endBlock() {
|
||||
return endBlock("}");
|
||||
}
|
||||
|
||||
public GraphTextWriter space() {
|
||||
return append(" ");
|
||||
}
|
||||
|
||||
public GraphTextWriter spaceBeforeCallParenthesies(int argCount) {
|
||||
if (argCount > 0) {
|
||||
if (formatting.spaceBeforeParenthesesMethodCallParentheses) {
|
||||
space();
|
||||
}
|
||||
} else {
|
||||
if (formatting.spaceBeforeParenthesesMethodCallEmptyParentheses) {
|
||||
space();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public enum HilightType {
|
||||
|
||||
TRAIT, CLASS, METHOD, OFFSET, SPECIAL
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class HilightedText implements Serializable {
|
||||
|
||||
public String text;
|
||||
public List<Highlighting> traitHilights;
|
||||
public List<Highlighting> classHilights;
|
||||
public List<Highlighting> methodHilights;
|
||||
public List<Highlighting> instructionHilights;
|
||||
public List<Highlighting> specialHilights;
|
||||
|
||||
public List<Highlighting> getTraitHighlights() {
|
||||
return traitHilights;
|
||||
}
|
||||
|
||||
public List<Highlighting> getMethodHighlights() {
|
||||
return methodHilights;
|
||||
}
|
||||
|
||||
public List<Highlighting> getClassHighlights() {
|
||||
return classHilights;
|
||||
}
|
||||
|
||||
public List<Highlighting> getSpecialHighligths() {
|
||||
return specialHilights;
|
||||
}
|
||||
|
||||
public HilightedText(HilightedTextWriter writer) {
|
||||
this.text = writer.toString();
|
||||
this.traitHilights = writer.traitHilights;
|
||||
this.classHilights = writer.classHilights;
|
||||
this.methodHilights = writer.methodHilights;
|
||||
this.instructionHilights = writer.instructionHilights;
|
||||
this.specialHilights = writer.specialHilights;
|
||||
}
|
||||
|
||||
public HilightedText(String text) {
|
||||
this.text = text;
|
||||
this.traitHilights = new ArrayList<>();
|
||||
this.classHilights = new ArrayList<>();
|
||||
this.methodHilights = new ArrayList<>();
|
||||
this.instructionHilights = new ArrayList<>();
|
||||
this.specialHilights = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class HilightedTextWriter extends GraphTextWriter {
|
||||
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
private final boolean hilight;
|
||||
private boolean newLine = true;
|
||||
private int indent = 0;
|
||||
private final Stack<GraphSourceItemPosition> offsets = new Stack<>();
|
||||
private boolean toStringCalled = false;
|
||||
private int newLineCount = 0;
|
||||
|
||||
private final Stack<Highlighting> hilightStack = new Stack<>();
|
||||
public List<Highlighting> traitHilights = new ArrayList<>();
|
||||
public List<Highlighting> classHilights = new ArrayList<>();
|
||||
public List<Highlighting> methodHilights = new ArrayList<>();
|
||||
public List<Highlighting> instructionHilights = new ArrayList<>();
|
||||
public List<Highlighting> specialHilights = new ArrayList<>();
|
||||
|
||||
public HilightedTextWriter(CodeFormatting formatting, boolean hilight) {
|
||||
super(formatting);
|
||||
this.hilight = hilight;
|
||||
}
|
||||
|
||||
public HilightedTextWriter(CodeFormatting formatting, boolean hilight, int indent) {
|
||||
super(formatting);
|
||||
this.hilight = hilight;
|
||||
this.indent = indent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsHighlighted() {
|
||||
return hilight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as instruction by adding special tags
|
||||
*
|
||||
* @param src
|
||||
* @param pos Offset of instruction
|
||||
* @return HilightedTextWriter
|
||||
*/
|
||||
@Override
|
||||
public HilightedTextWriter startOffset(GraphSourceItem src, int pos) {
|
||||
GraphSourceItemPosition itemPos = new GraphSourceItemPosition();
|
||||
itemPos.graphSourceItem = src;
|
||||
itemPos.position = pos;
|
||||
offsets.add(itemPos);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter endOffset() {
|
||||
offsets.pop();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as method by adding special tags
|
||||
*
|
||||
* @param index MethodInfo index
|
||||
* @return HilightedTextWriter
|
||||
*/
|
||||
@Override
|
||||
public HilightedTextWriter startMethod(long index) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("index", Long.toString(index));
|
||||
return start(data, HilightType.METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter endMethod() {
|
||||
return end(HilightType.METHOD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as class by adding special tags
|
||||
*
|
||||
* @param index Class index
|
||||
* @return HilightedTextWriter
|
||||
*/
|
||||
@Override
|
||||
public HilightedTextWriter startClass(long index) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("index", Long.toString(index));
|
||||
return start(data, HilightType.CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter endClass() {
|
||||
return end(HilightType.CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlights specified text as trait by adding special tags
|
||||
*
|
||||
* @param index Trait index
|
||||
* @return HilightedTextWriter
|
||||
*/
|
||||
@Override
|
||||
public HilightedTextWriter startTrait(long index) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("index", Long.toString(index));
|
||||
return start(data, HilightType.TRAIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter endTrait() {
|
||||
return end(HilightType.TRAIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter hilightSpecial(String text, String type) {
|
||||
return hilightSpecial(text, type, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter hilightSpecial(String text, String type, int index) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("subtype", type);
|
||||
data.put("index", Long.toString(index));
|
||||
start(data, HilightType.SPECIAL);
|
||||
appendNoHilight(text);
|
||||
return end(HilightType.SPECIAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter append(String str) {
|
||||
GraphSourceItemPosition itemPos = offsets.peek();
|
||||
GraphSourceItem src = itemPos.graphSourceItem;
|
||||
int pos = itemPos.position;
|
||||
Highlighting h = null;
|
||||
if (src != null && hilight) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("offset", Long.toString(src.getOffset() + pos + 1));
|
||||
h = new Highlighting(sb.length() - newLineCount, data, HilightType.OFFSET, str);
|
||||
instructionHilights.add(h);
|
||||
}
|
||||
appendToSb(str);
|
||||
if (h != null) {
|
||||
h.len = sb.length() - newLineCount - h.startPos;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter append(String str, long offset) {
|
||||
Highlighting h = null;
|
||||
if (hilight) {
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("offset", Long.toString(offset));
|
||||
h = new Highlighting(sb.length() - newLineCount, data, HilightType.OFFSET, str);
|
||||
instructionHilights.add(h);
|
||||
}
|
||||
appendToSb(str);
|
||||
if (h != null) {
|
||||
h.len = sb.length() - newLineCount - h.startPos;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter appendNoHilight(int i) {
|
||||
appendNoHilight(Integer.toString(i));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter appendNoHilight(String str) {
|
||||
appendToSb(str);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter indent() {
|
||||
indent++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter unindent() {
|
||||
indent--;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter newLine() {
|
||||
appendToSb(formatting.newLineChars);
|
||||
newLine = true;
|
||||
newLineCount++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return sb.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndent() {
|
||||
return indent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (toStringCalled) {
|
||||
throw new Error("HilightedTextWriter.toString() was already called.");
|
||||
}
|
||||
if (Configuration.debugMode.get()) {
|
||||
long stopTime = System.currentTimeMillis();
|
||||
long time = stopTime - startTime;
|
||||
if (time > 500) {
|
||||
System.out.println("Rendering is too slow: " + Helper.formatTimeSec(time) + " length: " + sb.length());
|
||||
}
|
||||
}
|
||||
toStringCalled = true;
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private HilightedTextWriter start(Map<String, String> data, HilightType type) {
|
||||
if (hilight) {
|
||||
Highlighting h = new Highlighting(sb.length() - newLineCount, data, type, null);
|
||||
hilightStack.add(h);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private HilightedTextWriter end(HilightType expectedType) {
|
||||
if (hilight) {
|
||||
Highlighting h = hilightStack.pop();
|
||||
h.len = sb.length() - newLineCount - h.startPos;
|
||||
|
||||
if (!expectedType.equals(h.type)) {
|
||||
throw new Error("Hilighting mismatch.");
|
||||
}
|
||||
|
||||
switch (h.type) {
|
||||
case CLASS:
|
||||
classHilights.add(h);
|
||||
break;
|
||||
case METHOD:
|
||||
methodHilights.add(h);
|
||||
break;
|
||||
case TRAIT:
|
||||
traitHilights.add(h);
|
||||
break;
|
||||
case SPECIAL:
|
||||
specialHilights.add(h);
|
||||
break;
|
||||
case OFFSET:
|
||||
instructionHilights.add(h);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void appendToSb(String str) {
|
||||
if (newLine) {
|
||||
newLine = false;
|
||||
appendIndent();
|
||||
}
|
||||
sb.append(str);
|
||||
}
|
||||
|
||||
private void appendIndent() {
|
||||
for (int i = 0; i < indent; i++) {
|
||||
appendNoHilight(formatting.indentString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class LoopWithType {
|
||||
|
||||
public static int LOOP_TYPE_LOOP = 0;
|
||||
public static int LOOP_TYPE_SWITCH = 1;
|
||||
|
||||
public long loopId;
|
||||
public int type;
|
||||
public boolean used;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class NulWriter extends GraphTextWriter {
|
||||
|
||||
private final Stack<LoopWithType> loopStack = new Stack<>();
|
||||
private final Stack<Boolean> stringAddedStack = new Stack<>();
|
||||
private boolean stringAdded = false;
|
||||
|
||||
public NulWriter() {
|
||||
super(new CodeFormatting());
|
||||
}
|
||||
|
||||
public void startLoop(long loopId, int loopType) {
|
||||
LoopWithType loop = new LoopWithType();
|
||||
loop.loopId = loopId;
|
||||
loop.type = loopType;
|
||||
loopStack.add(loop);
|
||||
}
|
||||
|
||||
public LoopWithType endLoop(long loopId) {
|
||||
LoopWithType loopIdInStack = loopStack.pop();
|
||||
if (loopId != loopIdInStack.loopId) {
|
||||
throw new Error("LoopId mismatch");
|
||||
}
|
||||
return loopIdInStack;
|
||||
}
|
||||
|
||||
public long getLoop() {
|
||||
if (loopStack.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
return loopStack.peek().loopId;
|
||||
}
|
||||
|
||||
public long getNonSwitchLoop() {
|
||||
if (loopStack.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int pos = loopStack.size() - 1;
|
||||
LoopWithType loop;
|
||||
do {
|
||||
loop = loopStack.get(pos);
|
||||
pos--;
|
||||
} while ((pos >= 0) && (loop.type == LoopWithType.LOOP_TYPE_SWITCH));
|
||||
|
||||
if (loop.type == LoopWithType.LOOP_TYPE_SWITCH) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return loop.loopId;
|
||||
}
|
||||
|
||||
public void setLoopUsed(long loopId) {
|
||||
if (loopStack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = loopStack.size() - 1;
|
||||
LoopWithType loop = null;
|
||||
do {
|
||||
loop = loopStack.get(pos);
|
||||
pos--;
|
||||
} while ((pos >= 0) && (loop.loopId != loopId));
|
||||
|
||||
if (loop.loopId == loopId) {
|
||||
loop.used = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter hilightSpecial(String text, String type) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter hilightSpecial(String text, String type, int index) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter append(String str) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter append(String str, long offset) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter appendNoHilight(int i) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter appendNoHilight(String str) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void mark() {
|
||||
stringAddedStack.add(stringAdded);
|
||||
stringAdded = false;
|
||||
}
|
||||
|
||||
public boolean getMark() {
|
||||
boolean result = stringAdded;
|
||||
stringAdded = stringAddedStack.pop() || result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.collections;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <K> Key
|
||||
* @param <V> Value
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MyEntry<K, V> implements Entry<K, V> {
|
||||
|
||||
public K key;
|
||||
public V value;
|
||||
|
||||
public MyEntry(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return key.toString() + " = " + value.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 61 * hash + Objects.hashCode(this.key);
|
||||
hash = 61 * hash + Objects.hashCode(this.value);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
final MyEntry<K, V> other = (MyEntry<K, V>) obj;
|
||||
if (!Objects.equals(this.key, other.key)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.value, other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
this.value = value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MyMap<K, V> implements Map<K, V> {
|
||||
|
||||
List<MyEntry<K, V>> values = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return values.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.key.equals(key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.value.equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.key.equals(key)) {
|
||||
return kv.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
if (kv.key.equals(key)) {
|
||||
kv.value = value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
values.add(new MyEntry<>(key, value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
MyEntry<K, V> kv = values.get(i);
|
||||
if (kv.key.equals(key)) {
|
||||
values.remove(i);
|
||||
return kv.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends K, ? extends V> m) {
|
||||
for (K k : m.keySet()) {
|
||||
put(k, m.get(k));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
values.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
Set<K> ret = new MySet<>();
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
ret.add(kv.key);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
Collection<V> ret = new ArrayList<>();
|
||||
for (MyEntry<K, V> kv : values) {
|
||||
ret.add(kv.value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
Set<Entry<K, V>> ret = new MySet<>();
|
||||
ret.addAll(values);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.collections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MySet<T> implements Set<T> {
|
||||
|
||||
List<T> items = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return items.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
for (T t : items) {
|
||||
if (t.equals(o)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
int pos = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return pos + 1 < items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
return items.get(pos++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
items.remove(pos--);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] ret = new Object[items.size()];
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
ret[i] = items.get(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T e) {
|
||||
items.add(e);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (items.get(i).equals(o)) {
|
||||
items.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> c) {
|
||||
for (T t : c) {
|
||||
add(t);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
items.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "[";
|
||||
boolean first = true;
|
||||
for (T t : items) {
|
||||
if (!first) {
|
||||
ret += ", ";
|
||||
}
|
||||
ret += t.toString();
|
||||
first = false;
|
||||
}
|
||||
ret += "]";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.helpers.hilight;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.helpers.HilightType;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides methods for highlighting positions of instructions in the text.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class Highlighting implements Serializable {
|
||||
|
||||
public HilightType type;
|
||||
public String hilightedText;
|
||||
/**
|
||||
* Starting position
|
||||
*/
|
||||
public int startPos;
|
||||
/**
|
||||
* Length of highlighted text
|
||||
*/
|
||||
public int len;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public Long getPropertyLong(String key) {
|
||||
String dataStr = getPropertyString(key);
|
||||
if (dataStr == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(dataStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPropertyString(String key) {
|
||||
return properties.get(key);
|
||||
}
|
||||
|
||||
public static Highlighting search(List<Highlighting> list, long pos) {
|
||||
return search(list, pos, null, null, -1, -1);
|
||||
}
|
||||
|
||||
public static Highlighting search(List<Highlighting> list, String property, String value) {
|
||||
return search(list, -1, property, value, -1, -1);
|
||||
}
|
||||
|
||||
public static Highlighting search(List<Highlighting> list, String property, String value, int from, int to) {
|
||||
return search(list, -1, property, value, from, to);
|
||||
}
|
||||
|
||||
public static Highlighting search(List<Highlighting> list, long pos, String property, String value, long from, long to) {
|
||||
Highlighting ret = null;
|
||||
for (Highlighting h : list) {
|
||||
if (property != null) {
|
||||
String v = h.getPropertyString(property);
|
||||
if (v == null) {
|
||||
if (value != null) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!v.equals(value)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (from > -1) {
|
||||
if (h.startPos < from) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (to > -1) {
|
||||
if (h.startPos > to) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (pos == -1 || (pos >= h.startPos && (pos < h.startPos + h.len))) {
|
||||
if (ret == null || h.startPos > ret.startPos) { //get the closest one
|
||||
ret = h;
|
||||
}
|
||||
}
|
||||
if (pos == -1 && ret != null) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (Configuration.debugMode.get()) {
|
||||
if (ret != null) {
|
||||
System.out.println("Highlight found: " + ret.hilightedText);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object
|
||||
*
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return startPos + "-" + (startPos + len) + " type:" + type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param startPos Starting position
|
||||
* @param data Highlighting data
|
||||
* @param type Highlighting type
|
||||
* @param text
|
||||
*/
|
||||
public Highlighting(int startPos, Map<String, String> data, HilightType type, String text) {
|
||||
this.startPos = startPos;
|
||||
this.type = type;
|
||||
if (Configuration.debugMode.get()) {
|
||||
this.hilightedText = text;
|
||||
}
|
||||
this.properties = data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user