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.StubBase;
020    import com.intellij.psi.stubs.StubElement;
021    import com.intellij.util.io.StringRef;
022    import org.jetbrains.annotations.Nullable;
023    import org.jetbrains.jet.lang.psi.JetTypeParameter;
024    import org.jetbrains.jet.lang.psi.stubs.PsiJetTypeParameterStub;
025    import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
026    import org.jetbrains.jet.lang.resolve.name.FqName;
027    
028    public class PsiJetTypeParameterStubImpl extends StubBase<JetTypeParameter> implements PsiJetTypeParameterStub {
029        private final StringRef name;
030        private final StringRef extendBoundTypeText;
031        private final boolean isInVariance;
032        private final boolean isOutVariance;
033    
034        public PsiJetTypeParameterStubImpl(
035                StubElement parent, StringRef name, StringRef extendBoundTypeText, boolean isInVariance, boolean isOutVariance
036        ) {
037            super(parent, JetStubElementTypes.TYPE_PARAMETER);
038    
039            this.name = name;
040            this.extendBoundTypeText = extendBoundTypeText;
041            this.isInVariance = isInVariance;
042            this.isOutVariance = isOutVariance;
043        }
044    
045        public PsiJetTypeParameterStubImpl(
046                StubElement parent, String name, String extendBoundTypeText, boolean isInVariance, boolean isOutVariance
047        ) {
048            this(parent, StringRef.fromString(name), StringRef.fromString(extendBoundTypeText), isInVariance, isOutVariance);
049        }
050    
051        @Override
052        public String getExtendBoundTypeText() {
053            return StringRef.toString(extendBoundTypeText);
054        }
055    
056        @Override
057        public boolean isInVariance() {
058            return isInVariance;
059        }
060    
061        @Override
062        public boolean isOutVariance() {
063            return isOutVariance;
064        }
065    
066        @Override
067        public String getName() {
068            return StringRef.toString(name);
069        }
070    
071        @Override
072        public String toString() {
073            StringBuilder builder = new StringBuilder();
074            builder.append("PsiJetTypeParameterStubImpl[");
075    
076            if (isInVariance()) {
077                builder.append("in ");
078            }
079    
080            if (isOutVariance()) {
081                builder.append("out ");
082            }
083    
084            builder.append("name=").append(getName());
085            builder.append(" extendText=").append(getExtendBoundTypeText());
086    
087            builder.append("]");
088    
089            return builder.toString();
090        }
091    
092        @Nullable
093        @Override
094        public FqName getFqName() {
095            // type parameters doesn't have FqNames
096            return null;
097        }
098    }