-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
2,619 additions
and
190 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
367 changes: 300 additions & 67 deletions
367
src/main/java/org/testshift/testcube/amplify/ShowCFGAction.java
Large diffs are not rendered by default.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
src/main/java/org/testshift/testcube/amplify/ShowCFGCoverageAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.testshift.testcube.amplify; | ||
|
||
import com.intellij.notification.Notification; | ||
import com.intellij.notification.NotificationAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowManager; | ||
import com.intellij.psi.PsiClass; | ||
import com.intellij.psi.PsiDocumentManager; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.PsiMethod; | ||
import com.intellij.ui.content.Content; | ||
import com.intellij.ui.content.ContentFactory; | ||
import eu.stamp_project.dspot.common.report.output.selector.branchcoverage.json.TestClassBranchCoverageJSON; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.testshift.testcube.branches.AllCoveredDialog; | ||
import org.testshift.testcube.branches.CFGWindow; | ||
import org.testshift.testcube.branches.CodeToUml; | ||
import org.testshift.testcube.branches.NoBranchDialog; | ||
import org.testshift.testcube.icons.TestCubeIcons; | ||
import org.testshift.testcube.misc.Util; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class ShowCFGCoverageAction extends NotificationAction { | ||
private final Project project; | ||
private final PsiClass targetClass; | ||
private final PsiMethod targetMethod; | ||
private PsiClass testClass; | ||
private String testMethods; | ||
private String moduleRootPath; | ||
|
||
public ShowCFGCoverageAction(Project project, PsiClass targetClass, PsiMethod targetMethod, PsiClass testClass, | ||
String testMethods, String moduleRootPath) { | ||
super("Inspect Control Flow Graph with Coverage"); | ||
this.project = project; | ||
this.targetClass = targetClass; | ||
this.targetMethod = targetMethod; | ||
this.testClass = testClass; | ||
this.testMethods = testMethods; | ||
this.moduleRootPath = moduleRootPath; | ||
} | ||
|
||
@Override | ||
public void update(AnActionEvent e) { | ||
// Set the availability based on whether a project is open | ||
Project project = e.getProject(); | ||
e.getPresentation().setEnabledAndVisible(project != null); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent event, @NotNull Notification notification) { | ||
TestClassBranchCoverageJSON coverageResult = (TestClassBranchCoverageJSON) Util.getBranchCoverageJSON(project, | ||
testClass.getQualifiedName()); | ||
Set<String> initialCoveredLines = Util.getInitialCoveredLine(coverageResult); | ||
Set<Util.Branch> initialCoveredBranches = Util.getInitialCoveredBranch(coverageResult); | ||
|
||
String targetMethodText = targetMethod.getBody().getText(); | ||
PsiFile containingFile = targetMethod.getContainingFile(); | ||
Project project = containingFile.getProject(); | ||
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); | ||
Document document = psiDocumentManager.getDocument(containingFile); | ||
int textOffset = targetMethod.getBody().getTextOffset(); | ||
int lineNumber = document.getLineNumber(textOffset); // this lineNumber +1 = starlinenumber | ||
|
||
|
||
Map<String, Integer> result = CodeToUml.codeToUml(targetMethodText, lineNumber + 1); | ||
String source = result.keySet().toArray()[0].toString(); | ||
int branchNum = result.get(source); | ||
|
||
if (branchNum == 0) { | ||
if(initialCoveredLines.isEmpty()) { | ||
NoBranchDialog dialog = new NoBranchDialog(); | ||
dialog.pack(); | ||
dialog.setVisible(true); | ||
} | ||
else{ | ||
AllCoveredDialog dialog = new AllCoveredDialog(); | ||
dialog.pack();; | ||
dialog.setVisible(true); | ||
} | ||
} | ||
|
||
String targetClassName = targetClass.getQualifiedName(); | ||
String targetMethodName = targetMethod.getName(); | ||
String testClassName = testClass.getQualifiedName(); | ||
|
||
CFGWindow cfgWindow = new CFGWindow(project, targetClassName, targetMethodName, source, initialCoveredLines, | ||
initialCoveredBranches, moduleRootPath, testClassName, testMethods, | ||
branchNum); | ||
|
||
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Test Cube"); | ||
|
||
if (toolWindow != null) { | ||
ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); | ||
Content content = contentFactory.createContent(cfgWindow.getContent(), cfgWindow.getDisplayName(), false); | ||
content.setCloseable(true); | ||
content.setIcon(TestCubeIcons.AMPLIFY_TEST); | ||
|
||
toolWindow.getContentManager().addContent(content); | ||
toolWindow.getContentManager().setSelectedContent(content); | ||
|
||
toolWindow.show(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/org/testshift/testcube/branches/AllCoveredDialog.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.testshift.testcube.branches.AllCoveredDialog"> | ||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="10" bottom="10" right="10"/> | ||
<constraints> | ||
<xy x="48" y="189" width="443" height="162"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="10"/> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<hspacer id="98af6"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</hspacer> | ||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="e7465" class="javax.swing.JButton" binding="buttonOK"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="OK"/> | ||
</properties> | ||
</component> | ||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Cancel"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="b6aed" class="javax.swing.JLabel" binding="Content"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="The selected method has no branches. All the lines have been covered."/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</form> |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/testshift/testcube/branches/AllCoveredDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.testshift.testcube.branches; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.*; | ||
|
||
public class AllCoveredDialog extends JDialog { | ||
private JPanel contentPane; | ||
private JButton buttonOK; | ||
private JButton buttonCancel; | ||
private JLabel Content; | ||
|
||
public AllCoveredDialog() { | ||
setContentPane(contentPane); | ||
setLocationRelativeTo(null); | ||
setModal(false); | ||
|
||
buttonOK.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
onOK(); | ||
} | ||
}); | ||
|
||
buttonCancel.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
onCancel(); | ||
} | ||
}); | ||
|
||
// call onCancel() when cross is clicked | ||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); | ||
addWindowListener(new WindowAdapter() { | ||
public void windowClosing(WindowEvent e) { | ||
onCancel(); | ||
} | ||
}); | ||
|
||
// call onCancel() on ESCAPE | ||
contentPane.registerKeyboardAction(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
onCancel(); | ||
} | ||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); | ||
} | ||
|
||
private void onOK() { | ||
dispose(); | ||
} | ||
|
||
private void onCancel() { | ||
// add your code here if necessary | ||
dispose(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
NoBranchDialog dialog = new NoBranchDialog(); | ||
dialog.pack(); | ||
dialog.setVisible(true); | ||
dialog.setSize(800,400); | ||
} | ||
} |
Oops, something went wrong.