Warnings fixed (mostly redundant cast)

GitOrigin-RevId: 63bdb7f359a1a2cd37cb6a691b3d94db8ba3ce02
This commit is contained in:
Tagir Valeev
2024-10-10 13:26:12 +02:00
committed by intellij-monorepo-bot
parent 8719731a84
commit feb2ee9625
17 changed files with 41 additions and 47 deletions

View File

@@ -269,22 +269,22 @@ public final class JavaSourceInference {
return contract;
});
}
public static boolean canInferFromSource(@NotNull PsiMethodImpl method) {
return getInferenceMode(method) == InferenceMode.ENABLED;
}
private static InferenceMode getInferenceMode(@NotNull PsiMethodImpl method) {
if (isLibraryCode(method) ||
((PsiMethod)method).hasModifierProperty(PsiModifier.ABSTRACT) ||
((PsiMethod)method).hasModifierProperty(PsiModifier.NATIVE)) {
method.hasModifierProperty(PsiModifier.ABSTRACT) ||
method.hasModifierProperty(PsiModifier.NATIVE)) {
return InferenceMode.DISABLED;
}
if (((PsiMethod)method).hasModifierProperty(PsiModifier.STATIC)) return InferenceMode.ENABLED;
if (method.hasModifierProperty(PsiModifier.STATIC)) return InferenceMode.ENABLED;
if (PsiUtil.canBeOverridden(method)) {
PsiClass containingClass = method.getContainingClass();
if (containingClass != null && (PsiUtil.isLocalClass(containingClass) ||
if (containingClass != null && (PsiUtil.isLocalClass(containingClass) ||
!containingClass.isInterface() && containingClass.hasModifierProperty(PsiModifier.PRIVATE))) {
if (ClassInheritorsSearch.search(containingClass, new LocalSearchScope(containingClass.getContainingFile()), false)
.findFirst() == null) {

View File

@@ -74,7 +74,7 @@ public final class BasicJavaParserUtil {
@Nullable
public static IElementType exprType(@Nullable final PsiBuilder.Marker marker) {
return marker != null ? ((LighterASTNode)marker).getTokenType() : null;
return marker != null ? marker.getTokenType() : null;
}
// used instead of PsiBuilder.error() as it keeps all subsequent error messages

View File

@@ -263,7 +263,7 @@ public final class PsiCodeBlockImpl extends LazyParseablePsiElement implements P
}
if (child == null) {
child = ((PsiElement)this).getLastChild();
child = this.getLastChild();
}
while (child != null) {

View File

@@ -265,7 +265,7 @@ public final class BuildDataManager {
finally {
SourceToOutputMappingWrapper sourceToOutput = buildTargetToSourceToOutputMapping.remove(target);
if (sourceToOutput != null && sourceToOutput.myDelegate != null) {
((StorageOwner)sourceToOutput.myDelegate).close();
sourceToOutput.myDelegate.close();
}
if (newDataManager != null) {
@@ -385,7 +385,7 @@ public final class BuildDataManager {
if (outputToTargetMapping != null) {
outputToTargetMapping.flush(memoryCachesOnly);
}
if (sourceToFormMap != null) {
sourceToFormMap.flush(memoryCachesOnly);
}
@@ -464,7 +464,7 @@ public final class BuildDataManager {
static <T extends Throwable> void execAll(Class<T> errorClass, IOOperation<T>... operations) throws T {
execAll(errorClass, Arrays.asList(operations));
}
static <T extends Throwable> void execAll(Class<T> errorClass, Iterable<IOOperation<T>> operations) throws T {
Throwable error = null;
for (IOOperation<T> operation : operations) {
@@ -616,7 +616,7 @@ public final class BuildDataManager {
private @NotNull StorageOwner allTargetStorages() {
return allTargetStorages(f -> {});
}
private static final class SourceToOutputMappingWrapper implements SourceToOutputMapping {
private final SourceToOutputMappingImpl myDelegate;
private final int myBuildTargetId;

View File

@@ -1,7 +1,6 @@
// 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.
package com.intellij.lang.pratt;
import com.intellij.lang.LighterASTNode;
import com.intellij.lang.PsiBuilder;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.psi.tree.IElementType;
@@ -22,7 +21,7 @@ public class MutableMarker {
myPath = path;
myStartMarker = startMarker;
myInitialPathLength = initialPathLength;
myMode = startMarker instanceof LighterASTNode && ((LighterASTNode)startMarker).getTokenType() != null? Mode.COMMITTED : Mode.READY;
myMode = startMarker != null && startMarker.getTokenType() != null ? Mode.COMMITTED : Mode.READY;
}
// for easier transition only
@@ -30,7 +29,7 @@ public class MutableMarker {
myPath = path;
myStartMarker = (PsiBuilder.Marker)builder.getLatestDoneMarker();
myInitialPathLength = path.size();
myResultType = myStartMarker != null ? ((LighterASTNode)myStartMarker).getTokenType() : null;
myResultType = myStartMarker != null ? myStartMarker.getTokenType() : null;
myMode = myResultType != null ? Mode.COMMITTED : Mode.READY;
}

View File

@@ -17,7 +17,6 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.ByteArraySequence;
import com.intellij.openapi.util.io.ByteSequence;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
@@ -546,7 +545,7 @@ final class FileTypeDetectionService implements Disposable {
file, true, true,
PlainTextFileType.INSTANCE, (@Nullable CharSequence text) -> {
if (toLog()) {
log("F: detectFromContentAndCache.processFirstBytes(" + file.getName() + "): bytes length=" + ((ByteSequence)bytes).length() +
log("F: detectFromContentAndCache.processFirstBytes(" + file.getName() + "): bytes length=" + bytes.length() +
"; isText=" + (text != null) + "; text='" + (text == null ? null : StringUtil.first(text, 100, true)) + "'" +
", detectors=" + detectors);
}
@@ -651,7 +650,7 @@ final class FileTypeDetectionService implements Disposable {
if (!file.isCharsetSet()) {
// when detecting type from content of a file with unknown charset we have to determine charset first,
// which in turn may require file content. But in this case, the whole file content because the UTF surrogates may very well be at the end of the file.
return FileUtilRt.getUserContentLoadLimit();
return FileUtilRt.getUserContentLoadLimit();
}
int bufferLength = cachedDetectFileBufferSize;
if (bufferLength == -1) {

View File

@@ -2,7 +2,6 @@
package com.intellij.openapi.roots.ui.util;
import com.intellij.ide.highlighter.ArchiveFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.ApiStatus;
@@ -17,7 +16,7 @@ public final class JarSubfileCellAppearance extends ValidFileCellAppearance {
@Override
protected Icon getIcon() {
return ((FileType)ArchiveFileType.INSTANCE).getIcon();
return ArchiveFileType.INSTANCE.getIcon();
}
@Override

View File

@@ -1,15 +1,14 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.vfs.newvfs.persistent.dev.content;
import com.intellij.platform.util.io.storages.DataExternalizerEx;
import com.intellij.platform.util.io.storages.KeyDescriptorEx;
import com.intellij.platform.util.io.storages.appendonlylog.AppendOnlyLogFactory;
import com.intellij.platform.util.io.storages.appendonlylog.AppendOnlyLogOverMMappedFile;
import com.intellij.platform.util.io.storages.DataExternalizerEx;
import com.intellij.platform.util.io.storages.enumerator.DurableEnumerator;
import com.intellij.platform.util.io.storages.enumerator.DurableEnumeratorFactory;
import com.intellij.platform.util.io.storages.KeyDescriptorEx;
import com.intellij.util.hash.ContentHashEnumerator;
import com.intellij.util.io.CleanableStorage;
import com.intellij.util.io.ScannableDataEnumeratorEx;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -96,14 +95,14 @@ public class ContentHashEnumeratorOverDurableEnumerator implements ContentHashEn
@Override
public boolean forEach(@NotNull ValueReader<? super byte[]> reader) throws IOException {
return ((ScannableDataEnumeratorEx<byte[]>)enumerator).forEach(
return enumerator.forEach(
(enumeratorId, hash) -> reader.read(enumeratorIdToHashId(enumeratorId), hash)
);
}
@Override
public int recordsCount() throws IOException {
return ((ScannableDataEnumeratorEx<byte[]>)enumerator).recordsCount();
return enumerator.recordsCount();
}
@Override
@@ -204,7 +203,7 @@ public class ContentHashEnumeratorOverDurableEnumerator implements ContentHashEn
}
@Override
public KnownSizeRecordWriter writerFor(byte @NotNull [] hash) throws IOException {
public KnownSizeRecordWriter writerFor(byte @NotNull [] hash) {
return DataExternalizerEx.fromBytes(hash);
}

View File

@@ -152,7 +152,7 @@ abstract class ConcurrentIntKeyRefValueHashMap<V> implements ConcurrentIntObject
@NotNull
private Iterator<Entry<V>> entriesIterator() {
final Iterator<Entry<IntReference<V>>> entryIterator = ((Iterable<Entry<IntReference<V>>>)myMap.entrySet()).iterator();
final Iterator<Entry<IntReference<V>>> entryIterator = myMap.entrySet().iterator();
return new Iterator<>() {
private Entry<V> nextVEntry;
private Entry<IntReference<V>> nextReferenceEntry;

View File

@@ -59,6 +59,8 @@ package org.jdom.filter;
import org.jdom.Element;
import org.jdom.Namespace;
import java.util.Objects;
/**
* @deprecated Use {@link org.jdom.filter2.ElementFilter}
*/
@@ -139,12 +141,7 @@ public final class ElementFilter extends AbstractFilter<Element> {
if (!(obj instanceof ElementFilter)) return false;
final ElementFilter filter = (ElementFilter)obj;
//noinspection StringEquality
if (!((name == filter.name) || (name != null && ((Object)name).equals(filter.name)))) return false;
if (!((namespace == filter.namespace) || (namespace != null && ((Object)namespace).equals(filter.namespace)))) return false;
return true;
return Objects.equals(name, filter.name) && Objects.equals(namespace, filter.namespace);
}
public int hashCode() {

View File

@@ -143,7 +143,7 @@ abstract class ConcurrentIntKeyRefValueHashMap<V> implements ConcurrentIntObject
}
private @NotNull Iterator<Entry<V>> entriesIterator() {
Iterator<Entry<IntReference<V>>> entryIterator = ((Iterable<Entry<IntReference<V>>>)myMap.entrySet()).iterator();
Iterator<Entry<IntReference<V>>> entryIterator = myMap.entrySet().iterator();
return new Iterator<Entry<V>>() {
private Entry<V> nextVEntry;
private Entry<IntReference<V>> nextReferenceEntry;

View File

@@ -108,7 +108,7 @@ public final class MavenKeymapExtension implements ExternalSystemKeymapExtension
return result;
}
static void updateActions(Project project, List<? extends MavenProject> mavenProjects) {
static void updateActions(Project project, List<MavenProject> mavenProjects) {
clearActions(project, mavenProjects);
createActions(project, mavenProjects);
}
@@ -124,7 +124,7 @@ public final class MavenKeymapExtension implements ExternalSystemKeymapExtension
return mavenGoalAction;
}
private static void createActions(Project project, List<? extends MavenProject> mavenProjects) {
private static void createActions(Project project, List<MavenProject> mavenProjects) {
ActionManager actionManager = ActionManager.getInstance();
MavenShortcutsManager shortcutsManager = MavenShortcutsManager.getInstance(project);
@@ -163,7 +163,7 @@ public final class MavenKeymapExtension implements ExternalSystemKeymapExtension
}
}
static void clearActions(Project project, List<? extends MavenProject> mavenProjects) {
static void clearActions(Project project, List<MavenProject> mavenProjects) {
ActionManager manager = ActionManager.getInstance();
for (MavenProject eachProject : mavenProjects) {
for (String eachAction : getActionIdList(project, eachProject)) {
@@ -187,7 +187,7 @@ public final class MavenKeymapExtension implements ExternalSystemKeymapExtension
if (info == null) continue;
for (MavenPluginInfo.Mojo m : info.getMojos()) {
((Set<? super String>)result).add(m.getQualifiedGoal());
result.add(m.getQualifiedGoal());
}
}

View File

@@ -155,13 +155,13 @@ public final class MavenShortcutsManager implements Disposable {
}
@Override
public void projectsIgnoredStateChanged(List<MavenProject> ignored, List<MavenProject> unignored, boolean fromImport) {
public void projectsIgnoredStateChanged(@NotNull List<MavenProject> ignored, @NotNull List<MavenProject> unignored, boolean fromImport) {
scheduleKeymapUpdate(unignored, true);
scheduleKeymapUpdate(ignored, false);
}
@Override
public void projectsUpdated(List<? extends Pair<MavenProject, MavenProjectChanges>> updated, List<MavenProject> deleted) {
public void projectsUpdated(@NotNull List<? extends Pair<MavenProject, MavenProjectChanges>> updated, @NotNull List<MavenProject> deleted) {
scheduleKeymapUpdate(MavenUtil.collectFirsts(updated), true);
scheduleKeymapUpdate(deleted, false);
}
@@ -176,7 +176,7 @@ public final class MavenShortcutsManager implements Disposable {
scheduleKeymapUpdate(Collections.singletonList(project), true);
}
private void scheduleKeymapUpdate(List<? extends MavenProject> mavenProjects, boolean forUpdate) {
private void scheduleKeymapUpdate(List<MavenProject> mavenProjects, boolean forUpdate) {
synchronized (mySheduledProjects) {
for (MavenProject each : mavenProjects) {
mySheduledProjects.put(each, forUpdate);

View File

@@ -16,7 +16,6 @@ import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.ProjectScope;
import com.intellij.util.Plow;
@@ -78,7 +77,7 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont
@Override
public boolean processSelectedItem(@NotNull YAMLKeyNavigationItem selected, int modifiers, @NotNull String searchText) {
((Navigatable)selected).navigate(true);
selected.navigate(true);
return true;
}

View File

@@ -25,6 +25,7 @@ import com.intellij.ui.AppUIUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.util.Consumer;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.NamedColorUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.xdebugger.XDebugSession;
@@ -134,7 +135,7 @@ final class PyUnitTestsDebuggingService {
*/
public static boolean isErrorInTestSetUpOrTearDown(@NotNull List<PyStackFrameInfo> frames) {
for (PyStackFrameInfo frameInfo : frames) {
if (SET_UP_AND_TEAR_DOWN_FUNCTIONS_BY_FRAMEWORK.values().stream().anyMatch(names -> names.contains(frameInfo.getName())))
if (ContainerUtil.exists(SET_UP_AND_TEAR_DOWN_FUNCTIONS_BY_FRAMEWORK.values(), names -> names.contains(frameInfo.getName())))
return true;
}
return false;
@@ -210,7 +211,7 @@ final class PyUnitTestsDebuggingService {
return UIUtil.getFontWithFallback(fontName, Font.PLAIN, fontSize);
}
private void drawStringToInlayBox(@NotNull String str, @NotNull Inlay inlay, @NotNull Graphics g, @NotNull Rectangle targetRegion) {
private void drawStringToInlayBox(@NotNull String str, @NotNull Inlay<?> inlay, @NotNull Graphics g, @NotNull Rectangle targetRegion) {
g.drawString(str, targetRegion.x + INLAY_TEXT_INDENT, targetRegion.y + inlay.getEditor().getLineHeight() * myCurrentLineNumber);
myCurrentLineNumber++;
}
@@ -240,7 +241,7 @@ final class PyUnitTestsDebuggingService {
}
private static @NotNull Color getInlayBackgroundColor() {
return UIUtil.isUnderDarcula() ? JBColor.WHITE : new JBColor(Gray._240, Gray._192);
return JBColor.isBright() ? new JBColor(Gray._240, Gray._192) : JBColor.WHITE;
}
private static @Nls String getFailedTestCaption() {
@@ -277,7 +278,7 @@ final class PyUnitTestsDebuggingService {
@Override
public int hashCode() {
return ((Object)this).hashCode();
return System.identityHashCode(this);
}
}
}

View File

@@ -73,7 +73,7 @@ public class ExeReader extends Bin.Structure {
long result = 0;
long lastVA = 0;
for (ImageSectionHeader header : mySectionHeaders) {
long va = ((Value)header.getVirtualAddress()).getValue();
long va = header.getVirtualAddress().getValue();
if (lastVA < va) {
result = header.getVirtualSize().getValue() + va;
}

View File

@@ -170,6 +170,7 @@ public class ProxyTest extends TestCase {
}, false, ArrayUtilRt.EMPTY_OBJECT_ARRAY);
assertEquals("a", proxy.sayA());
assertEquals("a", ((CovariantFromBaseClassTest.Base)proxy).sayA());
//noinspection RedundantCast
assertEquals("a", ((CovariantFromBaseClassTest.Intf)proxy).sayA());
}