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.openapi.util.text.StringUtil;
020 import com.intellij.psi.stubs.StubBase;
021 import com.intellij.psi.stubs.StubElement;
022 import com.intellij.util.ArrayUtil;
023 import com.intellij.util.io.StringRef;
024 import org.jetbrains.annotations.NotNull;
025 import org.jetbrains.annotations.Nullable;
026 import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
027 import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
028 import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
029 import org.jetbrains.jet.lang.resolve.name.FqName;
030
031 import java.util.ArrayList;
032 import java.util.List;
033
034 public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
035 private final StringRef name;
036 private final FqName fqName;
037 private final StringRef[] superNames;
038 private final boolean isTopLevel;
039 private final boolean isClassObject;
040 private final boolean isLocal;
041
042 public PsiJetObjectStubImpl(
043 @NotNull StubElement parent,
044 @Nullable String name,
045 @Nullable FqName fqName,
046 @NotNull List<String> superNames,
047 boolean isTopLevel,
048 boolean isClassObject,
049 boolean isLocal
050 ) {
051 this(parent, StringRef.fromString(name), fqName, Utils.instance$.wrapStrings(superNames), isTopLevel, isClassObject, isLocal);
052 }
053
054 public PsiJetObjectStubImpl(
055 @NotNull StubElement parent,
056 @Nullable StringRef name,
057 @Nullable FqName fqName,
058 @NotNull StringRef[] superNames,
059 boolean isTopLevel,
060 boolean isClassObject,
061 boolean isLocal
062 ) {
063 super(parent, JetStubElementTypes.OBJECT_DECLARATION);
064 this.name = name;
065 this.fqName = fqName;
066 this.superNames = superNames;
067 this.isTopLevel = isTopLevel;
068 this.isClassObject = isClassObject;
069 this.isLocal = isLocal;
070 }
071
072 @Override
073 public String getName() {
074 return StringRef.toString(name);
075 }
076
077 @Nullable
078 @Override
079 public FqName getFqName() {
080 return fqName;
081 }
082
083 @NotNull
084 @Override
085 public List<String> getSuperNames() {
086 List<String> result = new ArrayList<String>();
087 for (StringRef ref : superNames) {
088 result.add(ref.toString());
089 }
090 return result;
091 }
092
093 @Override
094 public boolean isTopLevel() {
095 return isTopLevel;
096 }
097
098 @Override
099 public boolean isClassObject() {
100 return isClassObject;
101 }
102
103 @Override
104 public boolean isLocal() {
105 return isLocal;
106 }
107
108 @Override
109 public String toString() {
110 StringBuilder builder = new StringBuilder();
111
112 builder.append("PsiJetObjectStubImpl[");
113
114 if (isClassObject) {
115 builder.append("class-object ");
116 }
117
118 if (isTopLevel) {
119 builder.append("top ");
120 }
121
122 if (isLocal()) {
123 builder.append("local ");
124 }
125
126 builder.append("name=").append(getName());
127 builder.append(" fqName=").append(fqName != null ? fqName.toString() : "null");
128 builder.append(" superNames=").append("[").append(StringUtil.join(ArrayUtil.toStringArray(getSuperNames()))).append("]");
129 builder.append("]");
130
131 return builder.toString();
132 }
133 }