Search in sources :

Example 16 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartPathPackageReferenceInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    if (!PubspecYamlUtil.PUBSPEC_YAML.equals(holder.getFile().getName()))
        return super.buildVisitor(holder, isOnTheFly);
    final Module module = ModuleUtilCore.findModuleForPsiElement(holder.getFile());
    final DartSdk sdk = DartSdk.getDartSdk(holder.getProject());
    if (module == null || sdk == null || !DartSdkLibUtil.isDartSdkEnabled(module)) {
        return super.buildVisitor(holder, isOnTheFly);
    }
    return new PsiElementVisitor() {

        @Override
        public void visitElement(final PsiElement element) {
            ProgressIndicatorProvider.checkCanceled();
            if (!(element instanceof YAMLKeyValue) || !PubspecYamlReferenceContributor.isPathPackageDefinition((YAMLKeyValue) element) || ((YAMLKeyValue) element).getValue() == null) {
                return;
            }
            final VirtualFile packageDir = checkReferences(holder, (YAMLKeyValue) element);
            if (packageDir == null) {
                return;
            }
            if (packageDir.findChild(PubspecYamlUtil.PUBSPEC_YAML) == null) {
                final String message = DartBundle.message("pubspec.yaml.not.found.in", FileUtil.toSystemDependentName(packageDir.getPath()));
                holder.registerProblem(((YAMLKeyValue) element).getValue(), message);
                return;
            }
            final VirtualFile file = DartResolveUtil.getRealVirtualFile(element.getContainingFile());
            if (file != null && packageDir.equals(file.getParent())) {
                holder.registerProblem(((YAMLKeyValue) element).getValue(), DartBundle.message("path.package.reference.to.itself"));
                return;
            }
            final VirtualFile libDir = packageDir.findChild(PubspecYamlUtil.LIB_DIR_NAME);
            if (libDir != null && libDir.isDirectory() && !ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInContent(libDir)) {
                final String message = DartBundle.message("folder.0.not.in.project.content", FileUtil.toSystemDependentName(packageDir.getPath()));
                holder.registerProblem(((YAMLKeyValue) element).getValue(), message, new AddContentRootFix(module, packageDir));
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartLibraryIndex method getSdkLibUriByRelativePath.

@Nullable
public static String getSdkLibUriByRelativePath(@NotNull final Project project, @NotNull final String relativePath) {
    final DartSdk sdk = DartSdk.getDartSdk(project);
    final List<String> libNames = sdk == null ? null : getSdkLibUriToRelativePathMap(project, sdk.getHomePath()).getKeysByValue(relativePath);
    return libNames == null || libNames.isEmpty() ? null : libNames.get(0);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartServerResolverTest method getPresentableElementPosition.

@NotNull
private static String getPresentableElementPosition(@NotNull final CodeInsightTestFixture fixture, @Nullable final PsiElement element) {
    if (element == null)
        return "";
    final StringBuilder buf = new StringBuilder(element.getText());
    DartComponent component = PsiTreeUtil.getParentOfType(element, DartComponent.class);
    while (component != null) {
        final DartComponentName componentName = component.getComponentName();
        if (componentName != null && componentName != element) {
            buf.insert(0, component.getName() + " -> ");
        }
        component = PsiTreeUtil.getParentOfType(component, DartComponent.class);
    }
    String path = element instanceof PsiDirectoryImpl ? ((PsiDirectoryImpl) element).getVirtualFile().getPath() : element.getContainingFile().getVirtualFile().getPath();
    final String contentRoot = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots()[0].getPath();
    if (path.equals(contentRoot))
        path = "[content root]";
    final String contentRootWithSlash = contentRoot + "/";
    path = StringUtil.trimStart(path, contentRootWithSlash);
    final DartSdk sdk = DartSdk.getDartSdk(element.getProject());
    if (sdk != null && path.startsWith(sdk.getHomePath()))
        path = "[Dart SDK]" + path.substring(sdk.getHomePath().length());
    if (buf.length() > 0)
        buf.insert(0, " -> ");
    buf.insert(0, path);
    return buf.toString();
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiDirectoryImpl(com.intellij.psi.impl.file.PsiDirectoryImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartAnnotator method canBeAnalyzedByServer.

@Contract("_, null -> false")
private static boolean canBeAnalyzedByServer(@NotNull final Project project, @Nullable final VirtualFile file) {
    if (!DartAnalysisServerService.isLocalAnalyzableFile(file))
        return false;
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk))
        return false;
    // server can highlight files from Dart SDK, packages and from modules with enabled Dart support
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    if (fileIndex.isInLibraryClasses(file))
        return true;
    final Module module = fileIndex.getModuleForFile(file);
    return module != null && DartSdkLibUtil.isDartSdkEnabled(module);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Contract(org.jetbrains.annotations.Contract)

Example 20 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartCommandLineRunningState method createCommandLine.

private GeneralCommandLine createCommandLine(@Nullable final String overriddenMainFilePath) throws ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(getEnvironment().getProject());
    if (sdk == null) {
        throw new ExecutionException(DartBundle.message("dart.sdk.is.not.configured"));
    }
    final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(myRunnerParameters.computeProcessWorkingDirectory(getEnvironment().getProject()));
    commandLine.setCharset(CharsetToolkit.UTF8_CHARSET);
    commandLine.setExePath(FileUtil.toSystemDependentName(DartSdkUtil.getDartExePath(sdk)));
    commandLine.getEnvironment().putAll(myRunnerParameters.getEnvs());
    commandLine.withParentEnvironmentType(myRunnerParameters.isIncludeParentEnvs() ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
    setupParameters(commandLine, overriddenMainFilePath);
    return commandLine;
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)8 Nullable (org.jetbrains.annotations.Nullable)8 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ExecutionException (com.intellij.execution.ExecutionException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 EvictingQueue (com.google.common.collect.EvictingQueue)2 Lists (com.google.common.collect.Lists)2 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)2 com.google.dart.server (com.google.dart.server)2 AnalysisServer (com.google.dart.server.generated.AnalysisServer)2 DebugPrintStream (com.google.dart.server.internal.remote.DebugPrintStream)2 RemoteAnalysisServerImpl (com.google.dart.server.internal.remote.RemoteAnalysisServerImpl)2 StdioServerSocket (com.google.dart.server.internal.remote.StdioServerSocket)2 Logging (com.google.dart.server.utilities.logging.Logging)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)2 Disposable (com.intellij.openapi.Disposable)2