FunctionsHighlightingVisitor.java 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright 2010-2012 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.jet.plugin.highlighter;

import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.psi.PsiElement;
21
import org.jetbrains.jet.lang.descriptors.*;
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;

/**
 * @author Evgeny Gerashchenko
 * @since 4/2/12
 */
public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
    public FunctionsHighlightingVisitor(AnnotationHolder holder, BindingContext bindingContext) {
        super(holder, bindingContext);
    }

    @Override
    public void visitNamedFunction(JetNamedFunction function) {
        PsiElement nameIdentifier = function.getNameIdentifier();
        if (nameIdentifier != null) {
39
            JetPsiChecker.highlightName(holder, nameIdentifier, JetHighlightingColors.FUNCTION_DECLARATION);
40 41 42 43 44 45 46 47 48 49 50 51 52 53
        }

        super.visitNamedFunction(function);
    }

    @Override
    public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
        JetConstructorCalleeExpression calleeExpression = call.getCalleeExpression();
        JetTypeReference typeRef = calleeExpression.getTypeReference();
        if (typeRef != null) {
            JetTypeElement typeElement = typeRef.getTypeElement();
            if (typeElement instanceof JetUserType) {
                JetSimpleNameExpression nameExpression = ((JetUserType)typeElement).getReferenceExpression();
                if (nameExpression != null) {
54
                    JetPsiChecker.highlightName(holder, nameExpression, JetHighlightingColors.CONSTRUCTOR_CALL);
55 56 57 58 59 60 61 62 63 64 65 66 67
                }
            }
        }
        super.visitDelegationToSuperCallSpecifier(call);
    }

    @Override
    public void visitCallExpression(JetCallExpression expression) {
        JetExpression callee = expression.getCalleeExpression();
        if (callee instanceof JetReferenceExpression) {
            DeclarationDescriptor calleeDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetReferenceExpression)callee);
            if (calleeDescriptor != null) {
                if (calleeDescriptor instanceof ConstructorDescriptor) {
68
                    JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.CONSTRUCTOR_CALL);
69
                }
70
                else if (calleeDescriptor instanceof FunctionDescriptor) {
71
                    FunctionDescriptor fun = (FunctionDescriptor)calleeDescriptor;
72 73
                    JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.FUNCTION_CALL);
                    if (fun.getContainingDeclaration() instanceof NamespaceDescriptor) {
74
                        JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.NAMESPACE_FUNCTION_CALL);
75
                    }
76 77
                    if (fun.getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) {
                        JetPsiChecker.highlightName(holder, callee, JetHighlightingColors.EXTENSION_FUNCTION_CALL);
78 79 80 81 82 83 84 85
                    }
                }
            }
        }

        super.visitCallExpression(expression);
    }
}