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