use of com.jetbrains.lang.dart.psi.DartFile in project intellij-plugins by JetBrains.
the class DartOutdatedDependenciesInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (!isOnTheFly)
return null;
if (!(psiFile instanceof DartFile))
return null;
if (DartPubActionBase.isInProgress())
return null;
final VirtualFile file = DartResolveUtil.getRealVirtualFile(psiFile);
if (file == null || !file.isInLocalFileSystem())
return null;
final Project project = psiFile.getProject();
if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file))
return null;
final DartSdk sdk = DartSdk.getDartSdk(project);
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null || sdk == null || !DartSdkLibUtil.isDartSdkEnabled(module))
return null;
if (FlutterUtil.isFlutterPluginInstalled() && FlutterUtil.isFlutterModule(module))
return null;
final VirtualFile pubspecFile = PubspecYamlUtil.findPubspecYamlFile(project, file);
if (pubspecFile == null || myIgnoredPubspecPaths.contains(pubspecFile.getPath()))
return null;
final String projectName = PubspecYamlUtil.getDartProjectName(pubspecFile);
// 'pub get' will fail anyway
if (projectName == null || !StringUtil.isJavaIdentifier(projectName))
return null;
final VirtualFile dotPackagesFile = pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
if (dotPackagesFile == null) {
return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pub.get.never.done"));
}
if (FileDocumentManager.getInstance().isFileModified(pubspecFile) || pubspecFile.getTimeStamp() > dotPackagesFile.getTimeStamp()) {
return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pubspec.edited"));
}
return null;
}
use of com.jetbrains.lang.dart.psi.DartFile in project intellij-plugins by JetBrains.
the class DartPostFormatProcessor method isApplicable.
private static boolean isApplicable(@NotNull final PsiFile psiFile, @NotNull final TextRange rangeToReformat) {
if (!(psiFile instanceof DartFile))
return false;
if (!psiFile.getTextRange().equals(rangeToReformat))
return false;
final Project project = psiFile.getProject();
if (!CodeStyleSettingsManager.getSettings(project).getCustomSettings(DartCodeStyleSettings.class).DELEGATE_TO_DARTFMT)
return false;
final VirtualFile vFile = psiFile.getVirtualFile();
if (!DartAnalysisServerService.isLocalAnalyzableFile(vFile))
return false;
final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
if (module == null || !DartSdkLibUtil.isDartSdkEnabled(module))
return false;
if (!ProjectFileIndex.getInstance(project).isInContent(vFile))
return false;
if (!DartAnalysisServerService.getInstance(project).serverReadyForRequest(project))
return false;
return true;
}
use of com.jetbrains.lang.dart.psi.DartFile in project flutter-intellij by flutter.
the class TestConfigProducer method setupConfigurationFromContext.
/**
* If the current file looks like a Flutter test, initializes the run config to run it.
* <p>
* Returns true if successfully set up.
*/
@Override
protected boolean setupConfigurationFromContext(TestConfig config, ConfigurationContext context, Ref<PsiElement> sourceElement) {
if (!isFlutterContext(context))
return false;
final PsiElement elt = context.getPsiLocation();
if (elt instanceof PsiDirectory) {
return setupForDirectory(config, (PsiDirectory) elt);
}
final DartFile file = FlutterRunConfigurationProducer.getDartFile(context);
if (file == null) {
return false;
}
if (supportsFiltering(config.getSdk())) {
final String testName = TestConfigUtils.findTestName(elt);
if (testName != null) {
return setupForSingleTest(config, context, file, testName);
}
}
return setupForDartFile(config, context, file);
}
use of com.jetbrains.lang.dart.psi.DartFile in project flutter-intellij by flutter.
the class FlutterDependencyInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (!isOnTheFly)
return null;
if (!(psiFile instanceof DartFile))
return null;
if (DartPlugin.isPubActionInProgress())
return null;
final VirtualFile file = FlutterUtils.getRealVirtualFile(psiFile);
if (file == null || !file.isInLocalFileSystem())
return null;
final Project project = psiFile.getProject();
if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file))
return null;
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (!FlutterModuleUtils.isFlutterModule(module))
return null;
final PubRoot root = PubRoot.forPsiFile(psiFile);
if (root == null || myIgnoredPubspecPaths.contains(root.getPubspec().getPath()))
return null;
if (root.getPackages() == null) {
return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("packages.get.never.done"));
}
if (!root.hasUpToDatePackages()) {
return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pubspec.edited"));
}
return null;
}
use of com.jetbrains.lang.dart.psi.DartFile in project flutter-intellij by flutter.
the class FlutterIconProvider method getIcon.
@Nullable
public Icon getIcon(@NotNull final PsiElement element, @Iconable.IconFlags final int flags) {
final Project project = element.getProject();
if (!FlutterModuleUtils.usesFlutter(project))
return null;
// Directories.
if (element instanceof PsiDirectory) {
final VirtualFile file = ((PsiDirectory) element).getVirtualFile();
if (!file.isInLocalFileSystem())
return null;
// Show an icon for flutter modules.
final PubRoot pubRoot = PubRoot.forDirectory(file);
if (pubRoot != null && pubRoot.declaresFlutter()) {
return FlutterIcons.Flutter;
}
final PubRoot root = PubRoot.forDirectory(file.getParent());
if (root == null)
return null;
// TODO(devoncarew): should we just make the folder a source kind?
if (file.equals(root.getLib()))
return AllIcons.Modules.SourceRoot;
if (Objects.equals(file, root.getAndroidDir()))
return AllIcons.Nodes.KeymapTools;
if (Objects.equals(file, root.getiOsDir()))
return AllIcons.Nodes.KeymapTools;
if (file.isDirectory() && file.getName().equals(".idea"))
return AllIcons.Modules.GeneratedFolder;
}
// Files.
if (element instanceof DartFile) {
final DartFile dartFile = (DartFile) element;
final VirtualFile file = dartFile.getVirtualFile();
if (!file.isInLocalFileSystem())
return null;
// TODO(pq): consider pushing up to the Dart Plugin.
if (FlutterUtils.isInTestDir(dartFile) && file.getName().endsWith("_test.dart")) {
return TEST_FILE;
}
}
return null;
}
Aggregations