Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit031f08c

Browse files
Merge pull request#69 from PhilippSalvisberg/feature/issue_60_snippets
#60 - add snippets for annotations and expectations
2 parentse8130c6 +1f124cc commit031f08c

File tree

7 files changed

+498
-1
lines changed

7 files changed

+498
-1
lines changed

‎sqldev/src/main/java/org/utplsql/sqldev/model/XMLTools.xtend

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
packageorg.utplsql.sqldev.model
1616

17+
importjava.io.StringWriter
18+
importjavax.xml.transform.OutputKeys
19+
importjavax.xml.transform.TransformerFactory
20+
importjavax.xml.transform.dom.DOMSource
21+
importjavax.xml.transform.stream.StreamResult
1722
importjavax.xml.xpath.XPathConstants
1823
importjavax.xml.xpath.XPathFactory
1924
importorg.w3c.dom.Node
@@ -34,4 +39,29 @@ class XMLTools {
3439
valNode node= expr.evaluate(doc,XPathConstants.NODE) asNode
3540
return node
3641
}
37-
}
42+
43+
defvoidtrimWhitespace(Nodenode) {
44+
val children= node.childNodes
45+
for (i:0 ..< children.length) {
46+
val child= children.item(i)
47+
if (child.nodeType==Node.TEXT_NODE) {
48+
child.textContent= child.textContent.trim
49+
}
50+
trimWhitespace(child);
51+
}
52+
}
53+
54+
defnodeToString(Nodenode,StringcdataSectionElements) {
55+
node.trimWhitespace
56+
val writer=newStringWriter()
57+
val factory=TransformerFactory.newInstance().newTransformer()
58+
factory.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes")
59+
factory.setOutputProperty(OutputKeys.INDENT,"yes")
60+
factory.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","3");
61+
factory.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, cdataSectionElements)
62+
factory.transform(newDOMSource(node),newStreamResult(writer))
63+
val result= writer.toString()
64+
val fixedResult= result.replaceAll('''<!\[CDATA\[\s*\]\]>''',"")
65+
return fixedResult
66+
}
67+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
packageorg.utplsql.sqldev.snippet
17+
18+
importjava.io.BufferedReader
19+
importjava.io.File
20+
importjava.io.IOException
21+
importjava.io.InputStreamReader
22+
importjava.io.StringReader
23+
importjava.nio.charset.Charset
24+
importjava.nio.file.Files
25+
importjava.nio.file.Paths
26+
importjava.util.stream.Collectors
27+
importjavax.xml.parsers.DocumentBuilderFactory
28+
importoracle.dbtools.util.Resource
29+
importorg.utplsql.sqldev.model.XMLTools
30+
importorg.xml.sax.InputSource
31+
32+
classSnippetMerger {
33+
val extensionXMLTools xmlTools=newXMLTools
34+
File userSnippetsFile
35+
String utplsqlSnippets
36+
37+
defgetUtplsqlSnippetsAsString()throwsIOException {
38+
val stream= class.getResourceAsStream("/org/utplsql/sqldev/resources/UtplsqlSnippets.xml")
39+
val reader=newBufferedReader(newInputStreamReader(stream,Charset.defaultCharset))
40+
return reader.lines.collect(Collectors.joining(System.lineSeparator))
41+
}
42+
43+
new() {
44+
// works in SQL Developer only, otherwise a ExceptionInInitializerError is thrown
45+
this (newFile(Resource.RAPTOR_USER.absolutePath+File.separator+"UserSnippets.xml"))
46+
}
47+
48+
new(File file) {
49+
utplsqlSnippets= utplsqlSnippetsAsString
50+
userSnippetsFile= file
51+
}
52+
53+
defmerge() {
54+
varString result
55+
if (userSnippetsFile.exists) {
56+
// file exists, proper merge required
57+
val userSnippets=newString(Files.readAllBytes(Paths.get(userSnippetsFile.absolutePath)))
58+
val docBuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder()
59+
valuserSnippetsDoc= docBuilder.parse(newInputSource(newStringReader(userSnippets)))
60+
val userSnippetsGroups= userSnippetsDoc.getNodeList('''/snippets/group[not(@category="utPLSQL Annotations" or @category="utPLSQL Expectations")]''')
61+
valutplsqlSnippetsDoc= docBuilder.parse(newInputSource(newStringReader(utplsqlSnippets)))
62+
val utplsqlSnippetsGroups= utplsqlSnippetsDoc.getNodeList('''/snippets/group''')
63+
result='''
64+
<?xml version ='1.0' encoding ='UTF-8'?>
65+
<snippets>
66+
«FOR i : 0 ..< userSnippetsGroups.length»
67+
«userSnippetsGroups.item(i).nodeToString("code")»
68+
«ENDFOR»
69+
«FOR i : 0 ..< utplsqlSnippetsGroups.length»
70+
«utplsqlSnippetsGroups.item(i).nodeToString("code")»
71+
«ENDFOR»
72+
</snippets>
73+
'''
74+
}else {
75+
// just copy
76+
result= utplsqlSnippets
77+
78+
}
79+
Files.write(Paths.get(userSnippetsFile.absolutePath), result.bytes)
80+
}
81+
82+
defgetTemplate() {
83+
return utplsqlSnippets
84+
}
85+
86+
defgetFile() {
87+
return userSnippetsFile
88+
}
89+
90+
}

‎sqldev/src/main/java/org/utplsql/sqldev/ui/preference/PreferencePanel.xtend

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import java.awt.event.ActionListener
2020
importjava.util.Map
2121
importjavax.swing.JButton
2222
importjavax.swing.JCheckBox
23+
importjavax.swing.JOptionPane
2324
importjavax.swing.JPanel
2425
importjavax.swing.JSpinner
2526
importjavax.swing.JTabbedPane
@@ -33,6 +34,7 @@ import oracle.ide.panels.TraversalException
3334
importoracle.javatools.ui.layout.FieldLayoutBuilder
3435
importorg.utplsql.sqldev.model.preference.PreferenceModel
3536
importorg.utplsql.sqldev.resources.UtplsqlResources
37+
importorg.utplsql.sqldev.snippet.SnippetMerger
3638
importorg.utplsql.sqldev.ui.common.DirectoryChooser
3739

3840
classPreferencePanelextendsDefaultTraversablePanel {
@@ -43,6 +45,7 @@ class PreferencePanel extends DefaultTraversablePanel {
4345
valJCheckBox clearScreenCheckBox=newJCheckBox
4446
valJCheckBox autoExecuteCheckBox=newJCheckBox
4547
valJCheckBox checkRunUtplsqlTestCheckBox=newJCheckBox
48+
valJButton importSnippetsButton=newJButton(UtplsqlResources.getString("PREF_IMPORT_SNIPPETS_BUTTON_LABEL"))
4649
valJPanel realtimeReporterPanel=newJPanel
4750
valSpinnerNumberModel numberOfRunsInHistoryModel=newSpinnerNumberModel(1,1,100,1);
4851
valJSpinner numberOfRunsInHistorySpinner=newJSpinner(numberOfRunsInHistoryModel);
@@ -101,6 +104,7 @@ class PreferencePanel extends DefaultTraversablePanel {
101104
runTab.add(
102105
runTab.field.label.withText(UtplsqlResources.getString("PREF_CHECK_RUN_UTPLSQL_TEST_LABEL")).component(
103106
checkRunUtplsqlTestCheckBox))
107+
runTab.addRow(importSnippetsButton)
104108
runTab.addVerticalSpring
105109

106110
// realtime reporter group
@@ -200,6 +204,13 @@ class PreferencePanel extends DefaultTraversablePanel {
200204
builder.addVerticalField("", tabbedPane)
201205
builder.addVerticalSpring
202206

207+
// register action listener for import snippets button
208+
importSnippetsButton.addActionListener(newActionListener() {
209+
override actionPerformed(ActionEvent event) {
210+
importSnippets
211+
}
212+
})
213+
203214
// register action listener for create code template button
204215
createCodeTemplatesButton.addActionListener(newActionListener() {
205216
override actionPerformed(ActionEvent event) {
@@ -216,6 +227,15 @@ class PreferencePanel extends DefaultTraversablePanel {
216227
})
217228
}
218229

230+
privatedefimportSnippets() {
231+
val snippetMerger=newSnippetMerger
232+
snippetMerger.merge
233+
val file= snippetMerger.file.absolutePath
234+
val message=String.format(UtplsqlResources.getString("PREF_CONFIRM_IMPORT_MESSAGE"), file)
235+
JOptionPane.showMessageDialog(null, message,UtplsqlResources.getString("PREF_CONFIRM_IMPORT_TITLE"),
236+
JOptionPane.INFORMATION_MESSAGE);
237+
}
238+
219239
privatedefloadCodeTemplates() {
220240
valMap<String,String> map=CodeTemplateUtil.loadFiles()
221241
for (key: map.keySet) {

‎sqldev/src/main/resources/org/utplsql/sqldev/resources/UtplsqlResources.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ PREF_RESET_PACKAGE_LABEL=Reset package before running utPLSQL?
3131
PREF_CLEAR_SCREEN_LABEL=Clear script output panel before running utPLSQL?
3232
PREF_AUTO_EXECUTE_LABEL=Execute unit test automatically?
3333
PREF_CHECK_RUN_UTPLSQL_TEST_LABEL=Check availability of menu option?
34+
PREF_IMPORT_SNIPPETS_BUTTON_LABEL=Import Snippets
3435
MENU_REALTIME_REPORTER_LABEL=Realtime Reporter
3536
PREF_NUMBER_OF_RUNS_IN_HISTORY_LABEL=Number of runs in history
3637
PREF_SHOW_DISABLED_COUNTER_LABEL=Show disabled counter?
@@ -56,6 +57,8 @@ PREF_GENERATE_FILES_LABEL=Generate files?
5657
PREF_OUTPUT_DIRECTORY_LABEL=Output directory
5758
PREF_OUTPUT_DIRECTORY_BUTTON_LABEL=Browse
5859
PREF_DELETE_EXISTING_FILES_LABEL=Delete existing files in output directory?
60+
PREF_CONFIRM_IMPORT_TITLE=Snippets imported
61+
PREF_CONFIRM_IMPORT_MESSAGE=Snippets imported into %s. Please restart SQL Developer for this change to take effect.
5962
MENU_RUN_TEST_LABEL=Run utPLSQL test
6063
MENU_CODE_COVERAGE_LABEL=Code coverage...
6164
MENU_GENERATE_TEST_LABEL=Generate utPLSQL test

‎sqldev/src/main/resources/org/utplsql/sqldev/resources/UtplsqlResources_de.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PREF_RESET_PACKAGE_LABEL=Package vor der Ausf
88
PREF_CLEAR_SCREEN_LABEL=Skriptausgabe-Fenster vor der Ausführung von utPLSQL leeren?
99
PREF_AUTO_EXECUTE_LABEL=Unit Test automatisch ausführen?
1010
PREF_CHECK_RUN_UTPLSQL_TEST_LABEL=Verfügbarkeit der Menüoption prüfen?
11+
PREF_IMPORT_SNIPPETS_BUTTON_LABEL=Code-Schnipsel importieren
1112
MENU_REALTIME_REPORTER_LABEL=Realtime Reporter
1213
PREF_NUMBER_OF_RUNS_IN_HISTORY_LABEL=Anzahl Ausführungen in der Historie
1314
PREF_SHOW_DISABLED_COUNTER_LABEL=Deaktiviert-Zähler anzeigen?
@@ -33,6 +34,8 @@ PREF_GENERATE_FILES_LABEL=Dateien generieren?
3334
PREF_OUTPUT_DIRECTORY_LABEL=Ausgabeverzeichnis
3435
PREF_OUTPUT_DIRECTORY_BUTTON_LABEL=Auswählen
3536
PREF_DELETE_EXISTING_FILES_LABEL=Bestehende Dateien im Ausgabeverzeichnis löschen?
37+
PREF_CONFIRM_IMPORT_TITLE=Code-Schnipsel importiert
38+
PREF_CONFIRM_IMPORT_MESSAGE=Code-Schnipsel in %s importiert. Bitte starten Sie den SQL Developer neu, um diese Änderung zu aktivieren.
3639
MENU_RUN_TEST_LABEL=utPLSQL Test ausführen
3740
MENU_CODE_COVERAGE_LABEL=Codeabdeckung...
3841
MENU_GENERATE_TEST_LABEL=utPLSQL Test generieren

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp