mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
Java: generate correct code for native methods (IDEA-373315)
for the "Generate overloaded method with default parameter values" intention GitOrigin-RevId: d595a7b1f736cdb60549c0a872da367a1ffe1a92
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4f8e253a17
commit
7a0ce59678
@@ -84,16 +84,15 @@ public final class DefineParamsDefaultValueAction extends PsiBasedModCommandActi
|
||||
protected @NotNull ModCommand perform(@NotNull ActionContext context, @NotNull PsiElement element) {
|
||||
PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiClass.class);
|
||||
PsiMethod method;
|
||||
if (parent instanceof PsiMethod) {
|
||||
method = (PsiMethod)parent;
|
||||
if (parent instanceof PsiMethod m) {
|
||||
method = m;
|
||||
}
|
||||
else if (parent instanceof PsiClass aClass && aClass.isRecord()) {
|
||||
method = JavaPsiRecordUtil.findCanonicalConstructor(aClass);
|
||||
assert method != null;
|
||||
}
|
||||
else throw new AssertionError();
|
||||
PsiParameterList parameterList = method.getParameterList();
|
||||
PsiParameter[] parameters = parameterList.getParameters();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if (parameters.length == 1) {
|
||||
return ModCommand.psiUpdate(method, (m, updater) -> {
|
||||
PsiMethod writableMethod = updater.getWritable(m);
|
||||
@@ -201,12 +200,13 @@ public final class DefineParamsDefaultValueAction extends PsiBasedModCommandActi
|
||||
(PsiMethod)method.copy();
|
||||
final PsiCodeBlock body = prototype.getBody();
|
||||
final PsiCodeBlock emptyBody = JavaPsiFacade.getElementFactory(method.getProject()).createCodeBlock();
|
||||
PsiModifierList modifierList = prototype.getModifierList();
|
||||
final PsiModifierList modifierList = prototype.getModifierList();
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
modifierList.setModifierProperty(PsiModifier.NATIVE, false);
|
||||
if (body != null) {
|
||||
body.replace(emptyBody);
|
||||
} else {
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
prototype.addBefore(emptyBody, null);
|
||||
prototype.add(emptyBody);
|
||||
}
|
||||
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Generate overloaded method with default parameter values" "true"
|
||||
class Test {
|
||||
static void foo() {
|
||||
foo(0);
|
||||
}
|
||||
|
||||
static native void foo(int ii) {}
|
||||
// native method intentionally has body
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Generate overloaded method with default parameter values" "true"
|
||||
class Test {
|
||||
static native void foo(int i<caret>i) {}
|
||||
// native method intentionally has body
|
||||
}
|
||||
Reference in New Issue
Block a user