Search in sources :

Example 6 with TextAttributesScheme

use of com.intellij.openapi.editor.colors.TextAttributesScheme in project intellij-community by JetBrains.

the class HighlightVisitorImpl method highlightReferencedMethodOrClassName.

private void highlightReferencedMethodOrClassName(@NotNull PsiJavaCodeReferenceElement element, PsiElement resolved) {
    PsiElement parent = element.getParent();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
    if (parent instanceof PsiMethodCallExpression) {
        PsiMethod method = ((PsiMethodCallExpression) parent).resolveMethod();
        PsiElement methodNameElement = element.getReferenceNameElement();
        if (method != null && methodNameElement != null && !(methodNameElement instanceof PsiKeyword)) {
            myHolder.add(HighlightNamesUtil.highlightMethodName(method, methodNameElement, false, colorsScheme));
            myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(element, colorsScheme));
        }
    } else if (parent instanceof PsiConstructorCall) {
        try {
            PsiMethod method = ((PsiConstructorCall) parent).resolveConstructor();
            PsiMember methodOrClass = method != null ? method : resolved instanceof PsiClass ? (PsiClass) resolved : null;
            if (methodOrClass != null) {
                final PsiElement referenceNameElement = element.getReferenceNameElement();
                if (referenceNameElement != null) {
                    // exclude type parameters from the highlighted text range
                    TextRange range = referenceNameElement.getTextRange();
                    myHolder.add(HighlightNamesUtil.highlightMethodName(methodOrClass, referenceNameElement, range, colorsScheme, false));
                }
            }
        } catch (IndexNotReadyException ignored) {
        }
    } else if (resolved instanceof PsiPackage) {
        // highlight package (and following dot) as a class
        myHolder.add(HighlightNamesUtil.highlightPackage(resolved, element, colorsScheme));
    } else if (resolved instanceof PsiClass) {
        myHolder.add(HighlightNamesUtil.highlightClassName((PsiClass) resolved, element, colorsScheme));
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributesScheme(com.intellij.openapi.editor.colors.TextAttributesScheme) TextRange(com.intellij.openapi.util.TextRange) LocalQuickFixAndIntentionActionOnPsiElement(com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)

Example 7 with TextAttributesScheme

use of com.intellij.openapi.editor.colors.TextAttributesScheme in project intellij-community by JetBrains.

the class HighlightVisitorImpl method visitMethod.

@Override
public void visitMethod(PsiMethod method) {
    super.visitMethod(method);
    if (!myHolder.hasErrorResults())
        myHolder.add(HighlightControlFlowUtil.checkUnreachableStatement(method.getBody()));
    if (!myHolder.hasErrorResults())
        myHolder.add(HighlightMethodUtil.checkConstructorHandleSuperClassExceptions(method));
    if (!myHolder.hasErrorResults())
        myHolder.add(HighlightMethodUtil.checkRecursiveConstructorInvocation(method));
    if (!myHolder.hasErrorResults())
        myHolder.add(GenericsHighlightUtil.checkSafeVarargsAnnotation(method, myLanguageLevel));
    PsiClass aClass = method.getContainingClass();
    if (!myHolder.hasErrorResults() && method.isConstructor()) {
        myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, aClass));
    }
    if (!myHolder.hasErrorResults() && method.hasModifierProperty(PsiModifier.DEFAULT)) {
        myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
    }
    if (!myHolder.hasErrorResults() && aClass != null && aClass.isInterface() && method.hasModifierProperty(PsiModifier.STATIC)) {
        myHolder.add(checkFeature(method, Feature.EXTENSION_METHODS));
    }
    if (!myHolder.hasErrorResults() && aClass != null) {
        myHolder.add(HighlightMethodUtil.checkDuplicateMethod(aClass, method, getDuplicateMethods(aClass)));
    }
    // method params are highlighted in visitMethod since we should make sure the method body was visited before
    PsiParameter[] parameters = method.getParameterList().getParameters();
    final TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
    for (PsiParameter parameter : parameters) {
        int info = myReassignedParameters.get(parameter);
        // out of this file
        if (info == 0)
            continue;
        PsiIdentifier nameIdentifier = parameter.getNameIdentifier();
        if (nameIdentifier != null) {
            if (info == 2) {
                // reassigned
                myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, nameIdentifier));
            } else {
                myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, nameIdentifier, colorsScheme));
            }
        }
    }
}
Also used : TextAttributesScheme(com.intellij.openapi.editor.colors.TextAttributesScheme)

Aggregations

TextAttributesScheme (com.intellij.openapi.editor.colors.TextAttributesScheme)7 LocalQuickFixAndIntentionActionOnPsiElement (com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement)6 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)2 TextRange (com.intellij.openapi.util.TextRange)2 Pair (com.intellij.openapi.util.Pair)1 PsiDocMethodOrFieldRef (com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef)1 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)1