Remove redundant conditions which are covered by some subsequent condition

This commit is contained in:
Tagir Valeev
2018-09-12 17:51:20 +07:00
parent a9405f37be
commit eb2783540d
29 changed files with 30 additions and 42 deletions

View File

@@ -620,9 +620,7 @@ public abstract class CompilerReferenceServiceBase<Reader extends CompilerRefere
}
protected static boolean requireIndexRebuild(@Nullable Throwable exception) {
return exception instanceof PersistentEnumeratorBase.CorruptedException ||
exception instanceof StorageException ||
exception instanceof IOException;
return exception instanceof StorageException || exception instanceof IOException;
}
protected enum IndexCloseReason {

View File

@@ -39,7 +39,7 @@ public final class MethodChainsSearchUtil {
for (PsiParameter parameter : m.getParameterList().getParameters()) {
PsiType t = parameter.getType();
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(t);
if (aClass != null && aClass == target) {
if (aClass == target) {
return false;
}
}

View File

@@ -299,7 +299,7 @@ public class ExpectedTypesProvider {
if (parent instanceof PsiMethodCallExpression) {
Collections.addAll(myResult, findClassesWithDeclaredMethod((PsiMethodCallExpression)parent));
}
else if (parent instanceof PsiReferenceExpression || parent instanceof PsiVariable ||
else if (parent instanceof PsiVariable ||
parent instanceof PsiExpression) {
if (LENGTH_SYNTHETIC_ARRAY_FIELD.equals(referenceName)) {
myResult.addAll(anyArrayType());

View File

@@ -638,8 +638,7 @@ public class CreateFromUsageUtils {
continue;
}
if (pparent instanceof PsiReferenceExpression ||
pparent instanceof PsiVariable ||
if (pparent instanceof PsiVariable ||
pparent instanceof PsiExpression) {
expectedFieldNames.add(refName);
}

View File

@@ -41,7 +41,6 @@ public class BasicSelectioner extends ExtendWordSelectionHandlerBase {
!(e instanceof PsiJavaCodeReferenceElement) &&
!(e instanceof PsiJavaToken &&
!(e instanceof PsiKeyword)) &&
!(e instanceof XmlToken) &&
!(e instanceof XmlElement) &&
!(e instanceof PsiDocTag);
}

View File

@@ -55,7 +55,7 @@ public class ReplaceCastWithVariableAction extends PsiElementBaseIntentionAction
final PsiReferenceExpression operandReference = (PsiReferenceExpression)operand;
final PsiElement resolved = operandReference.resolve();
if (resolved == null || (!(resolved instanceof PsiParameter) && !(resolved instanceof PsiLocalVariable))) {
if (!(resolved instanceof PsiParameter) && !(resolved instanceof PsiLocalVariable)) {
return false;
}

View File

@@ -55,7 +55,7 @@ public class ReplaceWithTernaryOperatorFix implements LocalQuickFix {
PsiElement element = descriptor.getPsiElement();
while (true) {
PsiElement parent = element.getParent();
if (parent instanceof PsiReferenceExpression || parent instanceof PsiCallExpression || parent instanceof PsiJavaCodeReferenceElement) {
if (parent instanceof PsiCallExpression || parent instanceof PsiJavaCodeReferenceElement) {
element = parent;
}
else {

View File

@@ -127,7 +127,7 @@ public class TypeConversionUtil {
}
}
return fromTypeRank == toTypeRank ||
fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK && fromTypeRank < toTypeRank;
fromTypeRank < toTypeRank && toTypeRank <= MAX_NUMERIC_RANK;
}
return fromTypeRank == toTypeRank ||
fromTypeRank <= MAX_NUMERIC_RANK && toTypeRank <= MAX_NUMERIC_RANK;

View File

@@ -825,7 +825,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
if (completePattern || variableNode == null) return false;
if (variableNode instanceof PsiLiteralExpression && ((PsiLiteralExpression)variableNode).getValue() instanceof String) return true;
final PsiElement parent = variableNode.getParent();
return parent instanceof PsiReferenceExpression || parent instanceof PsiJavaCodeReferenceElement;
return parent instanceof PsiJavaCodeReferenceElement;
default: return super.isApplicableConstraint(constraintName, variableNode, completePattern, target);
}
}

View File

@@ -204,8 +204,7 @@ public class IncProjectBuilder {
catch (ProjectBuildException e) {
LOG.info(e);
final Throwable cause = e.getCause();
if (cause instanceof PersistentEnumerator.CorruptedException ||
cause instanceof MappingFailedException ||
if (cause instanceof MappingFailedException ||
cause instanceof IOException ||
cause instanceof BuildDataCorruptedException ||
(cause instanceof RuntimeException && cause.getCause() instanceof IOException)) {

View File

@@ -387,7 +387,7 @@ public class TextChangesStorage {
int startChangeIndex = getChangeIndex(start);
int endChangeIndex = getChangeIndex(end);
boolean substringAffectedByChanges = startChangeIndex >= 0 || endChangeIndex >= 0 || startChangeIndex != endChangeIndex;
boolean substringAffectedByChanges = startChangeIndex != endChangeIndex || startChangeIndex >= 0;
int clientShift = 0;
int originalStart = 0;
if (startChangeIndex < 0) {

View File

@@ -239,7 +239,7 @@ public class SingleRootFileViewProvider extends AbstractFileViewProvider impleme
PsiFile prev = myPsiFile;
// jdk 6 doesn't have getAndSet()
if (myPsiFileUpdater.compareAndSet(this, prev, psiFile)) {
if (prev != null && prev != psiFile && prev instanceof PsiFileEx) {
if (prev != psiFile && prev instanceof PsiFileEx) {
((PsiFileEx)prev).markInvalidated();
}
break;

View File

@@ -109,7 +109,7 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
SmartPsiElementPointerImpl cachedPointer = SoftReference.dereference(data);
if (cachedPointer != null) {
PsiElement cachedElement = cachedPointer.getElement();
if (cachedElement == null || cachedElement != element) {
if (cachedElement != element) {
return null;
}
}

View File

@@ -24,7 +24,7 @@ public final class UINumericRange {
public final int max;
public UINumericRange(int defaultValue, int minimumValue, int maximumValue) {
if (minimumValue > maximumValue || defaultValue < minimumValue || defaultValue > maximumValue) {
if (defaultValue < minimumValue || defaultValue > maximumValue) {
throw new IllegalArgumentException("Wrong range values: [" + minimumValue + ".." + defaultValue + ".." + maximumValue + "]");
}
initial = defaultValue;

View File

@@ -374,7 +374,7 @@ abstract class ProjectViewDropTarget implements DnDNativeTarget {
@Override
public boolean shouldDelegateToParent(@NotNull TreePath[] sources, @NotNull TreePath target) {
PsiElement psiElement = getPsiElement(target);
return psiElement == null || !(psiElement instanceof PsiDirectoryContainer) && !(psiElement instanceof PsiDirectory);
return !(psiElement instanceof PsiDirectoryContainer) && !(psiElement instanceof PsiDirectory);
}
@Override

View File

@@ -100,8 +100,7 @@ public class EditorColorPaletteFactoryImpl extends EditorColorPaletteFactory {
private static boolean pageIsGoodForAnyLanguage(boolean filterOutRainbowNonConflictingAttrKeys,
@NotNull ColorSettingsPage page) {
return !filterOutRainbowNonConflictingAttrKeys
|| page instanceof DefaultLanguageColorsPage
|| page instanceof GeneralColorsPage
|| page instanceof RainbowColorSettingsPage;
|| page instanceof GeneralColorsPage
|| page instanceof RainbowColorSettingsPage;
}
}

View File

@@ -32,7 +32,7 @@ public class FileOffsetsManager {
private final boolean myLineOffsetsAreTheSame;
LineOffsets(final long modificationStamp, @NotNull final int[] originalLineOffsets, @NotNull final int[] convertedLineOffsets) {
assert originalLineOffsets.length > 0 && convertedLineOffsets.length > 0 && originalLineOffsets.length == convertedLineOffsets.length
assert convertedLineOffsets.length > 0 && originalLineOffsets.length == convertedLineOffsets.length
: originalLineOffsets.length + " " + convertedLineOffsets.length;
myFileModificationStamp = modificationStamp;

View File

@@ -356,8 +356,7 @@ public class IdeGlassPaneImpl extends JPanel implements IdeGlassPaneEx, IdeEvent
}
private boolean canProcessCursorFor(Component target) {
if (target instanceof JMenu ||
target instanceof JMenuItem ||
if (target instanceof JMenuItem ||
target instanceof Divider ||
target instanceof JSeparator ||
(target instanceof JEditorPane && ((JEditorPane)target).getEditorKit() instanceof HTMLEditorKit)) {

View File

@@ -132,7 +132,7 @@ public final class RequestFocusInToolWindowCmd extends FinalizableCommand {
}
if (c.isShowing()) {
final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
if (owner == null || owner != c) {
if (owner != c) {
Component defaultComponent = myToolWindow.getComponent().getFocusTraversalPolicy().getDefaultComponent(myToolWindow.getComponent());
if (defaultComponent != null) {
myManager.getFocusManager().requestFocusInProject(

View File

@@ -1887,7 +1887,7 @@ public class AbstractPopup implements JBPopup {
*/
private static Component getFrameOrDialog(Component component) {
while (component != null) {
if (component instanceof Frame || component instanceof Dialog || component instanceof Window) return component;
if (component instanceof Window) return component;
component = component.getParent();
}
return null;

View File

@@ -26,8 +26,7 @@ public class ModuleUtilCore {
if (isLibraryElement) {
List<OrderEntry> orders = projectFileIndex.getOrderEntriesForFile(file);
for(OrderEntry orderEntry:orders) {
if (orderEntry instanceof ModuleJdkOrderEntry || orderEntry instanceof JdkOrderEntry ||
orderEntry instanceof LibraryOrderEntry) {
if (orderEntry instanceof JdkOrderEntry || orderEntry instanceof LibraryOrderEntry) {
return true;
}
}
@@ -205,8 +204,7 @@ public class ModuleUtilCore {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
if (isLibraryElement) {
OrderEntry orderEntry = moduleRootManager.getFileIndex().getOrderEntryForFile(file);
return orderEntry instanceof ModuleJdkOrderEntry || orderEntry instanceof JdkOrderEntry ||
orderEntry instanceof LibraryOrderEntry;
return orderEntry instanceof JdkOrderEntry || orderEntry instanceof LibraryOrderEntry;
}
else {
return moduleRootManager.getFileIndex().isInContent(file);

View File

@@ -129,7 +129,7 @@ public class ControlFlowBuilderUtil {
if (pparent instanceof GrBlockStatement || pparent instanceof GrCatchClause || pparent instanceof GrLabeledStatement) {
pparent = pparent.getParent();
}
if (pparent instanceof GrIfStatement || pparent instanceof GrControlStatement || pparent instanceof GrTryCatchStatement) {
if (pparent instanceof GrControlStatement || pparent instanceof GrTryCatchStatement) {
return isCertainlyReturnStatement((GrStatement)pparent);
}
}

View File

@@ -146,7 +146,6 @@ public class GroovyBlock implements Block, ASTBlock {
}
if (psiParent instanceof GrBinaryExpression ||
psiParent instanceof GrConditionalExpression ||
psiParent instanceof GrCommandArgumentList ||
psiParent instanceof GrArgumentList ||
psiParent instanceof GrParameterList ||
psiParent instanceof GrListOrMap ||

View File

@@ -955,7 +955,6 @@ public class ExpressionGenerator extends Generator {
//all refs in script that are not resolved are saved in 'binding' of the script
if (qualifier == null &&
(resolved == null ||
resolved instanceof GrBindingVariable ||
resolved instanceof LightElement && !(resolved instanceof ClosureSyntheticParameter)) &&
(referenceExpression.getParent() instanceof GrIndexProperty || !(referenceExpression.getParent() instanceof GrCall)) &&
PsiUtil.getContextClass(referenceExpression) instanceof GroovyScriptClass) {
@@ -1389,7 +1388,7 @@ public class ExpressionGenerator extends Generator {
public void visitListOrMap(@NotNull GrListOrMap listOrMap) {
final PsiType type = listOrMap.getType();
LOG.assertTrue(type instanceof GrLiteralClassType || type instanceof PsiClassType);
LOG.assertTrue(type instanceof PsiClassType);
if (listOrMap.isMap()) {
if (listOrMap.getNamedArguments().length == 0) {

View File

@@ -60,7 +60,7 @@ public class PyTokenSeparatorGenerator implements TokenSeparatorGenerator {
}
private static boolean isStatementOrFunction(PsiElement element) {
return element instanceof PyFunction || element instanceof PyStatement;
return element instanceof PyStatement;
}
private static ASTNode createSpace(PsiManager manager) {

View File

@@ -51,7 +51,7 @@ public class PyTargetElementEvaluator implements TargetElementEvaluator {
PsiElement result = ref.resolve();
Set<PsiElement> visited = new HashSet<>();
visited.add(result);
while (result instanceof PyReferenceOwner && (result instanceof PyReferenceExpression || result instanceof PyTargetExpression)) {
while (result instanceof PyReferenceExpression || result instanceof PyTargetExpression) {
PsiElement nextResult = ((PyReferenceOwner)result).getReference(PyResolveContext.noImplicits()).resolve();
if (nextResult != null && !visited.contains(nextResult) &&
PsiTreeUtil.getParentOfType(element, ScopeOwner.class) == PsiTreeUtil.getParentOfType(result, ScopeOwner.class) &&

View File

@@ -141,8 +141,8 @@ public class PyPrefixExpressionImpl extends PyElementImpl implements PyPrefixExp
@Nullable
private static Ref<PyType> getGeneratorReturnType(@Nullable PyType type) {
if (type instanceof PyClassLikeType && type instanceof PyCollectionType) {
if (type instanceof PyClassType && PyNames.AWAITABLE.equals(((PyClassType)type).getPyClass().getName())) {
if (type instanceof PyCollectionType) {
if (PyNames.AWAITABLE.equals(((PyClassType)type).getPyClass().getName())) {
return Ref.create(((PyCollectionType)type).getIteratedItemType());
}
else {

View File

@@ -235,7 +235,7 @@ public class PythonLanguageLevelPusher implements FilePropertyPusher<LanguageLev
final Module module = entry.getKey();
final Sdk newSdk = entry.getValue();
final Sdk oldSdk = myModuleSdks.get(module);
return myModuleSdks.containsKey(module) && (newSdk != null || oldSdk != null) && newSdk != oldSdk;
return myModuleSdks.containsKey(module) && newSdk != oldSdk;
}));
myModuleSdks.putAll(moduleSdks);

View File

@@ -26,7 +26,6 @@ import com.intellij.psi.xml.XmlElement;
public class XmlBasicWordSelectionFilter implements Condition<PsiElement> {
@Override
public boolean value(final PsiElement e) {
return !(e instanceof XmlToken) &&
!(e instanceof XmlElement);
return !(e instanceof XmlElement);
}
}