mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[java-refactoring] MoveInstanceMethod: moving abstract method to interface should not change the 'default' modifier
GitOrigin-RevId: db6aca91eed8c0d7bebe6bb86dd398a3a372bfab
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a550238d23
commit
20c7b3400a
@@ -244,19 +244,20 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
PsiMethod patternMethod = createMethodToAdd();
|
||||
final List<PsiReference> docRefs = new ArrayList<>();
|
||||
for (UsageInfo usage : usages) {
|
||||
if (usage instanceof InheritorUsageInfo) {
|
||||
final PsiClass inheritor = ((InheritorUsageInfo)usage).getInheritor();
|
||||
if (usage instanceof InheritorUsageInfo inheritorUsage) {
|
||||
final PsiClass inheritor = inheritorUsage.getInheritor();
|
||||
addMethodToClass(inheritor, patternMethod, true);
|
||||
}
|
||||
else if (usage instanceof MethodCallUsageInfo && !((MethodCallUsageInfo)usage).isInternal()) {
|
||||
final PsiElement expression = ((MethodCallUsageInfo)usage).getMethodCallExpression();
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
correctMethodCall((PsiMethodCallExpression)expression, false);
|
||||
else if (usage instanceof MethodCallUsageInfo methodCallUsage && !methodCallUsage.isInternal()) {
|
||||
final PsiElement expression = methodCallUsage.getMethodCallExpression();
|
||||
if (expression instanceof PsiMethodCallExpression call) {
|
||||
correctMethodCall(call, false);
|
||||
}
|
||||
else if (expression instanceof PsiMethodReferenceExpression methodReferenceExpression) {
|
||||
PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression();
|
||||
|
||||
if (myTargetVariable instanceof PsiParameter && shouldBeExpandedToLambda(methodReferenceExpression, myMethod.getParameterList().getParameterIndex((PsiParameter)myTargetVariable))) {
|
||||
if (myTargetVariable instanceof PsiParameter parameter &&
|
||||
shouldBeExpandedToLambda(methodReferenceExpression, myMethod.getParameterList().getParameterIndex(parameter))) {
|
||||
PsiLambdaExpression lambdaExpression = LambdaRefactoringUtil.convertMethodReferenceToLambda(methodReferenceExpression, false, true);
|
||||
if (lambdaExpression != null) {
|
||||
List<PsiExpression> returnExpressions = LambdaUtil.getReturnExpressions(lambdaExpression);
|
||||
@@ -278,7 +279,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
exprText = myTargetVariable.getName();
|
||||
}
|
||||
PsiExpression newQualifier = JavaPsiFacade.getElementFactory(myProject).createExpressionFromText(exprText, null);
|
||||
((PsiMethodReferenceExpression)expression).setQualifierExpression(newQualifier);
|
||||
methodReferenceExpression.setQualifierExpression(newQualifier);
|
||||
JavaCodeStyleManager.getInstance(myProject).shortenClassReferences(expression);
|
||||
}
|
||||
}
|
||||
@@ -290,7 +291,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
|
||||
try {
|
||||
final PsiModifierList modifierList = patternMethod.getModifierList();
|
||||
if (myTargetClass.isInterface()) {
|
||||
if (myTargetClass.isInterface() && !myMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
if (!PsiUtil.isAvailable(JavaFeature.EXTENSION_METHODS, myTargetClass)) {
|
||||
patternMethod.getBody().delete();
|
||||
modifierList.setModifierProperty(PsiModifier.DEFAULT, false);
|
||||
@@ -454,7 +455,7 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
|
||||
}
|
||||
}
|
||||
|
||||
private PsiMethod createMethodToAdd () {
|
||||
private PsiMethod createMethodToAdd() {
|
||||
ChangeContextUtil.encodeContextInfo(myMethod, true);
|
||||
try {
|
||||
//correct internal references
|
||||
|
||||
Reference in New Issue
Block a user