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    
017    package org.jetbrains.jet.lang.psi.stubs.impl;
018    
019    import com.intellij.psi.stubs.StubElement;
020    import com.intellij.util.io.StringRef;
021    import org.jetbrains.annotations.NotNull;
022    import org.jetbrains.annotations.Nullable;
023    import org.jetbrains.jet.lang.psi.JetNamedFunction;
024    import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
025    import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
026    import org.jetbrains.jet.lang.resolve.name.FqName;
027    
028    public class PsiJetFunctionStubImpl extends JetStubBaseImpl<JetNamedFunction> implements PsiJetFunctionStub {
029    
030        private final StringRef nameRef;
031        private final boolean isTopLevel;
032        private final boolean isExtension;
033        private final FqName fqName;
034        private final boolean hasBlockBody;
035        private final boolean hasBody;
036        private final boolean hasTypeParameterListBeforeFunctionName;
037    
038        public PsiJetFunctionStubImpl(
039                @NotNull StubElement parent,
040                @Nullable StringRef nameRef,
041                boolean isTopLevel,
042                @Nullable FqName fqName,
043                boolean isExtension,
044                boolean hasBlockBody,
045                boolean hasBody,
046                boolean hasTypeParameterListBeforeFunctionName
047        ) {
048            super(parent, JetStubElementTypes.FUNCTION);
049    
050            if (isTopLevel && fqName == null) {
051                throw new IllegalArgumentException("fqName shouldn't be null for top level functions");
052            }
053    
054            this.nameRef = nameRef;
055            this.fqName = fqName;
056            this.isTopLevel = isTopLevel;
057            this.isExtension = isExtension;
058            this.hasBlockBody = hasBlockBody;
059            this.hasBody = hasBody;
060            this.hasTypeParameterListBeforeFunctionName = hasTypeParameterListBeforeFunctionName;
061        }
062    
063        @Override
064        public String getName() {
065            return StringRef.toString(nameRef);
066        }
067    
068        @Override
069        public boolean isTopLevel() {
070            return isTopLevel;
071        }
072    
073        @Override
074        public boolean isExtension() {
075            return isExtension;
076        }
077    
078        @Override
079        public boolean hasBlockBody() {
080            return hasBlockBody;
081        }
082    
083        @Override
084        public boolean hasBody() {
085            return hasBody;
086        }
087    
088        @Override
089        public boolean hasTypeParameterListBeforeFunctionName() {
090            return hasTypeParameterListBeforeFunctionName;
091        }
092    
093        @Nullable
094        @Override
095        public FqName getFqName() {
096            return fqName;
097        }
098    }