Cleanup: fix warnings

GitOrigin-RevId: d2cfcc9ff2295509a6ba2036a70d302c35574bcc
This commit is contained in:
Tagir Valeev
2025-09-11 22:53:24 +00:00
committed by intellij-monorepo-bot
parent d1de696b74
commit 9ae9626b90
25 changed files with 66 additions and 114 deletions
@@ -316,13 +316,13 @@ public final class APIWrappers {
@Override
public JavaFileObject createSourceFile(CharSequence name, Element... originatingElements) throws IOException {
addMapping(name, originatingElements != null? Arrays.asList(originatingElements) : Collections.<Element>emptyList());
addMapping(name, originatingElements != null? Arrays.asList(originatingElements) : Collections.emptyList());
return getWrapperDelegate().createSourceFile(name, originatingElements);
}
@Override
public JavaFileObject createClassFile(CharSequence name, Element... originatingElements) throws IOException {
addMapping(name, originatingElements != null? Arrays.asList(originatingElements) : Collections.<Element>emptyList());
addMapping(name, originatingElements != null? Arrays.asList(originatingElements) : Collections.emptyList());
return getWrapperDelegate().createClassFile(name, originatingElements);
}
@@ -418,7 +418,7 @@ public final class APIWrappers {
}
}
if (pair == null) {
pair = Pair.<Method, Object>create(method, delegateTo);
pair = Pair.create(method, delegateTo);
}
}
myCallHandlers.put(method, pair);
@@ -234,7 +234,7 @@ public final class JpsJavacFileManager extends ForwardingJavaFileManager<Standar
final File file = (dir == null? new File(fileName).getAbsoluteFile() : new File(dir, fileName));
final boolean isGenerated = (sibling instanceof OutputFileObject && ((OutputFileObject)sibling).getKind() == JavaFileObject.Kind.SOURCE) /*created from generated source*/ || hasOriginatingNames(className, fileName);
return new OutputFileObject(
myContext, dir, fileName, file, kind, className, originatingSources == null? Collections.<URI>emptyList() : originatingSources, myEncodingName, null, location, isGenerated
myContext, dir, fileName, file, kind, className, originatingSources == null ? Collections.emptyList() : originatingSources, myEncodingName, null, location, isGenerated
);
}
@@ -520,7 +520,7 @@ public final class JpsJavacFileManager extends ForwardingJavaFileManager<Standar
// we consider here only locations that are known to be file-based
Iterable<JavaFileObject> providersContent = Iterators.flat(
myJpsJavacFileProvider != null? myJpsJavacFileProvider.list(location, packageName, kinds, recurse) : Collections.<JavaFileObject>emptyList(),
myJpsJavacFileProvider != null? myJpsJavacFileProvider.list(location, packageName, kinds, recurse) : Collections.emptyList(),
Iterators.map(myInputFileDataProvider != null? myInputFileDataProvider.list(location, packageName, kinds, recurse) : null, new Function<InputFileDataProvider.FileData, JavaFileObject>() {
@Override
public JavaFileObject fun(InputFileDataProvider.FileData fd) {
@@ -7,7 +7,7 @@ import org.jetbrains.jps.incremental.BinaryContent;
import org.jetbrains.jps.util.Iterators;
import org.jetbrains.jps.util.Iterators.Function;
import javax.tools.JavaFileManager;
import javax.tools.*;
import java.io.*;
import java.net.URI;
@@ -78,7 +78,7 @@ public final class OutputFileObject extends JpsFileObject {
public File fun(URI uri) {
return "file".equalsIgnoreCase(uri.getScheme())? new File(uri) : null;
}
}), Iterators.<File>notNullFilter());
}), Iterators.notNullFilter());
}
@NotNull
@@ -109,7 +109,7 @@ public final class Iterators {
@SuppressWarnings("unchecked")
public static <T> Iterable<T> flat(final Iterable<? extends T> first, final Iterable<? extends T> second) {
if (isEmptyCollection(first)) {
return isEmptyCollection(second)? Collections.<T>emptyList() : (Iterable<T>)second;
return isEmptyCollection(second) ? Collections.emptyList() : (Iterable<T>)second;
}
if (isEmptyCollection(second)) {
return (Iterable<T>)first;
@@ -149,7 +149,7 @@ public final class Iterators {
}
public static <T> Iterable<T> flat(final Iterable<? extends Iterable<? extends T>> parts) {
return isEmptyCollection(parts)? Collections.<T>emptyList() : new Iterable<T>() {
return isEmptyCollection(parts) ? Collections.emptyList() : new Iterable<T>() {
@NotNull
@Override
public Iterator<T> iterator() {
@@ -195,7 +195,7 @@ public final class Iterators {
public static <I> Iterator<I> asIterator(final Iterable<? extends I> from) {
//noinspection unchecked
return from == null? Collections.<I>emptyIterator() : (Iterator<I>)from.iterator();
return from == null ? Collections.emptyIterator() : (Iterator<I>)from.iterator();
}
public static <T> Iterable<T> asIterable(final T elem) {
@@ -209,7 +209,7 @@ public final class Iterators {
}
public static <T> Iterable<T> asIterable(final T[] elem) {
return elem == null? Collections.<T>emptyList() : Arrays.asList(elem);
return elem == null ? Collections.emptyList() : Arrays.asList(elem);
}
public static <T> Iterable<T> reverse(final List<T> list) {
@@ -254,7 +254,7 @@ public final class Iterators {
}
public static <I,O> Iterable<O> map(final Iterable<? extends I> from, final Function<? super I, ? extends O> mapper) {
return isEmptyCollection(from)? Collections.<O>emptyList() : new Iterable<O>() {
return isEmptyCollection(from) ? Collections.emptyList() : new Iterable<O>() {
@NotNull
@Override
public Iterator<O> iterator() {
@@ -278,7 +278,7 @@ public final class Iterators {
}
public static <T> Iterable<T> filter(final Iterable<? extends T> it, final BooleanFunction<? super T> predicate) {
return isEmptyCollection(it)? Collections.<T>emptyList() : new Iterable<T>() {
return isEmptyCollection(it) ? Collections.emptyList() : new Iterable<T>() {
@NotNull
@Override
public Iterator<T> iterator() {
@@ -333,7 +333,7 @@ public final class Iterators {
}
public static <T> Iterable<T> filterWithOrder(final Iterable<? extends T> from, final Iterable<? extends BooleanFunction<? super T>> predicates) {
return isEmptyCollection(predicates) || isEmptyCollection(from)? Collections.<T>emptyList() : new Iterable<T>() {
return isEmptyCollection(predicates) || isEmptyCollection(from) ? Collections.emptyList() : new Iterable<T>() {
@NotNull
@Override
public Iterator<T> iterator() {
@@ -370,7 +370,7 @@ public final class Iterators {
}
public static <T> Iterable<T> unique(final Iterable<? extends T> it) {
return isEmptyCollection(it)? Collections.<T>emptyList() : new Iterable<T>() {
return isEmptyCollection(it) ? Collections.emptyList() : new Iterable<T>() {
@NotNull
@Override
public Iterator<T> iterator() {
@@ -393,7 +393,7 @@ public final class Iterators {
}
public static <T> Iterable<T> uniqueBy(final Iterable<? extends T> it, final Provider<? extends BooleanFunction<T>> predicateFactory) {
return isEmptyCollection(it)? Collections.<T>emptyList() : new Iterable<T>() {
return isEmptyCollection(it) ? Collections.emptyList() : new Iterable<T>() {
@NotNull
@Override
public Iterator<T> iterator() {
@@ -47,12 +47,10 @@ final class ModuleChecker {
PsiJavaModule javaModule = myVisitor.javaModule();
if (javaModule != null) {
String packageName = statement.getPackageName();
if (packageName != null) {
PsiJavaModule origin = JavaPsiModuleUtil.findOrigin(javaModule, packageName);
if (origin != null) {
PsiJavaCodeReferenceElement reference = statement.getPackageReference();
myVisitor.report(JavaErrorKinds.MODULE_CONFLICTING_PACKAGES.create(reference, origin));
}
PsiJavaModule origin = JavaPsiModuleUtil.findOrigin(javaModule, packageName);
if (origin != null) {
PsiJavaCodeReferenceElement reference = statement.getPackageReference();
myVisitor.report(JavaErrorKinds.MODULE_CONFLICTING_PACKAGES.create(reference, origin));
}
}
else {
@@ -233,7 +231,7 @@ final class ModuleChecker {
: JavaErrorKinds.MODULE_NOT_FOUND.create(refElement));
case 1 -> myVisitor.report(JavaErrorKinds.MODULE_NOT_ON_PATH.create(refElement));
default -> {
// ambiguous module is reported as warning
// an ambiguous module is reported as a warning
}
}
}
@@ -449,8 +449,7 @@ public class VirtualMachineProxyImpl extends UserDataHolderBase implements JdiTi
}
ThreadReferenceProxyImpl proxy = myAllThreads.computeIfAbsent(thread, t -> {
// do not cache virtual threads
//noinspection ConstantValue
if (!forceCache && thread instanceof ThreadReferenceImpl && ((ThreadReferenceImpl)thread).isVirtual()) {
if (!forceCache && thread instanceof ThreadReferenceImpl && thread.isVirtual()) {
return null;
}
return new ThreadReferenceProxyImpl(this, t);
@@ -141,7 +141,7 @@ public final class JavaNoVariantsDelegator extends CompletionContributor impleme
CompletionResultSet tagResultSet = result.withPrefixMatcher(tagMatcher);
tagResultSet.runRemainingContributors(parameters, downstream -> {
LookupElement element = downstream.getLookupElement();
if (element != null && !prefixMatcher.prefixMatches(element) && tagMatcher.prefixMatches(element)) {
if (!prefixMatcher.prefixMatches(element) && tagMatcher.prefixMatches(element)) {
LookupElement lookupElement = MethodTags.wrapLookupWithTags(element, prefixMatcher::prefixMatches, prefixMatcher.getPrefix(),
parameters.getCompletionType());
if (lookupElement != null) {
@@ -278,7 +278,7 @@ public final class JavaNoVariantsDelegator extends CompletionContributor impleme
}
element = highlighter.highlightIfNeeded(null, element, element.getObject());
if (!sameNamedBatch.isEmpty() && !element.getLookupString().equals(sameNamedBatch.get(0).getLookupString())) {
if (!sameNamedBatch.isEmpty() && !element.getLookupString().equals(sameNamedBatch.getFirst().getLookupString())) {
result.addAllElements(sameNamedBatch);
sameNamedBatch.clear();
}
@@ -125,7 +125,6 @@ public abstract class AbstractJavaCopyPasteReferenceProcessor<TRef extends PsiEl
() -> ReadAction.compute(
() -> findReferencesToRestore(file, bounds, referenceData)
), JavaBundle.message("progress.title.searching.references"), true, project);
if (refs == null) return;
if (CodeInsightSettings.getInstance().ADD_IMPORTS_ON_PASTE == CodeInsightSettings.ASK) {
askReferencesToRestore(project, refs, referenceData);
}
@@ -34,12 +34,7 @@ public final class IdeaAntLogger2 extends DefaultLogger {
public static final String OUTPUT_PREFIX = "IDEA_ANT_INTEGRATION";
private final ThreadLocal<Deque<String>> myCallingTasks = new ThreadLocal<Deque<String>>() {
@Override
protected Deque<String> initialValue() {
return new ArrayDeque<>();
}
};
private final ThreadLocal<Deque<String>> myCallingTasks = ThreadLocal.withInitial(() -> new ArrayDeque<>());
private final Priority myMessagePriority = new MessagePriority();
private final Priority myTargetPriority = new StatePriority(Project.MSG_INFO);
@@ -122,8 +122,8 @@ public final class CoroutinesDebugHelper {
variableNames.add(names);
fieldNames.add(fields);
} else {
variableNames.add(Collections.<String>emptyList());
fieldNames.add(Collections.<String>emptyList());
variableNames.add(Collections.emptyList());
fieldNames.add(Collections.emptyList());
}
continuationStack.add(current);
@@ -66,7 +66,8 @@ public abstract class ForkedByModuleSplitter {
final ProcessBuilder builder = initProcessBuilder();
builder.add(vmParameters);
//copy encoding from first VM, as encoding is added into command line explicitly and vm options do not contain it
// copy encoding from the first VM, as encoding is added into the command line explicitly
// and vm options do not contain it
String encoding = System.getProperty("file.encoding");
if (encoding != null) {
builder.add("-Dfile.encoding=" + encoding);
@@ -146,27 +147,24 @@ public abstract class ForkedByModuleSplitter {
}
private static Runnable createInputReader(final InputStream inputStream, final PrintStream outputStream) {
return new Runnable() {
@Override
public void run() {
try {
try (BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
while (true) {
String line = inputReader.readLine();
if (line == null) break;
outputStream.println(line);
}
return () -> {
try {
try (BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
while (true) {
String line = inputReader.readLine();
if (line == null) break;
outputStream.println(line);
}
}
catch (UnsupportedEncodingException ignored) { }
catch (IOException e) {
e.printStackTrace();
}
}
catch (UnsupportedEncodingException ignored) { }
catch (IOException e) {
e.printStackTrace();
}
};
}
//read file with classes grouped by module
//read a file with classes grouped by module
protected int splitPerModule(String repeatCount) throws IOException {
int result = 0;
try (BufferedReader perDirReader = new BufferedReader(new FileReader(myWorkingDirsPath))) {
@@ -241,7 +239,7 @@ public abstract class ForkedByModuleSplitter {
classpathForManifest.append(" ");
}
try {
classpathForManifest.append(new File(path).toURI().toURL().toString());
classpathForManifest.append(new File(path).toURI().toURL());
}
catch (NoSuchMethodError e) {
classpathForManifest.append(new File(path).toURL().toString());
@@ -64,8 +64,7 @@ public abstract class InspectionElementsMerger {
/**
* @param id suppress id in code
* @return new merged tool name
* null if merger is not found
* @return list of merged tool names
*/
public static @Unmodifiable List<String> getMergedToolNames(@NotNull String id) {
return EP_NAME.getExtensionList().stream()
@@ -12,7 +12,6 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.components.JBList;
import com.intellij.util.IconUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -36,8 +35,8 @@ final class TestDnd extends AnAction {
}
@Override
protected @Nullable JComponent createCenterPanel() {
JBList list = new JBList(new String[]{"1111111", "222222", "333333", "44444", "555555555555555555555555"});
protected @NotNull JComponent createCenterPanel() {
JBList<String> list = new JBList<>("1111111", "222222", "333333", "44444", "555555555555555555555555");
DnDSupport.createBuilder(list)
.setBeanProvider(info -> new DnDDragStartBean("something"))
.setImageProvider(info -> new DnDImage(IconUtil.toImage(AllIcons.FileTypes.Text)))
@@ -24,9 +24,9 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.Queue;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
@@ -235,7 +235,7 @@ final class DetailedEventWatcher implements EventWatcher, Disposable {
matcher.toMatchResult() :
null;
return matchResult instanceof Matcher ?
((Matcher)matchResult).group("description") :
matchResult.group("description") :
string;
}
@@ -6,7 +6,6 @@ import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem;
import com.intellij.testFramework.rules.TempDirectory;
import com.intellij.util.io.Compressor;
import com.intellij.util.io.URLUtil;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
@@ -41,11 +40,11 @@ public class CoreJarFileSystemTest {
assertThat(root.getChildren()).hasSize(3);
VirtualFile com = root.findFileByRelativePath("com");
Assertions.<VirtualFile>assertThat(com).isNotNull().matches(f -> f.isDirectory());
assertThat(com).isNotNull().matches(f -> f.isDirectory());
assertThat(com.getChildren()).isEmpty();
VirtualFile arrayList = root.findFileByRelativePath("java/util/ArrayList.class");
Assertions.<VirtualFile>assertThat(arrayList).isNotNull().matches(f -> !f.isDirectory());
assertThat(arrayList).isNotNull().matches(f -> !f.isDirectory());
assertThat(arrayList.getChildren()).isEmpty();
}
}
@@ -13,18 +13,15 @@ public class Pair<A, B> {
public final A first;
public final B second;
@NotNull
public static <A, B> Pair<A, B> create(A first, B second) {
public static @NotNull <A, B> Pair<A, B> create(A first, B second) {
return new Pair<>(first, second);
}
@NotNull
public static <A, B> NonNull<A, B> createNonNull(@NotNull A first, @NotNull B second) {
public static @NotNull <A, B> NonNull<A, B> createNonNull(@NotNull A first, @NotNull B second) {
return new NonNull<>(first, second);
}
@NotNull
public static <A, B> Pair<A, B> pair(A first, B second) {
public static @NotNull <A, B> Pair<A, B> pair(A first, B second) {
return new Pair<>(first, second);
}
@@ -39,9 +36,8 @@ public class Pair<A, B> {
@SuppressWarnings({"rawtypes", "unchecked"})
private static final Pair EMPTY = create(null, null);
@NotNull
@SuppressWarnings("unchecked")
public static <A, B> Pair<A, B> empty() {
public static @NotNull <A, B> Pair<A, B> empty() {
return EMPTY;
}
@@ -90,12 +86,7 @@ public class Pair<A, B> {
* @return a comparator that compares pair values by first value
*/
public static <A extends Comparable<? super A>, B> Comparator<Pair<A, B>> comparingByFirst() {
return new Comparator<Pair<A, B>>() {
@Override
public int compare(Pair<A, B> o1, Pair<A, B> o2) {
return o1.first.compareTo(o2.first);
}
};
return Comparator.comparing(o -> o.first);
}
/**
@@ -104,11 +95,6 @@ public class Pair<A, B> {
* @return a comparator that compares pair values by second value
*/
public static <A, B extends Comparable<? super B>> Comparator<Pair<A, B>> comparingBySecond() {
return new Comparator<Pair<A, B>>() {
@Override
public int compare(Pair<A, B> o1, Pair<A, B> o2) {
return o1.second.compareTo(o2.second);
}
};
return Comparator.comparing(o -> o.second);
}
}
@@ -26,12 +26,7 @@ public final class VersionComparatorUtil {
private static final Pattern DIGITS_PATTERN = Pattern.compile("\\d+");
private static final VersionTokenType[] VALUES = VersionTokenType.values();
public static final Comparator<String> COMPARATOR = new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return VersionComparatorUtil.compare(s1, s2);
}
};
public static final Comparator<String> COMPARATOR = VersionComparatorUtil::compare;
private static final TokenPrioritizer DEFAULT_TOKEN_PRIORITIZER = new TokenPrioritizer() {
@Override
@@ -317,13 +317,11 @@ public abstract class AbstractVcs extends StartedActivated {
@RequiresEdt
public void enableIntegration(@Nullable VirtualFile targetDirectory) {
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
if (vcsManager != null) {
if (targetDirectory != null) {
vcsManager.setDirectoryMappings(Collections.singletonList(new VcsDirectoryMapping(targetDirectory.getPath(), getName())));
}
else {
vcsManager.setDirectoryMappings(Collections.singletonList(VcsDirectoryMapping.createDefault(getName())));
}
if (targetDirectory != null) {
vcsManager.setDirectoryMappings(Collections.singletonList(new VcsDirectoryMapping(targetDirectory.getPath(), getName())));
}
else {
vcsManager.setDirectoryMappings(Collections.singletonList(VcsDirectoryMapping.createDefault(getName())));
}
}
@@ -139,7 +139,7 @@ public final class VcsUtil {
T result = null;
if (!project.isDisposed()) {
ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
result = manager != null ? provider.apply(manager) : null;
result = provider.apply(manager);
}
return result;
});
@@ -114,9 +114,6 @@ public abstract class GitRepositoryAction extends DumbAwareAction {
}
GitVcs vcs = GitVcs.getInstance(project);
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
if (roots == null || roots.length == 0) {
return false;
}
return true;
return roots.length != 0;
}
}
@@ -21,7 +21,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
class JarLoader extends Loader {
private static final List<Map.Entry<Resource.Attribute, Attributes.Name>> PACKAGE_FIELDS = Arrays.<Map.Entry<Resource.Attribute, Attributes.Name>>asList(
private static final List<Map.Entry<Resource.Attribute, Attributes.Name>> PACKAGE_FIELDS = Arrays.asList(
new AbstractMap.SimpleImmutableEntry<>(Resource.Attribute.SPEC_TITLE, Attributes.Name.SPECIFICATION_TITLE),
new AbstractMap.SimpleImmutableEntry<>(Resource.Attribute.SPEC_VERSION, Attributes.Name.SPECIFICATION_VERSION),
new AbstractMap.SimpleImmutableEntry<>(Resource.Attribute.SPEC_VENDOR, Attributes.Name.SPECIFICATION_VENDOR),
@@ -40,7 +40,7 @@ final class Hash {
}
public static int long2int(final long l) {
return (int)(l ^ (l >>> 32));
return Long.hashCode(l);
}
@SuppressWarnings("DuplicatedCode")
@@ -289,9 +289,6 @@ public final class HgVcs extends AbstractVcs {
return null;
}
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
if (vcsManager == null) {
return null;
}
return (HgVcs)vcsManager.findVcsByName(VCS_NAME);
}
@@ -76,10 +76,7 @@ public abstract class HgAbstractGlobalAction extends DumbAwareAction {
}
HgVcs vcs = Objects.requireNonNull(HgVcs.getInstance(project));
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
if (roots == null || roots.length == 0) {
return false;
}
return true;
return roots.length != 0;
}
@CalledInAny
@@ -115,10 +115,6 @@ public class VBStyleCollection<E, K> extends ArrayList<E> {
return map.get(key);
}
public E getLast() {
return super.get(super.size() - 1);
}
public boolean containsKey(K key) {
return map.containsKey(key);
}