Skip to content

Commit c997934

Browse files
committed
Minor improvements
1 parent ff5bb72 commit c997934

14 files changed

Lines changed: 102 additions & 118 deletions

src/org/netbeans/modules/php/wordpress/WordPressPhpModuleExtender.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ public Set<FileObject> extend(PhpModule pm) throws ExtendingException {
235235
if (result != null) {
236236
result.get();
237237
}
238-
} catch (InvalidPhpExecutableException ex) {
238+
} catch (InvalidPhpExecutableException | ExecutionException ex) {
239239
throw new ExtendingException(ex.getLocalizedMessage());
240240
} catch (InterruptedException ex) {
241241
Thread.currentThread().interrupt();
242-
} catch (ExecutionException ex) {
243-
throw new ExtendingException(ex.getLocalizedMessage());
244242
}
245243
// #18
246244
sourceDirectory.refresh(true);
@@ -383,14 +381,11 @@ private List<String> getSecretKey() {
383381
URLConnection connection = url.openConnection();
384382
if (connection instanceof HttpsURLConnection) {
385383
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
386-
BufferedReader reader = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream(), Charset.UTF8)); // NOI18N
387-
try {
384+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream(), Charset.UTF8))) {
388385
String line;
389386
while ((line = reader.readLine()) != null) {
390387
keys.add(line);
391388
}
392-
} finally {
393-
reader.close();
394389
}
395390
}
396391
} catch (MalformedURLException ex) {

src/org/netbeans/modules/php/wordpress/commands/WordPressCliCommandsXmlParser.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ public static void parse(Reader reader, List<FrameworkCommand> commands) {
7979
try {
8080
WordPressCliCommandsXmlParser parser = new WordPressCliCommandsXmlParser(commands);
8181
parser.xmlReader.parse(new InputSource(reader));
82-
} catch (SAXException ex) {
83-
Exceptions.printStackTrace(ex);
84-
} catch (IOException ex) {
82+
} catch (SAXException | IOException ex) {
8583
Exceptions.printStackTrace(ex);
8684
} finally {
8785
try {
@@ -94,19 +92,27 @@ public static void parse(Reader reader, List<FrameworkCommand> commands) {
9492

9593
@Override
9694
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
97-
if ("command".equals(qName)) { // NOI18N
98-
command = attributes.getValue("name").split(" "); // NOI18N
99-
displayname = attributes.getValue("displayname"); // NOI18N
100-
} else if ("description".equals(qName)) { // NOI18N
101-
content = "description"; // NOI18N
102-
} else if ("help".equals(qName)) { // NOI18N
103-
content = "help"; // NOI18N
95+
if (null != qName) {
96+
switch (qName) {
97+
case "command": // NOI18N
98+
command = attributes.getValue("name").split(" "); // NOI18N
99+
displayname = attributes.getValue("displayname"); // NOI18N
100+
break;
101+
case "description": // NOI18N
102+
content = "description"; // NOI18N
103+
break;
104+
case "help": // NOI18N
105+
content = "help"; // NOI18N
106+
break;
107+
default:
108+
break;
109+
}
104110
}
105111
}
106112

107113
@Override
108114
public void endElement(String uri, String localName, String qName) throws SAXException {
109-
if ("command".equals(qName)) {
115+
if ("command".equals(qName)) { // NOI18N
110116
commands.add(new WordPressCliCommand(command, description, help));
111117
command = null;
112118
description = null;

src/org/netbeans/modules/php/wordpress/editor/WordPressEditorExtender.java

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*/
4242
package org.netbeans.modules.php.wordpress.editor;
4343

44+
import java.util.Collections;
4445
import java.util.HashMap;
4546
import java.util.LinkedList;
4647
import java.util.List;
@@ -66,81 +67,81 @@ public class WordPressEditorExtender extends EditorExtender {
6667
* @see <a href="http://codex.wordpress.org/Global_Variables">Global
6768
* Variables</a>
6869
*/
69-
private static final Map<String, String> globalMap = new HashMap<>();
70-
private static final List<PhpBaseElement> elements = new LinkedList<>();
70+
private static final Map<String, String> GLOBAL_MAP = new HashMap<>();
71+
private static final List<PhpBaseElement> ELEMENTS = new LinkedList<>();
7172

7273
static {
7374
// object
74-
globalMap.put("$post", "WP_Post");
75-
globalMap.put("$wpdb", "wpdb");
76-
globalMap.put("$wp_admin_bar", "WP_Admin_Bar");
77-
globalMap.put("$wp_query", "WP_Query");
78-
globalMap.put("$wp_roles", "WP_Roles");
79-
globalMap.put("$wp_rewrite", "WP_Rewrite");
80-
globalMap.put("$wp", "WP");
81-
globalMap.put("$wp_locale", "WP_Locale");
75+
GLOBAL_MAP.put("$post", "WP_Post"); // NOI18N
76+
GLOBAL_MAP.put("$wpdb", "wpdb"); // NOI18N
77+
GLOBAL_MAP.put("$wp_admin_bar", "WP_Admin_Bar"); // NOI18N
78+
GLOBAL_MAP.put("$wp_query", "WP_Query"); // NOI18N
79+
GLOBAL_MAP.put("$wp_roles", "WP_Roles"); // NOI18N
80+
GLOBAL_MAP.put("$wp_rewrite", "WP_Rewrite"); // NOI18N
81+
GLOBAL_MAP.put("$wp", "WP"); // NOI18N
82+
GLOBAL_MAP.put("$wp_locale", "WP_Locale"); // NOI18N
8283
// others
83-
globalMap.put("$currentday", "string");
84-
globalMap.put("$currentmonth", "string");
85-
globalMap.put("$page", "int");
86-
globalMap.put("$pages", "int");
87-
globalMap.put("$multipage", "boolean");
88-
globalMap.put("$more", "boolean");
89-
globalMap.put("$numpages", "int");
90-
globalMap.put("$is_iphone", "boolean");
91-
globalMap.put("$is_chrome", "boolean");
92-
globalMap.put("$is_safari", "boolean");
93-
globalMap.put("$is_NS4", "boolean");
94-
globalMap.put("$is_opera", "boolean");
95-
globalMap.put("$is_macIE", "boolean");
96-
globalMap.put("$is_winIE", "boolean");
97-
globalMap.put("$is_gecko", "boolean");
98-
globalMap.put("$is_lynx", "boolean");
99-
globalMap.put("$is_IE", "boolean");
84+
GLOBAL_MAP.put("$currentday", "string"); // NOI18N
85+
GLOBAL_MAP.put("$currentmonth", "string"); // NOI18N
86+
GLOBAL_MAP.put("$page", "int"); // NOI18N
87+
GLOBAL_MAP.put("$pages", "int"); // NOI18N
88+
GLOBAL_MAP.put("$multipage", "boolean"); // NOI18N
89+
GLOBAL_MAP.put("$more", "boolean"); // NOI18N
90+
GLOBAL_MAP.put("$numpages", "int"); // NOI18N
91+
GLOBAL_MAP.put("$is_iphone", "boolean"); // NOI18N
92+
GLOBAL_MAP.put("$is_chrome", "boolean"); // NOI18N
93+
GLOBAL_MAP.put("$is_safari", "boolean"); // NOI18N
94+
GLOBAL_MAP.put("$is_NS4", "boolean"); // NOI18N
95+
GLOBAL_MAP.put("$is_opera", "boolean"); // NOI18N
96+
GLOBAL_MAP.put("$is_macIE", "boolean"); // NOI18N
97+
GLOBAL_MAP.put("$is_winIE", "boolean"); // NOI18N
98+
GLOBAL_MAP.put("$is_gecko", "boolean"); // NOI18N
99+
GLOBAL_MAP.put("$is_lynx", "boolean"); // NOI18N
100+
GLOBAL_MAP.put("$is_IE", "boolean"); // NOI18N
100101

101-
globalMap.put("$is_apache", "boolean");
102-
globalMap.put("$is_IIS", "boolean");
103-
globalMap.put("$is_iis7", "boolean");
102+
GLOBAL_MAP.put("$is_apache", "boolean"); // NOI18N
103+
GLOBAL_MAP.put("$is_IIS", "boolean"); // NOI18N
104+
GLOBAL_MAP.put("$is_iis7", "boolean"); // NOI18N
104105

105-
globalMap.put("$wp_version", "string");
106-
globalMap.put("$wp_db_version", "int");
107-
globalMap.put("$tynymce_version", "string");
108-
globalMap.put("$manifest_version", "string");
109-
globalMap.put("$required_php_version", "string");
110-
globalMap.put("$required_mysql_version", "string");
106+
GLOBAL_MAP.put("$wp_version", "string"); // NOI18N
107+
GLOBAL_MAP.put("$wp_db_version", "int"); // NOI18N
108+
GLOBAL_MAP.put("$tynymce_version", "string"); // NOI18N
109+
GLOBAL_MAP.put("$manifest_version", "string"); // NOI18N
110+
GLOBAL_MAP.put("$required_php_version", "string"); // NOI18N
111+
GLOBAL_MAP.put("$required_mysql_version", "string"); // NOI18N
111112

112-
globalMap.put("$pagenow", "string");
113-
globalMap.put("$allowedposttags", "array");
114-
globalMap.put("$allowedtags", "array");
113+
GLOBAL_MAP.put("$pagenow", "string"); // NOI18N
114+
GLOBAL_MAP.put("$allowedposttags", "array"); // NOI18N
115+
GLOBAL_MAP.put("$allowedtags", "array"); // NOI18N
115116

116-
Set<String> keySet = globalMap.keySet();
117+
Set<String> keySet = GLOBAL_MAP.keySet();
117118
for (String key : keySet) {
118-
String clazz = globalMap.get(key);
119+
String clazz = GLOBAL_MAP.get(key);
119120
PhpVariable phpVariable = new PhpVariable(key, new PhpClass(clazz, clazz));
120-
elements.add(phpVariable);
121+
ELEMENTS.add(phpVariable);
121122
}
122123
// $authordata
123-
PhpClass authorClass = new PhpClass("stdClass", "stdClass");
124-
authorClass.addField("$ID", "$ID");
125-
authorClass.addField("$user_login", "$user_login");
126-
authorClass.addField("$user_pass", "$user_pass");
127-
authorClass.addField("$user_nicename", "$user_nicename");
128-
authorClass.addField("$user_email", "$user_email");
129-
authorClass.addField("$user_url", "$user_url");
130-
authorClass.addField("$user_registered", "$user_registered");
131-
authorClass.addField("$user_activation_key", "$user_activation_key");
132-
authorClass.addField("$user_status", "$user_status");
133-
authorClass.addField("$display_name", "$display_name");
134-
elements.add(new PhpVariable("$authordata", authorClass));
124+
PhpClass authorClass = new PhpClass("stdClass", "stdClass"); // NOI18N
125+
authorClass.addField("$ID", "$ID"); // NOI18N
126+
authorClass.addField("$user_login", "$user_login"); // NOI18N
127+
authorClass.addField("$user_pass", "$user_pass"); // NOI18N
128+
authorClass.addField("$user_nicename", "$user_nicename"); // NOI18N
129+
authorClass.addField("$user_email", "$user_email"); // NOI18N
130+
authorClass.addField("$user_url", "$user_url"); // NOI18N
131+
authorClass.addField("$user_registered", "$user_registered"); // NOI18N
132+
authorClass.addField("$user_activation_key", "$user_activation_key"); // NOI18N
133+
authorClass.addField("$user_status", "$user_status"); // NOI18N
134+
authorClass.addField("$display_name", "$display_name"); // NOI18N
135+
ELEMENTS.add(new PhpVariable("$authordata", authorClass)); // NOI18N
135136
}
136137

137138
@Override
138139
public List<PhpBaseElement> getElementsForCodeCompletion(FileObject fo) {
139140
PhpModule phpModule = PhpModule.Factory.forFileObject(fo);
140141
// check whether project is WordPress
141142
if (!WPUtils.isWP(phpModule)) {
142-
return new LinkedList<>();
143+
return Collections.emptyList();
143144
}
144-
return elements;
145+
return ELEMENTS;
145146
}
146147
}

src/org/netbeans/modules/php/wordpress/editor/completion/WordPressCompletionDocumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*/
5252
public class WordPressCompletionDocumentation implements CompletionDocumentation {
5353

54-
private WordPressCompletionItem item;
54+
private final WordPressCompletionItem item;
5555

5656
WordPressCompletionDocumentation(WordPressCompletionItem item) {
5757
this.item = item;

src/org/netbeans/modules/php/wordpress/editor/completion/WordPressCompletionItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
*/
6868
public class WordPressCompletionItem implements CompletionItem {
6969

70-
private String text;
70+
private final String text;
7171
private String description;
7272
private static ImageIcon fieldIcon = new ImageIcon(ImageUtilities.loadImage(WordPress.WP_ICON_16)); // NOI18N
7373
private static Color fieldColor = Color.decode("0x21759b"); // NOI18N

src/org/netbeans/modules/php/wordpress/editor/navi/WordPressHyperlinkProviderExt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
@MimeRegistration(mimeType = "text/x-php5", service = HyperlinkProviderExt.class)
7575
public class WordPressHyperlinkProviderExt implements HyperlinkProviderExt {
7676

77-
private static final List<String> methods = Arrays.asList(
77+
private static final List<String> METHODS = Arrays.asList(
7878
"add_filter", // NOI18N
7979
"remove_filter", // NOI18N
8080
"add_action", // NOI18N
@@ -169,7 +169,7 @@ private boolean isValid(TokenSequence<PHPTokenId> ts) {
169169
if (text.contains("\n") || text.contains("{")) { // NOI18N
170170
break;
171171
}
172-
if (methods.contains(text)) {
172+
if (METHODS.contains(text)) {
173173
argCount = count;
174174
return true;
175175
}

src/org/netbeans/modules/php/wordpress/modules/WordPressModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ void resetNode() {
131131
//~ Inner class
132132
public static class Factory {
133133

134-
private static final Map<PhpModule, WordPressModule> modules = new HashMap<>();
134+
private static final Map<PhpModule, WordPressModule> MODULES = new HashMap<>();
135135

136136
public static WordPressModule forPhpModule(PhpModule phpModule) {
137-
WordPressModule module = modules.get(phpModule);
137+
WordPressModule module = MODULES.get(phpModule);
138138
if (module != null) {
139139
return module;
140140
}
@@ -147,14 +147,14 @@ public static WordPressModule forPhpModule(PhpModule phpModule) {
147147
}
148148
module = new WordPressModule(impl);
149149
if (impl instanceof WordPress3ModuleImpl) {
150-
modules.put(phpModule, module);
150+
MODULES.put(phpModule, module);
151151
}
152152
return module;
153153
}
154154

155155
public static void remove(PhpModule phpModule) {
156156
if (phpModule != null) {
157-
modules.remove(phpModule);
157+
MODULES.remove(phpModule);
158158
}
159159
}
160160
}

src/org/netbeans/modules/php/wordpress/ui/actions/CreatePluginAction.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,17 @@ private void createPluginFile(FileObject pluginDirectory, String name) throws IO
236236
LOGGER.log(Level.WARNING, "Not found:{0}", "plugin template");
237237
return;
238238
}
239-
OutputStream outputPlugin = pluginDirectory.createAndOpen(name + ".php"); // NOI18N
240-
try {
239+
240+
try (OutputStream outputPlugin = pluginDirectory.createAndOpen(name + ".php")) { // NOI18N
241241
List<String> lines = pluginTemplate.asLines(Charset.UTF8);
242-
PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputPlugin, Charset.UTF8));
243-
try {
242+
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(outputPlugin, Charset.UTF8))) {
244243
for (String line : lines) {
245244
if (line.contains(NAME_PLACE)) {
246245
line = line.replace(NAME_PLACE, name);
247246
}
248247
pw.println(line);
249248
}
250-
} finally {
251-
pw.close();
252249
}
253-
} finally {
254-
outputPlugin.close();
255250
}
256251
}
257252

src/org/netbeans/modules/php/wordpress/ui/actions/CreateUnderscoresThemeAction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ private void replace(FileObject directory) {
220220
}
221221
try {
222222
List<String> lines = child.asLines();
223-
PrintWriter pw = new PrintWriter(new OutputStreamWriter(child.getOutputStream(), Charset.UTF8));
224-
try {
223+
try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(child.getOutputStream(), Charset.UTF8))) {
225224
for (String line : lines) {
226225
line = line.replaceAll("_s_", _s_); // NOI18N
227226
line = line.replaceAll(" _s", " " + themeName); // NOI18N
@@ -237,8 +236,6 @@ private void replace(FileObject directory) {
237236
}
238237
pw.println(line);
239238
}
240-
} finally {
241-
pw.close();
242239
}
243240
} catch (FileAlreadyLockedException ex) {
244241
Exceptions.printStackTrace(ex);

src/org/netbeans/modules/php/wordpress/ui/wizards/CreateUnderscoresThemePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public class CreateUnderscoresThemePanel extends javax.swing.JPanel implements A
5959
private static final long serialVersionUID = -1760493304572967423L;
6060
private static final String WS = " "; // NOI18N
6161
private static final String REGEX = "^[ -.a-zA-Z0-9_]+$"; // NOI18N
62-
private DialogDescriptor descriptor;
62+
private final DialogDescriptor descriptor;
6363
private Dialog dialog;
6464
private boolean isOK = false;
65-
private Set<String> existingThemeNames;
65+
private final Set<String> existingThemeNames;
6666

6767
/**
6868
* Creates new form CreateUnderscoresThemePanel

0 commit comments

Comments
 (0)