Skip to content

Commit 96c3bac

Browse files
committed
Issue #440: Fix remaining style issues in net.sf.eclipsecs.ui
1 parent f2e4996 commit 96c3bac

6 files changed

Lines changed: 46 additions & 68 deletions

File tree

config/checkstyle_sevntu_checks.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,7 @@
1212
<property name="file" value="config/sevntu_suppressions.xml"/>
1313
</module>
1414

15-
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
16-
<property name="file" value="show.patch"/>
17-
<property name="strategy" value="patchedline" />
18-
</module>
19-
2015
<module name="TreeWalker">
21-
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionJavaPatchFilter">
22-
<property name="file" value="show.patch"/>
23-
<property name="strategy" value="patchedline" />
24-
</module>
25-
2616
<module name="SuppressWithNearbyCommentFilter">
2717
<property name="commentFormat" value="-@cs\[(\w{8,})\] \w[\(\)\-\.\'\`\,\:\;\w ]{10,}"/>
2818
<property name="checkFormat" value="$1"/>

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/util/CheckstylePluginException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public CheckstylePluginException(String msg) {
4646
* @param cause
4747
* the causing exception
4848
*/
49-
private CheckstylePluginException(String msg, Throwable cause) {
49+
public CheckstylePluginException(String msg, Throwable cause) {
5050
super(msg, cause);
5151
}
5252

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/PropertiesContentAssistProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ public class PropertiesContentAssistProcessor
4747

4848
@Override
4949
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
50-
return null;
50+
return new IContextInformation[0];
5151
}
5252

5353
@Override
5454
public IContextInformation[] computeContextInformation(
5555
IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
56-
return null;
56+
return new IContextInformation[0];
5757
}
5858

5959
@Override
6060
public char[] getCompletionProposalAutoActivationCharacters() {
61-
return null;
61+
return new char[0];
6262
}
6363

6464
@Override
6565
public char[] getContextInformationAutoActivationCharacters() {
66-
return null;
66+
return new char[0];
6767
}
6868

6969
@Override
@@ -78,7 +78,7 @@ public IContextInformationValidator getContextInformationValidator() {
7878

7979
@Override
8080
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
81-
return null;
81+
return new ICompletionProposal[0];
8282
}
8383

8484
@Override

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePlu
260260
mLocation.setText(location);
261261
} else if (!isFirstPartProject && workingSet instanceof GlobalCheckConfigurationWorkingSet) {
262262
throw new CheckstylePluginException(NLS
263-
.bind(Messages.ProjectConfigurationEditor_msgNoProjectInWorkspace, tmp.segment(0)));
263+
.bind(Messages.ProjectConfigurationEditor_msgNoProjectInWorkspace, tmp.segment(0)), ex);
264264
}
265265

266266
if (ensureFileExists(location)) {

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/quickfixes/coding/SimplifyBooleanReturnQuickfix.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Arrays;
2424
import java.util.Collection;
2525
import java.util.List;
26+
import java.util.Optional;
2627

2728
import org.eclipse.jdt.core.dom.AST;
2829
import org.eclipse.jdt.core.dom.ASTVisitor;
@@ -86,9 +87,9 @@ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
8687
public boolean visit(final IfStatement node) {
8788
if (containsPosition(node, markerStartOffset)) {
8889

89-
final Boolean isThenStatementTrue = isReturnStatementTrue(node.getThenStatement());
90+
final Optional<Boolean> isThenStatementTrue = isReturnStatementTrue(node.getThenStatement());
9091

91-
if (isThenStatementTrue == null) {
92+
if (isThenStatementTrue.isEmpty()) {
9293
// the AST structure of the if statement is not as expected
9394
return true;
9495
}
@@ -97,7 +98,7 @@ public boolean visit(final IfStatement node) {
9798
final boolean isNotCondition = condition != node.getExpression();
9899

99100
final ReturnStatement replacement;
100-
if (isThenStatementTrue ^ isNotCondition) {
101+
if (isThenStatementTrue.get() ^ isNotCondition) {
101102
// create replacement: return condition;
102103
replacement = node.getAST().newReturnStatement();
103104
replacement.setExpression(copy(condition));
@@ -123,21 +124,21 @@ public boolean visit(final IfStatement node) {
123124
return true;
124125
}
125126

126-
private Boolean isReturnStatementTrue(final Statement node) {
127-
if (node instanceof ReturnStatement) {
128-
final Expression expression = ((ReturnStatement) node).getExpression();
129-
if (expression instanceof BooleanLiteral) {
130-
return ((BooleanLiteral) expression).booleanValue();
127+
private Optional<Boolean> isReturnStatementTrue(final Statement node) {
128+
if (node instanceof ReturnStatement returnStatement) {
129+
final Expression expression = returnStatement.getExpression();
130+
if (expression instanceof BooleanLiteral booleanLiteral) {
131+
return Optional.of(booleanLiteral.booleanValue());
131132
}
132-
} else if (node instanceof Block) {
133+
} else if (node instanceof Block block) {
133134
// the return statement might be wrapped in a block statement
134135
@SuppressWarnings("unchecked")
135-
final List<Statement> statements = ((Block) node).statements();
136+
final List<Statement> statements = block.statements();
136137
if (!statements.isEmpty()) {
137138
return isReturnStatementTrue(statements.get(0));
138139
}
139140
}
140-
return null;
141+
return Optional.empty();
141142
}
142143

143144
private Expression removeNotFromCondition(final Expression condition) {

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/util/table/EnhancedCheckBoxTableViewer.java

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Enumeration;
1717
import java.util.List;
1818
import java.util.NoSuchElementException;
19+
import java.util.Objects;
1920

2021
import org.eclipse.core.runtime.Assert;
2122
import org.eclipse.core.runtime.ListenerList;
@@ -585,19 +586,6 @@ public boolean containsKey(Object key) {
585586
return getEntry(key) != null;
586587
}
587588

588-
/**
589-
* Answers an Enumeration on the values of this Hashtable. The results of the Enumeration may be
590-
* affected if the contents of this Hashtable are modified.
591-
*
592-
* @return an Enumeration of the values of this Hashtable
593-
*/
594-
public Enumeration<?> elements() {
595-
if (elementCount == 0) {
596-
return EMPTY_ENUMERATOR;
597-
}
598-
return new HashEnumerator(false);
599-
}
600-
601589
/**
602590
* Answers the value associated with the specified key in this Hashtable.
603591
*
@@ -673,36 +661,35 @@ public Enumeration<Object> keys() {
673661
* @return the old value associated with the specified key, null if the key did not exist
674662
*/
675663
public Object put(Object key, Object value) {
676-
if (key != null && value != null) {
677-
int index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length;
678-
HashMapEntry entry = elementData[index];
679-
while (entry != null && !keyEquals(key, entry.key)) {
680-
entry = entry.next;
664+
Objects.requireNonNull(key);
665+
Objects.requireNonNull(value);
666+
int index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length;
667+
HashMapEntry entry = elementData[index];
668+
while (entry != null && !keyEquals(key, entry.key)) {
669+
entry = entry.next;
670+
}
671+
if (entry == null) {
672+
if (++elementCount > threshold) {
673+
rehash();
674+
index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length;
681675
}
682-
if (entry == null) {
683-
if (++elementCount > threshold) {
684-
rehash();
685-
index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length;
686-
}
687-
if (index < firstSlot) {
688-
firstSlot = index;
689-
}
690-
if (index > lastSlot) {
691-
lastSlot = index;
692-
}
693-
entry = new HashMapEntry(key, value);
694-
entry.next = elementData[index];
695-
elementData[index] = entry;
696-
return null;
676+
if (index < firstSlot) {
677+
firstSlot = index;
678+
}
679+
if (index > lastSlot) {
680+
lastSlot = index;
697681
}
698-
Object result = entry.value;
699-
entry.key = key;
700-
// important to avoid hanging onto keys that
701-
// are equal but "old" -- see bug 30607
702-
entry.value = value;
703-
return result;
682+
entry = new HashMapEntry(key, value);
683+
entry.next = elementData[index];
684+
elementData[index] = entry;
685+
return null;
704686
}
705-
throw new NullPointerException();
687+
Object result = entry.value;
688+
entry.key = key;
689+
// important to avoid hanging onto keys that
690+
// are equal but "old" -- see bug 30607
691+
entry.value = value;
692+
return result;
706693
}
707694

708695
/**

0 commit comments

Comments
 (0)