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));
}
}
};
}
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);
}
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();
}
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);
}
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;
}
Aggregations