netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

syntax check in javafx fxml file is reporting 'does not support property' in KeyCodeCombination

Open sijskes opened this issue 1 year ago • 5 comments

Apache NetBeans version

Apache NetBeans 22

What happened

had scenebuilder create a fxml file. opened file in netbeans. netbeans indicated errors in file.

class 'javafx.scene.input.KeyCodeCombination' does not support property 'alt'. also for 'control' 'meta' 'shift' 'shortcut'.

Language / Project Type / NetBeans Component

javafx

How to reproduce

create stage with menubar with menuitem with shortcut in scenebuilder. open fxml file in netbeans.

Did this work correctly in an earlier version?

No / Don't know

Operating System

ubuntu linux mate hybrid

JDK

version "21.0.3" 2024-04-16 build 21.0.3+9-Ubuntu-1ubuntu122.04.1

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

always.

Are you willing to submit a pull request?

No

Screenshot at 2024-06-17 11-22-11 crop

Used version scenebuilder

21.0.0

Used version javafx

javafx 21

sijskes avatar Jun 17 '24 09:06 sijskes

Please provide a sample to make this reproducible.

matthiasblaesing avatar Jun 17 '24 16:06 matthiasblaesing

sample to reproduce.
remove .txt extension, github wouldn't attach without it.

sandbox.fxml.txt

sijskes avatar Jun 17 '24 17:06 sijskes

looking at org.netbeans.modules.javafx2.editor.parser.processors.PropertyResolver and the behaviour in this case, it looks (a bit of a gamble) that the PropertyResolver gets confused due to KeyCodeCombination not having property setters for the properties report as in error.

i have not yet found a mechanism to scan for parameters in the constructors. if there are (it should be) then it is a case the wrong constructor was chosen. this is also supported by the fact that 'code' is not reported as an error. the other constructor had 'code' and 'modifiers' as NamedArg.

https://github.com/apache/netbeans/blob/0d0bfcf3faf364a2643238f2a44e1bb6eb8217bd/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/parser/processors/PropertyResolver.java#L269-L298

sijskes avatar Jun 18 '24 13:06 sijskes

My reading of the BeanModelBuilder is, that properties are reported when:

  • there is a setter
  • there is a list/map getter
  • there is a getter with a corresponding @NamedArg parameter in the constructor with the most parameters

For KeyCodeCombination there are no getters for the individual keys and thus the third option does not match.

If I understand this correctly: https://github.com/openjdk/jfx/blob/6a586b662592be3eb81670f0c5ce48061c2fc07c/modules/javafx.fxml/src/main/java/com/sun/javafx/fxml/builder/ProxyBuilder.java#L248

  • JFX prefers to use an exactly matching constructor for the supplied parameters
  • if there is a default constructor and all supplied property values are covered by setters, this combination is used
  • else try to find a suitable constructor/setters combination to cover all parameters

I think the model needs to be updated to report the constructor parameters as a separate list and the use sited of the property need to take this into account.

The code for scanning the constructors with NamedArgs:

https://github.com/apache/netbeans/blob/02c66120a8d5c90cde4c706bb15e7121372fd513/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/completion/beans/BeanModelBuilder.java#L336-L357

looks like a good starting point. The name extraction is demonstrated there. The code in registerProperty for normal setter can be a template for extracting the type information.

https://github.com/apache/netbeans/blob/02c66120a8d5c90cde4c706bb15e7121372fd513/javafx/javafx2.editor/src/org/netbeans/modules/javafx2/editor/completion/beans/BeanModelBuilder.java#L580-L586

@sijskes will you look into this?

matthiasblaesing avatar Jun 23 '24 18:06 matthiasblaesing

@matthiasblaesing ideally there should be an InfoProxy that is reusable in the BeanModelBuilder and the PropertyResolver. This InfoProxy could mimic the information/logic from the JavaFx ProxyBuilder. I have a hard time following the javax.lang.model stuff, just by code inspection alone. I would assign some meaning by wrapping it in this InfoProxy. This InfoProxy could deliver information in <Name,Type> pairs and support 'completion-path' matching? Later this could grow to provide information regarding child elements.

@errael any insights to share? it looks like you worked on the completion.

Maybe FxBean is already the InfoProxy i'm talking about. Have to look if it is usable without completion code plumbing.

sijskes avatar Jun 24 '24 08:06 sijskes