create virtual parent action to connect with children

This commit is contained in:
Haoye TIAN
2020-02-19 18:11:29 +01:00
parent dd774fcc67
commit 62aa417523
@@ -44,6 +44,7 @@ public class HierarchicalRegrouperForC {
/* /*
* Second, group actions by their positions. * Second, group actions by their positions.
*/ */
HierarchicalActionSet actionSet = null; HierarchicalActionSet actionSet = null;
for(Action act : actions){ for(Action act : actions){
if(act.getNode().getType() == 2){ if(act.getNode().getType() == 2){
@@ -55,6 +56,7 @@ public class HierarchicalRegrouperForC {
actionSet = createActionSet(act, parentAct, null); actionSet = createActionSet(act, parentAct, null);
actionSets.add(actionSet); actionSets.add(actionSet);
} else { } else {
// if (!addToAactionSet(act, parentAct, actionSets)) {
if (!addToAactionSet(act, parentAct, actionSets)) { if (!addToAactionSet(act, parentAct, actionSets)) {
// The index of the parent action in the actions' list is larger than the index of this action. // The index of the parent action in the actions' list is larger than the index of this action.
actionSet = createActionSet(act, parentAct, null); actionSet = createActionSet(act, parentAct, null);
@@ -71,6 +73,7 @@ public class HierarchicalRegrouperForC {
Action parentAct = actSet.getParentAction(); Action parentAct = actSet.getParentAction();
if (parentAct != null) { if (parentAct != null) {
addToActionSets(actSet, parentAct, actionSets); addToActionSets(actSet, parentAct, actionSets);
actionSets.set(actionSets.indexOf(actSet), null);
} else { } else {
// TypeDeclaration, FieldDeclaration, MethodDeclaration, Statement. // TypeDeclaration, FieldDeclaration, MethodDeclaration, Statement.
// CatchClause, ConstructorInvocation, SuperConstructorInvocation, SwitchCase // CatchClause, ConstructorInvocation, SuperConstructorInvocation, SwitchCase
@@ -85,15 +88,39 @@ public class HierarchicalRegrouperForC {
} }
} }
// return reActionSets1;
// return reActionSets;
List<HierarchicalActionSet> re2ActionSets = new ArrayList<>();
for (HierarchicalActionSet act:reActionSets){
if (!act.getAction().getClass().equals(Update.class) || ((Update) act.getAction()).getflag() == true){
re2ActionSets.add(act);
continue;
}
findRealAction(act, re2ActionSets);
}
List<HierarchicalActionSet> reActionSets1 = new ArrayList<>(); List<HierarchicalActionSet> reActionSets1 = new ArrayList<>();
for(HierarchicalActionSet a:reActionSets){ for(HierarchicalActionSet a:re2ActionSets){
HierarchicalActionSet hierarchicalActionSet = removeBlocks(a); HierarchicalActionSet hierarchicalActionSet = removeBlocks(a);
hierarchicalActionSet = removeIFthenBlocks(hierarchicalActionSet); hierarchicalActionSet = removeIFthenBlocks(hierarchicalActionSet);
reActionSets1.add(hierarchicalActionSet); reActionSets1.add(hierarchicalActionSet);
} }
return reActionSets1; return reActionSets1;
// return reActionSets; }
private void findRealAction(HierarchicalActionSet act, List<HierarchicalActionSet> re2ActionSets) {
if (!act.getAction().getClass().equals(Update.class) || ((Update) act.getAction()).getflag() == true){
re2ActionSets.add(act);
return;
}
for (HierarchicalActionSet a:act.getSubActions()){
findRealAction(a, re2ActionSets);
}
} }
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){ private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){
@@ -191,7 +218,7 @@ public class HierarchicalRegrouperForC {
private void addToActionSets(HierarchicalActionSet actionSet, Action parentAct, List<HierarchicalActionSet> actionSets) { private void addToActionSets(HierarchicalActionSet actionSet, Action parentAct, List<HierarchicalActionSet> actionSets) {
Action act = actionSet.getAction(); Action act = actionSet.getAction();
for (HierarchicalActionSet actSet : actionSets) { for (HierarchicalActionSet actSet : actionSets) {
if (actSet.equals(actionSet)) continue; if (actSet == null || actSet.equals(actionSet)) continue;
Action action = actSet.getAction(); Action action = actSet.getAction();
if (!areRelatedActions(action, act)) continue; if (!areRelatedActions(action, act)) continue;