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

[BUG] Wrong class is tried when finding object creation expression #58

Open
Artur- opened this issue Jan 6, 2025 · 2 comments
Open
Assignees

Comments

@Artur-
Copy link
Member

Artur- commented Jan 6, 2025

Description of the Bug

Extracted from #56

The EventsView class contains

        SplitLayout splitLayout = new SplitLayout();
        splitLayout.addToPrimary(createGridLayout());
        splitLayout.addToSecondary(createEditorLayout());

When selecting either of the split layout children, the following is logged

2025-01-06T21:31:30.608+02:00 DEBUG 11274 --- [registration] [nio-8080-exec-6] c.v.copilot.plugins.i18n.I18nHandler     : Failed to get translatable properties

com.vaadin.copilot.javarewriter.exception.ComponentInfoNotFoundException: Expected to find an object creation expression such as "new SplitLayout()" at /.../src/main/java/ch/martinelli/oss/registration/ui/views/events/EventsView.java:35 but found "public static final String ID = "id";"
	at com.vaadin.copilot.javarewriter.ComponentInfo.find(ComponentInfo.java:88) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.javarewriter.ComponentInfo.findPossibleAttachExpressionFromParentInfo(ComponentInfo.java:257) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.javarewriter.ComponentInfo.find(ComponentInfo.java:161) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.javarewriter.JavaRewriter.findComponentInfo(JavaRewriter.java:460) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleGetTranslatableProperties(I18nHandler.java:266) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleMessage(I18nHandler.java:156) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.CopilotSession.handleMessageSync(CopilotSession.java:140) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.CopilotSession.handleMessage(CopilotSession.java:116) ~[copilot-24.6.0.jar:na]
	at com.vaadin.copilot.Copilot.handleMessage(Copilot.java:62) ~[copilot-24.6.0.jar:na]

Line 35 in EventsView.java does contain what it is looking for: SplitLayout splitLayout = new SplitLayout(); but line 35 in the super class EditView.java contains what is finds: public static final String ID = "id";

@Artur- Artur- changed the title [BUG] Wrong class is tried when finding constructor [BUG] Wrong class is tried when finding object creation expression Jan 6, 2025
@czp13 czp13 self-assigned this Jan 16, 2025
@czp13
Copy link
Contributor

czp13 commented Jan 20, 2025

My hunch is the problem lies in the fact that the EventsView is extending the EditView, and our class finder only looks for the superclass:

public class EventsView extends EditView<Event, EventRecord, EventRepository>
        implements BeforeEnterObserver, HasDynamicTitle```

Here:
https://github.com/martinellich/registration/blob/develop/src/main/java/ch/martinelli/oss/registration/ui/views/events/EventsView.java#L27C1-L28C56

I am trying to prove that theory atm.

@czp13
Copy link
Contributor

czp13 commented Jan 20, 2025

This is also a different error with 24.6.2 version.

This:

2025-01-20T16:20:08.854+01:00 DEBUG 14901 --- [registration] [nio-8080-exec-6] c.v.copilot.plugins.i18n.I18nHandler     : Failed to get translatable properties

java.lang.IllegalStateException: The component instance is not created in the project sources
	at com.vaadin.copilot.Copilot.lambda$static$0(Copilot.java:28) ~[copilot-24.6.2.jar:na]
	at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleGetTranslatableProperties(I18nHandler.java:264) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleMessage(I18nHandler.java:156) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.CopilotSession.handleMessageSync(CopilotSession.java:140) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.CopilotSession.handleMessage(CopilotSession.java:116) ~[copilot-24.6.2.jar:n

Or this:

2025-01-20T16:19:08.377+01:00 DEBUG 14901 --- [registration] [nio-8080-exec-1] c.v.copilot.plugins.i18n.I18nHandler     : Failed to get translatable properties

java.lang.IllegalArgumentException: Component has no create location in the project
	at com.vaadin.copilot.javarewriter.ComponentTypeAndSourceLocation.lambda$getCreateLocationOrThrow$0(ComponentTypeAndSourceLocation.java:49) ~[copilot-24.6.2.jar:na]
	at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
	at com.vaadin.copilot.javarewriter.ComponentTypeAndSourceLocation.getCreateLocationOrThrow(ComponentTypeAndSourceLocation.java:49) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.javarewriter.ComponentInfo.find(ComponentInfo.java:76) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.javarewriter.ComponentInfo.findPossibleAttachExpressionFromParentInfo(ComponentInfo.java:257) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.javarewriter.ComponentInfo.find(ComponentInfo.java:161) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.javarewriter.JavaRewriter.findComponentInfo(JavaRewriter.java:543) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleGetTranslatableProperties(I18nHandler.java:266) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.plugins.i18n.I18nHandler.handleMessage(I18nHandler.java:156) ~[copilot-24.6.2.jar:na]
	at com.vaadin.copilot.CopilotSession.handleMessageSync(CopilotSession.java:140) ~[copilot-24.6.2.jar:na]

Probaby there was a change around how we are handling files in the project between 24.6.1 and 2, but I would not go in the rabbit hole.

We have this test flow parent and children classes, which can trigger the same issue here:

It probably would be good to merge this everywhere on the branches, and then try to fix the separate new issues.

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

No branches or pull requests

2 participants