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