apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.59k stars 831 forks source link

Introduce Constant and others not working with Interfaces in Netbeans 22 #7500

Open tmulle opened 1 week ago

tmulle commented 1 week ago

Apache NetBeans version

Apache NetBeans 22

What happened

I'm trying to select a string in my code to make it a global constant in my code using the Refactor->Introduce Constant menu item but it keeps telling me "Invalid Selection"

I highlight the full text string System.out.println("Hello World") (Hello World for example) and then try to use the menu item and it doesn't work and gives me the error.

I also tried Introduce Variable and that says the same thing.

I thought we could do this before with strings and select them and make them constants?

UPDATE: I'm trying to do this in an interface and not a class

Language / Project Type / NetBeans Component

Java Maven Project

How to reproduce

Try to select a string in your code and make it a constant using the Refactor->Introduce Constant menu item.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Linux

JDK

21

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

Yes

matthiasblaesing commented 1 week ago

This is not reproducible with a clean user/cache dir. Steps:

  1. Ensure userdir and cache dir don't exist rm -r test-userdir test-cachedir
  2. Started NB-22 with a clean userdir ~/bin/netbeans-22/bin/netbeans --userdir test-userdir --cachedir test-cachedir (do not import settings from previous version if asked)
  3. Create maven Project: Select "New Project" on the start screen -> "Java with maven" -> "Java Application", Next (wait until clusters are activated)
  4. Accepts defaults and "Finish"
  5. Open Mavenproject1.java
  6. Change public class Mavenproject1 to public interface Mavenproject1 image
  7. Select string "Hello World!" and select "Refactor" -> "Introduce" -> "Variable"
  8. Dialog is displayed as expected, accept it as displayed image
  9. Observe text is updated: image
  10. Undo introduction and repeat with constant

You can check the message.log and see if something is visibile, but this is not a general problem. Please retest with a clean user+cachedir and see if it is still reproducible.

mbien commented 5 days ago

to extract a statement to a method you have to select the ; too, otherwise its not statement and it will say invalid selection. Can't reproduce the other things either, "introduce constant" worked too.