From 7814d85890ee34962f3b96a277c3947f4b740e61 Mon Sep 17 00:00:00 2001 From: OpticFusion1 <37254722+OpticFusion1@users.noreply.github.com> Date: Sun, 25 Sep 2022 22:58:16 -0400 Subject: [PATCH] Version 1.5 Organized vbs parser code Reorganized TODO comments in StatementFactory class Cleaned up code formatting --- pom.xml | 15 +++++- .../kitsune/parser/vbs/StatementFactory.java | 47 +++++++------------ .../kitsune/parser/vbs/StatementFilter.java | 4 +- .../kitsune/parser/vbs/VBSParser.java | 25 ++++++---- .../parser/vbs/{ => domain}/Comment.java | 2 +- .../vbs/{ => domain}/ConstStatement.java | 2 +- .../parser/vbs/{ => domain}/Constants.java | 17 +------ .../parser/vbs/{ => domain}/DataType.java | 2 +- .../vbs/{ => domain}/ElseIfStatement.java | 5 +- .../vbs/{ => domain}/ElseStatement.java | 5 +- .../vbs/{ => domain}/EmptyLineStatement.java | 2 +- .../vbs/{ => domain}/FileContainer.java | 5 +- .../parser/vbs/{ => domain}/Function.java | 5 +- .../parser/vbs/{ => domain}/IfStatement.java | 5 +- .../vbs/{ => domain}/LoopStatement.java | 6 ++- .../vbs/{ => domain}/MsgBoxStatement.java | 2 +- .../parser/vbs/{ => domain}/Parameter.java | 3 +- .../parser/vbs/{ => domain}/SetStatement.java | 2 +- .../parser/vbs/{ => domain}/Statement.java | 6 +-- .../parser/vbs/{ => domain}/VBStatement.java | 8 ++-- .../parser/vbs/{ => domain}/VariableInit.java | 2 +- .../vbs/{ => interfaces}/IContainer.java | 4 +- .../kitsune/parser/vbs/{ => util}/Utils.java | 20 ++------ .../analyze/analyzer/vbs/VBSAnalyzer.java | 11 ++--- 24 files changed, 99 insertions(+), 106 deletions(-) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/Comment.java (85%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/ConstStatement.java (89%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/Constants.java (93%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/DataType.java (93%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/ElseIfStatement.java (79%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/ElseStatement.java (75%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/EmptyLineStatement.java (74%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/FileContainer.java (78%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/Function.java (83%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/IfStatement.java (79%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/LoopStatement.java (79%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/MsgBoxStatement.java (86%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/Parameter.java (90%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/SetStatement.java (91%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/Statement.java (84%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/VBStatement.java (86%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => domain}/VariableInit.java (91%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => interfaces}/IContainer.java (57%) rename src/main/java/optic_fusion1/kitsune/parser/vbs/{ => util}/Utils.java (93%) diff --git a/pom.xml b/pom.xml index 9747da0..9c5529c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ optic_fusion1 Kitsune - 1.4.3 + 1.5 @@ -143,9 +143,20 @@ org.jsoup jsoup - 1.15.3 + 1.14.3 jar + + net.java.dev.jna + jna + 5.11.0 + jar + + + net.java.dev.jna + jna-platform + 5.12.1 + diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFactory.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFactory.java index 78e8bf4..0aa61d6 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFactory.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFactory.java @@ -1,17 +1,30 @@ package optic_fusion1.kitsune.parser.vbs; +import optic_fusion1.kitsune.parser.vbs.domain.Parameter; +import optic_fusion1.kitsune.parser.vbs.domain.VBStatement; +import optic_fusion1.kitsune.parser.vbs.domain.Comment; +import optic_fusion1.kitsune.parser.vbs.domain.LoopStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ConstStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ElseIfStatement; +import optic_fusion1.kitsune.parser.vbs.domain.VariableInit; +import optic_fusion1.kitsune.parser.vbs.domain.IfStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ElseStatement; +import optic_fusion1.kitsune.parser.vbs.domain.MsgBoxStatement; +import optic_fusion1.kitsune.parser.vbs.domain.SetStatement; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static optic_fusion1.kitsune.Kitsune.LOGGER; +import optic_fusion1.kitsune.parser.vbs.domain.Constants; +import optic_fusion1.kitsune.parser.vbs.domain.DataType; +import optic_fusion1.kitsune.parser.vbs.domain.Function; /* TODO: Implement support for Sub functions Sub SubName( param1, param2 ) || Sub SubName(param1,param2) // Or other variants // Statements End Sub - -TODO: Implement support for storing the values that variables get set to */ +// TODO: Implement support for storing the values that variables get set to +// TODO: Implement support for parsing operators (=, +, -, /, *, %) public class StatementFactory { /* @@ -21,21 +34,18 @@ public class StatementFactory { End Function */ public static Function buildFunctionStatements(int index, String line) { - Pattern pattern = Pattern.compile("( +.*?)\\(", Pattern.CASE_INSENSITIVE); + Pattern pattern = Pattern.compile("( +.*?)\\(?", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(line); matcher.find(); Function func = new Function(matcher.group(1)); func.setLineNumber(index); func.setText(line); - pattern = Pattern.compile("\\((.*?)\\)", Pattern.CASE_INSENSITIVE); matcher = pattern.matcher(line); matcher.find(); String paramstr = null; paramstr = matcher.group(1); - if (paramstr != null) { - String[] params = paramstr.split(","); for (String param : params) { param = param.trim(); @@ -46,12 +56,10 @@ public static Function buildFunctionStatements(int index, String line) { paramType = DataType.valueOf(pvPair[0].trim()); paramName = pvPair[1].trim(); } - Parameter p = new Parameter(paramName, paramType); func.getParameters().add(p); } } - return func; } @@ -90,44 +98,31 @@ public static VariableInit buildVariableInitStatements(int index, String lineTri } public static VBStatement buildGenericStatements(int index, String line) { - VBStatement stmt = new VBStatement(); stmt.setLineNumber(index); stmt.setText(line); - return stmt; - } public static LoopStatement buildLoopStatements(int index, String lineTrimmed) { - LoopStatement loop = new LoopStatement(); - loop.setText(lineTrimmed); loop.setLineNumber(index); - String loopStartRegex = Constants.WHILE_IDENTIFIER + "|" + Constants.DO_WHILE_IDENTIFIER + "|" + Constants.FOR_IDENTIFIER; String condition = lineTrimmed.replaceFirst(loopStartRegex, ""); - loop.setCondition(condition); - return loop; } public static IfStatement buildIFStatements(int index, String lineTrimmed) { - Pattern pattern = Pattern.compile("if(.+)then", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(lineTrimmed); matcher.find(); - IfStatement ifstmt = new IfStatement(); ifstmt.setText(lineTrimmed); ifstmt.setLineNumber(index); - String condition = matcher.group(1); - ifstmt.setCondition(condition); - return ifstmt; } @@ -135,10 +130,8 @@ public static SetStatement buildSetStatmenets(int index, String lineTrimmed) { Pattern pattern = Pattern.compile("set (.+) ?= ?(.+)", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(lineTrimmed); matcher.find(); - VBStatement stmt = new VBStatement(); stmt.setText(matcher.group(2)); - SetStatement setStmt = new SetStatement(matcher.group(1).trim(), stmt); return setStmt; } @@ -147,24 +140,18 @@ public static ElseIfStatement buildElseIFStatements(int index, String lineTrimme Pattern pattern = Pattern.compile("elseif(.+)then", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(lineTrimmed); matcher.find(); - ElseIfStatement ifstmt = new ElseIfStatement(); ifstmt.setText(lineTrimmed); ifstmt.setLineNumber(index); - String condition = matcher.group(1); - ifstmt.setCondition(condition); - return ifstmt; } public static ElseStatement buildElseStatements(int index, String lineTrimmed) { - ElseStatement elsestmt = new ElseStatement(); elsestmt.setText(lineTrimmed); elsestmt.setLineNumber(index); - return elsestmt; } diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFilter.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFilter.java index de1d694..4719cef 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFilter.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/StatementFilter.java @@ -5,8 +5,8 @@ public class StatementFilter { private Class filterClass; - public StatementFilter(Class clz) { - this.filterClass = clz; + public StatementFilter(Class clazz) { + this.filterClass = clazz; } public Class getFilterClass() { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/VBSParser.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/VBSParser.java index 3a9c14c..1399265 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/VBSParser.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/VBSParser.java @@ -1,5 +1,22 @@ package optic_fusion1.kitsune.parser.vbs; +import optic_fusion1.kitsune.parser.vbs.util.Utils; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.domain.VBStatement; +import optic_fusion1.kitsune.parser.vbs.domain.EmptyLineStatement; +import optic_fusion1.kitsune.parser.vbs.domain.Comment; +import optic_fusion1.kitsune.parser.vbs.domain.LoopStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ConstStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ElseIfStatement; +import optic_fusion1.kitsune.parser.vbs.domain.Function; +import optic_fusion1.kitsune.parser.vbs.domain.Statement; +import optic_fusion1.kitsune.parser.vbs.domain.Constants; +import optic_fusion1.kitsune.parser.vbs.domain.VariableInit; +import optic_fusion1.kitsune.parser.vbs.domain.IfStatement; +import optic_fusion1.kitsune.parser.vbs.domain.ElseStatement; +import optic_fusion1.kitsune.parser.vbs.domain.SetStatement; +import optic_fusion1.kitsune.parser.vbs.domain.MsgBoxStatement; +import optic_fusion1.kitsune.parser.vbs.domain.FileContainer; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; @@ -173,7 +190,6 @@ private IContainer getLastContainerFromStack() { } private void popLastContainerFromStack() { - if (containerStack.size() > 1) { containerStack.remove(containerStack.size() - 1); } @@ -193,23 +209,17 @@ public void setContainer(FileContainer container) { public List getParsedStatementLines() { List parsedLines = new ArrayList<>(); - parsedLines = visitContainersAndExtractRecursively(parsedLines, fileContainer); - return parsedLines; } public List getParsedStatements() { - return flatStructuredStatements; } private List visitContainersAndExtractRecursively(List stmtList, IContainer container) { - List parsedStmtList = stmtList; - List statementsInContainer = container.getStatements(); - for (Statement st : statementsInContainer) { if (st instanceof IContainer iContainer) { parsedStmtList.add(st.getText()); @@ -218,7 +228,6 @@ private List visitContainersAndExtractRecursively(List stmtList, parsedStmtList.add(st.getText()); } } - return parsedStmtList; } diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Comment.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Comment.java similarity index 85% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Comment.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Comment.java index f2393f5..6256fa4 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Comment.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Comment.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class Comment extends Statement { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/ConstStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ConstStatement.java similarity index 89% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/ConstStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ConstStatement.java index a1f2ca5..68da2b7 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/ConstStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ConstStatement.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class ConstStatement extends Statement { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Constants.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Constants.java similarity index 93% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Constants.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Constants.java index 92230f0..94e878e 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Constants.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Constants.java @@ -1,36 +1,21 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public final class Constants { public static final String FUNCTION_IDENTIFIER = "function"; - public static final String END_FUNCTION_IDENTIFIER = "end"; - public static final String DIM_IDENTIFIER = "dim"; - public static final String FOR_IDENTIFIER = "for"; - public static final String DO_WHILE_IDENTIFIER = "do while"; - public static final String WHILE_IDENTIFIER = "while"; - public static final String END_LOOP_REGEX = "(loop|next|wend)"; - public static final String IF_IDENTIFIER = "if"; - public static final String ELSE_IF_IDENTIFIER = "elseif"; - public static final String END_IF_REGEX = "end if"; - public static final String ELSE_IDENTIFIER = "else"; - public static final String MSG_IDENTIFIER = "msg"; - public static final String MSGBOX_IDENTIFIER = "msgbox"; - public static final String SET_IDENTIFIER = "set"; - public static final String CONST_IDENTIFIER = "const"; - public static final String COMMENT_IDENTIFIER = "'"; } diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/DataType.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/DataType.java similarity index 93% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/DataType.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/DataType.java index 34d9ba2..c801596 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/DataType.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/DataType.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public enum DataType { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/ElseIfStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseIfStatement.java similarity index 79% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/ElseIfStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseIfStatement.java index e1f3fa7..1c98d77 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/ElseIfStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseIfStatement.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class ElseIfStatement extends Statement implements IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/ElseStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseStatement.java similarity index 75% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/ElseStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseStatement.java index 32fb929..3b5ed83 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/ElseStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/ElseStatement.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class ElseStatement extends Statement implements IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/EmptyLineStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/EmptyLineStatement.java similarity index 74% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/EmptyLineStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/EmptyLineStatement.java index dcb3606..31a06ae 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/EmptyLineStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/EmptyLineStatement.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class EmptyLineStatement extends Statement { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/FileContainer.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/FileContainer.java similarity index 78% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/FileContainer.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/FileContainer.java index 7fbdbf0..0ec98dc 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/FileContainer.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/FileContainer.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class FileContainer implements IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Function.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Function.java similarity index 83% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Function.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Function.java index 85c81fd..d437504 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Function.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Function.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class Function extends Statement implements IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/IfStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/IfStatement.java similarity index 79% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/IfStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/IfStatement.java index 38eca2c..d31d696 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/IfStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/IfStatement.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class IfStatement extends Statement implements IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/LoopStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/LoopStatement.java similarity index 79% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/LoopStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/LoopStatement.java index 3a07a4c..e6a54cf 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/LoopStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/LoopStatement.java @@ -1,7 +1,10 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; +import optic_fusion1.kitsune.parser.vbs.util.Utils; public class LoopStatement extends Statement implements IContainer { @@ -34,7 +37,6 @@ public List getStatements() { @Override public List filterStatements(StatementFilter filter) { - return Utils.filterStatements(statements, filter); } } diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/MsgBoxStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/MsgBoxStatement.java similarity index 86% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/MsgBoxStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/MsgBoxStatement.java index 350ae9a..1a951e2 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/MsgBoxStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/MsgBoxStatement.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class MsgBoxStatement extends Statement { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Parameter.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Parameter.java similarity index 90% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Parameter.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Parameter.java index c1c6acb..b849911 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Parameter.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Parameter.java @@ -1,9 +1,8 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class Parameter { private String name; - private DataType type; public Parameter(String name, DataType type) { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/SetStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/SetStatement.java similarity index 91% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/SetStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/SetStatement.java index 7b45240..b48f57b 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/SetStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/SetStatement.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; public class SetStatement extends Statement { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Statement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Statement.java similarity index 84% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Statement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Statement.java index ae1f2af..b1eaeaf 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Statement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/Statement.java @@ -1,11 +1,11 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; + +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; public abstract class Statement { private int lineNumber; - private IContainer parent; - private String text; public abstract Class getType(); diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/VBStatement.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VBStatement.java similarity index 86% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/VBStatement.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VBStatement.java index b9f66e1..c00330e 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/VBStatement.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VBStatement.java @@ -1,22 +1,20 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; + +import optic_fusion1.kitsune.parser.vbs.interfaces.IContainer; public class VBStatement extends Statement { private String text; - private IContainer parent; - private int lineNumber; @Override public Class getType() { - return this.getClass(); } @Override public String getText() { - return text; } diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/VariableInit.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VariableInit.java similarity index 91% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/VariableInit.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VariableInit.java index 960b127..f41599a 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/VariableInit.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/domain/VariableInit.java @@ -1,4 +1,4 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.domain; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/IContainer.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/interfaces/IContainer.java similarity index 57% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/IContainer.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/interfaces/IContainer.java index 1a29ba9..99052a1 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/IContainer.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/interfaces/IContainer.java @@ -1,6 +1,8 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.interfaces; +import optic_fusion1.kitsune.parser.vbs.domain.Statement; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; public interface IContainer { diff --git a/src/main/java/optic_fusion1/kitsune/parser/vbs/Utils.java b/src/main/java/optic_fusion1/kitsune/parser/vbs/util/Utils.java similarity index 93% rename from src/main/java/optic_fusion1/kitsune/parser/vbs/Utils.java rename to src/main/java/optic_fusion1/kitsune/parser/vbs/util/Utils.java index f3640e9..aa1aac1 100644 --- a/src/main/java/optic_fusion1/kitsune/parser/vbs/Utils.java +++ b/src/main/java/optic_fusion1/kitsune/parser/vbs/util/Utils.java @@ -1,5 +1,6 @@ -package optic_fusion1.kitsune.parser.vbs; +package optic_fusion1.kitsune.parser.vbs.util; +import optic_fusion1.kitsune.parser.vbs.domain.Statement; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -8,38 +9,30 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import optic_fusion1.kitsune.parser.vbs.StatementFilter; import static optic_fusion1.kitsune.Kitsune.LOGGER; public class Utils { public static List filterStatements(List list, StatementFilter filter) { - List result = new ArrayList<>(); - for (Statement item : list) { if (item.getType().equals(filter.getFilterClass())) { result.add(item); } } - return result; } public static List getLines(File inputfile) { List lines = new ArrayList<>(); - BufferedReader br = null; - try { - String sCurrentLine; - br = new BufferedReader(new FileReader(inputfile)); - while ((sCurrentLine = br.readLine()) != null) { lines.add(sCurrentLine); } - } catch (IOException e) { LOGGER.error("Exception", e); } finally { @@ -51,12 +44,10 @@ public static List getLines(File inputfile) { LOGGER.error("Exception", ex); } } - return lines; } public static void writeLinesToFile(List lines, File outputfile) { - BufferedWriter bw = null; try { StringBuilder builder = new StringBuilder(); @@ -64,18 +55,14 @@ public static void writeLinesToFile(List lines, File outputfile) { if (!outputfile.exists()) { outputfile.createNewFile(); } - for (String line : lines) { builder.append(line).append("\n"); } - FileWriter fw = new FileWriter(outputfile.getAbsoluteFile()); bw = new BufferedWriter(fw); bw.write(builder.toString()); bw.close(); - System.out.println("Done"); - } catch (IOException e) { LOGGER.error("Exception", e); } finally { @@ -87,7 +74,6 @@ public static void writeLinesToFile(List lines, File outputfile) { LOGGER.error("Exception", ex); } } - } } diff --git a/src/main/java/optic_fusion1/kitsune/tool/impl/analyze/analyzer/vbs/VBSAnalyzer.java b/src/main/java/optic_fusion1/kitsune/tool/impl/analyze/analyzer/vbs/VBSAnalyzer.java index f6cde13..baee022 100644 --- a/src/main/java/optic_fusion1/kitsune/tool/impl/analyze/analyzer/vbs/VBSAnalyzer.java +++ b/src/main/java/optic_fusion1/kitsune/tool/impl/analyze/analyzer/vbs/VBSAnalyzer.java @@ -2,12 +2,11 @@ import java.io.File; import static optic_fusion1.kitsune.Kitsune.LOGGER; -import optic_fusion1.kitsune.parser.vbs.Comment; -import optic_fusion1.kitsune.parser.vbs.ConstStatement; -import optic_fusion1.kitsune.parser.vbs.MsgBoxStatement; -import optic_fusion1.kitsune.parser.vbs.Parameter; -import optic_fusion1.kitsune.parser.vbs.SetStatement; -import optic_fusion1.kitsune.parser.vbs.Statement; +import optic_fusion1.kitsune.parser.vbs.domain.Comment; +import optic_fusion1.kitsune.parser.vbs.domain.ConstStatement; +import optic_fusion1.kitsune.parser.vbs.domain.MsgBoxStatement; +import optic_fusion1.kitsune.parser.vbs.domain.SetStatement; +import optic_fusion1.kitsune.parser.vbs.domain.Statement; import optic_fusion1.kitsune.parser.vbs.VBSParser; import optic_fusion1.kitsune.tool.impl.analyze.analyzer.Analyzer;