Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record classes are now handled the same as normal classes #1822

Merged
merged 1 commit into from
Dec 6, 2024
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
Expand Up @@ -380,6 +380,27 @@ public void testBug549126() throws Exception {
assertEquals(2, fParameterNameCodeMiningProvider.provideCodeMinings(viewer, new NullProgressMonitor()).get().size());
}

@Test
public void testRecordConstructorOneParameter() throws Exception {
String contents= """
public class Ant {
record Ca (int size){

}

Ca c = new Ca(0);

}
""";
ICompilationUnit compilationUnit= fPackage.createCompilationUnit("Ant.java", contents, true, new NullProgressMonitor());
JavaEditor editor= (JavaEditor) EditorUtility.openInEditor(compilationUnit);
fParameterNameCodeMiningProvider.setContext(editor);
JavaSourceViewer viewer= (JavaSourceViewer)editor.getViewer();
waitReconciled(viewer);

assertEquals(0, fParameterNameCodeMiningProvider.provideCodeMinings(viewer, new NullProgressMonitor()).get().size());
}

@Test
public void testRecordConstructorOK() throws Exception {
String contents= "import java.util.Map;\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected void collectParameterNamesCodeMinings(IMethod method, List<?> argument

protected void collectParameterNamesCodeMinings(IMethodBinding mbinding, List<?> arguments, boolean isVarArgs) {
// synthetic method of a record
if (mbinding.getDeclaringClass().isRecord()) {
if (mbinding.getDeclaringClass().isRecord() && !skipParameterNamesCodeMinings(mbinding)) {
String[] parameterNames= mbinding.getParameterNames();
for (int i= 0; i < Math.min(arguments.size(), parameterNames.length); i++) {
if (!skipParameterNameCodeMining(parameterNames, arguments, i)) {
Expand Down Expand Up @@ -168,6 +168,10 @@ private boolean skipParameterNamesCodeMinings(IMethod method) {
return method.getNumberOfParameters() <= 1;
}

private boolean skipParameterNamesCodeMinings(IMethodBinding methodBinding) {
return methodBinding.getParameterNames().length <= 1;
}

private boolean skipParameterNamesCodeMinings(IMethod method, String[] parameterNames) {
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
boolean filter= store.getBoolean(PreferenceConstants.EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES);
Expand Down
Loading