Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 246819 | Differences between
and this patch

Collapse All | Expand All

(-)a/api.debugger.jpda/src/org/netbeans/spi/debugger/jpda/EditorContext.java (-2 / +38 lines)
 Lines 373-379    Link Here 
373
                                                    int bytecodeIndex) {
373
                                                    int bytecodeIndex) {
374
        return new Operation(startPosition, endPosition,
374
        return new Operation(startPosition, endPosition,
375
                             methodStartPosition, methodEndPosition,
375
                             methodStartPosition, methodEndPosition,
376
                             methodName, methodClassType, bytecodeIndex);
376
                             methodName, methodClassType, bytecodeIndex, false);
377
    }
378
    
379
    /**
380
     * Creates a method operation.
381
     * @param startPosition The starting position of the operation
382
     * @param endPosition The ending position of the operation
383
     * @param methodStartPosition The starting position of the method name
384
     * @param methodEndPosition The ending position of the method name
385
     * @param methodName The string representation of the method name
386
     * @param methodClassType The class type, which defines this method
387
     * @param bytecodeIndex The bytecode index of this method call
388
     * @param isNative <code>true</code> when the method is determined as a native
389
     *                 method by the parser.
390
     */
391
    protected final Operation createMethodOperation(Position startPosition,
392
                                                    Position endPosition,
393
                                                    Position methodStartPosition,
394
                                                    Position methodEndPosition,
395
                                                    String methodName,
396
                                                    String methodClassType,
397
                                                    int bytecodeIndex,
398
                                                    boolean isNative) {
399
        return new Operation(startPosition, endPosition,
400
                             methodStartPosition, methodEndPosition,
401
                             methodName, methodClassType, bytecodeIndex,
402
                             isNative);
377
    }
403
    }
378
    
404
    
379
    /**
405
    /**
 Lines 502-507    Link Here 
502
        private String methodDescriptor; // TODO: Add API get/set, accessed through reflection in the meantime.
528
        private String methodDescriptor; // TODO: Add API get/set, accessed through reflection in the meantime.
503
        private String methodClassType;
529
        private String methodClassType;
504
        private Variable returnValue;
530
        private Variable returnValue;
531
        private boolean isNative;
505
        
532
        
506
        private List<Operation> nextOperations;
533
        private List<Operation> nextOperations;
507
        
534
        
 Lines 520-526    Link Here 
520
        Operation(Position startPosition, Position endPosition,
547
        Operation(Position startPosition, Position endPosition,
521
                  Position methodStartPosition, Position methodEndPosition,
548
                  Position methodStartPosition, Position methodEndPosition,
522
                  String methodName, String methodClassType,
549
                  String methodName, String methodClassType,
523
                  int bytecodeIndex) {
550
                  int bytecodeIndex, boolean isNative) {
524
            this.startPosition = startPosition;
551
            this.startPosition = startPosition;
525
            this.endPosition = endPosition;
552
            this.endPosition = endPosition;
526
            this.bytecodeIndex = bytecodeIndex;
553
            this.bytecodeIndex = bytecodeIndex;
 Lines 528-533    Link Here 
528
            this.methodEndPosition = methodEndPosition;
555
            this.methodEndPosition = methodEndPosition;
529
            this.methodName = methodName;
556
            this.methodName = methodName;
530
            this.methodClassType = methodClassType;
557
            this.methodClassType = methodClassType;
558
            this.isNative = isNative;
531
        }
559
        }
532
        
560
        
533
        synchronized void addNextOperation(Operation next) {
561
        synchronized void addNextOperation(Operation next) {
 Lines 580-585    Link Here 
580
        }
608
        }
581
        
609
        
582
        /**
610
        /**
611
         * Indicates whether the method was determined as native by the parser.
612
         * @return 
613
         */
614
        public boolean isNative() {
615
            return isNative;
616
        }
617
        
618
        /**
583
         * Get the bytecode index of this operation.
619
         * Get the bytecode index of this operation.
584
         */
620
         */
585
        public int getBytecodeIndex() {
621
        public int getBytecodeIndex() {
(-)a/api.debugger/src/org/netbeans/api/debugger/SessionBridge.java (+178 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 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 2014 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.api.debugger;
44
45
import java.beans.Customizer;
46
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
48
import java.util.ArrayList;
49
import java.util.Collections;
50
import java.util.HashMap;
51
import java.util.HashSet;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Set;
55
import java.util.concurrent.CopyOnWriteArraySet;
56
57
/**
58
 * Bridge between sessions.
59
 * 
60
 * @author Martin Entlicher
61
 */
62
public final class SessionBridge {
63
    
64
    private static SessionBridge instance;
65
    
66
    private final Map<String, Set<SessionChanger>> sessionChangers = new HashMap<String, Set<SessionChanger>>();
67
    private final List<SessionChanger> lookupSessionChangers;
68
    
69
    private SessionBridge() {
70
        Lookup lookup = new Lookup.MetaInf(null);
71
        final List<? extends SessionChanger> scList = lookup.lookup(null, SessionChanger.class);
72
        ((Customizer) scList).addPropertyChangeListener(new PropertyChangeListener() {
73
            @Override
74
            public void propertyChange(PropertyChangeEvent evt) {
75
                for (SessionChanger sc : lookupSessionChangers) {
76
                    removeSessionChangerListener(sc);
77
                }
78
                lookupSessionChangers.clear();
79
                for (SessionChanger sc : scList) {
80
                    lookupSessionChangers.add(sc);
81
                    addSessionChangerListener(sc);
82
                }
83
            }
84
        });
85
        lookupSessionChangers = new ArrayList<SessionChanger>();
86
        for (SessionChanger sc : scList) {
87
            lookupSessionChangers.add(sc);
88
            addSessionChangerListener(sc);
89
        }
90
    }
91
    
92
    /**
93
     * Get the default instance of SessionBridge.
94
     * @return the default instance
95
     */
96
    public static synchronized SessionBridge getDefault() {
97
        if (instance == null) {
98
            instance = new SessionBridge();
99
        }
100
        return instance;
101
    }
102
    
103
    /**
104
     * Suggest a session change to perform a particular action.
105
     * @param origin The original session suggesting the session change
106
     * @param action An action - a constant from ActionsManager.Action_*
107
     * @param properties Properties describing the current state of the current session before the given action.
108
     *                   The actual properties are specific for the particular session type.
109
     * @return <code>true</code> when the session is changed and another session
110
     *         decided to perform the given action. The call-back will be called later on.<br/>
111
     *         <code>false</code> when no other session would like to perform this action.
112
     */
113
    public boolean suggestChange(Session origin, String action, Map<Object, Object> properties) {
114
        Set<SessionChanger> scs;
115
        synchronized (sessionChangers) {
116
            scs = sessionChangers.get(action);
117
        }
118
        if (scs != null) {
119
            for (SessionChanger sc : scs) {
120
                Session newSession = sc.changeSuggested(origin, action, properties);
121
                if (newSession != null) {
122
                    if (DebuggerManager.getDebuggerManager().getCurrentSession() == origin) {
123
                        DebuggerManager.getDebuggerManager().setCurrentSession(newSession);
124
                    }
125
                    return true;
126
                }
127
            }
128
        }
129
        return false;
130
    }
131
    
132
    private void addSessionChangerListener(SessionChanger sc) {
133
        Set<String> actions = sc.getActions();
134
        synchronized (sessionChangers) {
135
            for (String action : actions) {
136
                Set<SessionChanger> scs = sessionChangers.get(action);
137
                if (scs == null) {
138
                    sessionChangers.put(action, Collections.singleton(sc));
139
                } else {
140
                    if (scs.size() == 1) {
141
                        SessionChanger old = scs.iterator().next();
142
                        scs = new CopyOnWriteArraySet<SessionChanger>();
143
                        scs.add(old);
144
                    }
145
                    scs.add(sc);
146
                }
147
            }
148
        }
149
    }
150
    
151
    private void removeSessionChangerListener(SessionChanger sc) {
152
        Set<String> actions = sc.getActions();
153
        synchronized (sessionChangers) {
154
            for (String action : actions) {
155
                Set<SessionChanger> scs = sessionChangers.get(action);
156
                if (scs == null) {
157
                    continue;
158
                }
159
                if (scs.size() == 1) {
160
                    SessionChanger old = scs.iterator().next();
161
                    if (sc.equals(old)) {
162
                        sessionChangers.remove(action);
163
                    }
164
                } else {
165
                    scs.remove(sc);
166
                }
167
            }
168
        }
169
    }
170
    
171
    public static interface SessionChanger {
172
        
173
        Set<String> getActions();
174
        
175
        Session changeSuggested(Session origin, String action, Map<Object, Object> properties);
176
    }
177
    
178
}

Return to bug 246819
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo