Netbeans Support for Tcl

Check-in [55a3ad0bc1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Changed: [info vars] is now splited to [info locals] and [info globals]. VariablesView adapted to locals and globals. Added support for displaying arrays in VariablesView.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 55a3ad0bc17081d9bbc154f5773e0a17146f67d7
User & Date: dmp 2011-07-28 14:50:15
Original Comment: Changed: [[info vars]] is now splited to [[info locals]] and [[info globals]]. VariablesView adapted to locals and globals. Added support for displaying arrays in VariablesView.
Context
2011-07-29
21:54
Fixed "current directory" in debug mode (previously set to projectDirectory, now it's a parent directory for tclRunFile). Added "cd" to proper one directory for "Run" functionality. check-in: 7f7480a2a4 user: dmp tags: trunk
2011-07-28
14:50
Changed: [info vars] is now splited to [info locals] and [info globals]. VariablesView adapted to locals and globals. Added support for displaying arrays in VariablesView. check-in: 55a3ad0bc1 user: dmp tags: trunk
00:54
Added new package org.netbeans.modules.languages.tcl.debugger.variables to handle VariablesView. Includes NameColumn, TclVariable and the most important TclVariablesModel. Also TclDebuggerActionsProvider is now registered via META-INF/ to be available for TclVariablesModel class and for general comunication with TclDebuggerJavaPart. debugServer.tcl upgraded to serve [info vars]. check-in: 689e69ec6f user: dmp tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to TclPlugin/src/org/netbeans/modules/languages/tcl/debugger/TclDebuggerJavaPart.java.

29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
	private File currentFile;
	private int currentLineNumber;
	ClientToTclPart tclPart=null;
	private TclDebuggerEngineProvider engineProvider;
	private File tclPartFile=null;
	private final String tclPartFileName="debugServer.tcl";
	private int tclPartPortNumber=31337;
	private String variablesString=null;

	private ModelListener modelListener=null;

	public void addModelListener( ModelListener ml ) {
		//System.out.println("addModelListner inside TclDebuggerJavaPart : "+ml);
		this.modelListener = ml;
	}








|
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	private File currentFile;
	private int currentLineNumber;
	ClientToTclPart tclPart=null;
	private TclDebuggerEngineProvider engineProvider;
	private File tclPartFile=null;
	private final String tclPartFileName="debugServer.tcl";
	private int tclPartPortNumber=31337;
	private String variablesStringLocals="";
	private String variablesStringGlobals="";
	private ModelListener modelListener=null;

	public void addModelListener( ModelListener ml ) {
		//System.out.println("addModelListner inside TclDebuggerJavaPart : "+ml);
		this.modelListener = ml;
	}

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135








136
137
138
139
140
141
142
			String fileName=tclPart.nextLineFromFromSocket();
			currentFile=new File( fileName );

			// get second line → line in file
			currentLineNumber=Integer.parseInt( tclPart.nextLineFromFromSocket() );
			programCounter.modify();

			// get third line → number of variablesString
			int numberOfVariables=Integer.parseInt( tclPart.nextLineFromFromSocket() );
			variablesString = "";

			// every following numberOfVariables line contains name nad value of variable
			for( int i=1; i <= numberOfVariables; i++ ) {
				variablesString += tclPart.nextLineFromFromSocket()+"\n";
			}









			updateTclVariablesModel();
			
		} catch( NoSuchElementException e ) {
			System.out.println( ">>> End of debugging…" );
			actionKill();
		}
		







|

|



|


>
>
>
>
>
>
>
>







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
			String fileName=tclPart.nextLineFromFromSocket();
			currentFile=new File( fileName );

			// get second line → line in file
			currentLineNumber=Integer.parseInt( tclPart.nextLineFromFromSocket() );
			programCounter.modify();

			// get third line → number of variablesStringLocals
			int numberOfVariables=Integer.parseInt( tclPart.nextLineFromFromSocket() );
			variablesStringLocals = "";

			// every following numberOfVariables line contains name nad value of variable
			for( int i=1; i <= numberOfVariables; i++ ) {
				variablesStringLocals += tclPart.nextLineFromFromSocket()+"\n";
			}

			// get next line → number of variablesStringGlobals
			numberOfVariables=Integer.parseInt( tclPart.nextLineFromFromSocket() );
			variablesStringGlobals = "";
			// every following numberOfVariables line contains name nad value of variable
			for( int i=1; i <= numberOfVariables; i++ ) {
				variablesStringGlobals += tclPart.nextLineFromFromSocket()+"\n";
			}
			
			updateTclVariablesModel();
			
		} catch( NoSuchElementException e ) {
			System.out.println( ">>> End of debugging…" );
			actionKill();
		}
		
188
189
190
191
192
193
194
195
196
197
198


199
200

		return currentFile;
	}

	public int getCurrentLineNumber() {
		return currentLineNumber;
	}

	public String getVariablesString() {
		return variablesString;
	}
	



}








|
|


>
>
|
|
>
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
		return currentFile;
	}

	public int getCurrentLineNumber() {
		return currentLineNumber;
	}

	public String getVariablesStringLocals() {
		return variablesStringLocals;
	}
	
	public String getVariablesStringGlobals() {
		return variablesStringGlobals;
	}

}

Changes to TclPlugin/src/org/netbeans/modules/languages/tcl/debugger/resources/debugServer.tcl.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

# other globals
  variable startLevel
  variable socketFd



proc listVars args {

	set level [expr [info level] - 2]
	set listVars [uplevel $level info vars]
	set formatted ""
	set count 0
	foreach var $listVars {
			set isArray [uplevel $level array exists $var]
			if { $isArray } {
				set names [uplevel $level array names $var]

				#puts "$var = ISARRAY"
				set toAppend "$var = ISARRAY\n"
				append formatted $toAppend
				incr count

				#puts "[set var]KEYS = $names"
				set toAppend "[set var]_KEYS = $names\n"
				append formatted $toAppend
				incr count







|

|
|







|
|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

# other globals
  variable startLevel
  variable socketFd



proc listVars {type level} {

#	set level [expr [info level] - 2]
	set listVars [uplevel $level info $type]
	set formatted ""
	set count 0
	foreach var $listVars {
			set isArray [uplevel $level array exists $var]
			if { $isArray } {
				set names [uplevel $level array names $var]

				#puts "$var = ARRAY"
				set toAppend "$var = <ARRAY>\n"
				append formatted $toAppend
				incr count

				#puts "[set var]KEYS = $names"
				set toAppend "[set var]_KEYS = $names\n"
				append formatted $toAppend
				incr count
68
69
70
71
72
73
74

75



76

77
78
79
80
81




82
83

84
85
86
87
88
89
90
}


proc setData args {
	set debug::infoFrame [info frame]
	set infoDict [info frame [expr $debug::infoFrame - $debug::startLevel]]


	set debug::lineNumber [dict get $infoDict line]



	set debug::fileName [dict get $infoDict file]

}

proc sendData args {
 	puts $debug::socketFd $debug::fileName
	puts $debug::socketFd $debug::lineNumber




	set flist [listVars]
	puts -nonewline $debug::socketFd $flist

	flush $debug::socketFd
}

proc serverProc {channel clientaddr clientport} {
	set debug::socketFd $channel
	puts stderr ">>> connection from $clientaddr:$clientport"








>
|
>
>
>
|
>





>
>
>
>
|

>







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
}


proc setData args {
	set debug::infoFrame [info frame]
	set infoDict [info frame [expr $debug::infoFrame - $debug::startLevel]]

	if { [dict exists $infoDict line] } {
		set debug::lineNumber [dict get $infoDict line]
	}

	if { [dict exists $infoDict file] } {
		set debug::fileName [dict get $infoDict file]
	}
}

proc sendData args {
 	puts $debug::socketFd $debug::fileName
	puts $debug::socketFd $debug::lineNumber

	set flist [listVars locals [expr [info level] - 1]]
	puts -nonewline $debug::socketFd $flist

	set flist [listVars globals #0]
	puts -nonewline $debug::socketFd $flist

	flush $debug::socketFd
}

proc serverProc {channel clientaddr clientport} {
	set debug::socketFd $channel
	puts stderr ">>> connection from $clientaddr:$clientport"

Changes to TclPlugin/src/org/netbeans/modules/languages/tcl/debugger/variables/TclVariable.java.

11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
 */
public class TclVariable {

	private String name;
	private String value;
	private String type;

	public TclVariable( String name, String value ) {
		this.name=name;

		this.value=value;
	}

	public String getName() {
		return name;
	}








|

>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 */
public class TclVariable {

	private String name;
	private String value;
	private String type;

	public TclVariable( String name, String type, String value ) {
		this.name=name;
		this.type=type;
		this.value=value;
	}

	public String getName() {
		return name;
	}

Changes to TclPlugin/src/org/netbeans/modules/languages/tcl/debugger/variables/TclVariablesModel.java.

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
 */
public class TclVariablesModel implements TreeModel, NodeModel, TableModel {

	private static final String VARROOT="ROOT";
	private ArrayList<ModelListener> listeners=new ArrayList<ModelListener>();
//	private final ContextProvider lookupProvider;
	private TclDebuggerJavaPart tclDebugger;
	private Properties variableProperties;


	public TclVariablesModel( ContextProvider lookupProvider ) {
		TclDebuggerActionsProvider tclDebuggerActionsProvider=( TclDebuggerActionsProvider )lookupProvider.lookupFirst( null, TclDebuggerActionsProvider.class );
		tclDebugger=tclDebuggerActionsProvider.getTclDebuggerJavaPart();
		//this.lookupProvider=lookupProvider;
	}








|
>







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 */
public class TclVariablesModel implements TreeModel, NodeModel, TableModel {

	private static final String VARROOT="ROOT";
	private ArrayList<ModelListener> listeners=new ArrayList<ModelListener>();
//	private final ContextProvider lookupProvider;
	private TclDebuggerJavaPart tclDebugger;
	private Properties variablePropertiesLocals;
	private Properties variablePropertiesGlobals;

	public TclVariablesModel( ContextProvider lookupProvider ) {
		TclDebuggerActionsProvider tclDebuggerActionsProvider=( TclDebuggerActionsProvider )lookupProvider.lookupFirst( null, TclDebuggerActionsProvider.class );
		tclDebugger=tclDebuggerActionsProvider.getTclDebuggerJavaPart();
		//this.lookupProvider=lookupProvider;
	}

58
59
60
61
62
63
64
65
66






















67
68
69

70












71
72
73
74
75
76
77
78
79

80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97






98
99
100
101
102
103
104
	@Override
	public boolean isReadOnly( Object o, String string ) throws UnknownTypeException {
		return true;
	}

	@Override
	public Object[] getChildren( Object o, int i, int i1 ) throws UnknownTypeException {
		System.out.println( "getChildren of o:" + o );
		ArrayList<Object> kids=new ArrayList<Object>();






















		String name;
		String value;
		String variablesString = tclDebugger.getVariablesString();

		












		if( o == VARROOT && !variablesString.isEmpty()) {
			StringReader sr=new StringReader( variablesString );
			this.variableProperties=new Properties();
			try {
				variableProperties.load( sr );
				System.out.println( variableProperties.keySet().size());
				for( Object object:variableProperties.keySet() ) {
					name=( String )object;
					value=variableProperties.getProperty( name );

					kids.add( new TclVariable( name, value ) );

				}
			} catch( IOException ex ) {
				Exceptions.printStackTrace( ex );
			}
		}

		return kids.toArray();

	}

	@Override
	public boolean isLeaf( Object o ) throws UnknownTypeException {
		if( o instanceof String ) {
			String s=( String )o;
			if( s.compareTo( VARROOT ) == 0 ) {
				return false;
			}






		}
		return true;
	}

	@Override
	public int getChildrenCount( Object o ) throws UnknownTypeException {
		return 2;







|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>

>
>
>
>
>
>
>
>
>
>
>
>
|
|
<

|
<
|

|
>
|
>





<
|
<









>
>
>
>
>
>







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110

111
112
113
114
115
116
117
118
119
120
121

122

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	@Override
	public boolean isReadOnly( Object o, String string ) throws UnknownTypeException {
		return true;
	}

	@Override
	public Object[] getChildren( Object o, int i, int i1 ) throws UnknownTypeException {

		ArrayList<Object> kids=new ArrayList<Object>();

		if( o == VARROOT ) {
			// Locals
			variablePropertiesLocals=transformVariablesStringToProperties( kids, tclDebugger.getVariablesStringLocals(), "local" );
			// Globals
			variablePropertiesGlobals=transformVariablesStringToProperties( kids, tclDebugger.getVariablesStringGlobals(), "global" );
		}

		if( o instanceof TclVariable ) {
			TclVariable var=( TclVariable )o;
			if( var.getType().equals( "local" ) ) {
				childrenOfArray( var.getName(), kids, variablePropertiesLocals, "local" );
			} else if( var.getType().equals( "global" ) ) {
				childrenOfArray( var.getName(), kids, variablePropertiesGlobals, "global" );
			}
		}

		return kids.toArray();
	}

	private void childrenOfArray( String arrayName, ArrayList<Object> kids, Properties vProperties, String type ) {

		String keys, value;
		String arrayKeys=arrayName + "_KEYS";
		
		keys=vProperties.getProperty( arrayKeys );
		
		for( String s:keys.split( " " ) ) {
			value = vProperties.getProperty( arrayName + "(" + s + ")");
			kids.add( new TclVariable( s, type, value ));
		}

	}

	private Properties transformVariablesStringToProperties( ArrayList<Object> kids, String vString, String type ) {

		String name;
		String value;
		Properties vProperties=new Properties();
		if( !vString.isEmpty() ) {
			StringReader sr=new StringReader( vString );

			try {
				vProperties.load( sr );

				for( Object object:vProperties.keySet() ) {
					name=( String )object;
					value=vProperties.getProperty( name );
					if( !name.contains( "(" ) && !name.contains( "_KEYS" ) ) { // Ommit arrays and *_KEYS
						kids.add( new TclVariable( name, type, value ) );
					}
				}
			} catch( IOException ex ) {
				Exceptions.printStackTrace( ex );
			}
		}

		return vProperties;

	}

	@Override
	public boolean isLeaf( Object o ) throws UnknownTypeException {
		if( o instanceof String ) {
			String s=( String )o;
			if( s.compareTo( VARROOT ) == 0 ) {
				return false;
			}
		}
		if( o instanceof TclVariable ) {
			TclVariable v=( TclVariable )o;
			if( "<ARRAY>".equals( v.getValue() ) ) {
				return false;
			}
		}
		return true;
	}

	@Override
	public int getChildrenCount( Object o ) throws UnknownTypeException {
		return 2;
129
130
131
132
133
134
135
136



137
138
139
140
141
142
	public Object getValueAt( Object o, String string ) throws UnknownTypeException {
		if( o instanceof TclVariable ) {
			TclVariable var=( TclVariable )o;
			if( string.compareTo( Constants.LOCALS_VALUE_COLUMN_ID ) == 0 ) {
				return var.getValue();
			}
			if( string.compareTo( Constants.LOCALS_TYPE_COLUMN_ID ) == 0 ) {
				return "String";



			}
		}
		return "";
	}

}







|
>
>
>






169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	public Object getValueAt( Object o, String string ) throws UnknownTypeException {
		if( o instanceof TclVariable ) {
			TclVariable var=( TclVariable )o;
			if( string.compareTo( Constants.LOCALS_VALUE_COLUMN_ID ) == 0 ) {
				return var.getValue();
			}
			if( string.compareTo( Constants.LOCALS_TYPE_COLUMN_ID ) == 0 ) {
				return var.getType();
			}
			if( string.compareTo( Constants.LOCALS_TO_STRING_COLUMN_ID ) == 0 ) {
				return var.getValue();
			}
		}
		return "";
	}

}