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.JetParameter;
024    import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterStub;
025    import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
026    import org.jetbrains.jet.lang.resolve.name.FqName;
027    
028    public class PsiJetParameterStubImpl extends StubBase<JetParameter> implements PsiJetParameterStub {
029        private final StringRef name;
030        private final boolean isMutable;
031        private final boolean isVarArg;
032        private final StringRef typeText;
033        private final StringRef defaultValueText;
034        private final FqName fqName;
035    
036        public PsiJetParameterStubImpl(
037                StubElement parent,
038                FqName fqName, StringRef name,
039                boolean isMutable,
040                boolean isVarArg,
041                StringRef typeText, StringRef defaultValueText
042        ) {
043            super(parent, JetStubElementTypes.VALUE_PARAMETER);
044            this.name = name;
045            this.isMutable = isMutable;
046            this.isVarArg = isVarArg;
047            this.typeText = typeText;
048            this.defaultValueText = defaultValueText;
049            this.fqName = fqName;
050        }
051    
052        public PsiJetParameterStubImpl(
053                StubElement parent,
054                FqName fqName, String name,
055                boolean isMutable,
056                boolean isVarArg,
057                String typeText,
058                String defaultValueText
059        ) {
060            this(parent, fqName, StringRef.fromString(name), isMutable, isVarArg,
061                 StringRef.fromString(typeText), StringRef.fromString(defaultValueText));
062        }
063    
064        @Override
065        public String getName() {
066            return StringRef.toString(name);
067        }
068    
069        @Override
070        public boolean isMutable() {
071            return isMutable;
072        }
073    
074        @Override
075        public boolean isVarArg() {
076            return isVarArg;
077        }
078    
079        @Nullable
080        @Override
081        public String getTypeText() {
082            return StringRef.toString(typeText);
083        }
084    
085        @Override
086        public String getDefaultValueText() {
087            return StringRef.toString(defaultValueText);
088        }
089    
090        @Override
091        public String toString() {
092            StringBuilder builder = new StringBuilder();
093            builder.append("PsiJetParameterStubImpl[");
094    
095            builder.append(isMutable() ? "var " : "val ");
096    
097            if (isVarArg()) {
098                builder.append("vararg ");
099            }
100    
101            builder.append("name=").append(getName());
102            if (fqName != null) {
103                builder.append(" fqName=").append(fqName.toString()).append(" ");
104            }
105            builder.append(" typeText=").append(getTypeText());
106            builder.append(" defaultValue=").append(getDefaultValueText());
107    
108            builder.append("]");
109    
110            return builder.toString();
111        }
112    
113        @Nullable
114        @Override
115        public FqName getFqName() {
116            return fqName;
117        }
118    }