1 /*
2  * Breakpoint.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 package org.rstudio.studio.client.common.debugging.model;
17 
18 import com.google.gwt.core.client.JavaScriptObject;
19 
20 // This class represents a breakpoint in nearly every context:
21 // instances are used in the editor (AceEditorWidget), in the breakpoint manager
22 // (BreakpointManager), and are also persisted raw in the project state
23 // (BreakpointState).
24 public class Breakpoint extends JavaScriptObject
25 {
Breakpoint()26    protected Breakpoint() {}
27 
28    // Syntactically an enum would be preferable here but GWT enum wrappers
29    // don't serialize well inside native JS objects. Do not change these values;
30    // they are persisted in project storage.
31    public final static int STATE_PROCESSING = 0;
32    public final static int STATE_ACTIVE = 1;
33    public final static int STATE_INACTIVE = 2;
34    public final static int STATE_REMOVING = 3;
35 
36    public final static int TYPE_FUNCTION = 0;
37    public final static int TYPE_TOPLEVEL = 1;
38 
create( int breakpointId, String path, String functionName, int lineNumber, int initialState, int type)39    public native static Breakpoint create(
40          int breakpointId,
41          String path,
42          String functionName,
43          int lineNumber,
44          int initialState,
45          int type)
46    /*-{
47       return {
48          id : breakpointId,
49          path : path.trim(),
50          line_number : lineNumber,
51          function_steps : "",
52          function_name : functionName,
53          state : initialState,
54          editor_state: initialState,
55          editor_line_number: lineNumber,
56          is_pending_debug_completion: false,
57          needs_updated_steps: false,
58          type: type,
59          is_package_breakpoint: false,
60          package_name: ""
61       };
62    }-*/;
63 
addFunctionSteps( String function_name, int lineNumber, String functionSteps)64    public final native void addFunctionSteps(
65          String function_name,
66          int lineNumber,
67          String functionSteps)
68    /*-{
69       this.function_name = function_name;
70       this.line_number = lineNumber;
71       this.function_steps = functionSteps;
72    }-*/;
73 
getBreakpointId()74    public final native int getBreakpointId()
75    /*-{
76       return this.id;
77    }-*/;
78 
getLineNumber()79    public final native int getLineNumber()
80    /*-{
81       return this.line_number;
82    }-*/;
83 
getFunctionName()84    public final native String getFunctionName()
85    /*-{
86       return this.function_name;
87    }-*/;
88 
getFunctionSteps()89    public final native String getFunctionSteps()
90    /*-{
91       return this.function_steps;
92    }-*/;
93 
getState()94    public final native int getState()
95    /*-{
96       return this.state;
97    }-*/;
98 
setState(int state)99    public final native void setState (int state)
100    /*-{
101       this.state = state;
102       // when the breakpoint becomes active, clear the flag indicating that
103       // it needs updating
104       if (this.state == 1)
105       {
106          this.needs_updated_steps = false;
107       }
108    }-*/;
109 
getEditorState()110    public final native int getEditorState()
111    /*-{
112       return this.editor_state;
113    }-*/;
114 
setEditorState(int state)115    public final native void setEditorState (int state)
116    /*-{
117       this.editor_state = state;
118    }-*/;
119 
getEditorLineNumber()120    public final native int getEditorLineNumber()
121    /*-{
122       return this.editor_line_number;
123    }-*/;
124 
setEditorLineNumber(int lineNumber)125    public final native void setEditorLineNumber(int lineNumber)
126    /*-{
127       this.editor_line_number = lineNumber;
128    }-*/;
129 
moveToLineNumber(int lineNumber)130    public final native void moveToLineNumber(int lineNumber)
131    /*-{
132      this.line_number = lineNumber;
133      this.editor_line_number = lineNumber;
134    }-*/;
135 
isPendingDebugCompletion()136    public final native boolean isPendingDebugCompletion()
137    /*-{
138      return this.is_pending_debug_completion;
139    }-*/;
140 
setPendingDebugCompletion(boolean pending)141    public final native boolean setPendingDebugCompletion(boolean pending)
142    /*-{
143      this.is_pending_debug_completion = pending;
144    }-*/;
145 
needsUpdatedSteps()146    public final native boolean needsUpdatedSteps()
147    /*-{
148      return this.needs_updated_steps;
149    }-*/;
150 
markStepsNeedUpdate()151    public final native void markStepsNeedUpdate()
152    /*-{
153       this.needs_updated_steps = true;
154    }-*/;
155 
isInFile(String filename)156    public final native boolean isInFile(String filename)
157    /*-{
158       return this.path == filename;
159    }-*/;
160 
isInPath(String path)161    public final native boolean isInPath(String path)
162    /*-{
163       return this.path.indexOf(path) == 0;
164    }-*/;
165 
getPath()166    public final native String getPath()
167    /*-{
168      return this.path;
169    }-*/;
170 
getType()171    public final native int getType()
172    /*-{
173       return this.type;
174    }-*/;
175 
getPackageName()176    public final native String getPackageName() /*-{
177       return this.package_name;
178    }-*/;
179 
isPackageBreakpoint()180    public final native boolean isPackageBreakpoint() /*-{
181       return this.is_package_breakpoint;
182    }-*/;
183 
markAsPackageBreakpoint(String packageName)184    public final native void markAsPackageBreakpoint(String packageName) /*-{
185       this.is_package_breakpoint = true;
186       this.package_name = packageName;
187    }-*/;
188 }
189