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

Conversation

jannisCode
Copy link
Contributor

@jannisCode jannisCode commented Nov 29, 2024

What it does

Record classes are now handled the same way as normal classes.
This bug fix was proposed here: #1813

Before

Record classes were not checked for the amount of parameters which their methods had. Normal classes where though. That posed the problem, that when only one argument was given, the code minings were shown for record classes but not for normal classes.

How to test

Use this code snippet:

import java.util.Objects;

class Main {
	public static void main(String...args) {
		Car c = new Car(3);
		Cat car = new Cat(5);
		car.equals(c);
		car.doSomething(12, 13);
	}
}

 class Cat {
    private int size;

    public Cat(int size) {
        this.size = size;
    }
    public Cat(long age) {}

    public int getSize() {
        return size;
    }

    public void doSomething(int a, int b) {}
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        Cat cat = (Cat) obj;
        return size == cat.size;
    }

    @Override
    public int hashCode() {
        return Objects.hash(size);
    }

    @Override
    public String toString() {
        return "Cat{size=" + size + "}";
    }
}

public record Car(int side) {}

it will result in this:
Screenshot 2024-11-29 113901

After the changes

Record classes are checked for the number of parameters the same way as normal classes and methods are checked. For the discussion on when they should be checked please take a look at #1813 (comment) and feel free to tell us your opinion.

Author checklist

Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@fedejeanne
Copy link
Contributor

@jukzi would you kindly (review and) merge this?

I don't have commit rights :-)

@jukzi
Copy link
Contributor

jukzi commented Dec 3, 2024

The code change looks good, but it would be better if you could add a junit test to avoid regression. Can you work on that?

@jannisCode jannisCode force-pushed the bug_fix_code_minigs branch 2 times, most recently from c03e5fe to 4f9e796 Compare December 3, 2024 12:11
@eclipse-jdt-bot
Copy link
Contributor

eclipse-jdt-bot commented Dec 3, 2024

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
org.eclipse.jdt.text.tests/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From 2b73646777d63531bdf3935852e981274885e210 Mon Sep 17 00:00:00 2001
From: Eclipse JDT Bot <jdt-bot@eclipse.org>
Date: Tue, 3 Dec 2024 14:25:32 +0000
Subject: [PATCH] Version bump(s) for 4.35 stream


diff --git a/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
index 5fa7dbb471..b3b6d006ff 100644
--- a/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.text.tests
 Bundle-ManifestVersion: 2
 Bundle-Name: %Plugin.name
 Bundle-SymbolicName: org.eclipse.jdt.text.tests;singleton:=true
-Bundle-Version: 3.14.600.qualifier
+Bundle-Version: 3.14.700.qualifier
 Bundle-Activator: org.eclipse.jdt.text.tests.JdtTextTestPlugin
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: %Plugin.providerName
diff --git a/org.eclipse.jdt.text.tests/pom.xml b/org.eclipse.jdt.text.tests/pom.xml
index 67c19fdd52..e2192b0866 100644
--- a/org.eclipse.jdt.text.tests/pom.xml
+++ b/org.eclipse.jdt.text.tests/pom.xml
@@ -20,7 +20,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.text.tests</artifactId>
-  <version>3.14.600-SNAPSHOT</version>
+  <version>3.14.700-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
-- 
2.47.0

Further information are available in Common Build Issues - Missing version increments.

@jannisCode jannisCode force-pushed the bug_fix_code_minigs branch 2 times, most recently from 836f2af to b595b4c Compare December 6, 2024 08:19
@@ -124,6 +124,7 @@ public class Foo {
assertEquals(3, fParameterNameCodeMiningProvider.provideCodeMinings(viewer, new NullProgressMonitor()).get().size());
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it!

Copy link
Contributor

@jukzi jukzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, manually tested, that the test fails without the change.
thanks for contributing.

@jukzi
Copy link
Contributor

jukzi commented Dec 6, 2024

unrelated build error, i don't know how to handle that
00:05:04.844 Caused by: org.apache.maven.plugin.MojoFailureException: Version has moved backwards for (org.eclipse.jdt.core.manipulation/1.21.300.v20241101-2227). Baseline has 1.21.300.v20241108-2119) with delta: 0.0.0
lets try rebase.

also 1 Test was added which test the bugfix
@jukzi jukzi force-pushed the bug_fix_code_minigs branch from 175e16c to 37d127b Compare December 6, 2024 08:56
@jukzi
Copy link
Contributor

jukzi commented Dec 6, 2024

There will be unrelated know 12 fails #1833 that can be ignored today

@fedejeanne
Copy link
Contributor

There will be unrelated know 12 fails #1833 that can be ignored today

so.... merge? :-)

@jukzi jukzi merged commit 44356af into eclipse-jdt:master Dec 6, 2024
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants