Skip to content

Commit 3645ef0

Browse files
committed
Resolving more deprecations and warnings
1 parent 86ab2b1 commit 3645ef0

22 files changed

+112
-135
lines changed

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/AbstractRulePanelManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import net.sourceforge.pmd.eclipse.util.ResourceManager;
3434
import net.sourceforge.pmd.properties.PropertyDescriptor;
3535
import net.sourceforge.pmd.properties.StringProperty;
36-
import net.sourceforge.pmd.util.StringUtil;
3736

3837
/**
3938
* Concrete subclasses can also be used as tab folders outside of a wizard
@@ -171,11 +170,11 @@ public boolean validate() {
171170
updateTabUI(warnings, errors);
172171
}
173172

174-
String errorText = errors.isEmpty() ? null : StringUtil.asString(errors.toArray(), ", ");
173+
String errorText = errors.isEmpty() ? null : StringUtils.join(errors, ", ");
175174

176175
setErrorMessage(errorText);
177176

178-
setPageComplete(StringUtil.isEmpty(errorText));
177+
setPageComplete(StringUtils.isBlank(errorText));
179178

180179
return errorText == null;
181180
}
@@ -273,7 +272,7 @@ protected void changed(StringProperty property, String newValue) {
273272
String cleanValue = newValue.trim();
274273
String existingValue = rules.commonStringValue(property);
275274

276-
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) {
275+
if (StringUtils.equals(StringUtils.stripToNull(existingValue), StringUtils.stripToNull(cleanValue))) {
277276
return;
278277
}
279278

@@ -329,7 +328,7 @@ protected void show(Combo control, String value) {
329328

330329
int index = -1;
331330
for (int i = 0; i < choices.length; i++) {
332-
if (StringUtil.areSemanticEquals(choices[i], value)) {
331+
if (StringUtils.equals(StringUtils.stripToNull(choices[i]), StringUtils.stripToNull(value))) {
333332
index = i;
334333
break;
335334
}
@@ -355,7 +354,7 @@ protected void show(CCombo control, String value) {
355354

356355
int index = -1;
357356
for (int i = 0; i < choices.length; i++) {
358-
if (StringUtil.areSemanticEquals(choices[i], value)) {
357+
if (StringUtils.equals(StringUtils.stripToNull(choices[i]), StringUtils.stripToNull(value))) {
359358
index = i;
360359
break;
361360
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/DescriptionPanelManager.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener;
3434
import net.sourceforge.pmd.eclipse.ui.preferences.editors.SWTUtil;
3535
import net.sourceforge.pmd.lang.rule.RuleReference;
36-
import net.sourceforge.pmd.util.StringUtil;
3736

3837
/**
3938
*
@@ -48,8 +47,6 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
4847
private Label messageLabel;
4948
private Text messageField;
5049

51-
private static final int MIN_MESSAGE_LENGTH = 10; // chars
52-
5350
public static final String ID = "description";
5451

5552
public DescriptionPanelManager(String theTitle, EditorUsageMode theMode, ValueChangeListener theListener) {
@@ -115,7 +112,7 @@ public void modifyText(ModifyEvent event) {
115112
String cleanValue = asCleanString(descriptionBox.getText());
116113
String existingValue = soleRule.getDescription();
117114

118-
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) {
115+
if (StringUtils.equals(StringUtils.stripToNull(existingValue), StringUtils.stripToNull(cleanValue))) {
119116
return;
120117
}
121118

@@ -135,7 +132,7 @@ private void validateRuleParams() {
135132

136133
validate();
137134

138-
boolean urlOK = StringUtil.isEmpty(externalURLField.getText()) || hasValidURL();
135+
boolean urlOK = StringUtils.isBlank(externalURLField.getText()) || hasValidURL();
139136
adjustBrowseButton(urlOK);
140137
}
141138

@@ -201,7 +198,8 @@ private void handleExternalURLChange() {
201198
String newURL = asCleanString(externalURLField.getText());
202199
Rule rule = soleRule();
203200

204-
if (!StringUtil.areSemanticEquals(asCleanString(rule.getExternalInfoUrl()), newURL)) {
201+
if (!StringUtils.equals(StringUtils.stripToNull(asCleanString(rule.getExternalInfoUrl())),
202+
StringUtils.stripToNull(newURL))) {
205203
rule.setExternalInfoUrl(newURL);
206204
valueChanged(null, newURL);
207205
}
@@ -214,7 +212,8 @@ private void handleMessageChange() {
214212
String newMessage = asCleanString(messageField.getText());
215213
Rule rule = soleRule();
216214

217-
if (!StringUtil.areSemanticEquals(asCleanString(rule.getMessage()), newMessage)) {
215+
if (!StringUtils.equals(StringUtils.stripToNull(asCleanString(rule.getMessage())),
216+
StringUtils.stripToNull(newMessage))) {
218217
rule.setMessage(newMessage);
219218
updateUI();
220219
}
@@ -291,16 +290,6 @@ private boolean hasValidURL() {
291290
return isValidURL(url);
292291
}
293292

294-
private boolean hasValidMessage() {
295-
String message = messageField.getText().trim();
296-
return StringUtil.isNotEmpty(message) && (message.length() > MIN_MESSAGE_LENGTH);
297-
}
298-
299-
private boolean hasValidDescription() {
300-
String description = descriptionBox.getText().trim();
301-
return StringUtil.isNotEmpty(description) && (description.length() > MIN_MESSAGE_LENGTH);
302-
}
303-
304293
private void adjustBrowseButton(boolean hasValidURL) {
305294

306295
browseButton.setEnabled(hasValidURL);
@@ -311,10 +300,10 @@ protected List<String> fieldErrors() {
311300

312301
List<String> errors = new ArrayList<String>(3);
313302

314-
if (StringUtil.isEmpty(descriptionBox.getText().trim())) {
303+
if (StringUtils.isBlank(descriptionBox.getText().trim())) {
315304
errors.add("Missing description");
316305
}
317-
if (StringUtil.isEmpty(messageField.getText().trim())) {
306+
if (StringUtils.isBlank(messageField.getText().trim())) {
318307
errors.add("Missing message");
319308
}
320309

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/ExamplePanelManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void handleEvent(Event event) {
8585
String cleanValue = exampleField.getText().trim();
8686
String existingValue = soleRule.getDescription();
8787

88-
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) {
88+
if (StringUtils.equals(StringUtils.stripToNull(existingValue), StringUtils.stripToNull(cleanValue))) {
8989
return;
9090
}
9191

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/PerRulePropertyPanelManager.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.sourceforge.pmd.Rule;
2020
import net.sourceforge.pmd.eclipse.ui.preferences.br.EditorFactory;
2121
import net.sourceforge.pmd.eclipse.ui.preferences.br.RuleSelection;
22+
import net.sourceforge.pmd.eclipse.ui.preferences.br.RuleUtil;
2223
import net.sourceforge.pmd.eclipse.ui.preferences.br.SizeChangeListener;
2324
import net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener;
2425
import net.sourceforge.pmd.eclipse.ui.preferences.editors.BooleanEditorFactory;
@@ -30,7 +31,6 @@
3031
import net.sourceforge.pmd.eclipse.ui.preferences.editors.MultiStringEditorFactory;
3132
import net.sourceforge.pmd.eclipse.ui.preferences.editors.RegexEditorFactory;
3233
import net.sourceforge.pmd.eclipse.ui.preferences.editors.StringEditorFactory;
33-
import net.sourceforge.pmd.lang.rule.XPathRule;
3434
import net.sourceforge.pmd.properties.PropertyDescriptor;
3535
import net.sourceforge.pmd.properties.PropertySource;
3636

@@ -82,15 +82,8 @@ protected boolean canManageMultipleRules() {
8282
}
8383

8484
protected boolean canWorkWith(Rule rule) {
85-
86-
// TODO if (rule.hasDescriptor(XPathRule.XPATH_DESCRIPTOR)) return true;
87-
// won't work, need to tweak Rule implementation as map is empty
88-
89-
// alternate approach for now
90-
for (PropertyDescriptor<?> desc : rule.getPropertyDescriptors()) {
91-
if (desc.equals(XPathRule.XPATH_DESCRIPTOR)) {
92-
return true;
93-
}
85+
if (RuleUtil.isXPathRule(rule)) {
86+
return true;
9487
}
9588

9689
return !Configuration.filteredPropertiesOf(rule).isEmpty();

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/SummaryPanelManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88
import java.util.Map;
99

10+
import org.apache.commons.lang3.StringUtils;
1011
import org.eclipse.swt.SWT;
1112
import org.eclipse.swt.custom.StyledText;
1213
import org.eclipse.swt.layout.FillLayout;
@@ -21,7 +22,6 @@
2122
import net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener;
2223
import net.sourceforge.pmd.properties.PropertyDescriptor;
2324
import net.sourceforge.pmd.util.ClassUtil;
24-
import net.sourceforge.pmd.util.StringUtil;
2525

2626
/**
2727
*
@@ -86,7 +86,7 @@ public void showFor(Rule rule) {
8686
pb.addRawText(arranger.format(rule.getDescription()).toString());
8787

8888
String url = rule.getExternalInfoUrl();
89-
if (StringUtil.isNotEmpty(url)) {
89+
if (StringUtils.isNotBlank(url)) {
9090
pb.addRawText(arranger.withIndent("More information can be found "));
9191
pb.addLink("here.\n", url);
9292
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/panelmanagers/XPathPanelManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import net.sourceforge.pmd.lang.rule.RuleReference;
3333
import net.sourceforge.pmd.lang.rule.XPathRule;
3434
import net.sourceforge.pmd.properties.EnumeratedProperty;
35-
import net.sourceforge.pmd.util.StringUtil;
3635

3736
/**
3837
*
@@ -128,7 +127,7 @@ public void modifyText(ModifyEvent event) {
128127
String newValue = xpathField.getText().trim();
129128
String existingValue = soleRule.getProperty(XPathRule.XPATH_DESCRIPTOR).trim();
130129

131-
if (StringUtil.areSemanticEquals(existingValue, newValue)) {
130+
if (StringUtils.equals(StringUtils.stripToNull(existingValue), StringUtils.stripToNull(newValue))) {
132131
return;
133132
}
134133

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/priority/PriorityDescriptor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.HashMap;
99
import java.util.Map;
1010

11+
import org.apache.commons.lang3.StringUtils;
1112
import org.eclipse.jface.resource.ImageDescriptor;
1213
import org.eclipse.swt.graphics.Image;
1314
import org.eclipse.swt.graphics.ImageData;
@@ -20,7 +21,6 @@
2021
import net.sourceforge.pmd.eclipse.ui.ShapeDescriptor;
2122
import net.sourceforge.pmd.eclipse.ui.ShapePainter;
2223
import net.sourceforge.pmd.eclipse.ui.views.actions.AbstractPMDAction;
23-
import net.sourceforge.pmd.util.StringUtil;
2424

2525
/**
2626
*
@@ -120,11 +120,12 @@ public boolean equals(Object other) {
120120

121121
PriorityDescriptor otherOne = (PriorityDescriptor) other;
122122

123-
return priority.equals(otherOne.priority) && StringUtil.isSame(label, otherOne.label, false, false, false)
123+
return priority.equals(otherOne.priority)
124+
&& StringUtils.equals(label, otherOne.label)
124125
&& shape.equals(otherOne.shape)
125-
&& StringUtil.isSame(description, otherOne.description, false, false, false)
126-
&& StringUtil.isSame(filterText, otherOne.filterText, false, false, false)
127-
&& StringUtil.isSame(iconId, otherOne.iconId, false, false, false);
126+
&& StringUtils.equals(description, otherOne.description)
127+
&& StringUtils.equals(filterText, otherOne.filterText)
128+
&& StringUtils.equals(iconId, otherOne.iconId);
128129
}
129130

130131
public int hashCode() {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/PMDProjectPropertyPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.sourceforge.pmd.RuleSets;
4343
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
4444
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
45+
import net.sourceforge.pmd.eclipse.ui.actions.internal.InternalRuleSetUtil;
4546
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
4647
import net.sourceforge.pmd.eclipse.ui.preferences.PMDPreferencePage;
4748
import net.sourceforge.pmd.eclipse.ui.preferences.RuleLabelProvider;
@@ -583,8 +584,8 @@ private RuleSet getProjectRuleSet() {
583584

584585
final RuleSets activeRuleSet = model.getProjectRuleSets();
585586
for (RuleSet rs : activeRuleSet.getAllRuleSets()) {
586-
ruleSet = RuleSetUtil.addExcludePatterns(ruleSet, rs.getExcludePatterns());
587-
ruleSet = RuleSetUtil.addIncludePatterns(ruleSet, rs.getIncludePatterns());
587+
ruleSet = InternalRuleSetUtil.addFileExclusions(ruleSet, rs.getFileExclusions());
588+
ruleSet = InternalRuleSetUtil.addFileInclusions(ruleSet, rs.getFileInclusions());
588589
}
589590

590591
return ruleSet;

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/UpdateProjectPropertiesCmd.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
*/
2121
public class UpdateProjectPropertiesCmd extends AbstractProjectCommand {
2222

23-
private static final long serialVersionUID = 1L;
24-
2523
// private IProject project;
2624
private boolean pmdEnabled;
2725
private IWorkingSet projectWorkingSet;

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/quickfix/PMDResolutionGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class PMDResolutionGenerator implements IMarkerResolutionGenerator {
4242

4343
public static final IMarkerResolution[] EMPTY_RESOLUTIONS = new IMarkerResolution[0];
4444

45-
public static Class<Fix> fixClassFor(String className, String ruleName) {
45+
public static Class<? extends Fix> fixClassFor(String className, String ruleName) {
4646

4747
if (StringUtils.isBlank(className)) {
4848
return null;
@@ -51,7 +51,7 @@ public static Class<Fix> fixClassFor(String className, String ruleName) {
5151
try {
5252
Class<?> cls = Class.forName(className);
5353
if (Fix.class.isAssignableFrom(cls)) {
54-
return (Class<Fix>) cls;
54+
return cls.asSubclass(Fix.class);
5555
} else {
5656
BROKEN_FIXES.put(ruleName, className);
5757
return null;
@@ -108,7 +108,7 @@ private static void loadFixesFor(String ruleName) {
108108
if (StringUtils.isBlank(fixClassName)) {
109109
continue;
110110
}
111-
Class<Fix> fixClass = fixClassFor(fixClassName.trim(), ruleName);
111+
Class<? extends Fix> fixClass = fixClassFor(fixClassName.trim(), ruleName);
112112
if (fixClass != null) {
113113
Fix fix = fixFor(ruleName, fixClass);
114114
if (fix != null) {
@@ -141,10 +141,10 @@ public static boolean hasFixesFor(Rule rule) {
141141
return FIXERS_BY_RULE_NAME.containsKey(ruleName);
142142
}
143143

144-
private static Fix fixFor(String ruleName, Class<Fix> fixClass) {
144+
private static Fix fixFor(String ruleName, Class<? extends Fix> fixClass) {
145145

146146
try {
147-
return fixClass.newInstance();
147+
return fixClass.getConstructor().newInstance();
148148
} catch (Exception ex) {
149149
BROKEN_FIXES.put(ruleName, fixClass.getName());
150150
return null;

0 commit comments

Comments
 (0)