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.openapi.util.text.StringUtil;
020    import com.intellij.psi.stubs.IStubElementType;
021    import com.intellij.psi.stubs.StubBase;
022    import com.intellij.psi.stubs.StubElement;
023    import com.intellij.util.ArrayUtil;
024    import com.intellij.util.io.StringRef;
025    import org.jetbrains.annotations.NotNull;
026    import org.jetbrains.annotations.Nullable;
027    import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
028    import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
029    import org.jetbrains.jet.lang.resolve.name.FqName;
030    
031    import java.util.ArrayList;
032    import java.util.List;
033    
034    public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
035        private final StringRef name;
036        private final FqName fqName;
037        private final StringRef[] superNames;
038        private final boolean isTopLevel;
039        private final boolean isClassObject;
040        private final boolean isLocal;
041    
042        public PsiJetObjectStubImpl(
043                @NotNull IStubElementType elementType,
044                StubElement parent,
045                @Nullable String name,
046                @Nullable FqName fqName,
047                @NotNull List<String> superNames,
048                boolean isTopLevel,
049                boolean isClassObject,
050                boolean isLocal
051        ) {
052            this(elementType, parent, StringRef.fromString(name), fqName, Utils.instance$.wrapStrings(superNames), isTopLevel, isClassObject, isLocal);
053        }
054    
055        public PsiJetObjectStubImpl(
056                @NotNull IStubElementType elementType,
057                StubElement parent,
058                @Nullable StringRef name,
059                @Nullable FqName fqName,
060                @NotNull StringRef[] superNames,
061                boolean isTopLevel,
062                boolean isClassObject,
063                boolean isLocal) {
064            super(parent, elementType);
065    
066            this.name = name;
067            this.fqName = fqName;
068            this.superNames = superNames;
069            this.isTopLevel = isTopLevel;
070            this.isClassObject = isClassObject;
071            this.isLocal = isLocal;
072        }
073    
074        @Override
075        public String getName() {
076            return StringRef.toString(name);
077        }
078    
079        @Nullable
080        @Override
081        public FqName getFqName() {
082            return fqName;
083        }
084    
085        @NotNull
086        @Override
087        public List<String> getSuperNames() {
088            List<String> result = new ArrayList<String>();
089            for (StringRef ref : superNames) {
090                result.add(ref.toString());
091            }
092            return result;
093        }
094    
095        @Override
096        public boolean isTopLevel() {
097            return isTopLevel;
098        }
099    
100        @Override
101        public boolean isClassObject() {
102            return isClassObject;
103        }
104    
105        @Override
106        public boolean isLocal() {
107            return isLocal;
108        }
109    
110        @Override
111        public String toString() {
112            StringBuilder builder = new StringBuilder();
113    
114            builder.append("PsiJetObjectStubImpl[");
115    
116            if (isClassObject) {
117                builder.append("class-object ");
118            }
119    
120            if (isTopLevel) {
121                builder.append("top ");
122            }
123    
124            if (isLocal()) {
125                builder.append("local ");
126            }
127    
128            builder.append("name=").append(getName());
129            builder.append(" fqName=").append(fqName != null ? fqName.toString() : "null");
130            builder.append(" superNames=").append("[").append(StringUtil.join(ArrayUtil.toStringArray(getSuperNames()))).append("]");
131            builder.append("]");
132    
133            return builder.toString();
134        }
135    }