@Nullable
public static DartFunctionDeclarationWithBodyOrNative getMainFunction(final @Nullable PsiFile file) {
if (!(file instanceof DartFile)) return null;
final ArrayList<DartComponentName> result = new ArrayList<DartComponentName>();
DartPsiCompositeElementImpl.processDeclarationsImpl(file, new DartResolveProcessor(result, "main"), ResolveState.initial(), null);
for (DartComponentName componentName : result) {
final PsiElement parent = componentName.getParent();
if (parent instanceof DartFunctionDeclarationWithBodyOrNative) {
return (DartFunctionDeclarationWithBodyOrNative)parent;