mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java: fix converting multi-dimensional arrays to atomic
GitOrigin-RevId: 43a811d589e04404cfe717e2b79e254be369ea23
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6ed4b62348
commit
886c37df33
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.refactoring.typeMigration.rules;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -81,15 +67,18 @@ enum AtomicConversionType {
|
||||
final PsiTypeParameter[] typeParameters = atomicClass.getTypeParameters();
|
||||
if (typeParameters.length != 1) return false;
|
||||
final PsiType toTypeParameterValue = resolveResult.getSubstitutor().substitute(typeParameters[0]);
|
||||
if (from instanceof PsiArrayType arrayType) {
|
||||
from = arrayType.getComponentType();
|
||||
}
|
||||
if (toTypeParameterValue != null) {
|
||||
if (from.getDeepComponentType() instanceof PsiPrimitiveType) {
|
||||
if (from instanceof PsiPrimitiveType) {
|
||||
final PsiPrimitiveType unboxedInitialType = PsiPrimitiveType.getUnboxedType(toTypeParameterValue);
|
||||
if (unboxedInitialType != null) {
|
||||
return TypeConversionUtil.areTypesConvertible(unboxedInitialType, from.getDeepComponentType());
|
||||
return TypeConversionUtil.areTypesConvertible(unboxedInitialType, from);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return TypeConversionUtil.isAssignable(PsiUtil.captureToplevelWildcards(toTypeParameterValue, context), from.getDeepComponentType());
|
||||
return TypeConversionUtil.isAssignable(PsiUtil.captureToplevelWildcards(toTypeParameterValue, context), from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.refactoring.typeMigration.TypeMigrationProcessor;
|
||||
import com.intellij.refactoring.typeMigration.intentions.ConvertFieldToAtomicIntention;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @see ConvertFieldToAtomicIntention
|
||||
* @author anna
|
||||
*/
|
||||
public class ConvertToAtomicIntentionTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Convert to atomic" "true-preview"
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
class X {
|
||||
|
||||
final AtomicReferenceArray<String[]> field = new AtomicReferenceArray<>(foo());
|
||||
|
||||
String[][] foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Convert to atomic" "true-preview"
|
||||
|
||||
class X {
|
||||
|
||||
final String[][] <caret>field = foo();
|
||||
|
||||
String[][] foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
AtomicReferenceArray<String[]> field = new AtomicReferenceArray<>(...)
|
||||
Reference in New Issue
Block a user