Search in sources :

Example 1 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.

the class ModuleGroupingRule method groupUsage.

@Override
public UsageGroup groupUsage(@NotNull Usage usage) {
    if (usage instanceof UsageInModule) {
        UsageInModule usageInModule = (UsageInModule) usage;
        Module module = usageInModule.getModule();
        if (module != null)
            return new ModuleUsageGroup(module);
    }
    if (usage instanceof UsageInLibrary) {
        UsageInLibrary usageInLibrary = (UsageInLibrary) usage;
        OrderEntry entry = usageInLibrary.getLibraryEntry();
        if (entry != null)
            return new LibraryUsageGroup(entry);
    }
    return null;
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) UsageInModule(com.intellij.usages.rules.UsageInModule) UsageInLibrary(com.intellij.usages.rules.UsageInLibrary) UsageInModule(com.intellij.usages.rules.UsageInModule) Module(com.intellij.openapi.module.Module)

Example 2 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.

the class ArtifactEditorContextImpl method selectLibrary.

@Override
public void selectLibrary(@NotNull Library library) {
    final LibraryTable table = library.getTable();
    if (table != null) {
        ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
    } else {
        final Module module = ((LibraryImpl) library).getModule();
        if (module != null) {
            final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
            final String libraryName = library.getName();
            for (OrderEntry entry : rootModel.getOrderEntries()) {
                if (entry instanceof ModuleLibraryOrderEntryImpl) {
                    final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
                    if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
                        ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
                        return;
                    }
                }
            }
        }
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) ModuleRootModel(com.intellij.openapi.roots.ModuleRootModel) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Module(com.intellij.openapi.module.Module)

Example 3 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project android by JetBrains.

the class AndroidModuleDependenciesSetupTest method getLibraryOrderEntries.

@NotNull
private static List<LibraryOrderEntry> getLibraryOrderEntries(@NotNull Module module) {
    List<LibraryOrderEntry> libraryOrderEntries = new ArrayList<>();
    OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry) {
            libraryOrderEntries.add((LibraryOrderEntry) orderEntry);
        }
    }
    return libraryOrderEntries;
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ArrayList(java.util.ArrayList) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project android by JetBrains.

the class AndroidPrecompileTask method checkAndroidDependencies.

private static void checkAndroidDependencies(@NotNull CompileContext context) {
    for (Module module : context.getCompileScope().getAffectedModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            continue;
        }
        final Pair<String, VirtualFile> manifestMergerProp = AndroidRootUtil.getProjectPropertyValue(module, AndroidUtils.ANDROID_MANIFEST_MERGER_PROPERTY);
        if (manifestMergerProp != null && Boolean.parseBoolean(manifestMergerProp.getFirst())) {
            context.addMessage(CompilerMessageCategory.WARNING, "[" + module.getName() + "] " + AndroidBundle.message("android.manifest.merger.not.supported.error"), manifestMergerProp.getSecond().getUrl(), -1, -1);
        }
        if (facet.isAppProject()) {
            for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
                if (entry instanceof ModuleOrderEntry) {
                    final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) entry;
                    if (moduleOrderEntry.getScope() == DependencyScope.COMPILE) {
                        final Module depModule = moduleOrderEntry.getModule();
                        if (depModule != null) {
                            final AndroidFacet depFacet = AndroidFacet.getInstance(depModule);
                            if (depFacet != null && !depFacet.canBeDependency()) {
                                String message = "Suspicious module dependency " + module.getName() + " -> " + depModule.getName() + ": Android application module depends on other application module. Possibly, you should ";
                                if (AndroidMavenUtil.isMavenizedModule(depModule)) {
                                    message += "change packaging type of module " + depModule.getName() + " to 'apklib' in pom.xml file or ";
                                }
                                message += "change dependency scope to 'Provided'.";
                                context.addMessage(CompilerMessageCategory.WARNING, message, null, -1, -1);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 5 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.

the class AppEngineForbiddenCodeInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    final Project project = manager.getProject();
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    final AppEngineFacet appEngineFacet = AppEngineFacet.getAppEngineFacetByModule(module);
    if (appEngineFacet == null) {
        return null;
    }
    final AppEngineSdk appEngineSdk = appEngineFacet.getSdk();
    if (!appEngineSdk.isValid()) {
        return null;
    }
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final List<ProblemDescriptor> problems = new ArrayList<>();
    file.accept(new JavaRecursiveElementWalkingVisitor() {

        @Override
        public void visitDocComment(PsiDocComment comment) {
        }

        @Override
        public void visitMethod(PsiMethod method) {
            final PsiModifierList modifierList = method.getModifierList();
            if (modifierList.hasModifierProperty(PsiModifier.NATIVE)) {
                if (!isNativeMethodAllowed(method)) {
                    problems.add(manager.createProblemDescriptor(modifierList, "Native methods aren't allowed in App Engine application", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                }
            }
            super.visitMethod(method);
        }

        @Override
        public void visitNewExpression(PsiNewExpression expression) {
            final PsiJavaCodeReferenceElement classReference = expression.getClassReference();
            if (classReference != null) {
                final PsiElement resolved = classReference.resolve();
                if (resolved instanceof PsiClass) {
                    final String qualifiedName = ((PsiClass) resolved).getQualifiedName();
                    if (qualifiedName != null && appEngineSdk.isMethodInBlacklist(qualifiedName, "new")) {
                        final String message = "App Engine application should not create new instances of '" + qualifiedName + "' class";
                        problems.add(manager.createProblemDescriptor(classReference, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitNewExpression(expression);
        }

        @Override
        public void visitMethodCallExpression(PsiMethodCallExpression expression) {
            final PsiReferenceExpression methodExpression = expression.getMethodExpression();
            final PsiElement element = methodExpression.resolve();
            if (element instanceof PsiMethod) {
                final PsiMethod method = (PsiMethod) element;
                final PsiClass psiClass = method.getContainingClass();
                if (psiClass != null) {
                    final String qualifiedName = psiClass.getQualifiedName();
                    final String methodName = method.getName();
                    if (qualifiedName != null && appEngineSdk.isMethodInBlacklist(qualifiedName, methodName)) {
                        final String message = "AppEngine application should not call '" + StringUtil.getShortName(qualifiedName) + "." + methodName + "' method";
                        problems.add(manager.createProblemDescriptor(methodExpression, message, isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                    }
                }
            }
            super.visitMethodCallExpression(expression);
        }

        @Override
        public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
            final PsiElement resolved = reference.resolve();
            if (resolved instanceof PsiClass) {
                final PsiFile psiFile = resolved.getContainingFile();
                if (psiFile != null) {
                    final VirtualFile virtualFile = psiFile.getVirtualFile();
                    if (virtualFile != null && !fileIndex.isInSource(virtualFile)) {
                        final List<OrderEntry> list = fileIndex.getOrderEntriesForFile(virtualFile);
                        for (OrderEntry entry : list) {
                            if (entry instanceof JdkOrderEntry) {
                                final String className = ClassUtil.getJVMClassName((PsiClass) resolved);
                                if (className != null && !appEngineSdk.isClassInWhiteList(className)) {
                                    problems.add(manager.createProblemDescriptor(reference, "Class '" + className + "' is not included in App Engine JRE White List", isOnTheFly, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
                                }
                            }
                        }
                    }
                }
            }
            super.visitReferenceElement(reference);
        }
    });
    return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) AppEngineFacet(com.intellij.appengine.facet.AppEngineFacet) ArrayList(java.util.ArrayList) List(java.util.List) AppEngineSdk(com.intellij.appengine.sdk.AppEngineSdk) PsiDocComment(com.intellij.psi.javadoc.PsiDocComment) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module)

Aggregations

OrderEntry (com.intellij.openapi.roots.OrderEntry)54 Module (com.intellij.openapi.module.Module)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)18 Project (com.intellij.openapi.project.Project)14 Library (com.intellij.openapi.roots.libraries.Library)12 ArrayList (java.util.ArrayList)11 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)10 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)10 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)8 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)5 List (java.util.List)5 Sdk (com.intellij.openapi.projectRoots.Sdk)4 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 AccessToken (com.intellij.openapi.application.AccessToken)3 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3