001/*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.jetbrains.jet.codegen.context;
018
019import org.jetbrains.annotations.NotNull;
020import org.jetbrains.annotations.Nullable;
021import org.jetbrains.jet.codegen.OwnerKind;
022import org.jetbrains.jet.codegen.state.JetTypeMapper;
023import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
024
025import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLOSURE;
026
027public class ClassContext extends FieldOwnerContext<ClassDescriptor> {
028
029    public ClassContext(
030            @NotNull JetTypeMapper typeMapper,
031            @NotNull ClassDescriptor contextDescriptor,
032            @NotNull OwnerKind contextKind,
033            @Nullable CodegenContext parentContext,
034            @Nullable LocalLookup localLookup
035    ) {
036        //noinspection SuspiciousMethodCalls
037        super(contextDescriptor, contextKind, parentContext, typeMapper.getBindingContext().get(CLOSURE, contextDescriptor),
038              contextDescriptor, localLookup);
039        initOuterExpression(typeMapper, contextDescriptor);
040    }
041
042
043    @Nullable
044    public CodegenContext getClassObjectContext() {
045        if (getContextDescriptor().getClassObjectDescriptor() != null) {
046            return findChildContext(getContextDescriptor().getClassObjectDescriptor());
047        }
048        return null;
049    }
050
051    @Override
052    public boolean isStatic() {
053        return false;
054    }
055
056    @Override
057    public String toString() {
058        return "Class: " + getContextDescriptor();
059    }
060}