OPENIDE fix some problems from static analyser

This commit is contained in:
Nikita Iarychenko
2025-10-28 13:21:03 +04:00
parent ea0f8f2969
commit 0f1d91d293
11 changed files with 57 additions and 6 deletions

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.refactoring.introduceVariable;
import com.intellij.codeInsight.CodeInsightUtil;
@@ -372,6 +375,7 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
final PsiFile file = anchorStatement.getContainingFile();
IntroduceVariableUtil.LOG.assertTrue(file != null, "expr.getContainingFile() == null");
final PsiElement nameSuggestionContext = editor == null ? null : file.findElementAt(editor.getCaretModel().getOffset());
if (editor == null) return false;
final RefactoringSupportProvider supportProvider = LanguageRefactoringSupport.getInstance().forContext(expr);
final boolean isInplaceAvailableOnDataContext =
supportProvider != null &&

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.codeInsight.daemon.impl;
import com.intellij.openapi.diagnostic.Logger;
@@ -127,6 +130,7 @@ public final class CollectHighlightsUtil {
PsiElement commonParent = PsiTreeUtil.findCommonParent(left, right);
if (commonParent == null) {
LOG.error("No common parent for "+left+" and "+right+"; root: "+root+"; startOffset: "+startOffset+"; endOffset: "+endOffset);
return null;
}
LOG.assertTrue(commonParent.getTextRange() != null, commonParent);

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.openapi.editor;
import com.intellij.lang.Language;
@@ -10,10 +13,11 @@ import org.jetbrains.annotations.Nullable;
public class LanguageIndentStrategy extends LanguageExtension<IndentStrategy> {
public static final String EP_NAME = "com.intellij.lang.indentStrategy";
public static final LanguageIndentStrategy INSTANCE = new LanguageIndentStrategy();
private static final DefaultIndentStrategy DEFAULT_INDENT_STRATEGY = new DefaultIndentStrategy();
public static final LanguageIndentStrategy INSTANCE = new LanguageIndentStrategy();
public LanguageIndentStrategy() {
super(EP_NAME, DEFAULT_INDENT_STRATEGY);
}

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.codeInspection.ui;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
@@ -86,9 +89,9 @@ public final class InspectionTreeModel extends BaseTreeModel<InspectionTreeNode>
JBIterable<InspectionTreeNode> traverseFrom(InspectionTreeNode node, boolean direction) {
return JBIterable.generate(node, n -> getParent(n)).filter(n -> getParent(n) != null).flatMap(n1 -> {
InspectionTreeNode p = getParent(n1);
assert p != null;
int idx = getIndexOfChild(p, n1);
if (idx < 0) return JBIterable.empty();
assert p != null;
InspectionTreeNode.Children children = p.myChildren;
if (children == null) return JBIterable.empty();
InspectionTreeNode[] arr = children.myChildren;

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.openapi.module;
import com.intellij.codeInsight.multiverse.*;
@@ -62,7 +65,8 @@ public class ModuleUtilCore {
PsiFile file = element.getContainingFile();
if (file == null) return true;
VirtualFile vFile = file.getVirtualFile();
Module module = vFile == null ? null : projectFileIndex.getModuleForFile(vFile);
if (vFile == null) return true;
Module module = projectFileIndex.getModuleForFile(vFile);
// element may be in library
return module == null ? !projectFileIndex.isInLibraryClasses(vFile) : module.isDisposed();
}

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.openapi.projectRoots.impl;
import com.intellij.openapi.Disposable;
@@ -14,6 +17,7 @@ import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.platform.workspace.jps.entities.SdkEntity;
import com.intellij.util.ArrayUtil;
import com.intellij.util.concurrency.ThreadingAssertions;
import com.intellij.workspaceModel.ide.impl.legacyBridge.sdk.SdkBridgeImpl;
import org.jdom.Element;
@@ -174,6 +178,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void commitChanges() {
if (modificator == null) {
LOG.error("Forbidden to call `commitChanges` outside of `SdkModificator`");
return;
}
ThreadingAssertions.assertWriteAccess();
modificator.commitChanges();
@@ -217,6 +222,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public VirtualFile @NotNull [] getRoots(@NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to call `getRoots` outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return VirtualFile.EMPTY_ARRAY;
}
return modificator.getRoots(rootType);
}
@@ -225,6 +231,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public String @NotNull [] getUrls(@NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to call `getUrls` outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return ArrayUtil.EMPTY_STRING_ARRAY;
}
return modificator.getUrls(rootType);
}
@@ -233,6 +240,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.addRoot(root, rootType);
}
@@ -241,6 +249,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void addRoot(@NotNull String url, @NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.addRoot(url, rootType);
}
@@ -249,6 +258,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.removeRoot(root, rootType);
}
@@ -257,6 +267,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void removeRoot(@NotNull String url, @NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.removeRoot(url, rootType);
}
@@ -265,6 +276,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void removeRoots(@NotNull OrderRootType rootType) {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.removeRoots(rootType);
}
@@ -273,6 +285,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements SdkBridge, Sdk
public void removeAllRoots() {
if (modificator == null) {
LOG.error("Forbidden to mutate SDK outside of the `SdkModificator`. Please, use `com.intellij.openapi.projectRoots.Sdk.getSdkModificator`");
return;
}
modificator.removeAllRoots();
}

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.ide.util.treeView.smartTree;
import com.intellij.ide.structureView.StructureViewModel;
@@ -159,12 +162,14 @@ public abstract class CachingChildrenTreeNode <Value> extends AbstractTreeNode<V
for (Group group : groups) {
if (group == null) {
LOG.error(grouper + " returned null group: "+groups);
continue;
}
GroupWrapper groupWrapper = groupNodes.get(group);
Collection<TreeElement> children = group.getChildren();
for (TreeElement node : children) {
if (node == null) {
LOG.error(group + " returned null child: " + children);
continue;
}
CachingChildrenTreeNode child = createChildNode(node);
groupWrapper.addSubElement(child);

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.ide.util.treeView.smartTree;
@@ -36,6 +39,7 @@ public class GroupWrapper extends CachingChildrenTreeNode<Group> {
for (TreeElement child : children) {
if (child == null) {
LOG.error(group + " returned null child: " + children);
continue;
}
TreeElementWrapper childNode = createChildNode(child);
addSubElement(childNode);

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package com.intellij.usages.impl.rules;
import com.intellij.openapi.application.ApplicationManager;
@@ -10,6 +13,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public final class UsageType {
private static final Logger LOG = Logger.getInstance(UsageType.class);
public static final UsageType CLASS_INSTANCE_OF = new UsageType(UsageViewBundle.messagePointer("usage.type.instanceof"));
public static final UsageType CLASS_IMPORT = new UsageType(UsageViewBundle.messagePointer("usage.type.import"));
public static final UsageType CLASS_CAST_TO = new UsageType(UsageViewBundle.messagePointer("usage.type.cast.target"));
@@ -45,8 +50,6 @@ public final class UsageType {
public static final UsageType DELEGATE_TO_ANOTHER_INSTANCE = new UsageType(UsageViewBundle.messagePointer("usage.type.delegate.to.another.instance.method"));
public static final UsageType DELEGATE_TO_ANOTHER_INSTANCE_PARAMETERS_CHANGED = new UsageType(UsageViewBundle.messagePointer("usage.type.delegate.to.another.instance.method.parameters.changed"));
private static final Logger LOG = Logger.getInstance(UsageType.class);
private final Supplier<@Nls(capitalization = Nls.Capitalization.Sentence) String> myNameComputable;
/**

View File

@@ -1,5 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
/*
* @author max
*/
@@ -29,6 +31,7 @@ import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import static java.nio.file.StandardOpenOption.READ;

View File

@@ -1,4 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Nikita Iarychenko at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
package org.jetbrains.plugins.groovy.codeInspection.confusing;
import com.intellij.codeInspection.LocalQuickFix;
@@ -79,6 +82,7 @@ public final class GrUnusedIncDecInspection extends BaseInspection {
if (cur == null) {
LOG.error("no instruction found in flow." + "operand: " + operand.getText(), new Attachment("", owner.getText()));
return;
}
//get write access for inc or dec