mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
suggest casting int to long when Long is expecting
This commit is contained in:
@@ -90,6 +90,10 @@ public abstract class ArgumentFixerActionFactory {
|
||||
if (parameterType instanceof PsiWildcardType) continue;
|
||||
if (!GenericsUtil.isFromExternalTypeLanguage(parameterType)) continue;
|
||||
if (suggestedCasts.contains(parameterType.getCanonicalText())) continue;
|
||||
if (exprType instanceof PsiPrimitiveType && parameterType instanceof PsiClassType) {
|
||||
parameterType = PsiPrimitiveType.getUnboxedType(parameterType);
|
||||
if (parameterType == null) continue;
|
||||
}
|
||||
// strict compare since even widening cast may help
|
||||
if (Comparing.equal(exprType, parameterType)) continue;
|
||||
PsiCall newCall = (PsiCall) call.copy();
|
||||
|
||||
@@ -66,6 +66,10 @@ public class CastMethodArgumentFix extends MethodArgumentFix {
|
||||
parameterType = ((PsiPrimitiveType)parameterType).getBoxedType(context); //unboxing from type of cast expression will take place at runtime
|
||||
if (parameterType == null) return false;
|
||||
}
|
||||
if (exprType instanceof PsiPrimitiveType && parameterType instanceof PsiClassType) {
|
||||
parameterType = PsiPrimitiveType.getUnboxedType(parameterType);
|
||||
if (parameterType == null) return false;
|
||||
}
|
||||
return parameterType.isConvertibleFrom(exprType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l) {}
|
||||
void g() {
|
||||
f((long) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l) {}
|
||||
void g() {
|
||||
f(<caret>0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
public class CastMethodParameters15Test extends LightQuickFixTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testPrimitiveWrappers() throws Exception {
|
||||
doSingleTest(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/castMethodParameters15";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user