4343import com .intellij .openapi .vfs .VirtualFile ;
4444import com .intellij .psi .PsiClass ;
4545import com .intellij .psi .search .GlobalSearchScope ;
46+ import com .intellij .psi .util .PsiMethodUtil ;
4647import com .microsoft .azure .hdinsight .common .logger .ILogger ;
4748import com .microsoft .azuretools .azurecommons .helpers .NotNull ;
4849import com .microsoft .azuretools .azurecommons .helpers .Nullable ;
5455import java .util .List ;
5556
5657public class ManifestFileUtilsEx implements ILogger {
57- private static class JarClassFilter implements ClassFilter {
58+ private static class MainClassFilter implements ClassFilter {
5859 final private String filePath ;
59- public JarClassFilter (@ NotNull String filePath ) {
60+ public MainClassFilter (@ NotNull String filePath ) {
6061 this .filePath = filePath ;
6162 }
6263 public boolean isAccepted (final PsiClass aClass ) {
6364 return ReadAction .compute (() ->
64- aClass .getContainingFile ().getVirtualFile ().getPath ().startsWith (filePath ));
65+ aClass .getContainingFile ().getVirtualFile ().getPath ().startsWith (filePath ) &&
66+ PsiMethodUtil .MAIN_CLASS .value (aClass ) &&
67+ !aClass .getName ().endsWith ("$" ) &&
68+ aClass .findMethodsByName ("main" , true ).length > 0 );
6569 }
6670 }
6771
@@ -86,7 +90,7 @@ public PsiClass selectMainClass(@Nullable VirtualFile jarFile) {
8690 // should be the initialClass. Currently we don't enable this method since exception happens with the following code.
8791 // final PsiClass aClass = initialClassName != null ? JavaPsiFacade.getInstance(project).findClass(initialClassName, searchScope) : null;
8892 final TreeClassChooser chooser =
89- chooserFactory .createWithInnerClassesScopeChooser ("Select Main Class" , searchScope , new JarClassFilter (jarFile .getPath ()), null );
93+ chooserFactory .createWithInnerClassesScopeChooser ("Select Main Class" , searchScope , new MainClassFilter (jarFile .getPath ()), null );
9094
9195 ((TreeJavaClassChooserDialog ) chooser ).getWindow ().addWindowListener (new WindowAdapter () {
9296 // These fields are recorded to help remove the artifact and the module.
0 commit comments