use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class LibraryPackagingElement method findLibrary.
@Nullable
public Library findLibrary(@NotNull PackagingElementResolvingContext context) {
if (myModuleName == null) {
return context.findLibrary(myLevel, myLibraryName);
}
final ModulesProvider modulesProvider = context.getModulesProvider();
final Module module = modulesProvider.getModule(myModuleName);
if (module != null) {
for (OrderEntry entry : modulesProvider.getRootModel(module).getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
if (libraryEntry.isModuleLevel()) {
final String libraryName = libraryEntry.getLibraryName();
if (libraryName != null && libraryName.equals(myLibraryName)) {
return libraryEntry.getLibrary();
}
}
}
}
}
return null;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ChooseLibrariesDialogBase method collectChildren.
protected void collectChildren(Object element, final List<Object> result) {
if (element instanceof Application) {
Collections.addAll(result, ProjectManager.getInstance().getOpenProjects());
final LibraryTablesRegistrar instance = LibraryTablesRegistrar.getInstance();
//1
result.add(instance.getLibraryTable());
//2
result.addAll(instance.getCustomLibraryTables());
} else if (element instanceof Project) {
Collections.addAll(result, ModuleManager.getInstance((Project) element).getModules());
result.add(LibraryTablesRegistrar.getInstance().getLibraryTable((Project) element));
} else if (element instanceof LibraryTable) {
Collections.addAll(result, ((LibraryTable) element).getLibraries());
} else if (element instanceof Module) {
for (OrderEntry entry : ModuleRootManager.getInstance((Module) element).getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
if (LibraryTableImplUtil.MODULE_LEVEL.equals(libraryOrderEntry.getLibraryLevel())) {
final Library library = libraryOrderEntry.getLibrary();
result.add(library);
}
}
}
}
}
use of com.intellij.openapi.roots.OrderEntry 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.OrderEntry in project intellij-community by JetBrains.
the class OrderEntryTest method removeLibs.
private void removeLibs() {
ApplicationManager.getApplication().runWriteAction(() -> {
try {
for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel model = rootManager.getModifiableModel();
for (OrderEntry orderEntry : model.getOrderEntries()) {
model.removeOrderEntry(orderEntry);
}
model.commit();
}
} catch (Throwable e) {
// when running test from within IDEA it would fail because junit.jar cache is locked by host IDEA instance
e.printStackTrace();
}
});
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class FindClassUtil method findModulesWithClass.
/**
* Searches the project for modules that contain the class with the specified full-qualified name within
* the module dependencies or libraries.
*
* @param qualifiedName the full-qualified name of the class to find.
* @return the modules that contain the given class in dependencies or libraries.
*/
@NotNull
public static Collection<Module> findModulesWithClass(@NotNull Project project, @NonNls @NotNull String qualifiedName) {
GlobalSearchScope allScope = GlobalSearchScope.allScope(project);
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
PsiClass[] possibleClasses = facade.findClasses(qualifiedName, allScope);
if (possibleClasses.length == 0) {
return Collections.emptyList();
}
Set<Module> relevantModules = ContainerUtil.newLinkedHashSet();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiClass aClass : possibleClasses) {
VirtualFile classFile = aClass.getContainingFile().getVirtualFile();
for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(classFile)) {
relevantModules.add(orderEntry.getOwnerModule());
}
}
return relevantModules;
}
Aggregations