Search in sources :

Example 1 with LightJavaModule

use of com.intellij.psi.impl.light.LightJavaModule in project intellij-community by JetBrains.

the class ModuleHighlightUtil method checkPackageAccessibility.

private static HighlightInfo checkPackageAccessibility(PsiJavaCodeReferenceElement ref, PsiJavaModule refModule, PsiJavaModule targetModule, String packageName) {
    if (!refModule.equals(targetModule)) {
        if (targetModule == null) {
            String message = JavaErrorMessages.message("module.package.on.classpath");
            return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(ref).descriptionAndTooltip(message).create();
        }
        String refModuleName = refModule.getName();
        String requiredName = targetModule.getName();
        if (!(targetModule instanceof LightJavaModule || JavaModuleGraphUtil.exports(targetModule, packageName, refModule))) {
            String message = JavaErrorMessages.message("module.package.not.exported", requiredName, packageName, refModuleName);
            return HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(ref).descriptionAndTooltip(message).create();
        }
        if (!(PsiJavaModule.JAVA_BASE.equals(requiredName) || JavaModuleGraphUtil.reads(refModule, targetModule))) {
            String message = JavaErrorMessages.message("module.not.in.requirements", refModuleName, requiredName);
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).range(ref).descriptionAndTooltip(message).create();
            QuickFixAction.registerQuickFixAction(info, new AddRequiredModuleFix(refModule, requiredName));
            return info;
        }
    }
    return null;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) LightJavaModule(com.intellij.psi.impl.light.LightJavaModule)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 LightJavaModule (com.intellij.psi.impl.light.LightJavaModule)1