Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Microsoft Corporation and others.
* Copyright (c) 2019, 2026 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -24,6 +24,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
Expand Down Expand Up @@ -1284,7 +1285,13 @@ private boolean getMakeMethodStaticRefactoringProposal(CodeActionParams params,
if (!(element instanceof IMethod method)){
return false;
}

try {
if (Flags.isDefaultMethod(method.getFlags())) {
return false;
}
} catch (JavaModelException e) {
return false;
}
MakeStaticRefactoring refactoring = new MakeStaticRefactoring(method);
try {
if (refactoring.checkInitialConditions(monitor).isOK()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,20 @@ public void testDuplicateParamName() throws Exception {
assertCodeActions(cu, CodeActionUtil.getRange(cu, "bar(String foo)", 0), expected);

}

@Test
public void testDefaultInterfaceMethodNotOffered() throws Exception {
IPackageFragment pack1 = testSourceFolder.createPackageFragment("", false, null);

String input = "public interface Foo {\n"
+ "\n"
+ " default void bar() {\n"
+ " System.out.println(\"bar\");\n"
+ " }\n"
+ "}";

ICompilationUnit cu = pack1.createCompilationUnit("Foo.java", input, false, null);

assertCodeActionNotExists(cu, CodeActionUtil.getRange(cu, "bar()", 0), MAKE_STATIC);
}
}
Loading