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.jet.lang.psi.JetClass;
023    import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
024    import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
025    import org.jetbrains.jet.lang.resolve.name.FqName;
026    
027    import java.util.ArrayList;
028    import java.util.List;
029    
030    public class PsiJetClassStubImpl extends JetStubBaseImpl<JetClass> implements PsiJetClassStub {
031        private final StringRef qualifiedName;
032        private final StringRef name;
033        private final StringRef[] superNames;
034        private final boolean isTrait;
035        private final boolean isEnumEntry;
036        private final boolean isLocal;
037        private final boolean isTopLevel;
038    
039        public PsiJetClassStubImpl(
040                JetClassElementType type,
041                StubElement parent,
042                StringRef qualifiedName,
043                StringRef name,
044                StringRef[] superNames,
045                boolean isTrait,
046                boolean isEnumEntry,
047                boolean isLocal,
048                boolean isTopLevel
049        ) {
050            super(parent, type);
051            this.qualifiedName = qualifiedName;
052            this.name = name;
053            this.superNames = superNames;
054            this.isTrait = isTrait;
055            this.isEnumEntry = isEnumEntry;
056            this.isLocal = isLocal;
057            this.isTopLevel = isTopLevel;
058        }
059    
060        @Override
061        public FqName getFqName() {
062            String stringRef = StringRef.toString(qualifiedName);
063            if (stringRef == null) {
064                return null;
065            }
066            return new FqName(stringRef);
067        }
068    
069        @Override
070        public boolean isTrait() {
071            return isTrait;
072        }
073    
074        @Override
075        public boolean isEnumEntry() {
076            return isEnumEntry;
077        }
078        
079        @Override
080        public boolean isLocal() {
081            return isLocal;
082        }
083    
084        @Override
085        public String getName() {
086            return StringRef.toString(name);
087        }
088    
089        @NotNull
090        @Override
091        public List<String> getSuperNames() {
092            List<String> result = new ArrayList<String>();
093            for (StringRef ref : superNames) {
094                result.add(ref.toString());
095            }
096            return result;
097        }
098    
099        @Override
100        public boolean isTopLevel() {
101            return isTopLevel;
102        }
103    }