[hg] main-silver: #109831: Show conditions in breakpoint annotat...

  • From:
  • To:
  • Subject: [hg] main-silver: #109831: Show conditions in breakpoint annotat...
  • Date: Sun, 31 Mar 2013 04:41:22 -0700

changeset 2bb02f1ef298 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/2bb02f1ef298
description:
        #109831: Show conditions in breakpoint annotation tooltip. Patch 
provided by markiewb.

diffstat:

 
debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java
               |   34 +-
 
debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/Bundle.properties
                               |    6 +
 
debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotation.java
               |   57 ++-
 
debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
                          |    5 +-
 
debugger.jpda.projects/test/unit/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotationTest.java
 |  205 ++++++++++
 5 files changed, 290 insertions(+), 17 deletions(-)

diffs (383 lines):

diff --git 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java
 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java
--- 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java
+++ 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/BreakpointAnnotationProvider.java
@@ -531,19 +531,8 @@
         if (lines == null || lines.length == 0) {
             return ;
         }
-        String condition;
-        if (b instanceof LineBreakpoint) {
-            condition = ((LineBreakpoint) b).getCondition();
-        } else if (b instanceof FieldBreakpoint) {
-            condition = ((FieldBreakpoint) b).getCondition();
-        } else if (b instanceof MethodBreakpoint) {
-            condition = ((MethodBreakpoint) b).getCondition();
-        } else if (b instanceof ClassLoadUnloadBreakpoint) {
-            condition = null;
-        } else {
-            throw new IllegalStateException(b.toString());
-        }
-        boolean isConditional = (condition != null) && 
condition.trim().length() > 0;
+        String condition = getCondition(b);
+        boolean isConditional = condition.trim().length() > 0;
         String annotationType = getAnnotationType(b, isConditional, 
breakpointsActive);
         DataObject dataObject;
         try {
@@ -589,6 +578,25 @@
         }
     }
     
+    /**
+     * Gets the condition of a breakpoint.
+     * @param b The breakpoint
+     * @return The condition or empty {@link String} if no condition is 
supported.
+     */
+    static String getCondition(JPDABreakpoint b) {
+        if (b instanceof LineBreakpoint) {
+            return ((LineBreakpoint) b).getCondition();
+        } else if (b instanceof FieldBreakpoint) {
+            return ((FieldBreakpoint) b).getCondition();
+        } else if (b instanceof MethodBreakpoint) {
+            return ((MethodBreakpoint) b).getCondition();
+        } else if (b instanceof ClassLoadUnloadBreakpoint) {
+            return "";
+        } else {
+            throw new IllegalStateException(b.toString());
+        }
+    }
+    
     /*
     // Not used
     @Override
diff --git 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/Bundle.properties
 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/Bundle.properties
--- 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/Bundle.properties
+++ 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/Bundle.properties
@@ -66,6 +66,12 @@
 TOOLTIP_CLASS_BREAKPOINT=Class Breakpoint
 TOOLTIP_DISABLED_CLASS_BREAKPOINT=Disabled Class Breakpoint
 TOOLTIP_BREAKPOINT_STROKE=Deactivated breakpoint
+# A condition expression follows this message on a next line
+TOOLTIP_CONDITION=Hits when:
+# {0} - a number
+TOOLTIP_HITCOUNT_EQUAL=Hit count \= {0}
+TOOLTIP_HITCOUNT_GREATER=Hit count > {0}
+TOOLTIP_HITCOUNT_MULTIPLE=Hit count is multiple of {0}
 
 #SourcesNodeModel
 CTL_SourcesModel_Column_Name_LibrarySources = {0}
diff --git 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotation.java
 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotation.java
--- 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotation.java
+++ 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotation.java
@@ -44,7 +44,11 @@
 
 package org.netbeans.modules.debugger.jpda.projects;
 
+import java.util.LinkedList;
+import java.util.List;
 import org.netbeans.api.debugger.Breakpoint;
+import org.netbeans.api.debugger.Breakpoint.HIT_COUNT_FILTERING_STYLE;
+import org.netbeans.api.debugger.jpda.JPDABreakpoint;
 import org.netbeans.spi.debugger.jpda.EditorContext;
 import org.netbeans.spi.debugger.ui.BreakpointAnnotation;
 
@@ -62,10 +66,10 @@
 
     private final Line        line;
     private final String      type;
-    private final Breakpoint  breakpoint;
+    private final JPDABreakpoint breakpoint;
 
 
-    DebuggerBreakpointAnnotation (String type, Line line, Breakpoint 
breakpoint) {
+    DebuggerBreakpointAnnotation (String type, Line line, JPDABreakpoint 
breakpoint) {
         this.type = type;
         this.line = line;
         this.breakpoint = breakpoint;
@@ -83,6 +87,55 @@
     
     @Override
     public String getShortDescription () {
+
+        List<String> list = new LinkedList<String>();
+        //add condition if available
+        String condition = 
BreakpointAnnotationProvider.getCondition(breakpoint);
+        if (!condition.trim().isEmpty()) {
+            list.add(condition);
+        }
+
+        // add hit count if available
+        HIT_COUNT_FILTERING_STYLE hitCountFilteringStyle = 
breakpoint.getHitCountFilteringStyle();
+        if (null != hitCountFilteringStyle) {
+            int hcf = breakpoint.getHitCountFilter();
+            String tooltip;
+            switch (hitCountFilteringStyle) {
+                case EQUAL:
+                    tooltip = 
NbBundle.getMessage(DebuggerBreakpointAnnotation.class, 
"TOOLTIP_HITCOUNT_EQUAL", hcf);
+                    break;
+                case GREATER:
+                    tooltip = 
NbBundle.getMessage(DebuggerBreakpointAnnotation.class, 
"TOOLTIP_HITCOUNT_GREATER", hcf);
+                    break;
+                case MULTIPLE:
+                    tooltip = 
NbBundle.getMessage(DebuggerBreakpointAnnotation.class, 
"TOOLTIP_HITCOUNT_MULTIPLE", hcf);
+                    break;
+                default:
+                    throw new IllegalStateException("Unknown 
HitCountFilteringStyle: "+hitCountFilteringStyle);
+            }
+            list.add(tooltip);
+        }
+
+        String shortDesc = getShortDescriptionIntern();
+        if (list.isEmpty()) {
+            return shortDesc;
+        }
+        StringBuilder result = new StringBuilder();
+        if (null != shortDesc) {
+            result.append(shortDesc);
+        }
+        //append more information
+        result.append("\n");
+        
result.append(NbBundle.getMessage(DebuggerBreakpointAnnotation.class, 
"TOOLTIP_CONDITION"));
+        for (String text : list) {
+            result.append("\n");
+            result.append(text);
+        }
+
+        return result.toString();
+    }
+
+    private String getShortDescriptionIntern () {
         if (type.endsWith("_broken")) {
             if (breakpoint.getValidity() == Breakpoint.VALIDITY.INVALID) {
                 String msg = breakpoint.getValidityMessage();
diff --git 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
--- 
a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
+++ 
b/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java
@@ -113,6 +113,7 @@
 import org.netbeans.api.debugger.Properties;
 import org.netbeans.api.debugger.Session;
 import org.netbeans.api.debugger.jpda.InvalidExpressionException;
+import org.netbeans.api.debugger.jpda.JPDABreakpoint;
 import org.netbeans.api.debugger.jpda.JPDAThread;
 import org.netbeans.api.debugger.jpda.LineBreakpoint;
 
@@ -327,8 +328,8 @@
             return null;
         }
         Annotation annotation;
-        if (timeStamp instanceof Breakpoint) {
-            annotation = new DebuggerBreakpointAnnotation(annotationType, l, 
(Breakpoint) timeStamp);
+        if (timeStamp instanceof JPDABreakpoint) {
+            annotation = new DebuggerBreakpointAnnotation(annotationType, l, 
(JPDABreakpoint) timeStamp);
         } else {
             annotation = new DebuggerAnnotation (annotationType, l, thread);
         }
diff --git 
a/debugger.jpda.projects/test/unit/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotationTest.java
 
b/debugger.jpda.projects/test/unit/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotationTest.java
new file mode 100644
--- /dev/null
+++ 
b/debugger.jpda.projects/test/unit/src/org/netbeans/modules/debugger/jpda/projects/DebuggerBreakpointAnnotationTest.java
@@ -0,0 +1,205 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Oracle
+ * Portions Copyrighted 2013 

+ */
+package org.netbeans.modules.debugger.jpda.projects;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.netbeans.api.debugger.Breakpoint;
+import org.netbeans.api.debugger.jpda.FieldBreakpoint;
+import org.netbeans.api.debugger.jpda.LineBreakpoint;
+import org.netbeans.api.debugger.jpda.MethodBreakpoint;
+import org.netbeans.spi.debugger.jpda.EditorContext;
+import org.openide.text.Line;
+import org.openide.util.Lookup;
+
+/**
+ *
+ * @author 

+ */
+public class DebuggerBreakpointAnnotationTest {
+
+    private LineBreakpoint breakpoint;
+
+    @Before
+    public void setUp () {
+        breakpoint = LineBreakpoint.create("", 2);
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_None () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        assertEquals("Conditional Breakpoint", sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_HitCount_Equal () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setHitCountFilter(42, 
Breakpoint.HIT_COUNT_FILTERING_STYLE.EQUAL);
+
+        assertEquals("Conditional Breakpoint\nHits when:\nHit count = 42", 
sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_HitCount_Greater () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setHitCountFilter(42, 
Breakpoint.HIT_COUNT_FILTERING_STYLE.GREATER);
+
+        assertEquals("Conditional Breakpoint\nHits when:\nHit count > 42", 
sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_HitCount_MultipleOf () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setHitCountFilter(2, 
Breakpoint.HIT_COUNT_FILTERING_STYLE.MULTIPLE);
+
+        assertEquals("Conditional Breakpoint\nHits when:\nHit count is 
multiple of 2", sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_Code_Null () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setCondition(null);
+
+        assertEquals("Conditional Breakpoint", sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_Code_NotNull () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setCondition("a==6");
+
+        assertEquals("Conditional Breakpoint\nHits when:\na==6", 
sut.getShortDescription());
+    }
+
+    @Test
+    public void testGetShortDescription_Condition_Multiple () {
+        DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+        breakpoint.setCondition("a==6");
+        breakpoint.setHitCountFilter(42, 
Breakpoint.HIT_COUNT_FILTERING_STYLE.EQUAL);
+
+        assertEquals("Conditional Breakpoint\nHits when:\na==6\nHit count = 
42", sut.getShortDescription());
+    }
+
+    /**
+     * Test whether {@link FieldBreakpoint}, {@link MethodBreakpoint} and 
{@link
+     * LineBreakpoint} are supported. Tests the {@link 
DebuggerBreakpointAnnotation#getCondition(org.netbeans.api.debugger.Breakpoint)}
 too.
+     */
+    @Test
+    public void testGetShortDescription_Condition_SupportedBreakpointTypes 
() {
+        {
+            FieldBreakpoint b = FieldBreakpoint.create(
+                    "org.netbeans.modules.editor.EditorPanel",
+                    "state",
+                    FieldBreakpoint.TYPE_MODIFICATION);
+            DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), b);
+            b.setCondition("a==6");
+            assertEquals("Conditional Breakpoint\nHits when:\na==6", 
sut.getShortDescription());
+        }
+        {
+            MethodBreakpoint b = MethodBreakpoint.create(
+                    "org.netbeans.modules.editor.EditorPanel",
+                    "state");
+            DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), b);
+            b.setCondition("a==6");
+
+            assertEquals("Conditional Breakpoint\nHits when:\na==6", 
sut.getShortDescription());
+
+        }
+        {
+            DebuggerBreakpointAnnotation sut = new 
DebuggerBreakpointAnnotation((EditorContext.CONDITIONAL_BREAKPOINT_ANNOTATION_TYPE),
 new LineMock(), breakpoint);
+            breakpoint.setCondition("a==6");
+
+            assertEquals("Conditional Breakpoint\nHits when:\na==6", 
sut.getShortDescription());
+
+        }
+
+    }
+
+    private static class LineMock extends Line {
+
+        public LineMock () {
+            super(Lookup.EMPTY);
+        }
+
+        @Override
+        public int getLineNumber () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void show (int kind, int column) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void setBreakpoint (boolean b) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public boolean isBreakpoint () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void markError () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void unmarkError () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void markCurrentLine () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        @Override
+        public void unmarkCurrentLine () {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+    }
+}

[hg] main-silver: #109831: Show conditions in breakpoint annotat...

mentlicher 03/31/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close