Skip to content

Commit 11b891e

Browse files
committed
Fix main class display in double when list classes in user selected jar
1 parent 017304c commit 11b891e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/helpers/ManifestFileUtilsEx.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.intellij.openapi.vfs.VirtualFile;
4444
import com.intellij.psi.PsiClass;
4545
import com.intellij.psi.search.GlobalSearchScope;
46+
import com.intellij.psi.util.PsiMethodUtil;
4647
import com.microsoft.azure.hdinsight.common.logger.ILogger;
4748
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
4849
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
@@ -54,14 +55,17 @@
5455
import java.util.List;
5556

5657
public 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

Comments
 (0)