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.lang.resolve.java.provider;
018
019import com.intellij.psi.PsiClass;
020import org.jetbrains.annotations.NotNull;
021import org.jetbrains.annotations.Nullable;
022import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
023import org.jetbrains.jet.lang.resolve.java.PsiClassFinder;
024
025import static org.jetbrains.jet.lang.resolve.java.provider.DeclarationOrigin.JAVA;
026import static org.jetbrains.jet.lang.resolve.java.provider.DeclarationOrigin.KOTLIN;
027
028public class ClassPsiDeclarationProviderImpl extends PsiDeclarationProviderBase implements ClassPsiDeclarationProvider {
029
030    @NotNull
031    protected final DeclarationOrigin declarationOrigin;
032    @NotNull
033    protected final PsiClassFinder psiClassFinder;
034
035    @NotNull
036    private final PsiClass psiClass;
037
038    private final boolean staticMembers;
039
040    protected ClassPsiDeclarationProviderImpl(@NotNull PsiClass psiClass, boolean staticMembers, @NotNull PsiClassFinder psiClassFinder) {
041        this.staticMembers = staticMembers;
042        this.psiClass = psiClass;
043        this.psiClassFinder = psiClassFinder;
044        this.declarationOrigin = determineOrigin(psiClass);
045    }
046
047    @Override
048    @NotNull
049    protected MembersCache buildMembersCache() {
050        return MembersCache.buildMembersByNameCache(new MembersCache(), psiClassFinder, psiClass, null, staticMembers, getDeclarationOrigin() == KOTLIN);
051    }
052
053    @Override
054    @NotNull
055    public PsiClass getPsiClass() {
056        return psiClass;
057    }
058
059    @Override
060    @NotNull
061    public DeclarationOrigin getDeclarationOrigin() {
062        return declarationOrigin;
063    }
064
065    @NotNull
066    private static DeclarationOrigin determineOrigin(@Nullable PsiClass psiClass) {
067        return ((psiClass != null) && DescriptorResolverUtils.isKotlinClass(psiClass)) ? KOTLIN : JAVA;
068    }
069
070    @Override
071    public boolean isStaticMembers() {
072        return staticMembers;
073    }
074}