This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 237233
Collapse All | Expand All

(-)a/api.debugger.jpda/apichanges.xml (+18 lines)
Lines 857-862 Link Here
857
        <issue number="228894"/>
857
        <issue number="228894"/>
858
    </change>
858
    </change>
859
859
860
    <change>
861
        <api name="JPDADebuggerAPI"/>
862
        <summary>Add a way to create mirror objects in the target VM and execute static methods.</summary>
863
        <version major="2" minor="47"/>
864
        <date day="24" month="10" year="2013"/>
865
        <author login="mentlicher"/>
866
        <compatibility addition="yes" source="compatible" binary="compatible"/>
867
        <description>
868
            createMirrorVar() methods are introduced in JPDADebugger class. They
869
            create a mirror object in the target virtual machine.
870
            <p/>
871
            Similar to invokeMethod() method on ObjectVariable, invokeMethod()
872
            is introduced on JPDAClassType for invocation of static methods.
873
        </description>
874
        <class package="org.netbeans.api.debugger.jpda" name="JPDADebugger" />
875
        <class package="org.netbeans.api.debugger.jpda" name="JPDAClassType" />
876
        <issue number="237233"/>
877
    </change>
860
878
861
</changes>
879
</changes>
862
880
(-)a/api.debugger.jpda/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.debugger.jpda/2
2
OpenIDE-Module: org.netbeans.api.debugger.jpda/2
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/debugger/jpda/Bundle.properties
4
OpenIDE-Module-Specification-Version: 2.46
4
OpenIDE-Module-Specification-Version: 2.47
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
5
OpenIDE-Module-Package-Dependencies: com.sun.jdi[VirtualMachineManager]
6
6
(-)a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDAClassType.java (+19 lines)
Lines 99-104 Link Here
99
    List<Field> staticFields();
99
    List<Field> staticFields();
100
    
100
    
101
    /**
101
    /**
102
     * Calls given static method in debugged JVM on this class and returns
103
     * its value.
104
     *
105
     * @param methodName a name of method to be called
106
     * @param signature a signature of method to be called
107
     * @param arguments arguments to be used
108
     *
109
     * @return value of given method call on this instance
110
     * @throws NoSuchMethodException when the method does not exist
111
     * @throws InvalidExpressionException in case of execution problems
112
     * @since 2.47
113
     */
114
    public abstract Variable invokeMethod (
115
        String methodName,
116
        String signature,
117
        Variable[] arguments
118
    ) throws NoSuchMethodException, InvalidExpressionException;
119
120
    /**
102
     * Retrieves the number of instances this class.
121
     * Retrieves the number of instances this class.
103
     * Use {@link JPDADebugger#canGetInstanceInfo} to determine if this operation is supported.
122
     * Use {@link JPDADebugger#canGetInstanceInfo} to determine if this operation is supported.
104
     * @return the number of instances.
123
     * @return the number of instances.
(-)a/api.debugger.jpda/src/org/netbeans/api/debugger/jpda/JPDADebugger.java (+27 lines)
Lines 51-56 Link Here
51
51
52
import java.beans.PropertyChangeListener;
52
import java.beans.PropertyChangeListener;
53
import java.io.File;
53
import java.io.File;
54
import java.io.InvalidObjectException;
54
import java.lang.annotation.ElementType;
55
import java.lang.annotation.ElementType;
55
import java.lang.annotation.Retention;
56
import java.lang.annotation.Retention;
56
import java.lang.annotation.RetentionPolicy;
57
import java.lang.annotation.RetentionPolicy;
Lines 594-599 Link Here
594
    }
595
    }
595
    
596
    
596
    /**
597
    /**
598
     * Create a mirror object in the target virtual machine
599
     * 
600
     * @param obj the object to create the mirror from
601
     * @return variable containing the mirror value
602
     * @throws InvalidObjectException when the mirror operation fails
603
     * @since 2.47
604
     */
605
    public Variable createMirrorVar(Object obj) throws InvalidObjectException {
606
        return createMirrorVar(obj, false);
607
    }
608
    
609
    /**
610
     * Create a mirror object in the target virtual machine
611
     * 
612
     * @param obj the object to create the mirror from
613
     * @param isPrimitive when <code>true</code> and the object is an encapsulation
614
     *                    of a primitive value, then primitive mirror is created.
615
     * @return variable containing the mirror value
616
     * @throws InvalidObjectException when the mirror operation fails
617
     * @since 2.47
618
     */
619
    public Variable createMirrorVar(Object obj, boolean isPrimitive) throws InvalidObjectException {
620
        throw new InvalidObjectException("Object "+obj+" not supported");
621
    }
622
    
623
    /**
597
     * Retrieves the number of instances of each class in the list.
624
     * Retrieves the number of instances of each class in the list.
598
     * Use {@link #canGetInstanceInfo} to determine if this operation is supported.
625
     * Use {@link #canGetInstanceInfo} to determine if this operation is supported.
599
     * @return an array of <code>long</code> containing one instance counts for
626
     * @return an array of <code>long</code> containing one instance counts for
(-)a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/MethodInvocationTest.java (+105 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.api.debugger.jpda;
44
45
import com.sun.jdi.ClassType;
46
import com.sun.jdi.ObjectReference;
47
import com.sun.jdi.StringReference;
48
import com.sun.jdi.Value;
49
import java.util.List;
50
import java.util.Properties;
51
import junit.framework.Test;
52
import org.netbeans.api.debugger.DebuggerManager;
53
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.modules.debugger.jpda.expr.JDIVariable;
55
56
/**
57
 *
58
 * @author Martin
59
 */
60
public class MethodInvocationTest extends NbTestCase {
61
    
62
    private JPDASupport     support;
63
    private DebuggerManager dm = DebuggerManager.getDebuggerManager ();
64
    
65
    public MethodInvocationTest(String s) {
66
        super(s);
67
    }
68
    
69
    public static Test suite() {
70
        return JPDASupport.createTestSuite(MethodInvocationTest.class);
71
    }
72
    
73
    public void testTargetMirrors() throws Exception {
74
        try {
75
            Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src") + 
76
                    "org/netbeans/api/debugger/jpda/testapps/MirrorValuesApp.java");
77
            LineBreakpoint lb = bp.getLineBreakpoints().get(0);
78
            dm.addBreakpoint (lb);
79
            
80
            support = JPDASupport.attach ("org.netbeans.api.debugger.jpda.testapps.MirrorValuesApp");
81
82
            support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit
83
            
84
            JPDADebugger debugger = support.getDebugger();
85
            
86
            List<JPDAClassType> systemClasses = debugger.getClassesByName("java.lang.System");
87
            assertEquals(systemClasses.size(), 1);
88
            JPDAClassType systemClass = systemClasses.get(0);
89
            Properties properties = System.getProperties();
90
            Variable propertiesVar = systemClass.invokeMethod("getProperties", "()Ljava/util/Properties;", new Variable[]{});
91
            Value pv = ((JDIVariable) propertiesVar).getJDIValue();
92
            assertTrue("Properties "+pv, (pv instanceof ObjectReference) &&
93
                                         Properties.class.getName().equals(((ClassType) pv.type()).name()));
94
            String userHomeProperty = properties.getProperty("user.home");
95
            Variable propVar = ((ObjectVariable) propertiesVar).invokeMethod("getProperty",
96
                    "(Ljava/lang/String;)Ljava/lang/String;",
97
                    new Variable[] { debugger.createMirrorVar("user.home") });
98
            Value p = ((JDIVariable) propVar).getJDIValue();
99
            assertTrue(p instanceof StringReference);
100
            assertEquals(userHomeProperty, ((StringReference) p).value());
101
        } finally {
102
            support.doFinish ();
103
        }
104
    }
105
}
(-)a/debugger.jpda/test/unit/src/org/netbeans/api/debugger/jpda/MirrorValuesTest.java (+42 lines)
Lines 41-46 Link Here
41
 */
41
 */
42
package org.netbeans.api.debugger.jpda;
42
package org.netbeans.api.debugger.jpda;
43
43
44
import com.sun.jdi.ClassType;
45
import com.sun.jdi.IntegerValue;
46
import com.sun.jdi.StringReference;
47
import com.sun.jdi.Value;
44
import java.awt.Color;
48
import java.awt.Color;
45
import java.awt.Point;
49
import java.awt.Point;
46
import java.beans.FeatureDescriptor;
50
import java.beans.FeatureDescriptor;
Lines 58-63 Link Here
58
import junit.framework.Test;
62
import junit.framework.Test;
59
import org.netbeans.api.debugger.DebuggerManager;
63
import org.netbeans.api.debugger.DebuggerManager;
60
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.junit.NbTestCase;
65
import org.netbeans.modules.debugger.jpda.expr.JDIVariable;
61
import org.openide.util.Exceptions;
66
import org.openide.util.Exceptions;
62
67
63
/**
68
/**
Lines 223-228 Link Here
223
        
228
        
224
    }
229
    }
225
    
230
    
231
    public void testTargetMirrors() throws Exception {
232
        try {
233
            Utils.BreakPositions bp = Utils.getBreakPositions(System.getProperty ("test.dir.src") + 
234
                    "org/netbeans/api/debugger/jpda/testapps/MirrorValuesApp.java");
235
            LineBreakpoint lb = bp.getLineBreakpoints().get(0);
236
            dm.addBreakpoint (lb);
237
            
238
            support = JPDASupport.attach (CLASS_NAME);
239
240
            support.waitState (JPDADebugger.STATE_STOPPED);  // breakpoint hit
241
            
242
            JPDADebugger debugger = support.getDebugger();
243
            
244
            Variable mirrorVar = debugger.createMirrorVar("Test");
245
            Value v = ((JDIVariable) mirrorVar).getJDIValue();
246
            assertTrue("Value "+v+" should be a String", v instanceof StringReference);
247
            assertEquals("Test", ((StringReference) v).value());
248
            
249
            Point p = new Point(-1, 1);
250
            mirrorVar = debugger.createMirrorVar(p);
251
            Object mp = mirrorVar.createMirrorObject();
252
            assertTrue("Correct point was created: "+mp, p.equals(mp));
253
            
254
            mirrorVar = debugger.createMirrorVar(1);
255
            v = ((JDIVariable) mirrorVar).getJDIValue();
256
            assertTrue("Value "+v+" should be an Integer object.",
257
                       (v.type() instanceof ClassType) && Integer.class.getName().equals(((ClassType) v.type()).name()));
258
            
259
            mirrorVar = debugger.createMirrorVar(1, true);
260
            v = ((JDIVariable) mirrorVar).getJDIValue();
261
            assertTrue("Value "+v+" should be an int.", v instanceof IntegerValue);
262
            assertEquals(((IntegerValue) v).value(), 1);
263
        } finally {
264
            support.doFinish ();
265
        }
266
    }
267
    
226
    private static boolean compareArrays(Object arr1, Object arr2) {
268
    private static boolean compareArrays(Object arr1, Object arr2) {
227
        if (arr1 instanceof Object[]) {
269
        if (arr1 instanceof Object[]) {
228
            return Arrays.deepEquals((Object[]) arr1, (Object[]) arr2);
270
            return Arrays.deepEquals((Object[]) arr1, (Object[]) arr2);

Return to bug 237233