Search in sources :

Example 6 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class ColorSettingsUtil method addInspectionSeverityAttributes.

private static void addInspectionSeverityAttributes(List<AttributesDescriptor> descriptors) {
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unknown.symbol"), CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.deprecated.symbol"), CodeInsightColors.DEPRECATED_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.unused.symbol"), CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.error"), CodeInsightColors.ERRORS_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.warning"), CodeInsightColors.WARNINGS_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.weak.warning"), CodeInsightColors.WEAK_WARNING_ATTRIBUTES));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.problems"), CodeInsightColors.GENERIC_SERVER_ERROR_OR_WARNING));
    descriptors.add(new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.server.duplicate"), CodeInsightColors.DUPLICATE_FROM_SERVER));
    for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
        for (HighlightInfoType highlightInfoType : provider.getSeveritiesHighlightInfoTypes()) {
            final TextAttributesKey attributesKey = highlightInfoType.getAttributesKey();
            descriptors.add(new AttributesDescriptor(toDisplayName(attributesKey), attributesKey));
        }
    }
}
Also used : AttributesDescriptor(com.intellij.openapi.options.colors.AttributesDescriptor) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SeveritiesProvider(com.intellij.codeInsight.daemon.impl.SeveritiesProvider) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Example 7 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class HighlightMethodUtil method checkAmbiguousMethodCallIdentifier.

@Nullable
static HighlightInfo checkAmbiguousMethodCallIdentifier(@NotNull PsiReferenceExpression referenceToMethod, @NotNull JavaResolveResult[] resolveResults, @NotNull PsiExpressionList list, final PsiElement element, @NotNull JavaResolveResult resolveResult, @NotNull PsiMethodCallExpression methodCall, @NotNull PsiResolveHelper resolveHelper, @NotNull LanguageLevel languageLevel, @NotNull PsiFile file) {
    MethodCandidateInfo methodCandidate1 = null;
    MethodCandidateInfo methodCandidate2 = null;
    for (JavaResolveResult result : resolveResults) {
        if (!(result instanceof MethodCandidateInfo))
            continue;
        MethodCandidateInfo candidate = (MethodCandidateInfo) result;
        if (candidate.isApplicable() && !candidate.getElement().isConstructor()) {
            if (methodCandidate1 == null) {
                methodCandidate1 = candidate;
            } else {
                methodCandidate2 = candidate;
                break;
            }
        }
    }
    MethodCandidateInfo[] candidates = toMethodCandidates(resolveResults);
    HighlightInfoType highlightInfoType = HighlightInfoType.ERROR;
    if (methodCandidate2 != null) {
        return null;
    }
    String description;
    PsiElement elementToHighlight;
    if (element != null && !resolveResult.isAccessible()) {
        description = HighlightUtil.buildProblemWithAccessDescription(referenceToMethod, resolveResult);
        elementToHighlight = referenceToMethod.getReferenceNameElement();
    } else if (element != null && !resolveResult.isStaticsScopeCorrect()) {
        description = null;
        elementToHighlight = ObjectUtils.notNull(referenceToMethod.getReferenceNameElement(), referenceToMethod);
        if (element instanceof PsiMethod && ((PsiMethod) element).hasModifierProperty(PsiModifier.STATIC)) {
            PsiClass containingClass = ((PsiMethod) element).getContainingClass();
            if (containingClass != null && containingClass.isInterface()) {
                HighlightInfo info = HighlightUtil.checkFeature(elementToHighlight, HighlightUtil.Feature.STATIC_INTERFACE_CALLS, languageLevel, file);
                if (info != null)
                    return info;
                description = checkStaticInterfaceMethodCallQualifier(referenceToMethod, resolveResult.getCurrentFileResolveScope(), containingClass);
            }
        }
        if (description == null) {
            description = HighlightUtil.buildProblemWithStaticDescription(element);
        }
    } else {
        String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list);
        description = JavaErrorMessages.message("cannot.resolve.method", methodName);
        if (candidates.length == 0) {
            elementToHighlight = referenceToMethod.getReferenceNameElement();
            highlightInfoType = HighlightInfoType.WRONG_REF;
        } else {
            return null;
        }
    }
    String toolTip = XmlStringUtil.escapeString(description);
    HighlightInfo info = HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight).description(description).escapedToolTip(toolTip).create();
    registerMethodCallIntentions(info, methodCall, list, resolveHelper);
    if (element != null && !resolveResult.isStaticsScopeCorrect()) {
        HighlightUtil.registerStaticProblemQuickFixAction(element, info, referenceToMethod);
    }
    TextRange fixRange = getFixRange(elementToHighlight);
    CastMethodArgumentFix.REGISTRAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapArrayToArraysAsListFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapLongWithMathToIntExactFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapObjectWithOptionalOfNullableFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapLongWithMathToIntExactFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    PermuteArgumentsFix.registerFix(info, methodCall, candidates, fixRange);
    WrapExpressionFix.registerWrapAction(candidates, list.getExpressions(), info);
    registerChangeParameterClassFix(methodCall, list, info);
    return info;
}
Also used : MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class HighlightMethodUtil method checkAmbiguousMethodCallArguments.

@Nullable
static HighlightInfo checkAmbiguousMethodCallArguments(@NotNull PsiReferenceExpression referenceToMethod, @NotNull JavaResolveResult[] resolveResults, @NotNull PsiExpressionList list, final PsiElement element, @NotNull JavaResolveResult resolveResult, @NotNull PsiMethodCallExpression methodCall, @NotNull PsiResolveHelper resolveHelper, @NotNull PsiElement elementToHighlight) {
    MethodCandidateInfo methodCandidate1 = null;
    MethodCandidateInfo methodCandidate2 = null;
    for (JavaResolveResult result : resolveResults) {
        if (!(result instanceof MethodCandidateInfo))
            continue;
        MethodCandidateInfo candidate = (MethodCandidateInfo) result;
        if (candidate.isApplicable() && !candidate.getElement().isConstructor()) {
            if (methodCandidate1 == null) {
                methodCandidate1 = candidate;
            } else {
                methodCandidate2 = candidate;
                break;
            }
        }
    }
    MethodCandidateInfo[] candidates = toMethodCandidates(resolveResults);
    String description;
    String toolTip;
    HighlightInfoType highlightInfoType = HighlightInfoType.ERROR;
    if (methodCandidate2 != null) {
        PsiMethod element1 = methodCandidate1.getElement();
        String m1 = PsiFormatUtil.formatMethod(element1, methodCandidate1.getSubstitutor(false), PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
        PsiMethod element2 = methodCandidate2.getElement();
        String m2 = PsiFormatUtil.formatMethod(element2, methodCandidate2.getSubstitutor(false), PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
        VirtualFile virtualFile1 = PsiUtilCore.getVirtualFile(element1);
        VirtualFile virtualFile2 = PsiUtilCore.getVirtualFile(element2);
        if (!Comparing.equal(virtualFile1, virtualFile2)) {
            if (virtualFile1 != null)
                m1 += " (In " + virtualFile1.getPresentableUrl() + ")";
            if (virtualFile2 != null)
                m2 += " (In " + virtualFile2.getPresentableUrl() + ")";
        }
        description = JavaErrorMessages.message("ambiguous.method.call", m1, m2);
        toolTip = createAmbiguousMethodHtmlTooltip(new MethodCandidateInfo[] { methodCandidate1, methodCandidate2 });
    } else {
        if (element != null && !resolveResult.isAccessible()) {
            return null;
        }
        if (element != null && !resolveResult.isStaticsScopeCorrect()) {
            return null;
        }
        String methodName = referenceToMethod.getReferenceName() + buildArgTypesList(list);
        description = JavaErrorMessages.message("cannot.resolve.method", methodName);
        if (candidates.length == 0) {
            return null;
        }
        toolTip = XmlStringUtil.escapeString(description);
    }
    HighlightInfo info = HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight).description(description).escapedToolTip(toolTip).create();
    if (methodCandidate2 == null) {
        registerMethodCallIntentions(info, methodCall, list, resolveHelper);
    }
    if (!resolveResult.isAccessible() && resolveResult.isStaticsScopeCorrect() && methodCandidate2 != null) {
        HighlightUtil.registerAccessQuickFixAction((PsiMember) element, referenceToMethod, info, resolveResult.getCurrentFileResolveScope());
    }
    if (element != null && !resolveResult.isStaticsScopeCorrect()) {
        HighlightUtil.registerStaticProblemQuickFixAction(element, info, referenceToMethod);
    }
    TextRange fixRange = getFixRange(elementToHighlight);
    CastMethodArgumentFix.REGISTRAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapArrayToArraysAsListFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapLongWithMathToIntExactFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapObjectWithOptionalOfNullableFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    WrapStringWithFileFix.REGISTAR.registerCastActions(candidates, methodCall, info, fixRange);
    PermuteArgumentsFix.registerFix(info, methodCall, candidates, fixRange);
    WrapExpressionFix.registerWrapAction(candidates, list.getExpressions(), info);
    registerChangeParameterClassFix(methodCall, list, info);
    return info;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) TextRange(com.intellij.openapi.util.TextRange) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class HighlightUtil method checkUnhandledExceptions.

@Nullable
static HighlightInfo checkUnhandledExceptions(@NotNull final PsiElement element, @Nullable TextRange textRange) {
    final List<PsiClassType> unhandledExceptions = ExceptionUtil.getUnhandledExceptions(element);
    if (unhandledExceptions.isEmpty())
        return null;
    final HighlightInfoType highlightType = getUnhandledExceptionHighlightType(element);
    if (highlightType == null)
        return null;
    if (textRange == null)
        textRange = element.getTextRange();
    final String description = getUnhandledExceptionsDescriptor(unhandledExceptions);
    HighlightInfo errorResult = HighlightInfo.newHighlightInfo(highlightType).range(textRange).descriptionAndTooltip(description).create();
    registerUnhandledExceptionFixes(element, errorResult, unhandledExceptions);
    return errorResult;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType)

Example 10 with HighlightInfoType

use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.

the class ModuleHighlightUtil method checkPackageReference.

@Nullable
static HighlightInfo checkPackageReference(@NotNull PsiPackageAccessibilityStatement statement) {
    PsiJavaCodeReferenceElement refElement = statement.getPackageReference();
    if (refElement != null) {
        PsiElement target = refElement.resolve();
        Module module = findModule(refElement);
        PsiDirectory[] directories = target instanceof PsiPackage && module != null ? ((PsiPackage) target).getDirectories(module.getModuleScope(false)) : null;
        String packageName = refText(refElement);
        HighlightInfoType type = statement.getRole() == Role.OPENS ? HighlightInfoType.WARNING : HighlightInfoType.ERROR;
        if (directories == null || directories.length == 0) {
            String message = JavaErrorMessages.message("package.not.found", packageName);
            return HighlightInfo.newHighlightInfo(type).range(refElement).descriptionAndTooltip(message).create();
        }
        if (PsiUtil.isPackageEmpty(directories, packageName)) {
            String message = JavaErrorMessages.message("package.is.empty", packageName);
            return HighlightInfo.newHighlightInfo(type).range(refElement).descriptionAndTooltip(message).create();
        }
    }
    return null;
}
Also used : Module(com.intellij.openapi.module.Module) LightJavaModule(com.intellij.psi.impl.light.LightJavaModule) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)22 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)14 TextRange (com.intellij.openapi.util.TextRange)8 Nullable (org.jetbrains.annotations.Nullable)6 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)4 SeveritiesProvider (com.intellij.codeInsight.daemon.impl.SeveritiesProvider)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)2 HtmlTag (com.intellij.psi.html.HtmlTag)2 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)2 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)2 QuickFixActionRegistrarImpl (com.intellij.codeInsight.daemon.impl.quickfix.QuickFixActionRegistrarImpl)1 SeverityEditorDialog (com.intellij.codeInspection.ex.SeverityEditorDialog)1 ASTNode (com.intellij.lang.ASTNode)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 Module (com.intellij.openapi.module.Module)1 AttributesDescriptor (com.intellij.openapi.options.colors.AttributesDescriptor)1