Skip to content

Commit

Permalink
CHE-5829. Fix non-exhaustive switch statements
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Aug 22, 2017
1 parent 3c9df76 commit 0343393
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Key(Class<?> type, Class<? extends Annotation> annotationType) {
@SuppressWarnings("unchecked")
LifecycleModule() {
cache =
CacheBuilder.<Key, Method[]>newBuilder()
CacheBuilder.newBuilder()
.maximumSize(1_000)
.expireAfterWrite(1, TimeUnit.HOURS)
.build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void accept(String endpointId, FileStateUpdateDto params) {

break;
}
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void onFileOperation(FileEvent event) {

break;
}
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
* Event that describes the fact that dev machine state has been changed.
*
* @author Roman Nikitenko
* @deprecated in favor of {@link MachineStateEvent}
*/
@Deprecated
public class DevMachineStateEvent extends GwtEvent<DevMachineStateEvent.Handler> {

public interface Handler extends EventHandler {
Expand Down Expand Up @@ -94,6 +96,7 @@ protected void dispatch(DevMachineStateEvent.Handler handler) {
case DESTROYED:
handler.onDevMachineDestroyed(this);
break;
default:
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
package org.eclipse.che.ide.client;

import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Arrays.asList;
import static org.eclipse.che.ide.websocket.events.WebSocketClosedEvent.CLOSE_ABNORMAL;
import static org.eclipse.che.ide.websocket.events.WebSocketClosedEvent.CLOSE_FAILURE_TLS_HANDSHAKE;
import static org.eclipse.che.ide.websocket.events.WebSocketClosedEvent.CLOSE_GOING_AWAY;
Expand All @@ -24,6 +26,8 @@
import static org.eclipse.che.ide.websocket.events.WebSocketClosedEvent.CLOSE_VIOLATE_POLICY;

import com.google.inject.Inject;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.ConnectionClosedInformer;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
Expand All @@ -39,6 +43,22 @@ public class ConnectionClosedInformerImpl implements ConnectionClosedInformer {
private DialogFactory dialogFactory;
private CoreLocalizationConstant localizationConstant;

private static final Set<Integer> CLOSE_CODES =
new HashSet<>(
asList(
CLOSE_ABNORMAL,
CLOSE_NORMAL,
CLOSE_GOING_AWAY,
CLOSE_PROTOCOL_ERROR,
CLOSE_UNSUPPORTED,
CLOSE_NO_STATUS,
CLOSE_INCONSISTENT_DATA,
CLOSE_VIOLATE_POLICY,
CLOSE_TOO_LARGE,
CLOSE_NEGOTIATE_EXTENSION,
CLOSE_UNEXPECTED_CONDITION,
CLOSE_FAILURE_TLS_HANDSHAKE));

@Inject
public ConnectionClosedInformerImpl(
DialogFactory dialogFactory, CoreLocalizationConstant localizationConstant) {
Expand All @@ -48,31 +68,20 @@ public ConnectionClosedInformerImpl(

@Override
public void onConnectionClosed(WebSocketClosedEvent event) {
switch (event.getCode()) {
case CLOSE_ABNORMAL:
String reason = event.getReason();
if (reason == null || reason.isEmpty()) {
break;
}
case CLOSE_NORMAL:
case CLOSE_GOING_AWAY:
case CLOSE_PROTOCOL_ERROR:
case CLOSE_UNSUPPORTED:
case CLOSE_NO_STATUS:
case CLOSE_INCONSISTENT_DATA:
case CLOSE_VIOLATE_POLICY:
case CLOSE_TOO_LARGE:
case CLOSE_NEGOTIATE_EXTENSION:
case CLOSE_UNEXPECTED_CONDITION:
case CLOSE_FAILURE_TLS_HANDSHAKE:
showMessageDialog(
localizationConstant.connectionClosedDialogTitle(),
localizationConstant.messagesServerFailure());
Integer code = event.getCode();
String reason = event.getReason();

if (CLOSE_ABNORMAL == code && isNullOrEmpty(reason)) {
return;
}
}

/** Displays dialog using title and message. */
private void showMessageDialog(String title, String message) {
dialogFactory.createMessageDialog(title, message, null).show();
if (CLOSE_CODES.contains(code)) {
dialogFactory
.createMessageDialog(
localizationConstant.connectionClosedDialogTitle(),
localizationConstant.messagesServerFailure(),
null)
.show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void onMachineStatusChanged(final MachineStatusChangedEvent event) {
case ERROR:
handleMachineError(event);
break;
default:
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void onCloseProcessOutputClick(ProcessTreeNode node) {
case TERMINAL_NODE:
delegate.onCloseTerminal(node);
break;
default:
}
}
});
Expand Down Expand Up @@ -290,6 +291,7 @@ public void onWidgetRemoving(SubPanel.RemoveCallback removeCallback) {
case MACHINE_NODE:
removeCallback.remove();
break;
default:
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public Promise<Void> loadState(@NotNull JsonObject state) {
loadPartStackState(
partStacks.get(TOOLING), rightPartController, partStackState, perspectiveMaximized);
break;
default:
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anySet;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
Expand All @@ -35,7 +36,6 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

Expand Down Expand Up @@ -77,7 +77,7 @@ public void shouldSetViewDelegate() throws Exception {
@Test
public void shouldInitializeView() throws Exception {
verify(goalRegistry).getAllGoals();
verify(view).setAvailableGoals(Matchers.<CommandGoal>anySet());
verify(view).setAvailableGoals(anySet());
verify(view).setGoal(eq(COMMAND_GOAL_ID));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ private void setPositionStyle() {
Elements.addClassName(css.tooltipRight(), contentElement);
}
break;
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ public CharacterClass build(String... characterClass) {
case ZERO_OR_MORE:
strBuilder.append('*');
break;
default:
}

return new CharacterClass(strBuilder.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public String format(LogMessage logMessage) {
case DOCKER:
sb.append("[DOCKER]");
break;
default:
}
final String content = logMessage.getContent();
if (content != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ protected boolean createJobPod(
switch (phase) {
case POD_PHASE_FAILED:
LOG.info("Pod command {} failed", Arrays.toString(jobCommand));
// fall through
case POD_PHASE_SUCCEEDED:
openShiftClient.resource(pod).delete();
updateCreatedDirs(command, phase, allDirsArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public void updatePresentation(@NotNull NodePresentation presentation) {
return;
case COPIED:
presentation.setPresentableTextCss("color: purple;");
return;
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ResourceDeltaImpl implements IResourceDelta {
public ResourceDeltaImpl(File workspace, ProjectItemModifiedEvent event) {
this.workspace = workspace;
path = event.getPath();
// status|= KIND_MASK;

switch (event.getType()) {
case UPDATED:
status |= CHANGED | CONTENT;
Expand All @@ -42,6 +42,8 @@ public ResourceDeltaImpl(File workspace, ProjectItemModifiedEvent event) {
break;
case DELETED:
status |= REMOVED;
break;
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static boolean hasSourceAvailable(IMember member) throws JavaModelExcepti

public static IResource[] setMinus(IResource[] setToRemoveFrom, IResource[] elementsToRemove) {
Set<IResource> setMinus =
new HashSet<IResource>(setToRemoveFrom.length - setToRemoveFrom.length);
new HashSet<IResource>(setToRemoveFrom.length - elementsToRemove.length);
setMinus.addAll(Arrays.asList(setToRemoveFrom));
setMinus.removeAll(Arrays.asList(elementsToRemove));
return setMinus.toArray(new IResource[setMinus.size()]);
Expand All @@ -270,7 +270,7 @@ public static IResource[] setMinus(IResource[] setToRemoveFrom, IResource[] elem
public static IJavaElement[] setMinus(
IJavaElement[] setToRemoveFrom, IJavaElement[] elementsToRemove) {
Set<IJavaElement> setMinus =
new HashSet<IJavaElement>(setToRemoveFrom.length - setToRemoveFrom.length);
new HashSet<IJavaElement>(setToRemoveFrom.length - elementsToRemove.length);
setMinus.addAll(Arrays.asList(setToRemoveFrom));
setMinus.removeAll(Arrays.asList(elementsToRemove));
return setMinus.toArray(new IJavaElement[setMinus.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public Promise<Void> updateAfterRefactoring(List<ChangeInfo> changes) {
pathChanged.add(change.getPath());
registerRemovedFile(change);
}
continue;
default:
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void onFileOperation(FileEvent event) {

break;
}
default:
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void setUp() throws Exception {
when(editorAgent.getActiveEditor()).thenReturn(editor);
}

@Test
public void prepareAction() throws Exception {
verify(locale).organizeImportsName();
verify(locale).organizeImportsDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void computeQuickAssistProposals(
QueryAnnotationsEvent.QueryCallback annotationCallback =
new QueryAnnotationsEvent.QueryCallback() {

@SuppressWarnings("ReturnValueIgnored")
@Override
public void respond(
Map<Annotation, org.eclipse.che.ide.api.editor.text.Position> annotations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public String from(SymbolKind kind) {
return "number";
case Boolean:
return "boolean";
default:
return "property";
}
return "property";
}
}

0 comments on commit 0343393

Please sign in to comment.