You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2020/10/15 16:39:08 UTC
[netbeans] branch master updated: NETBEANS-4852 add tooltip with
code coverage stats
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 3065c0b NETBEANS-4852 add tooltip with code coverage stats
3065c0b is described below
commit 3065c0be894417ab69cae5cc36e591f6361e676f
Author: Jakub Herkel <j....@uniq.sk>
AuthorDate: Tue Aug 18 20:50:16 2020 +0200
NETBEANS-4852 add tooltip with code coverage stats
---
.../modules/gsf/codecoverage/CoverageAction.java | 33 +++--
.../modules/gsf/codecoverage/CoverageBar.java | 156 ++++++++++-----------
.../modules/gsf/codecoverage/CoverageDocInfo.java | 1 +
.../codecoverage/CoverageHighlightsContainer.java | 71 +++++-----
.../CoverageHighlightsLayerFactory.java | 8 +-
.../gsf/codecoverage/CoverageManagerImpl.java | 41 +++---
.../codecoverage/CoverageReportTopComponent.java | 76 ++++++----
.../modules/gsf/codecoverage/CoverageSideBar.java | 40 +++---
.../modules/gsf/codecoverage/api/CoverageType.java | 16 +--
.../gsf/codecoverage/api/FileCoverageSummary.java | 21 +--
10 files changed, 253 insertions(+), 210 deletions(-)
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageAction.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageAction.java
index 4ea0d78..c3da79a 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageAction.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageAction.java
@@ -38,13 +38,14 @@ import org.openide.util.actions.Presenter;
// TODO - ShowMenu extends AbstractAction implements DynamicMenuContent {
// See ShowMenu.java in mercurial for simpler way to do this
public final class CoverageAction extends AbstractAction implements ContextAwareAction {
+
private static final int ACTION_TOGGLE_COLLECT = 1;
private static final int ACTION_TOGGLE_AGGREGATION = 2;
private static final int ACTION_CLEAR_RESULTS = 3;
private static final int ACTION_SHOW_REPORT = 4;
private static final int ACTION_TOGGLE_EDITORBAR = 5;
- private Action configureAction;
- private Action[] extraActions;
+ private final Action configureAction;
+ private final Action[] extraActions;
public CoverageAction(Action configureAction, Action[] extraActions) {
super();
@@ -57,6 +58,7 @@ public final class CoverageAction extends AbstractAction implements ContextAware
assert false : "Action should never be called without a context";
}
+ @Override
public Action createContextAwareInstance(Lookup actionContext) {
return new ContextAction(actionContext, configureAction, extraActions);
}
@@ -68,14 +70,16 @@ public final class CoverageAction extends AbstractAction implements ContextAware
return new LazyMenu(project, configureAction, extraActions);
}
- /** Build up a nested menu of migration tasks for the given project */
+ /**
+ * Build up a nested menu of migration tasks for the given project
+ */
static void buildMenu(JMenu menu, Project project, Action configureAction, Action[] extraActions) {
boolean enabled = true;
if (configureAction != null && configureAction.isEnabled()) {
enabled = false;
- JMenuItem menuitem =
- new JMenuItem((String) configureAction.getValue(Action.NAME));
+ JMenuItem menuitem
+ = new JMenuItem((String) configureAction.getValue(Action.NAME));
menuitem.addActionListener(configureAction);
menu.add(menuitem);
@@ -86,7 +90,6 @@ public final class CoverageAction extends AbstractAction implements ContextAware
}
CoverageManagerImpl manager = CoverageManagerImpl.getInstance();
-
boolean selected = manager.isEnabled(project);
JMenuItem menuitem = new JCheckBoxMenuItem(NbBundle.getMessage(CoverageAction.class, "LBL_CollectCoverageAction"), selected);
menuitem.addActionListener(new CoverageItemHandler(project, ACTION_TOGGLE_COLLECT));
@@ -121,7 +124,7 @@ public final class CoverageAction extends AbstractAction implements ContextAware
menu.addSeparator();
menuitem = new JMenuItem(NbBundle.getMessage(CoverageAction.class,
- "LBL_ShowReportAction"));
+ "LBL_ShowReportAction"));
menuitem.addActionListener(new CoverageItemHandler(project, ACTION_SHOW_REPORT));
//menuitem.setToolTipText(target.getDescription());
if (!enabled || !on) {
@@ -131,7 +134,7 @@ public final class CoverageAction extends AbstractAction implements ContextAware
menu.addSeparator();
menuitem = new JCheckBoxMenuItem(NbBundle.getMessage(CoverageAction.class, "LBL_ShowEditorBar"),
- manager.getShowEditorBar());
+ manager.getShowEditorBar());
menuitem.addActionListener(new CoverageItemHandler(project, ACTION_TOGGLE_EDITORBAR));
if (!enabled || !on) {
menuitem.setEnabled(false);
@@ -166,9 +169,10 @@ public final class CoverageAction extends AbstractAction implements ContextAware
* The particular instance of this action for a given project.
*/
private static final class ContextAction extends AbstractAction implements Presenter.Popup {
+
private final Project project;
- private Action configureAction;
- private Action[] extraActions;
+ private final Action configureAction;
+ private final Action[] extraActions;
public ContextAction(Lookup lkp, Action configureAction, Action[] extraActions) {
super(NbBundle.getMessage(CoverageAction.class, "LBL_CodeCoverage"));
@@ -186,10 +190,12 @@ public final class CoverageAction extends AbstractAction implements ContextAware
super.setEnabled(project != null);
}
+ @Override
public void actionPerformed(ActionEvent e) {
assert false : "Action should not be called directly";
}
+ @Override
public JMenuItem getPopupPresenter() {
if (project != null) {
return createMenu(project, configureAction, extraActions);
@@ -205,10 +211,11 @@ public final class CoverageAction extends AbstractAction implements ContextAware
}
private static final class LazyMenu extends JMenu {
+
private final Project project;
private boolean initialized = false;
- private Action configureAction;
- private Action[] extraActions;
+ private final Action configureAction;
+ private final Action[] extraActions;
public LazyMenu(Project project, Action configureAction, Action[] extraActions) {
super(NbBundle.getMessage(CoverageAction.class, "LBL_CodeCoverage"));
@@ -234,6 +241,7 @@ public final class CoverageAction extends AbstractAction implements ContextAware
* Action handler for a menu item representing one target.
*/
private static final class CoverageItemHandler implements ActionListener {
+
private final Project project;
private final int action;
@@ -242,6 +250,7 @@ public final class CoverageAction extends AbstractAction implements ContextAware
this.action = action;
}
+ @Override
public void actionPerformed(ActionEvent ev) {
CoverageManagerImpl manager = CoverageManagerImpl.getInstance();
switch (action) {
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageBar.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageBar.java
index e9f314c..3742170 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageBar.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageBar.java
@@ -30,33 +30,56 @@ import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.util.Map;
import javax.swing.JComponent;
import javax.swing.JLabel;
+import javax.swing.ToolTipManager;
/**
- * Custom component for painting code coverage.
- * I was initially using a JProgressBar, with the BasicProgressBarUI associated with it
- * (to get red/green colors set correctly even on OSX), but it was pretty plain
- * and ugly looking - no nice gradients etc. Hence this component.
+ * Custom component for painting code coverage. I was initially using a JProgressBar, with the
+ * BasicProgressBarUI associated with it (to get red/green colors set correctly even on OSX), but it
+ * was pretty plain and ugly looking - no nice gradients etc. Hence this component.
+ *
* @todo Add a getBaseline
*
* @author Tor Norbye
*/
public class CoverageBar extends JComponent {
+
private static final Color NOT_COVERED_LIGHT = new Color(255, 160, 160);
private static final Color NOT_COVERED_DARK = new Color(180, 50, 50);
private static final Color COVERED_LIGHT = new Color(160, 255, 160);
private static final Color COVERED_DARK = new Color(30, 180, 30);
private boolean emphasize;
private boolean selected;
- /** Coverage percentage: 0.0f <= x <= 100f */
+ /**
+ * Coverage percentage: 0.0f <= x <= 100f
+ */
private float coveragePercentage;
+ private int totalLines;
+ private int executedLines;
+ private int partialLines;
+ private int inferredLines;
public CoverageBar() {
+ addHierarchyListener(new HierarchyListener() {
+ @Override
+ public void hierarchyChanged(HierarchyEvent e) {
+ if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
+ if (isShowing()) {
+ ToolTipManager.sharedInstance().registerComponent(CoverageBar.this);
+ } else {
+ ToolTipManager.sharedInstance().unregisterComponent(CoverageBar.this);
+ }
+ }
+ }
+ });
updateUI();
}
@@ -95,7 +118,7 @@ public class CoverageBar extends JComponent {
}
@Override
- public void updateUI() {
+ public final void updateUI() {
Font f = new JLabel().getFont();
f = new Font(f.getName(), Font.BOLD, f.getSize());
setFont(f);
@@ -103,8 +126,7 @@ public class CoverageBar extends JComponent {
repaint();
}
- public
- @Override
+ public @Override
void paint(Graphics g) {
// Antialiasing if necessary
Object value = (Map) (Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
@@ -163,19 +185,19 @@ public class CoverageBar extends JComponent {
}
g2.setPaint(new GradientPaint(0, 0, notCoveredLight,
- 0, height / 2, notCoveredDark));
+ 0, height / 2, notCoveredDark));
g2.fillRect(amountFull, 1, width - 1, height / 2);
g2.setPaint(new GradientPaint(0, height / 2, notCoveredDark,
- 0, 2 * height, notCoveredLight));
+ 0, 2 * height, notCoveredLight));
g2.fillRect(amountFull, height / 2, width - 1, height / 2);
g2.setColor(getForeground());
g2.setPaint(new GradientPaint(0, 0, coveredLight,
- 0, height / 2, coveredDark));
+ 0, height / 2, coveredDark));
g2.fillRect(1, 1, amountFull, height / 2);
g2.setPaint(new GradientPaint(0, height / 2, coveredDark,
- 0, 2 * height, coveredLight));
+ 0, 2 * height, coveredLight));
g2.fillRect(1, height / 2, amountFull, height / 2);
Rectangle oldClip = g2.getClipBounds();
@@ -208,8 +230,8 @@ public class CoverageBar extends JComponent {
if (stringWidth > size.width) {
size.width = stringWidth;
}
- int stringHeight = fontSizer.getHeight() +
- fontSizer.getDescent();
+ int stringHeight = fontSizer.getHeight()
+ + fontSizer.getDescent();
if (stringHeight > size.height) {
size.height = stringHeight;
}
@@ -233,6 +255,7 @@ public class CoverageBar extends JComponent {
}
//@Override JDK6
+ @Override
public int getBaseline(int w, int h) {
FontMetrics fm = getFontMetrics(getFont());
return h - fm.getDescent() - ((h - fm.getHeight()) / 2);
@@ -334,73 +357,44 @@ public class CoverageBar extends JComponent {
FontMetrics fm = g.getFontMetrics();
int textWidth = fm.stringWidth(text);
g.drawString(text, (w - textWidth) / 2,
- h - fm.getDescent() - ((h - fm.getHeight()) / 2));
+ h - fm.getDescent() - ((h - fm.getHeight()) / 2));
+ }
+
+ public void setStats(int totalLines, int executedLines, int partialLines, int inferredLines) {
+ this.totalLines = totalLines;
+ this.executedLines = executedLines;
+ this.partialLines = partialLines;
+ this.inferredLines = inferredLines;
+ }
+
+ @Override
+ public String getToolTipText(MouseEvent arg0) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<html><body>"); // NOI18N
+ sb.append("Total Lines: ");
+ sb.append(Integer.toString(totalLines));
+ sb.append("<br>"); // NOI18N
+ sb.append("Executed Lines: ");
+ sb.append(Integer.toString(executedLines));
+ sb.append("<br>"); // NOI18N
+ if (partialLines >= 0) {
+ sb.append(" "); // NOI18N
+ sb.append("Partial Lines: ");
+ sb.append(Integer.toString(partialLines));
+ sb.append("<br>"); // NOI18N
+ }
+ if (inferredLines >= 0) {
+ sb.append(" "); // NOI18N
+ sb.append("Inferred Executed Lines: ");
+ sb.append(Integer.toString(inferredLines));
+ sb.append("<br>"); // NOI18N
+ }
+
+ sb.append("Not Executed Lines: ");
+ int notExecutedLines = totalLines - executedLines;
+ sb.append(Integer.toString(notExecutedLines));
+ sb.append("<br>"); // NOI18N
+ return sb.toString();
}
-// More specific stats. TODO:
-// (1) Show in tooltips. This works (commented out below) but requires component
-// visible/unvisible listening. Just adding to addNotify/removeNotify leaves a bunch
-// of components registered with the tooltip manager. (Just overriding getToolTipText() itself
-// doesn't work in an editor sidebar
-// (2) Paint more detailed coverage bars, showing partial coverage explicitly.
-//
-// private int totalLines;
-// private int executedLines;
-// private int partialLines;
-// private int inferredLines;
-//
-// public void setStats(int totalLines, int executedLines, int partialLines, int inferredLines) {
-// this.totalLines = totalLines;
-// this.executedLines = executedLines;
-// this.partialLines = partialLines;
-// this.inferredLines = inferredLines;
-// }
-//
-//
-// @Override
-// public String getToolTipText() {
-// return getToolTipText(null);
-// }
-//
-// @Override
-// public String getToolTipText(MouseEvent arg0) {
-// StringBuilder sb = new StringBuilder();
-// sb.append("<html><body>"); // NOI18N
-// sb.append("Total Lines: ");
-// sb.append(Integer.toString(totalLines));
-// sb.append("<br>"); // NOI18N
-// sb.append("Executed Lines: ");
-// sb.append(Integer.toString(executedLines));
-// sb.append("<br>"); // NOI18N
-// if (partialLines >= 0) {
-// sb.append(" "); // NOI18N
-// sb.append("Partial Lines: ");
-// sb.append(Integer.toString(partialLines));
-// sb.append("<br>"); // NOI18N
-// }
-// if (inferredLines >= 0) {
-// sb.append(" "); // NOI18N
-// sb.append("Inferred Executed Lines: ");
-// sb.append(Integer.toString(inferredLines));
-// sb.append("<br>"); // NOI18N
-// }
-//
-// sb.append("Not Executed Lines: ");
-// int notExecutedLines = totalLines - executedLines;
-// sb.append(Integer.toString(notExecutedLines));
-// sb.append("<br>"); // NOI18N
-// return sb.toString();
-// }
-//
-// @Override
-// public void addNotify() {
-// super.addNotify();
-// ToolTipManager.sharedInstance().registerComponent(this);
-// }
-//
-// @Override
-// public void removeNotify() {
-// super.removeNotify();
-// ToolTipManager.sharedInstance().unregisterComponent(this);
-// }
}
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageDocInfo.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageDocInfo.java
index 2a890ff..d5183e5 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageDocInfo.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageDocInfo.java
@@ -27,6 +27,7 @@ import org.netbeans.modules.gsf.codecoverage.api.FileCoverageDetails;
* @author Tor Norbye
*/
public class CoverageDocInfo {
+
private final PropertyChangeSupport pcs;
private final FileCoverageDetails details;
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
index ac110e7..758d882 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsContainer.java
@@ -33,13 +33,13 @@ import javax.swing.text.JTextComponent;
import javax.swing.text.Position;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
+import org.netbeans.api.editor.document.LineDocumentUtils;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.settings.AttributesUtilities;
import org.netbeans.api.editor.settings.FontColorSettings;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.Utilities;
import org.netbeans.modules.csl.spi.GsfUtilities;
import org.netbeans.modules.gsf.codecoverage.api.CoverageType;
import org.netbeans.modules.gsf.codecoverage.api.FileCoverageDetails;
@@ -55,6 +55,7 @@ import org.openide.util.WeakListeners;
* @author Tor Norbye
*/
public class CoverageHighlightsContainer extends AbstractHighlightsContainer implements DocumentListener {
+
private AttributeSet covered;
private AttributeSet uncovered;
private AttributeSet inferred;
@@ -70,10 +71,10 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
private FileObject fileObject;
private Project project;
- private static final String COLORING_COVERED = "coverage-covered"; //NOI18N
+ private static final String COLORING_COVERED = "coverage-covered"; //NOI18N
private static final String COLORING_UNCOVERED = "coverage-uncovered"; //NOI18N
- private static final String COLORING_INFERRED = "coverage-inferred"; //NOI18N
- private static final String COLORING_PARTIAL = "coverage-partial"; //NOI18N
+ private static final String COLORING_INFERRED = "coverage-inferred"; //NOI18N
+ private static final String COLORING_PARTIAL = "coverage-partial"; //NOI18N
CoverageHighlightsContainer(JTextComponent component) {
this.component = component;
@@ -160,17 +161,17 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
covered = coveredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
- StyleConstants.Background, coveredBc,
- ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
+ StyleConstants.Background, coveredBc,
+ ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
uncovered = uncoveredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
- StyleConstants.Background, uncoveredBc,
- ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
+ StyleConstants.Background, uncoveredBc,
+ ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
inferred = inferredBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
- StyleConstants.Background, inferredBc,
- ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
+ StyleConstants.Background, inferredBc,
+ ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
partial = partialBc == null ? SimpleAttributeSet.EMPTY : AttributesUtilities.createImmutable(
- StyleConstants.Background, partialBc,
- ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
+ StyleConstants.Background, partialBc,
+ ATTR_EXTENDS_EOL, Boolean.TRUE, ATTR_EXTENDS_EMPTY_LINE, Boolean.TRUE);
}
void refresh() {
@@ -197,25 +198,25 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
// add and subtract spaces to the document to implement
// smart-indent
if ((s.trim().length() == 0)) { // whitespace changes only?
- if (Utilities.isRowEmpty(doc, offset) ||
- (offset >= Utilities.getRowLastNonWhite(doc, offset) + 1) ||
- (offset <= Utilities.getRowFirstNonWhite(doc, offset))) {
+ if (LineDocumentUtils.isLineEmpty(doc, offset)
+ || (offset >= LineDocumentUtils.getLineLastNonWhitespace(doc, offset) + 1)
+ || (offset <= LineDocumentUtils.getLineFirstNonWhitespace(doc, offset))) {
fireHighlightsChange(offset, offset + length);
return;
}
}
}
- int lineStart = Utilities.getRowFirstNonWhite(doc, offset);
+ int lineStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
if (lineStart == -1) {
- lineStart = Utilities.getRowStart(doc, offset);
+ lineStart = LineDocumentUtils.getLineStart(doc, offset);
}
List<Position> positions = lastPositions;
if (positions != null) {
int positionIndex = findPositionIndex(positions, lineStart);
if (positionIndex >= 0) {
// Create a new list to avoid sync problems
- List<Position> copy = new ArrayList<Position>(positions);
+ List<Position> copy = new ArrayList<>(positions);
copy.remove(positionIndex);
lastPositions = copy;
fireHighlightsChange(offset, offset + length);
@@ -226,27 +227,32 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
}
+ @Override
public void insertUpdate(DocumentEvent ev) {
if (enabled) {
handleEdits(ev.getOffset(), ev.getLength(), true);
}
}
+ @Override
public void removeUpdate(DocumentEvent ev) {
//if (enabled) {
// handleEdits(ev.getOffset(), ev.getLength(), false);
//}
}
+ @Override
public void changedUpdate(DocumentEvent ev) {
}
private int findPositionIndex(List<Position> positions, final int target) {
return Collections.binarySearch(positions, new Position() {
+ @Override
public int getOffset() {
return target;
}
}, new Comparator<Position>() {
+ @Override
public int compare(Position pos1, Position pos2) {
return pos1.getOffset() - pos2.getOffset();
}
@@ -254,6 +260,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
private class Highlights implements HighlightsSequence {
+
private final List<Position> positions;
private final List<CoverageType> types;
private final long version;
@@ -271,14 +278,14 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
this.endOffsetBoundary = endOffset;
if (lastPositions == null) {
- positions = new ArrayList<Position>();
- types = new ArrayList<CoverageType>();
+ positions = new ArrayList<>();
+ types = new ArrayList<>();
for (int lineno = 0, maxLines = details.getLineCount(); lineno < maxLines; lineno++) {
CoverageType type = details.getType(lineno);
- if (type == CoverageType.COVERED || type == CoverageType.INFERRED ||
- type == CoverageType.NOT_COVERED || type == CoverageType.PARTIAL) {
+ if (type == CoverageType.COVERED || type == CoverageType.INFERRED
+ || type == CoverageType.NOT_COVERED || type == CoverageType.PARTIAL) {
try {
- int offset = Utilities.getRowStartFromLineOffset(doc, lineno);
+ int offset = LineDocumentUtils.getLineStartFromIndex(doc, lineno);
if (offset == -1) {
continue;
}
@@ -286,7 +293,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
// that if we insert a new line at the beginning of a line (or in
// the whitespace region) the highlight will move down with the
// text
- int rowStart = Utilities.getRowFirstNonWhite(doc, offset);
+ int rowStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, offset);
if (rowStart != -1) {
offset = rowStart;
}
@@ -306,9 +313,9 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
try {
- int lineStart = Utilities.getRowFirstNonWhite(doc, startOffsetBoundary);
+ int lineStart = LineDocumentUtils.getLineFirstNonWhitespace(doc, startOffsetBoundary);
if (lineStart == -1) {
- lineStart = Utilities.getRowStart(doc, startOffsetBoundary);
+ lineStart = LineDocumentUtils.getLineStart(doc, startOffsetBoundary);
index = findPositionIndex(positions, lineStart);
if (index < 0) {
index = -index;
@@ -322,18 +329,14 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
for (; index < positions.size(); index++) {
Position pos = positions.get(index);
int offset = pos.getOffset();
- try {
- offset = Utilities.getRowStart(doc, offset);
- } catch (BadLocationException ex) {
- Exceptions.printStackTrace(ex);
- }
+ offset = LineDocumentUtils.getLineStart(doc, offset);
if (offset > endOffsetBoundary) {
break;
}
if (offset >= startOffsetBoundary) {
startOffset = offset;
try {
- endOffset = Utilities.getRowEnd(doc, offset);
+ endOffset = LineDocumentUtils.getLineEnd(doc, offset);
if (endOffset < doc.getLength()) {
endOffset++; // Include end of line
}
@@ -365,6 +368,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
return false;
}
+ @Override
public boolean moveNext() {
synchronized (CoverageHighlightsContainer.this) {
if (checkVersion()) {
@@ -378,6 +382,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
return false;
}
+ @Override
public int getStartOffset() {
synchronized (CoverageHighlightsContainer.this) {
if (finished) {
@@ -388,6 +393,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
}
+ @Override
public int getEndOffset() {
synchronized (CoverageHighlightsContainer.this) {
if (finished) {
@@ -398,6 +404,7 @@ public class CoverageHighlightsContainer extends AbstractHighlightsContainer imp
}
}
+ @Override
public AttributeSet getAttributes() {
synchronized (CoverageHighlightsContainer.this) {
if (finished) {
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsLayerFactory.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsLayerFactory.java
index 3acbc20..3d2ca29 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsLayerFactory.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageHighlightsLayerFactory.java
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.netbeans.modules.gsf.codecoverage;
-import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
@@ -30,15 +28,17 @@ import org.netbeans.spi.editor.highlighting.ZOrder;
* @author Tor Norbye
*/
public class CoverageHighlightsLayerFactory implements HighlightsLayerFactory {
+
private static final String CONTAINER_PROP_NAME = "gsf-codecoverage-highlight-layer"; // NOI18N
+ @Override
public HighlightsLayer[] createLayers(Context context) {
JTextComponent component = context.getComponent();
CoverageHighlightsContainer container = new CoverageHighlightsContainer(component);
component.putClientProperty(CONTAINER_PROP_NAME, container);
return new HighlightsLayer[]{HighlightsLayer.create(CONTAINER_PROP_NAME,
- ZOrder.DEFAULT_RACK.forPosition(80),
- true, container)}; //NOI18N
+ ZOrder.DEFAULT_RACK.forPosition(80),
+ true, container)}; //NOI18N
}
public static CoverageHighlightsContainer getContainer(JTextComponent component) {
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageManagerImpl.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageManagerImpl.java
index 2a99c1c..8fa6c7e 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageManagerImpl.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageManagerImpl.java
@@ -75,33 +75,32 @@ public class CoverageManagerImpl implements CoverageManager {
enabledMimeTypes.addAll(mimeTypes);
} else {
enabledMimeTypes.removeAll(mimeTypes);
- SwingUtilities.invokeLater(new Runnable() {
+ SwingUtilities.invokeLater(new Runnable() {
@Override
- public void run() {
- for (JTextComponent target : EditorRegistry.componentList()) {
- Document document = target.getDocument();
- FileObject fileForDocument = GsfUtilities.findFileObject(document);
- // show/hide code coverage toolbar in all open file editors belonging only to this project
- if (fileForDocument != null && project.equals(FileOwnerQuery.getOwner(fileForDocument))) {
- CoverageSideBar sb = CoverageSideBar.getSideBar(target);
- if (sb != null) {
- sb.showCoveragePanel(enabled);
+ public void run() {
+ for (JTextComponent target : EditorRegistry.componentList()) {
+ Document document = target.getDocument();
+ FileObject fileForDocument = GsfUtilities.findFileObject(document);
+ // show/hide code coverage toolbar in all open file editors belonging only to this project
+ if (fileForDocument != null && project.equals(FileOwnerQuery.getOwner(fileForDocument))) {
+ CoverageSideBar sb = CoverageSideBar.getSideBar(target);
+ if (sb != null) {
+ sb.showCoveragePanel(enabled);
+ }
}
}
- }
- // code coverage is being disabled, so close the report window for this project
- if(!enabled) {
- CoverageReportTopComponent report = showingReports.get(project);
- if(report != null) {
- report.close();
+ // code coverage is being disabled, so close the report window for this project
+ if (!enabled) {
+ CoverageReportTopComponent report = showingReports.get(project);
+ if (report != null) {
+ report.close();
+ }
}
- }
-
- }
- });
- }
+ }
+ });
+ }
provider.setEnabled(enabled);
}
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageReportTopComponent.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageReportTopComponent.java
index e4fc57f..bdca717 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageReportTopComponent.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageReportTopComponent.java
@@ -68,11 +68,12 @@ import org.openide.windows.TopComponent;
* Window which displays a code coverage report.
*
* <p>
- * <b>NOTE</b>: You must compile this module before attempting to open this form
- * in the GUI builder! The design depends on the CoverageBar class and Matisse can
- * only load the form if the .class, not just the .java file, is available!
+ * <b>NOTE</b>: You must compile this module before attempting to open this form in the GUI builder!
+ * The design depends on the CoverageBar class and Matisse can only load the form if the .class, not
+ * just the .java file, is available!
*/
final class CoverageReportTopComponent extends TopComponent {
+
private CoverageTableModel model;
private Project project;
private static final String PREFERRED_ID = "CoverageReportTopComponent"; // NOI18N
@@ -90,11 +91,10 @@ final class CoverageReportTopComponent extends TopComponent {
// Pad out the cells a bit more - causes clipping so we have to increase
// the row height as well!
table.setIntercellSpacing(new Dimension(6, 4));
- table.setRowHeight(table.getRowHeight()+4);
+ table.setRowHeight(table.getRowHeight() + 4);
//Color color = table.getBackground();
//table.setGridColor(color.darker());
-
//table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
resizeColumnWidth(table);
@@ -136,7 +136,7 @@ final class CoverageReportTopComponent extends TopComponent {
//table.setAutoCreateRowSorter(true);
try {
// Try with reflection:
- Method method = JTable.class.getMethod("setAutoCreateRowSorter", new Class[] { Boolean.TYPE }); // NOI18N
+ Method method = JTable.class.getMethod("setAutoCreateRowSorter", new Class[]{Boolean.TYPE}); // NOI18N
if (method != null) {
method.invoke(table, Boolean.TRUE);
}
@@ -166,8 +166,10 @@ final class CoverageReportTopComponent extends TopComponent {
// for (int i = 0; i < 4; i++) {
// sorter.setComparator(i, comparableComparator);
// }
-
totalCoverage.setCoveragePercentage(model.getTotalCoverage());
+ FileCoverageSummary summary = model.getCoverageSummary();
+ totalCoverage.setStats(summary.getLineCount(), summary.getExecutedLineCount(),
+ summary.getPartialCount(), summary.getInferredCount());
}
public void resizeColumnWidth(JTable table) {
@@ -285,9 +287,9 @@ final class CoverageReportTopComponent extends TopComponent {
// JDK6 only...
// Try with reflection:
//row = table.convertRowIndexToModel(row);
- Method method = JTable.class.getMethod("convertRowIndexToModel", new Class[] { Integer.TYPE }); // NOI18N
+ Method method = JTable.class.getMethod("convertRowIndexToModel", new Class[]{Integer.TYPE}); // NOI18N
if (method != null) {
- row = (Integer)method.invoke(table, Integer.valueOf(row));
+ row = (Integer) method.invoke(table, Integer.valueOf(row));
}
} catch (InvocationTargetException ex) {
// No complaints - we may not be on JDK6
@@ -361,18 +363,22 @@ final class CoverageReportTopComponent extends TopComponent {
model = new CoverageTableModel(results);
table.setModel(model);
totalCoverage.setCoveragePercentage(model.getTotalCoverage());
+ FileCoverageSummary summary = model.getCoverageSummary();
+ totalCoverage.setStats(summary.getLineCount(), summary.getExecutedLineCount(),
+ summary.getPartialCount(), summary.getInferredCount());
resizeColumnWidth(table);
}
private static class CoverageTableModel implements TableModel {
+
List<FileCoverageSummary> results;
FileCoverageSummary total;
//List<TableModelListener> listeners = new ArrayList<TableModelListener>();
float totalCoverage = 0.0f;
public CoverageTableModel(List<FileCoverageSummary> results) {
- if (results == null || results.size() == 0) {
- results = new ArrayList<FileCoverageSummary>();
+ if (results == null || results.isEmpty()) {
+ results = new ArrayList<>();
} else {
Collections.sort(results);
}
@@ -388,30 +394,38 @@ final class CoverageReportTopComponent extends TopComponent {
partialCount += result.getPartialCount();
}
- if (results.size() == 0) {
+ if (results.isEmpty()) {
results.add(new FileCoverageSummary(null, NbBundle.getMessage(CoverageReportTopComponent.class, "NoData"), 0, 0, 0, 0));
} else {
- total = new FileCoverageSummary(null, "<html><b>" + // NOI18N
- NbBundle.getMessage(CoverageReportTopComponent.class, "Total") +
- "</b></html>", lineCount, executedLineCount, inferredCount, partialCount); // NOI18N
+ total = new FileCoverageSummary(null, "<html><b>"
+ + // NOI18N
+ NbBundle.getMessage(CoverageReportTopComponent.class, "Total")
+ + "</b></html>", lineCount, executedLineCount, inferredCount, partialCount); // NOI18N
totalCoverage = total.getCoveragePercentage();
results.add(total);
}
this.results = results;
}
+ FileCoverageSummary getCoverageSummary() {
+ return total;
+ }
+
float getTotalCoverage() {
return totalCoverage;
}
+ @Override
public int getRowCount() {
return results.size();
}
+ @Override
public int getColumnCount() {
return 4;
}
+ @Override
public String getColumnName(int col) {
switch (col) {
case 0:
@@ -427,6 +441,7 @@ final class CoverageReportTopComponent extends TopComponent {
}
}
+ @Override
public Class<?> getColumnClass(int col) {
switch (col) {
case 1:
@@ -441,10 +456,12 @@ final class CoverageReportTopComponent extends TopComponent {
}
}
+ @Override
public boolean isCellEditable(int row, int col) {
return false;
}
+ @Override
public Object getValueAt(int row, int col) {
FileCoverageSummary result = results.get(row);
switch (col) {
@@ -458,34 +475,41 @@ final class CoverageReportTopComponent extends TopComponent {
return result.getLineCount();
case 3:
//return result.getExecutedLineCount();
- return result.getLineCount()-result.getExecutedLineCount();
+ return result.getLineCount() - result.getExecutedLineCount();
default:
return null;
}
}
+ @Override
public void setValueAt(Object arg0, int arg1, int arg2) {
throw new UnsupportedOperationException("Not supported yet.");
}
+ @Override
public void addTableModelListener(TableModelListener listener) {
+ // nothing to do
}
+ @Override
public void removeTableModelListener(TableModelListener listener) {
+ // nothing to do
}
}
private static class FileRenderer extends JLabel implements TableCellRenderer {
+
@Override
public boolean isOpaque() {
return true;
}
+ @Override
public Component getTableCellRendererComponent(JTable table, Object value,
- boolean isSelected, boolean hasFocus, int row, int column) {
+ boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
- isSelected, hasFocus, row, column);
+ isSelected, hasFocus, row, column);
}
if (isSelected) {
@@ -511,7 +535,6 @@ final class CoverageReportTopComponent extends TopComponent {
setBorder(new EmptyBorder(1, 1, 1, 1));
}
-
FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
FileObject file = summary.getFile();
@@ -529,40 +552,41 @@ final class CoverageReportTopComponent extends TopComponent {
setIcon(null);
}
-
return this;
}
}
private class CoverageRenderer extends CoverageBar implements TableCellRenderer {
+
public CoverageRenderer() {
}
+ @Override
public Component getTableCellRendererComponent(JTable table, Object value,
- boolean isSelected, boolean hasFocus, int row, int column) {
+ boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null) {
return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
- isSelected, hasFocus, row, column);
+ isSelected, hasFocus, row, column);
}
// This doesn't work in the presence of table row sorting:
//boolean isTotalRow = row == table.getModel().getRowCount()-1;
FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
- boolean isTotalRow = summary == ((CoverageTableModel)table.getModel()).total;
+ boolean isTotalRow = summary == ((CoverageTableModel) table.getModel()).total;
setEmphasize(isTotalRow);
setSelected(isSelected);
float coverage = (Float) value;
setCoveragePercentage(coverage);
-
- //setStats(summary.getLineCount(), summary.getExecutedLineCount(),
- // summary.getInferredCount(), summary.getPartialCount());
+ setStats(summary.getLineCount(), summary.getExecutedLineCount(),
+ summary.getInferredCount(), summary.getPartialCount());
return this;
}
}
private static class EmptyPaintingTable extends JTable {
+
@Override
public boolean getScrollableTracksViewportHeight() {
return getParent() instanceof JViewport && getPreferredSize().height < getParent().getHeight();
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageSideBar.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageSideBar.java
index cc6acbb..51ef8a4 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageSideBar.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/CoverageSideBar.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.netbeans.modules.gsf.codecoverage;
import java.awt.Dimension;
@@ -37,11 +36,11 @@ import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
-import org.netbeans.editor.SideBarFactory;
import org.netbeans.modules.csl.spi.GsfUtilities;
import org.netbeans.modules.gsf.codecoverage.api.CoverageProvider;
import org.netbeans.modules.gsf.codecoverage.api.FileCoverageDetails;
import org.netbeans.modules.gsf.codecoverage.api.FileCoverageSummary;
+import org.netbeans.spi.editor.SideBarFactory;
import org.netbeans.spi.project.ActionProvider;
import org.openide.awt.Mnemonics;
import org.openide.filesystems.FileObject;
@@ -52,24 +51,27 @@ import org.openide.util.Lookup;
import org.openide.util.NbBundle;
/**
- * Editor footer for files while in code coverage mode: Show file coverage rate,
- * warnings about files being out of date, and quick buttons for enabling/disabling
- * highlights and clearing results.
+ * Editor footer for files while in code coverage mode: Show file coverage rate, warnings about
+ * files being out of date, and quick buttons for enabling/disabling highlights and clearing
+ * results.
* <p>
- * <b>NOTE</b>: You must compile this module before attempting to open this form
- * in the GUI builder! The design depends on the CoverageBar class and Matisse can
- * only load the form if the .class, not just the .java file, is available!
+ * <b>NOTE</b>: You must compile this module before attempting to open this form in the GUI builder!
+ * The design depends on the CoverageBar class and Matisse can only load the form if the .class, not
+ * just the .java file, is available!
*
* @author Tor Norbye
*/
public class CoverageSideBar extends javax.swing.JPanel {
+
private static final String COVERAGE_SIDEBAR_PROP = "coverageSideBar"; // NOI18N
private static final String COVERAGE_SIDEBAR_FOCUS = "coverageSideBarFocus"; // NOI18N
private static final String FOCUS_KEY_BINDING = "control shift F11";
private final FileObject fileForDocument;
private boolean enabled;
- /** Creates new form CoverageSideBar */
+ /**
+ * Creates new form CoverageSideBar
+ */
public CoverageSideBar(final JTextComponent target) {
Document document = target.getDocument();
fileForDocument = GsfUtilities.findFileObject(document);
@@ -109,7 +111,7 @@ public class CoverageSideBar extends javax.swing.JPanel {
}
public static CoverageSideBar getSideBar(JTextComponent target) {
- return (CoverageSideBar)target.getClientProperty(COVERAGE_SIDEBAR_PROP);
+ return (CoverageSideBar) target.getClientProperty(COVERAGE_SIDEBAR_PROP);
}
public void setCoverage(FileCoverageDetails details) {
@@ -120,8 +122,8 @@ public class CoverageSideBar extends javax.swing.JPanel {
if (coverage >= 0.0) {
coverageBar.setCoveragePercentage(coverage);
}
- //coverageBar.setStats(summary.getLineCount(), summary.getExecutedLineCount(),
- // summary.getInferredCount(), summary.getPartialCount());
+ coverageBar.setStats(summary.getLineCount(), summary.getExecutedLineCount(),
+ summary.getInferredCount(), summary.getPartialCount());
long dataModified = details.lastUpdated();
FileObject fo = details.getFile();
@@ -143,6 +145,7 @@ public class CoverageSideBar extends javax.swing.JPanel {
}
} else {
coverageBar.setCoveragePercentage(0.0f);
+ coverageBar.setStats(0, 0, 0, 0);
warningsLabel.setText("");
}
}
@@ -182,10 +185,9 @@ public class CoverageSideBar extends javax.swing.JPanel {
revalidate();
}
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
+ /**
+ * This method is called from within the constructor to initialize the form. WARNING: Do NOT
+ * modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -332,7 +334,7 @@ public class CoverageSideBar extends javax.swing.JPanel {
}
}
}
-
+
private String getAllTestAction() {
String action = ActionProvider.COMMAND_TEST;
CoverageProvider provider = getProvider();
@@ -341,7 +343,7 @@ public class CoverageSideBar extends javax.swing.JPanel {
}
return action;
}
-
+
private boolean isActionSupported(String action) {
Project project = getProject();
if (project != null) {
@@ -383,6 +385,8 @@ public class CoverageSideBar extends javax.swing.JPanel {
// End of variables declaration//GEN-END:variables
public static final class Factory implements SideBarFactory {
+
+ @Override
public JComponent createSideBar(JTextComponent target) {
return new CoverageSideBar(target);
}
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/CoverageType.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/CoverageType.java
index f6f9b05..0a66aac 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/CoverageType.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/CoverageType.java
@@ -20,7 +20,7 @@ package org.netbeans.modules.gsf.codecoverage.api;
/**
* Information about the type of coverage for a given line.
- *
+ *
* @author Tor Norbye
*/
public enum CoverageType {
@@ -33,22 +33,22 @@ public enum CoverageType {
*/
NOT_COVERED("Not Covered"),
/**
- * The line may have been touched, not sure. Typically, comments and whitespace
- * between executed statements fall into this category.
+ * The line may have been touched, not sure. Typically, comments and whitespace between executed
+ * statements fall into this category.
*/
INFERRED("Inferred"),
/**
- * Parts of the line were touched, and other parts were not. This happens
- * for example when you have conditional statements or multiple statements
- * on the line and not all parts were executed.
+ * Parts of the line were touched, and other parts were not. This happens for example when you
+ * have conditional statements or multiple statements on the line and not all parts were
+ * executed.
*/
PARTIAL("Partial"),
/**
* We have no information about this line
*/
UNKNOWN("Unknown");
-
- private String desc;
+
+ private final String desc;
private CoverageType(String desc) {
this.desc = desc;
diff --git a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/FileCoverageSummary.java b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/FileCoverageSummary.java
index 77ec36f..b27635e 100644
--- a/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/FileCoverageSummary.java
+++ b/ide/gsf.codecoverage/src/org/netbeans/modules/gsf/codecoverage/api/FileCoverageSummary.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.netbeans.modules.gsf.codecoverage.api;
import org.openide.filesystems.FileObject;
@@ -26,6 +25,7 @@ import org.openide.filesystems.FileObject;
* @author Tor Norbye
*/
public class FileCoverageSummary implements Comparable<FileCoverageSummary> {
+
private final FileObject file;
private final String displayName;
private final int lineCount;
@@ -40,13 +40,15 @@ public class FileCoverageSummary implements Comparable<FileCoverageSummary> {
* @param file The file we collected data from
* @param displayName A display name for the file (often the path itself)
* @param lineCount The total number of lines in the file
- * @param executedLineCount The total number of lines that were executed (including inferred and partial)
- * @param inferredCount The lines not recorded but inferred to be executed (such as comments and whitespace
- * between executed statements) Return 0 for "unknown/not recorded".
- * @param partialCount The lines that were partially executed. Return 0 for "unknown/not recorded".
+ * @param executedLineCount The total number of lines that were executed (including inferred and
+ * partial)
+ * @param inferredCount The lines not recorded but inferred to be executed (such as comments and
+ * whitespace between executed statements) Return 0 for "unknown/not recorded".
+ * @param partialCount The lines that were partially executed. Return 0 for "unknown/not
+ * recorded".
*/
public FileCoverageSummary(FileObject file, String displayName, int lineCount, int executedLineCount,
- int inferredCount, int partialCount) {
+ int inferredCount, int partialCount) {
this.file = file;
this.displayName = displayName;
this.lineCount = lineCount;
@@ -60,16 +62,19 @@ public class FileCoverageSummary implements Comparable<FileCoverageSummary> {
//return 100.0f;
return 0f;
} else {
- return (100.0f*executedLineCount)/lineCount;
+ return (100.0f * executedLineCount) / lineCount;
}
}
+ @Override
public int compareTo(FileCoverageSummary other) {
float cov = getCoveragePercentage();
float otherCov = other.getCoveragePercentage();
if (cov == otherCov) {
return 0;
- } else return cov < otherCov ? -1 : 1;
+ } else {
+ return cov < otherCov ? -1 : 1;
+ }
}
public FileObject getFile() {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists