use of com.intellij.openapi.roots.JdkOrderEntry in project android by JetBrains.
the class AndroidSdkResolveScopeProvider method getResolveScope.
@Nullable
@Override
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
if (!ProjectFacetManager.getInstance(project).hasFacets(AndroidFacet.ID))
return null;
ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
JdkOrderEntry entry = ContainerUtil.findInstance(index.getOrderEntriesForFile(file), JdkOrderEntry.class);
final Sdk sdk = entry == null ? null : entry.getJdk();
if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
return null;
}
return new MyJdkScope(project, entry, index.isInLibrarySource(file));
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class ProjectUtilCore method displayUrlRelativeToProject.
public static String displayUrlRelativeToProject(@NotNull VirtualFile file, @NotNull String url, @NotNull Project project, boolean includeFilePath, boolean keepModuleAlwaysOnTheLeft) {
final VirtualFile baseDir = project.getBaseDir();
if (baseDir != null && includeFilePath) {
//noinspection ConstantConditions
final String projectHomeUrl = baseDir.getPresentableUrl();
if (url.startsWith(projectHomeUrl)) {
url = "..." + url.substring(projectHomeUrl.length());
}
}
if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
final VirtualFile fileForJar = ((LocalFileProvider) file.getFileSystem()).getLocalVirtualFileFor(file);
if (fileForJar != null) {
final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
if (libraryEntry != null) {
if (libraryEntry instanceof JdkOrderEntry) {
url = url + " - [" + ((JdkOrderEntry) libraryEntry).getJdkName() + "]";
} else {
url = url + " - [" + libraryEntry.getPresentableName() + "]";
}
} else {
url = url + " - [" + fileForJar.getName() + "]";
}
}
}
final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (module == null)
return url;
return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url;
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class MagicConstantInspection method checkAnnotationsJarAttached.
private static void checkAnnotationsJarAttached(@NotNull PsiFile file, @NotNull ProblemsHolder holder) {
final Project project = file.getProject();
if (!holder.isOnTheFly()) {
final Boolean found = project.getUserData(NO_ANNOTATIONS_FOUND);
if (found != null)
return;
}
PsiClass event = JavaPsiFacade.getInstance(project).findClass("java.awt.event.InputEvent", GlobalSearchScope.allScope(project));
// no jdk to attach
if (event == null)
return;
PsiMethod[] methods = event.findMethodsByName("getModifiers", false);
// no jdk to attach
if (methods.length != 1)
return;
PsiMethod getModifiers = methods[0];
PsiAnnotation annotation = ExternalAnnotationsManager.getInstance(project).findExternalAnnotation(getModifiers, MagicConstant.class.getName());
if (annotation != null)
return;
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(getModifiers);
// no jdk to attach
if (virtualFile == null)
return;
final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
Sdk jdk = null;
for (OrderEntry orderEntry : entries) {
if (orderEntry instanceof JdkOrderEntry) {
jdk = ((JdkOrderEntry) orderEntry).getJdk();
if (jdk != null)
break;
}
}
// no jdk to attach
if (jdk == null)
return;
if (!holder.isOnTheFly()) {
project.putUserData(NO_ANNOTATIONS_FOUND, Boolean.TRUE);
}
final Sdk finalJdk = jdk;
String path = finalJdk.getHomePath();
String text = "No IDEA annotations attached to the JDK " + finalJdk.getName() + (path == null ? "" : " (" + FileUtil.toSystemDependentName(path) + ")") + ", some issues will not be found";
holder.registerProblem(file, text, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new LocalQuickFix() {
@NotNull
@Override
public String getFamilyName() {
return "Attach annotations";
}
@Nullable
@Override
public PsiElement getElementToMakeWritable(@NotNull PsiFile file) {
return null;
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
SdkModificator modificator = finalJdk.getSdkModificator();
JavaSdkImpl.attachJdkAnnotations(modificator);
modificator.commitChanges();
}
});
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class PyBuiltinCache method findSdkForNonModuleFile.
@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
Project project = psiFile.getProject();
Sdk sdk = null;
final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
if (vfile != null) {
// reality
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
sdk = projectRootManager.getProjectSdk();
if (sdk == null) {
final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
sdk = ((JdkOrderEntry) orderEntry).getJdk();
} else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
}
}
}
}
return sdk;
}
use of com.intellij.openapi.roots.JdkOrderEntry in project intellij-community by JetBrains.
the class PyTreeStructureProvider method getPythonSdk.
@Nullable
private static Sdk getPythonSdk(@NotNull AbstractTreeNode node) {
if (node instanceof NamedLibraryElementNode) {
final NamedLibraryElement value = ((NamedLibraryElementNode) node).getValue();
if (value != null) {
final LibraryOrSdkOrderEntry entry = value.getOrderEntry();
if (entry instanceof JdkOrderEntry) {
final Sdk sdk = ((JdkOrderEntry) entry).getJdk();
final SdkTypeId type = sdk.getSdkType();
if (type instanceof PythonSdkType) {
return sdk;
}
}
}
}
return null;
}
Aggregations