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