Search in sources :

Example 1 with DartFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartFile(com.jetbrains.lang.dart.psi.DartFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DartFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartFile(com.jetbrains.lang.dart.psi.DartFile) Module(com.intellij.openapi.module.Module)

Example 3 with DartFile

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);
}
Also used : DartFile(com.jetbrains.lang.dart.psi.DartFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiElement(com.intellij.psi.PsiElement)

Example 4 with DartFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartFile(com.jetbrains.lang.dart.psi.DartFile) FlutterSdk(io.flutter.sdk.FlutterSdk) PubRoot(io.flutter.pub.PubRoot) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DartFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartFile(com.jetbrains.lang.dart.psi.DartFile) PsiDirectory(com.intellij.psi.PsiDirectory) PubRoot(io.flutter.pub.PubRoot) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DartFile (com.jetbrains.lang.dart.psi.DartFile)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 PsiFile (com.intellij.psi.PsiFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 Module (com.intellij.openapi.module.Module)3 PsiElement (com.intellij.psi.PsiElement)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PubRoot (io.flutter.pub.PubRoot)2 NotNull (org.jetbrains.annotations.NotNull)2 ASTNode (com.intellij.lang.ASTNode)1 DocumentBasedFormattingModel (com.intellij.psi.formatter.DocumentBasedFormattingModel)1 DartCallExpression (com.jetbrains.lang.dart.psi.DartCallExpression)1 DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)1 FlutterSdk (io.flutter.sdk.FlutterSdk)1