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 017package org.jetbrains.jet.lang.psi.stubs.impl; 018 019import com.intellij.psi.stubs.IStubElementType; 020import com.intellij.psi.stubs.StubBase; 021import com.intellij.psi.stubs.StubElement; 022import com.intellij.util.io.StringRef; 023import org.jetbrains.annotations.Nullable; 024import org.jetbrains.jet.lang.psi.JetParameter; 025import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterStub; 026 027public class PsiJetParameterStubImpl extends StubBase<JetParameter> implements PsiJetParameterStub { 028 private final StringRef name; 029 private final boolean isMutable; 030 private final boolean isVarArg; 031 private final StringRef typeText; 032 private final StringRef defaultValueText; 033 034 public PsiJetParameterStubImpl(IStubElementType elementType, StubElement parent, 035 StringRef name, 036 boolean isMutable, 037 boolean isVarArg, 038 StringRef typeText, StringRef defaultValueText) { 039 super(parent, elementType); 040 this.name = name; 041 this.isMutable = isMutable; 042 this.isVarArg = isVarArg; 043 this.typeText = typeText; 044 this.defaultValueText = defaultValueText; 045 } 046 047 public PsiJetParameterStubImpl(IStubElementType elementType, StubElement parent, 048 String name, 049 boolean isMutable, 050 boolean isVarArg, 051 String typeText, String defaultValueText) { 052 this(elementType, parent, StringRef.fromString(name), isMutable, isVarArg, 053 StringRef.fromString(typeText), StringRef.fromString(defaultValueText)); 054 } 055 056 @Override 057 public String getName() { 058 return StringRef.toString(name); 059 } 060 061 @Override 062 public boolean isMutable() { 063 return isMutable; 064 } 065 066 @Override 067 public boolean isVarArg() { 068 return isVarArg; 069 } 070 071 @Nullable 072 @Override 073 public String getTypeText() { 074 return StringRef.toString(typeText); 075 } 076 077 @Override 078 public String getDefaultValueText() { 079 return StringRef.toString(defaultValueText); 080 } 081 082 @Override 083 public String toString() { 084 StringBuilder builder = new StringBuilder(); 085 builder.append("PsiJetParameterStubImpl["); 086 087 builder.append(isMutable() ? "var " : "val "); 088 089 if (isVarArg()) { 090 builder.append("vararg "); 091 } 092 093 builder.append("name=").append(getName()); 094 builder.append(" typeText=").append(getTypeText()); 095 builder.append(" defaultValue=").append(getDefaultValueText()); 096 097 builder.append("]"); 098 099 return builder.toString(); 100 } 101}