use of com.jetbrains.lang.dart.psi.DartFile in project flutter-intellij by flutter.
the class MainFile method verify.
/**
* Verifies that the given path points to an entrypoint file within a Flutter app.
* <p>
* If there is an error, {@link Result#canLaunch} will return false and the error is available via {@link Result#getError}
*/
@NotNull
public static MainFile.Result verify(@Nullable String path, Project project) {
if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
throw new IllegalStateException("need read access");
}
if (StringUtil.isEmptyOrSpaces(path)) {
return error(FlutterBundle.message("entrypoint.not.set"));
}
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
if (file == null) {
return error(FlutterBundle.message("entrypoint.not.found", FileUtil.toSystemDependentName(path)));
}
if (file.getFileType() != DartFileType.INSTANCE) {
return error(FlutterBundle.message("entrypoint.not.dart"));
}
final PsiFile psi = PsiManager.getInstance(project).findFile(file);
if (!(psi instanceof DartFile)) {
return error(FlutterBundle.message("entrypoint.not.dart"));
}
final DartFile dart = (DartFile) psi;
if (DartResolveUtil.getMainFunction(dart) == null) {
return error(FlutterBundle.message("main.not.in.entrypoint"));
}
if (!inProject(file, project)) {
return error(FlutterBundle.message("entrypoint.not.in.project"));
}
final VirtualFile dir = findAppDir(file, project);
if (dir == null) {
return error(FlutterBundle.message("entrypoint.not.in.app.dir"));
}
final boolean hasFlutterImports = findImportUrls(dart).anyMatch((url) -> url.startsWith("package:flutter/"));
return new MainFile.Result(new MainFile(file, dir, hasFlutterImports), null);
}
Aggregations