Menu

#778 LazyImporter: removes import of implemented interfaces

open
nobody
None
5
2007-01-11
2007-01-11
No

In jEdit 4.3pre8 LazyImporter's 'remove unused imports' removes imports of classes that are implemented by the present class and not otherwise referenced in the source file.
example:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

final class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
}
}

becomes

import java.awt.event.ActionEvent;

final class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
}
}

which will not compile.
LazyImporter 1.08 and jEdit 4.3pre8

Discussion

  • Moritz Ringler

    Moritz Ringler - 2007-01-17

    Logged In: YES
    user_id=730046
    Originator: YES

    After I have had a look at the source of org.etheridge.lazyimporter.importer.JavaClass
    I think the problem will probably go away if '{' is included with the String constant
    msValidPostClassCharacters.
    So line 88 should be
    private static String msValidPostClassCharacters = "\t)( .\n[,;{";
    instead of
    private static String msValidPostClassCharacters = "\t)( .\n[,;";

    Until this is fixed you can circumvent the problem by inserting a blank between the
    name of the implemented class and the curly bracket.

    The problem does not arise in the modified example
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    final class MyActionListener implements ActionListener {
    public void actionPerformed(ActionEvent e){
    }
    }

     
  • Moritz Ringler

    Moritz Ringler - 2007-01-17

    Logged In: YES
    user_id=730046
    Originator: YES

    By the way, neither msValidPreClassCharacters nor msValidPostClassCharacters needs to contain '\n' since '\n' is removed by the StringTokenizer.

    Maybe, it would be better anyway to replace
    isValidPostClassCharacter(char ch) with !Character.isJavaIdentifierPart(char ch)
    and isValidPreClassCharacter(char ch) with (char c != '.' && !Character.isJavaIdentifierPart(char ch))

    It is rather obvious that this way findClassUsage will not miss any class uses. And i suppose there will not be too many additional false positives. Anyways, false positives are less severe than false negatives in this case, since an unnecessary import that survives is much less of a problem than a necessary import that is removed.

     
  • Moritz Ringler

    Moritz Ringler - 2007-01-17
     
  • Moritz Ringler

    Moritz Ringler - 2007-01-17

    Logged In: YES
    user_id=730046
    Originator: YES

    File Added: JavaClass.patch

     

Log in to post a comment.