Skip to content

Commit ed4f498

Browse files
committed
Finished moving pytemplate_defaults.py to java code.
1 parent ae01bc4 commit ed4f498

File tree

3 files changed

+215
-37
lines changed

3 files changed

+215
-37
lines changed

plugins/org.python.pydev.jython/jysrc/pytemplate_defaults.py

+17-32
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,22 @@ def _IsGrammar3(context):
5757
# ISO-8601 Dates
5858
#===============================================================================
5959
def GetISODate(context):
60+
# Migrated to java
6061
return time.strftime("%Y-%m-%d")
6162

6263
def GetISODateString1(context):
64+
# Migrated to java
6365
return time.strftime("%Y-%m-%d %H:%M")
6466

6567
def GetISODateString2(context):
68+
# Migrated to java
6669
return time.strftime("%Y-%m-%d %H:%M:%S")
6770

6871
#===================================================================================================
6972
# GetModuleName
7073
#===================================================================================================
7174
def GetModuleName(context):
75+
# Migrated to java
7276
return context.getModuleName()
7377

7478

@@ -79,6 +83,7 @@ def _GetCurrentASTPath(context, reverse=False):
7983
'''
8084
@return: ArrayList(SimpleNode)
8185
'''
86+
# Migrated to java
8287
FastParser = context.getFastParserClass() # from org.python.pydev.parser.fastparser import FastParser
8388
selection = _CreateSelection(context)
8489
ret = FastParser.parseToKnowGloballyAccessiblePath(
@@ -94,6 +99,7 @@ def _GetCurrentASTPath(context, reverse=False):
9499
# GetQualifiedNameScope
95100
#===================================================================================================
96101
def GetQualifiedNameScope(context):
102+
# Migrated to java
97103
NodeUtils = context.getNodeUtilsClass() # from org.python.pydev.parser.visitors import NodeUtils
98104

99105
ret = ''
@@ -108,6 +114,7 @@ def GetQualifiedNameScope(context):
108114
# _GetCurrentClassStmt
109115
#===================================================================================================
110116
def _GetCurrentClassStmt(context):
117+
# Migrated to java
111118
NodeUtils = context.getNodeUtilsClass() #from org.python.pydev.parser.visitors import NodeUtils
112119
ClassDef = context.getClassDefClass() # from org.python.pydev.parser.jython.ast import ClassDef
113120

@@ -116,11 +123,11 @@ def _GetCurrentClassStmt(context):
116123
return stmt
117124
return None
118125

119-
120126
#===================================================================================================
121127
# GetCurrentClass
122128
#===================================================================================================
123129
def GetCurrentClass(context):
130+
# Migrated to java
124131
NodeUtils = context.getNodeUtilsClass() #from org.python.pydev.parser.visitors import NodeUtils
125132
ClassDef = context.getClassDefClass() # from org.python.pydev.parser.jython.ast import ClassDef
126133

@@ -130,14 +137,11 @@ def GetCurrentClass(context):
130137

131138
return ''
132139

133-
134-
template_helper.AddTemplateVariable(py_context_type, 'current_class', 'Current class', GetCurrentClass)
135-
136-
137140
#===================================================================================================
138141
# GetSelfOrCls
139142
#===================================================================================================
140143
def GetSelfOrCls(context):
144+
# Migrated to java
141145
FunctionDef = context.getFunctionDefClass() # from org.python.pydev.parser.jython.ast import ClassDef
142146

143147
FastParser = context.getFastParserClass() # from org.python.pydev.parser.fastparser import FastParser
@@ -151,36 +155,28 @@ def GetSelfOrCls(context):
151155

152156
return 'self'
153157

154-
template_helper.AddTemplateVariable(py_context_type, 'self_or_cls', 'Get `self` or `cls`', GetSelfOrCls)
155-
156-
157158
#===================================================================================================
158159
# GetPydevdFileLocation
159160
#===================================================================================================
160161
def GetPydevdFileLocation(context):
162+
# Migrated to java
161163
from org.python.pydev.debug.ui.launching import PythonRunnerConfig # @UnresolvedImport
162164
return PythonRunnerConfig.getDebugScript()
163165

164-
template_helper.AddTemplateVariable(
165-
py_context_type, 'pydevd_file_location', 'pydevd.py File Location', GetPydevdFileLocation)
166-
167166
#===================================================================================================
168167
# GetPydevdDirLocation
169168
#===================================================================================================
170169
def GetPydevdDirLocation(context):
170+
# Migrated to java
171171
from org.python.pydev.debug.ui.launching import PythonRunnerConfig # @UnresolvedImport
172172
import os
173173
return os.path.split(PythonRunnerConfig.getDebugScript())[0]
174174

175-
template_helper.AddTemplateVariable(
176-
py_context_type, 'pydevd_dir_location', 'pydevd.py Directory Location', GetPydevdDirLocation)
177-
178-
179-
180175
#===================================================================================================
181176
# GetCurrentMethod
182177
#===================================================================================================
183178
def GetCurrentMethod(context):
179+
# Migrated to java
184180
NodeUtils = context.getNodeUtilsClass() #from org.python.pydev.parser.visitors import NodeUtils
185181
FunctionDef = context.getFunctionDefClass() # from org.python.pydev.parser.jython.ast import FunctionDef
186182

@@ -189,15 +185,11 @@ def GetCurrentMethod(context):
189185
return NodeUtils.getRepresentationString(stmt)
190186
return ''
191187

192-
193-
194-
template_helper.AddTemplateVariable(py_context_type, 'current_method', 'Current method', GetCurrentMethod)
195-
196-
197188
#===================================================================================================
198189
# _GetPreviousOrNextClassOrMethod
199190
#===================================================================================================
200191
def _GetPreviousOrNextClassOrMethod(context, searchForward):
192+
# Migrated to java
201193
NodeUtils = context.getNodeUtilsClass() #from org.python.pydev.parser.visitors import NodeUtils
202194
FastParser = context.getFastParserClass() #from org.python.pydev.parser.fastparser import FastParser
203195
doc = context.getDocument()
@@ -215,26 +207,22 @@ def _GetPreviousOrNextClassOrMethod(context, searchForward):
215207
# GetPreviousClassOrMethod
216208
#===================================================================================================
217209
def GetPreviousClassOrMethod(context):
210+
# Migrated to java
218211
return _GetPreviousOrNextClassOrMethod(context, False)
219212

220-
template_helper.AddTemplateVariable(
221-
py_context_type, 'prev_class_or_method', 'Previous class or method', GetPreviousClassOrMethod)
222-
223213
#===================================================================================================
224214
# GetNextClassOrMethod
225215
#===================================================================================================
226216
def GetNextClassOrMethod(context):
217+
# Migrated to java
227218
return _GetPreviousOrNextClassOrMethod(context, True)
228219

229-
template_helper.AddTemplateVariable(
230-
py_context_type, 'next_class_or_method', 'Next class or method', GetNextClassOrMethod)
231-
232-
233-
234220
#===================================================================================================
235221
# GetSuperclass
236222
#===================================================================================================
237223
def GetSuperclass(context):
224+
# Migrated to java
225+
238226
selection = _CreateSelection(context)
239227
stmt = _GetCurrentClassStmt(context)
240228
BadLocationException = context.getBadLocationExceptionClass() # from org.eclipse.jface.text import BadLocationException
@@ -283,6 +271,3 @@ def GetSuperclass(context):
283271
return contents.strip()
284272

285273
return ''
286-
287-
template_helper.AddTemplateVariable(
288-
py_context_type, 'superclass', 'Superclass of the current class', GetSuperclass)

plugins/org.python.pydev/src/org/python/pydev/editor/templates/PyContextType.java

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ private void addGlobalResolvers() {
6262
addResolver(PyTemplatesDefault.IsoDate2());
6363
addResolver(PyTemplatesDefault.ModuleName());
6464
addResolver(PyTemplatesDefault.QualifiedNameScope());
65+
addResolver(PyTemplatesDefault.CurrentClass());
66+
addResolver(PyTemplatesDefault.SelfOrCls());
67+
addResolver(PyTemplatesDefault.PydevdFileLocation());
68+
addResolver(PyTemplatesDefault.PydevdDirLocation());
69+
addResolver(PyTemplatesDefault.CurrentMethod());
70+
addResolver(PyTemplatesDefault.PreviousClassOrMethod());
71+
addResolver(PyTemplatesDefault.NextClassOrMethod());
72+
addResolver(PyTemplatesDefault.Superclass());
6573

6674
PyContextTypeVariables.addResolvers(this);
6775
HashMap<String, Object> locals = new HashMap<String, Object>();

0 commit comments

Comments
 (0)