zero-tolerance fixes !Optional#isPresent() -> Optional#empty()
authorIlyas Selimov <ilyas.selimov@jetbrains.com>
Wed, 12 Aug 2020 06:47:50 +0000 (13:47 +0700)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 06:48:24 +0000 (06:48 +0000)
GitOrigin-RevId: 5294e395bb38747ad6a82d0e0e68cae3f1b76bae

16 files changed:
java/debugger/impl/src/com/intellij/debugger/actions/JavaSmartStepIntoHandler.java
java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/MethodBreakpoint.java
java/java-impl/src/com/intellij/codeInspection/CapturingCleanerInspection.java
java/java-impl/src/com/intellij/codeInspection/SimplifyOptionalCallChainsInspection.java
json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java
platform/inspect/src/com/intellij/codeInspection/InspectionApplication.java
platform/lang-impl/src/com/intellij/ide/actions/SetShortcutAction.java
platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ComponentWithBrowseButtonFixture.java
platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/ToolWindowFixture.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleLocalChangeListsBrowser.java
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InstanceOfUtils.java
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/serialization/MissingSerialAnnotationInspection.java
plugins/InspectionGadgets/src/com/siyeh/ig/inheritance/MissingOverrideAnnotationInspection.java
plugins/editorconfig/src/org/editorconfig/language/psi/impl/EditorConfigPsiImplUtils.java
plugins/java-i18n/src/com/intellij/codeInspection/i18n/NlsInfo.java
plugins/maven/src/test/java/org/jetbrains/idea/maven/compiler/MavenCompilingTestCase.java

index 2fe85210fa0821fcfa196986464722451e2df9fa..674b564170c69af5485b8da63d07a5e94b2e9439 100644 (file)
@@ -398,7 +398,7 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
               visitLinesInstructions(frameProxy.location(), true, lines, visitor);
 
               // check if anything real left, fallback to the previous state
-              if (!targets.isEmpty() && !immediateMethodCalls(targets).findAny().isPresent()) {
+              if (!targets.isEmpty() && immediateMethodCalls(targets).findAny().isEmpty()) {
                 targets.clear();
                 targets.addAll(copy);
               }
index e46973218873e06a6e8e777df268ab554a636ceb..dfb214ce5b61be4f5d33db6ebbd5e3fdbc353284 100644 (file)
@@ -203,9 +203,9 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
     }
     Method lambdaMethod = MethodBytecodeUtil.getLambdaMethod(classType, classesByName);
     if (lambdaMethod != null &&
-        !breakpoint
+        breakpoint
           .matchingMethods(StreamEx.of(((ClassType)classType).interfaces()).flatCollection(ReferenceType::allMethods), debugProcess)
-          .findFirst().isPresent()) {
+          .findFirst().isEmpty()) {
       return;
     }
     StreamEx<Method> methods = lambdaMethod != null
index 6e25ed4e313e0b7c54ab2d1fb50b486176c144be..d94128b311e5fe81b46c4930dce9bbb869992ede 100644 (file)
@@ -59,7 +59,7 @@ public class CapturingCleanerInspection extends AbstractBaseJavaLocalInspectionT
           Optional<PsiElement> referenceExpression = StreamEx.ofTree(((PsiElement)runnableExpression), el -> StreamEx.of(el.getChildren()))
             .findAny(el -> el instanceof PsiReferenceExpression &&
                            ((PsiReferenceExpression)el).isReferenceTo(variable));
-          if (!referenceExpression.isPresent()) return;
+          if (referenceExpression.isEmpty()) return;
           String variableName = variable.getName();
           if (variableName == null) return;
           highlightingElement = referenceExpression.get();
index ecbbc61dcd86a839492dc42abd7df84a363fe8f4..9032e63bc59c57f7284dffa25c2ce4f88d9a3b84 100644 (file)
@@ -293,7 +293,7 @@ public class SimplifyOptionalCallChainsInspection extends AbstractBaseJavaLocalI
         .mapAll(expression)
         .filter(f -> f.myInspection.isAppropriateLanguageLevel(myLevel))
         .findAny();
-      if (!fix.isPresent()) return;
+      if (fix.isEmpty()) return;
       handleSimplification(expression, fix.get());
     }
 
index 76c4c08b1a37e8c4da2da57c11ecaff8d02126a0..5f413b877ee674dd3cf7e60e5c0e71b1b5db2801 100644 (file)
@@ -210,7 +210,7 @@ public class JsonSchemaServiceImpl implements JsonSchemaService, ModificationTra
       if (providers.size() > 1) {
         final Optional<JsonSchemaFileProvider> userSchema =
           providers.stream().filter(provider -> SchemaType.userSchema.equals(provider.getSchemaType())).findFirst();
-        if (!userSchema.isPresent()) return ContainerUtil.emptyList();
+        if (userSchema.isEmpty()) return ContainerUtil.emptyList();
         selected = userSchema.get();
       } else selected = providers.get(0);
       VirtualFile schemaFile = getSchemaForProvider(myProject, selected);
index c10ddaa54d00c9e3fcb225cfb7d9dfa3d47d7055..e0e9fe80246880eb90f400205ce4fb2482e60957 100644 (file)
@@ -531,7 +531,7 @@ public final class InspectionApplication implements CommandLineInspectionProgres
   private boolean secondAnalysisFilter(ChangeListManager changeListManager, String text, VirtualFile file, int line) {
     List<Range> ranges = getOrComputeUnchangedRanges(file, changeListManager);
     Optional<Range> first = StreamEx.of(ranges).findFirst(it -> it.start1 <= line && line < it.end1);
-    if (!first.isPresent()) {
+    if (first.isEmpty()) {
       logNotFiltered(text, file, line, -1);
       return true;
     }
index ec17525fae8853f59754eb224ca9b0a302d1d4d2..a2228cb400d89c7795c50e1a125b57275610bd78 100644 (file)
@@ -55,7 +55,7 @@ public class SetShortcutAction extends AnAction implements DumbAware {
     Presentation presentation = e.getPresentation();
 
     Optional<JBPopup> seDialog = getPopup(e);
-    if (!seDialog.isPresent()) {
+    if (seDialog.isEmpty()) {
       presentation.setEnabled(false);
       return;
     }
index 9c186eeeaef55dc476ea4166f090dcc9d1b09261..4cb2909bcf71473eed6e3aa185a5c7870d7e703f 100644 (file)
@@ -58,7 +58,7 @@ public class ComponentWithBrowseButtonFixture extends JComponentFixture<Componen
 
     final Optional<ExtendableTextComponent.Extension> extension =
       extendableTextField.getExtensions().stream().filter(extensionFilter).findFirst();
-    if (!extension.isPresent()) {
+    if (extension.isEmpty()) {
       throw new ComponentLookupException("Unable to find extension");
     }
 
index aa8cca72bd89469daae29a829bcccf0be4519234..eebb9f6d129d5ed7cf3d1affc449d038b43236b4 100644 (file)
@@ -242,7 +242,7 @@ public abstract class ToolWindowFixture {
       protected void executeInEDT() throws Throwable {
         Stream<Content> contentStream = Arrays.stream(myToolWindow.getContentManager().getContents());
         Optional<Content> contentOptional = contentStream.filter(content -> content.getTabName().equals(tabName)).findAny();
-        if (!contentOptional.isPresent()) {
+        if (contentOptional.isEmpty()) {
           throw new ComponentLookupException("Unable to find content with tab name: \"" + tabName +
                                              "\" for ToolWindow with id: \"" + myToolWindowId + "\"");
         }
index 6820d49555b74171ba72296e587c8912fc688134..767b4067e868851811772648329c2c1043387904 100644 (file)
@@ -363,7 +363,7 @@ class MultipleLocalChangeListsBrowser extends CommitDialogChangesBrowser impleme
   private static boolean containsCollapsedUnversionedNode(@NotNull VcsTreeModelData treeModelData) {
     Optional<ChangesBrowserNode<?>> node = treeModelData.nodesStream()
       .filter(it -> it instanceof ChangesBrowserUnversionedFilesNode).findAny();
-    if (!node.isPresent()) return false;
+    if (node.isEmpty()) return false;
 
     ChangesBrowserUnversionedFilesNode unversionedFilesNode = (ChangesBrowserUnversionedFilesNode)node.get();
     return unversionedFilesNode.isManyFiles();
index eba23bda2b91472caf28f6520bf13669f34ea75a..7d43626ae53d81bb2ffd7f68e3dad81decf4cfdb 100644 (file)
@@ -149,11 +149,11 @@ public final class InstanceOfUtils {
     if (condition == null) return false;
     checker.negate = true;
     OptionalInt argNum = condition.getArgumentComparedTo(ContractValue.booleanValue(true), true);
-    if (!argNum.isPresent()) {
+    if (argNum.isEmpty()) {
       checker.negate = false;
       argNum = condition.getArgumentComparedTo(ContractValue.booleanValue(false), true);
     }
-    if (!argNum.isPresent()) return false;
+    if (argNum.isEmpty()) return false;
     int index = argNum.getAsInt();
     PsiExpression[] args = call.getArgumentList().getExpressions();
     if (index >= args.length) return false;
index 56dbf130bd71d168e991667363579d4a15b8cff0..a0b09641c7e8c147f49cd3a774fd70291511e56c 100644 (file)
@@ -46,7 +46,7 @@ public class MissingSerialAnnotationInspection extends BaseInspection {
       if (field.hasAnnotation(JAVA_IO_SERIAL) || !isConstant(field)) return;
 
       Optional<PsiClass> pClass = getSerializablePsiClass(field);
-      if (!pClass.isPresent()) return;
+      if (pClass.isEmpty()) return;
 
       boolean candidateToBeAnnotated =
         SerializationUtils.isExternalizable(pClass.get()) ? isSerialFieldInExternalizable(field) : isSerialFieldInSerializable(field);
@@ -61,7 +61,7 @@ public class MissingSerialAnnotationInspection extends BaseInspection {
       if (method.hasAnnotation(JAVA_IO_SERIAL)) return;
 
       Optional<PsiClass> pClass = getSerializablePsiClass(method);
-      if (!pClass.isPresent()) return;
+      if (pClass.isEmpty()) return;
 
       boolean candidateToBeAnnotated =
         SerializationUtils.isExternalizable(pClass.get()) ? isSerialMethodInExternalizable(method) : isSerialMethodInSerializable(method);
index 7a15a252f078a7a7ff8b07925bb8505360d9a452..e7d83e5b5cbdd0beded3c502eb5fab5923d5fb33 100644 (file)
@@ -160,7 +160,7 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn
                                               !JavaOverridingMethodUtil.containsAnnotationWithName(m, OVERRIDE_SHORT_NAME);
         Stream<PsiMethod> overridingMethods = JavaOverridingMethodUtil.getOverridingMethodsIfCheapEnough(method, scope, preFilter);
         if (overridingMethods == null) return;
-        result.hierarchyAnnotated = ThreeState.fromBoolean(!overridingMethods.findAny().isPresent());
+        result.hierarchyAnnotated = ThreeState.fromBoolean(overridingMethods.findAny().isEmpty());
       }
 
       private void checkMissingOverride(@NotNull PsiMethod method,
index 4202fa83e762bc342293faa8d56580063cdd6770..1cd657f333e0fb02ffb6ec0527403f7de060029e 100644 (file)
@@ -86,7 +86,7 @@ public final class EditorConfigPsiImplUtils {
       .filter(child -> child instanceof EditorConfigDescribableElement)
       .findFirst();
 
-    if (!first.isPresent()) {
+    if (first.isEmpty()) {
       throw new IllegalStateException();
     }
 
@@ -100,7 +100,7 @@ public final class EditorConfigPsiImplUtils {
       .skip(1)
       .findFirst();
 
-    if (!second.isPresent()) {
+    if (second.isEmpty()) {
       throw new IllegalStateException();
     }
 
index 0aabf04aba9a51c157a409cd63098147541ca45d..c1c9614540ffcf928cb61bf062b14a243513c756 100644 (file)
@@ -310,7 +310,7 @@ public abstract class NlsInfo {
       .filter(i -> UastUtils.isUastChildOf(expression, UastLiteralUtils.wrapULiteral(arguments.get(i)), false))
       .findFirst();
 
-    if (!idx.isPresent()) return Unspecified.UNKNOWN;
+    if (idx.isEmpty()) return Unspecified.UNKNOWN;
 
     PsiMethod method = callExpression.resolve();
     if (method == null) return Unspecified.UNKNOWN;
index 52cb7ccdd4fea628f9128a00d468afd58df71272..a2485509d3f54ff9a7360f6f4e920a3859a48e0e 100644 (file)
@@ -107,7 +107,7 @@ public abstract class MavenCompilingTestCase extends MavenImportingTestCase {
     String jdkVersion = null;
     Optional<Sdk> sdk = Optional.ofNullable(ModuleRootManager.getInstance(module).getSdk());
 
-    if (!sdk.isPresent()) {
+    if (sdk.isEmpty()) {
       Optional<JdkOrderEntry> jdkEntry =
         Arrays.stream(ModuleRootManager.getInstance(module).getOrderEntries())
           .filter(JdkOrderEntry.class::isInstance)