facebook

MyEclipse adds strange import statement after copy paste

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #319546 Reply

    Hello!

    I have stumbled on a annoying problem with MyEclipse when copy paste a line of code containing a reference to a private static class.

    Lets say i have this code in a simple main args java class:

    
    private static class Global{
            static final String ISSUE_YEAR = "2001";
        }
    

    And also another similar main args java class but with a different value in the parameter:

    
    public class Mainargsclass {
    ....
    private static class Global{
            static final String ISSUE_YEAR = "2002";
        }
    ....
    }
    

    Then, when copying another line of code from the first main args class, lets say:

    
    if(Global.ISSUE_YEAR != null && !Global.ISSUE_YEAR.equals("")){
        ......
    }
    

    into the other main args class myeclipse is automatically generating a new import statement line in the class getting the new pasted code:

    
    import my.own.package.Mainargsclass.Global;
    

    And it generates an compilation error for the class getting the pasted code.

    Any input on this issue would be great.
    It is not critical, as long as i now of the problem i can remove the extra import statement manually.

    Im currently using ME 8.6.

    With Kind Regards
    Anders

    #319548 Reply

    support-swapna
    Moderator

    andersflodell ,

    When you are copying the statement

    if(Global.ISSUE_YEAR != null && !Global.ISSUE_YEAR.equals(“”)){ }

    it copies the reference for the outer class too. The reference is Mainargsclass.Global. So when you paste it in the second java class, it automatically adds an import statement for this reference. As the second class also has Mainargsclass.Global in this case even though the names are the same the references are different, it throws a compilation error. This behavior is not a bug.

    Let us know if you have any other issues.

    #319578 Reply

    could there be a feature request that adds “paste without references” or “paste as plain text” in MyEclipse?! Or maybe in Eclipse?!

    #319579 Reply

    support-swapna
    Moderator

    andersflodell,

    Go to Window > Preferences > Java > Typing and uncheck the Update Imports option to stop updating the imports.

    Let us know how it works for you.

    #319614 Reply

    Yes it worked. Thanks!

    And the setting was located under Window > Preferences > Java > Editor >Typing.

    However im not sure if this is a solution for me since most of the time i would like the support of auto-inserted import statements when copy-paste. It was just this time, using private class inside of the main class that things got weird when copy-paste.
    But now i know how to disable it when needed.

    Anders

    #319627 Reply

    support-swapna
    Moderator

    andersflodell ,

    Glad that it is working.
    Do let us know if you have any other issues.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: MyEclipse adds strange import statement after copy paste

You must be logged in to post in the forum log in