Skip to content

Commit

Permalink
ExecutionFlow V5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
williamniemiec committed Nov 6, 2020
1 parent 0fa2b54 commit 14f686e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 85 deletions.
Binary file modified dist/5.x/5.2/ExecutionFlow_ConsoleExporter_v5.2.0.jar
Binary file not shown.
Binary file modified dist/5.x/5.2/ExecutionFlow_FileExporter_v5.2.0.jar
Binary file not shown.
Binary file removed lib/Codyfier.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private int cleanup() {
eliminateComments();
if (debug) System.out.println("CLEANUP: Eliminated comments");
trimLines();
eliminateAnnotations();
// eliminateAnnotations();
if (debug) System.out.println("CLEANUP: Eliminated annotations");
trimLines();
removeBlankLines();
Expand Down Expand Up @@ -98,7 +98,7 @@ private int cleanup() {
separateCaseStatements();
if (debug) System.out.println("CLEANUP: Separated case statements");
trimLines();
prepareTryCatchBlocks();
// prepareTryCatchBlocks();

if (debug) System.out.println("CLEANUP DONE! Resulting code:");
if (debug) dumpCode();
Expand Down Expand Up @@ -275,7 +275,7 @@ private void moveOpeningBrackets() {
for (int i=0; i<processedCode.size(); i++) {
int oldLineId = i+numRemovedLines;

if (processedCode.get(i).equals("{")) {
if (processedCode.get(i).equals("{") && !processedCode.get(i).contains("catch(Throwable _")) {
processedCode.set(i-1, processedCode.get(i-1) + "{");

mapping.put(oldLineId, Helper.initArray(i-1));
Expand Down Expand Up @@ -309,7 +309,7 @@ private void moveCodeAfterOpenedBracket() {
boolean hasCodeAfterBracket = (idx > -1
&& idx < processedCode.get(i).length()-1);

if (hasCodeAfterBracket) {
if (hasCodeAfterBracket && !processedCode.get(i).contains("catch(Throwable _")) {
String preceding = processedCode.get(i).substring(0, idx+1);
String trailing = processedCode.get(i).substring(idx+1);
processedCode.add(i+1, trailing); //insert the text right of the { as the next line
Expand Down Expand Up @@ -339,7 +339,7 @@ private void moveClosingBrackets() {
targetLinesIds.add(i);

int idx = Helper.getIndexOfReservedChar(processedCode.get(i), "}");
if (idx > 1) { // this means the } is not starting a line
if (idx > 1 && !processedCode.get(i).contains("catch(Throwable _")) { // this means the } is not starting a line
String trailing = processedCode.get(i).substring(idx);
String preceding = processedCode.get(i).substring(0, idx);
processedCode.add(i+1, trailing); // insert the text starting with the } as the next line
Expand Down Expand Up @@ -369,7 +369,7 @@ private void moveCodeAfterClosedBracket() {
targetLinesIds.add(i);

int idx = Helper.getIndexOfReservedChar(processedCode.get(i), "}");
if (idx > -1 && processedCode.get(i).length() > 1) { // this means there is text after the }
if (idx > -1 && processedCode.get(i).length() > 1 && !processedCode.get(i).contains("catch(Throwable _")) { // this means there is text after the }
String trailing = processedCode.get(i).substring(idx+1);
String preceding = processedCode.get(i).substring(0, idx+1);

Expand Down Expand Up @@ -397,7 +397,7 @@ private void separateLinesWithSemicolons() {
List<String> statements = Helper.splitByReserved(processedCode.get(i), ';');

targetLinesIds.add(i);
if (statements.size() > 1) {
if (statements.size() > 1 && !processedCode.get(i).contains("catch(Throwable _")) {
boolean lineEndsWithSemicolon = processedCode.get(i).matches("^.*;$");
processedCode.set(i, statements.get(0) + ";");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
package executionFlow.io.processor.parser.trgeneration;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import executionFlow.util.DataUtil;

/**
* @author William Niemiec &lt; williamniemiec@hotmail.com &gt;
* @version 5.2.0
* @since 5.2.0
*/
public class CodeCleanerAdapter
public class CodeCleanerAdapter extends CodeCleaner
{
//-------------------------------------------------------------------------
// Attributes
//-------------------------------------------------------------------------
private List<String> sourceCode;
private CodeCleaner cc = new CodeCleaner(false);


//-------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------
public CodeCleanerAdapter(List<String> sourceCode)
{
super(false);
this.sourceCode = sourceCode;
}

Expand All @@ -36,18 +32,12 @@ public CodeCleanerAdapter(List<String> sourceCode)
//-------------------------------------------------------------------------
public List<String> parse()
{
List<String> processedCode;


cc.cleanupCode(sourceCode);
processedCode = cc.getProcessedCode();

cleanupCode(sourceCode);
deleteContentBetweenPercentages(processedCode);

return processedCode;
}


private void deleteContentBetweenPercentages(List<String> processedCode)
{
String line;
Expand Down Expand Up @@ -76,35 +66,16 @@ private void deleteContentBetweenPercentages(List<String> processedCode)
public Map<Integer, Integer> getMapping()
{
Map<Integer, Integer> mapping = new HashMap<>();
Set<Integer> updated = new HashSet<>();
List<Map<Integer, List<Integer>>> lineMappings = cc.getLineMappings();


// Gets first line change
for (Map.Entry<Integer, List<Integer>> lm : lineMappings.get(0).entrySet()) {
mapping.put(lm.getKey(), lm.getValue().get(0));
}

// Updates line changes from the second
for (int i=1; i<lineMappings.size(); i++) {
// For each mapping
for (Map.Entry<Integer, List<Integer>> lm : lineMappings.get(i).entrySet()) {
// If there is a value in the mapping with the current key
if (mapping.containsValue(lm.getKey())) {
// Updates this value with the value contained in the current key
for (Integer key : DataUtil.<Integer, Integer>findKeyFromValue(mapping, lm.getKey())) {
if (!updated.contains(key)) {
mapping.put(key, lm.getValue().get(0));
updated.add(key);
}
}
}
}
for (Map.Entry<Integer, List<Integer>> map : lineMappings.get(lineMappings.size()-1).entrySet()) {
int originalLine = map.getValue().get(0) + 1;
int newLine = map.getKey()+1;


// Resets update set
updated.clear();
mapping.put(originalLine, newLine);
}

return mapping;
}
}
6 changes: 4 additions & 2 deletions src/executionFlow/io/processor/parser/trgeneration/Defs.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package executionFlow.io.processor.parser.trgeneration;


/**
* @author Murilo Wolfart
* @see https://bitbucket.org/mwolfart/trgeneration/
*/
public class Defs {

public static final int failure = -1;
public static final int success = 0;


}
16 changes: 11 additions & 5 deletions src/executionFlow/io/processor/parser/trgeneration/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import executionFlow.util.FileUtil;


/**
* @author Murilo Wolfart
Expand Down Expand Up @@ -63,7 +65,7 @@ public static void createDir(String dirPath) {
if (dir.exists()) return;
if (!dir.mkdir()) {
System.err.println("Could not create directory " + dirPath);
System.exit(2);
// System.exit(2);
}
}

Expand Down Expand Up @@ -147,8 +149,8 @@ public static int findStartOfBlock(List<String> sourceCode, int startingLine, bo

if (openingLine == -1) {
System.err.println("Braces are not balanced");
System.err.println("When trying to find start of block ending at line " + (startingLine+1));
System.exit(2);
System.err.println("When trying to find start of block ending at line " + (startingLine+1));
// System.exit(2);
}

return openingLine;
Expand All @@ -172,10 +174,14 @@ public static int findEndOfBlock(List<String> sourceCode, int startingLine) {
}

if (closingLine == -1) {
System.out.println("----");
FileUtil.printFileWithLines(sourceCode);


System.err.println("Braces are not balanced");
System.err.println("When trying to find end of block starting at line " + (startingLine+1));
System.err.println("Line content: " + sourceCode.get(startingLine));
System.exit(2);
// System.exit(2);
}

return closingLine;
Expand All @@ -201,7 +207,7 @@ public static int findConditionalLine(List<String> sourceCode, int startingLine)
if (conditionalLine == -1) {
System.err.println("Continue without while or do");
System.err.println("When trying to find conditional of continue at line " + (startingLine+1));
System.exit(2);
// System.exit(2);
}

return conditionalLine;
Expand Down
16 changes: 9 additions & 7 deletions src/executionFlow/io/processor/parser/trgeneration/Regex.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package executionFlow.io.processor.parser.trgeneration;


/**
* @author Murilo Wolfart
* @see https://bitbucket.org/mwolfart/trgeneration/
*/
public class Regex {
public static String classSignature = "(((|public|final|abstract|private|static|protected)(\\s+))?(class)(\\s+)(\\w+)(<.*>)?(\\s+extends\\s+\\w+)?(<.*>)?(\\s+implements\\s+)?(.*)?(<.*>)?(\\s*))\\{$";
public static String methodSignature = "(public|protected|private|\\s)(\\s*static)? +[\\w\\<\\>\\[\\]]+\\s+(\\w+) *\\([^\\)]*\\) *(\\{?|[^;])";

// TODO [methodSignature] not all methods contain a scope, default is protected

public static String classSignature = "^[ \\t]*((public|private|protected)\\s+)?(static\\s+)?(final\\s+)?class\\s.*";
public static String methodSignature = ".*[a-zA-Z][a-zA-Z0-9]*\\s*\\(.*\\)\\s*\\{$";
public static String reservedMethods = "(if|while|for|class|switch|try|catch|finally)";

public static String reservedMethods = "(if|while|for|class|switch|try|catch|finally|return)";
public static String reservedInstructions = "^\\b(do|else(?!\\s+if)|case|default|continue|break|switch)\\b.*";
public static String nonExecutableLines = "^\\b(do|else(?!\\s+if)|default)\\b.*";

// TODO do not capture escaped quotes
public static String insideQuoteRestriction = "(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$).*";
public static String insideQuoteRestriction = "(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)(?=(?:[^']*'[^']*')*[^']*$).*";
}
49 changes: 23 additions & 26 deletions src/executionFlow/runtime/collector/TestMethodCollector.aj
Original file line number Diff line number Diff line change
Expand Up @@ -218,39 +218,36 @@ public aspect TestMethodCollector extends RuntimeCollector
* a mapping.
*
* @param mapping Mapping that will be used as base for the update
* @param testMethodSrcFile Test method source file
*/
public static void updateCollectorInvocationLines(Map<Path, Map<Integer, Integer>> mapping)
public static void updateCollectorInvocationLines(Map<Integer, Integer> mapping, Path testMethodSrcFile)
{
for (Map.Entry<Path, Map<Integer, Integer>> e : mapping.entrySet()) {
Path modifiedTestSrcFile = e.getKey();
Map<Integer, Integer> map = e.getValue();
int invocationLine;
int invocationLine;


// Updates constructor invocation lines If it is declared in the
// same file as the processed test method file
for (CollectorInfo cc : constructorCollector.values()) {
invocationLine = cc.getConstructorInfo().getInvocationLine();

if (!cc.getTestMethodInfo().getSrcPath().equals(testMethodSrcFile) ||
!mapping.containsKey(invocationLine))
continue;

// Updates constructor invocation lines If it is declared in the
// same file as the processed test method file
for (CollectorInfo cc : constructorCollector.values()) {
invocationLine = cc.getConstructorInfo().getInvocationLine();
cc.getConstructorInfo().setInvocationLine(mapping.get(invocationLine));
}

// Updates method invocation lines If it is declared in the
// same file as the processed test method file
for (List<CollectorInfo> methodCollectorList : methodCollector.values()) {
for (CollectorInfo mc : methodCollectorList) {
invocationLine = mc.getMethodInfo().getInvocationLine();

if (!cc.getTestMethodInfo().getSrcPath().equals(modifiedTestSrcFile) ||
!map.containsKey(invocationLine))
if (!mc.getTestMethodInfo().getSrcPath().equals(testMethodSrcFile) ||
!mapping.containsKey(invocationLine))
continue;

cc.getConstructorInfo().setInvocationLine(map.get(invocationLine));
}

// Updates method invocation lines If it is declared in the
// same file as the processed test method file
for (List<CollectorInfo> methodCollectorList : methodCollector.values()) {
for (CollectorInfo mc : methodCollectorList) {
invocationLine = mc.getMethodInfo().getInvocationLine();

if (!mc.getTestMethodInfo().getSrcPath().equals(modifiedTestSrcFile) ||
!map.containsKey(invocationLine))
continue;

mc.getMethodInfo().setInvocationLine(map.get(invocationLine));
}
mc.getMethodInfo().setInvocationLine(mapping.get(invocationLine));
}
}
}
Expand Down

0 comments on commit 14f686e

Please sign in to comment.