Skip to content

Commit

Permalink
Issue checkstyle#440: resolves ConfusingConditionCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Jan 27, 2023
1 parent 84f1b61 commit b9b1d1b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,17 @@ private void storeToPersistence(ProjectConfigurationWorkingCopy config)
// create or overwrite the .checkstyle file
IProject project = config.getProject();
IFile file = project.getFile(ProjectConfigurationFactory.PROJECT_CONFIGURATION_FILE);
if (!file.exists()) {
file.create(pipeIn, true, null);
file.refreshLocal(IResource.DEPTH_INFINITE, null);
} else {

if (file.exists()) {
if (file.isReadOnly()) {
ResourceAttributes attrs = ResourceAttributes.fromFile(file.getFullPath().toFile());
attrs.setReadOnly(true);
file.setResourceAttributes(attrs);
}

file.setContents(pipeIn, true, true, null);
} else {
file.create(pipeIn, true, null);
file.refreshLocal(IResource.DEPTH_INFINITE, null);
}

config.getLocalCheckConfigWorkingSet().store();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,47 +98,47 @@ public void addSetting(final CheckstyleSetting setting) {
String module;
while (modit.hasNext()) {
module = modit.next();
if (!mCheckerModules.keySet().contains(module)) {
mCheckerModules.put(module, setting.getmCheckerModules().get(module));
} else {
if (mCheckerModules.keySet().contains(module)) {
final Iterator<String> propit = setting.getmCheckerModules().get(module).keySet()
.iterator();
String property;
while (propit.hasNext()) {
property = propit.next();
if (!mCheckerModules.get(module).containsKey(property)) {
mCheckerModules.get(module).put(property,
setting.getmCheckerModules().get(module).get(property));
} else {
if (mCheckerModules.get(module).containsKey(property)) {
if (!mCheckerModules.get(module).get(property)
.equals(setting.getmCheckerModules().get(module).get(property))) {
}
} else {
mCheckerModules.get(module).put(property,
setting.getmCheckerModules().get(module).get(property));
}
}
} else {
mCheckerModules.put(module, setting.getmCheckerModules().get(module));
}
}

// add treewalker-modules
modit = setting.getmTreeWalkerModules().keySet().iterator();
while (modit.hasNext()) {
module = modit.next();
if (!mTreeWalkerModules.keySet().contains(module)) {
mTreeWalkerModules.put(module, setting.getmTreeWalkerModules().get(module));
} else {
if (mTreeWalkerModules.keySet().contains(module)) {
final Iterator<String> propit = setting.getmTreeWalkerModules().get(module).keySet()
.iterator();
String property;
while (propit.hasNext()) {
property = propit.next();
if (!mTreeWalkerModules.get(module).containsKey(property)) {
mTreeWalkerModules.get(module).put(property,
setting.getmTreeWalkerModules().get(module).get(property));
} else {
if (mTreeWalkerModules.get(module).containsKey(property)) {
if (!mTreeWalkerModules.get(module).get(property)
.equals(setting.getmTreeWalkerModules().get(module).get(property))) {
}
} else {
mTreeWalkerModules.get(module).put(property,
setting.getmTreeWalkerModules().get(module).get(property));
}
}
} else {
mTreeWalkerModules.put(module, setting.getmTreeWalkerModules().get(module));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ private void initialize() {

this.setTitle(
NLS.bind(Messages.RuleConfigurationEditDialog_titleRuleConfigEditor, mRule.getName()));
if (!mReadonly) {
this.setMessage(Messages.RuleConfigurationEditDialog_msgEditRuleConfig);
} else {
if (mReadonly) {
this.setMessage(Messages.RuleConfigurationEditDialog_msgReadonlyModule);
} else {
this.setMessage(Messages.RuleConfigurationEditDialog_msgEditRuleConfig);
}

String comment = mRule.getComment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ private class TokenLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
String translation = null;
if (!mTranslateTokens) {
translation = "" + element; //$NON-NLS-1$
} else {
if (mTranslateTokens) {
try {
translation = TOKEN_BUNDLE.getString((String) element);
} catch (MissingResourceException ex) {
translation = "" + element; //$NON-NLS-1$
}
} else {
translation = "" + element; //$NON-NLS-1$
}
return translation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ public void checkStateChanged(CheckStateChangedEvent event) {
Object element = event.getElement();
if (element instanceof IFilter) {
IFilter filter = (IFilter) element;
if (!filter.isReadonly()) {
filter.setEnabled(event.getChecked());
} else {
if (filter.isReadonly()) {
event.getCheckable().setChecked(event.getElement(), true);
} else {
filter.setEnabled(event.getChecked());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,16 +431,15 @@ protected void computeResult() {

List<Object> checked = Arrays.asList(mViewer.getCheckedElements());

if (!mRecursivelyExcludeSubPackages) {
setResult(checked);
} else {

if (mRecursivelyExcludeSubPackages) {
List<Object> grayed = Arrays.asList(mViewer.getGrayedElements());

List<Object> pureChecked = new ArrayList<>(checked);
pureChecked.removeAll(grayed);

setResult(pureChecked);
} else {
setResult(checked);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public boolean visit(SwitchCase node) {
for (int i = defaultStatementIndex + 1; i < switchStatement.statements().size(); i++) {
ASTNode tmpNode = (ASTNode) switchStatement.statements().get(i);

if (!(tmpNode instanceof SwitchCase)) {
defaultCaseStatements.add(tmpNode);
} else {
if (tmpNode instanceof SwitchCase) {
break;
} else {
defaultCaseStatements.add(tmpNode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ public IMarker[] findMarkers(IProgressMonitor mon) throws CoreException {

List<IMarker> unfiltered = Collections.emptyList();

if (!isEnabled()) {
unfiltered = findCheckstyleMarkers(
new IResource[] { ResourcesPlugin.getWorkspace().getRoot() },
IResource.DEPTH_INFINITE, mon);
} else {

if (isEnabled()) {
switch (getOnResource()) {
case ON_ANY_RESOURCE: {
unfiltered = findCheckstyleMarkers(
Expand Down Expand Up @@ -169,6 +164,10 @@ public IMarker[] findMarkers(IProgressMonitor mon) throws CoreException {
break;
}
}
} else {
unfiltered = findCheckstyleMarkers(
new IResource[] { ResourcesPlugin.getWorkspace().getRoot() },
IResource.DEPTH_INFINITE, mon);
}

if (unfiltered == null) {
Expand Down

0 comments on commit b9b1d1b

Please sign in to comment.