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.ArrayUtil; 023import com.intellij.util.io.StringRef; 024import org.jetbrains.annotations.NotNull; 025import org.jetbrains.annotations.Nullable; 026import org.jetbrains.jet.lang.psi.JetNamedFunction; 027import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub; 028import org.jetbrains.jet.lang.resolve.name.FqName; 029 030public class PsiJetFunctionStubImpl extends StubBase<JetNamedFunction> implements PsiJetFunctionStub { 031 032 private final StringRef nameRef; 033 private final boolean isTopLevel; 034 private final boolean isExtension; 035 private final FqName topFQName; 036 037 public PsiJetFunctionStubImpl( 038 @NotNull IStubElementType elementType, 039 @NotNull StubElement parent, 040 @Nullable String name, 041 boolean isTopLevel, 042 @Nullable FqName topFQName, 043 boolean isExtension) { 044 this(elementType, parent, StringRef.fromString(name), isTopLevel, topFQName, isExtension); 045 } 046 047 public PsiJetFunctionStubImpl( 048 @NotNull IStubElementType elementType, 049 @NotNull StubElement parent, 050 @Nullable StringRef nameRef, 051 boolean isTopLevel, 052 @Nullable FqName topFQName, 053 boolean isExtension) { 054 super(parent, elementType); 055 056 if (isTopLevel && topFQName == null) { 057 throw new IllegalArgumentException("topFQName shouldn't be null for top level functions"); 058 } 059 060 this.nameRef = nameRef; 061 this.topFQName = topFQName; 062 this.isTopLevel = isTopLevel; 063 this.isExtension = isExtension; 064 } 065 066 @Override 067 public String getName() { 068 return StringRef.toString(nameRef); 069 } 070 071 @Nullable 072 @Override 073 public FqName getTopFQName() { 074 return topFQName; 075 } 076 077 @Override 078 public boolean isTopLevel() { 079 return isTopLevel; 080 } 081 082 @Override 083 public boolean isExtension() { 084 return isExtension; 085 } 086 087 @NotNull 088 @Override 089 public String[] getAnnotations() { 090 // TODO (stubs) 091 return ArrayUtil.EMPTY_STRING_ARRAY; 092 } 093 094 @Override 095 public String toString() { 096 StringBuilder builder = new StringBuilder(); 097 builder.append("PsiJetFunctionStubImpl["); 098 099 if (isTopLevel()) { 100 assert topFQName != null; 101 builder.append("top ").append("topFQName=").append(topFQName.toString()).append(" "); 102 } 103 104 if (isExtension()) { 105 builder.append("ext "); 106 } 107 108 builder.append("name=").append(getName()); 109 110 builder.append("]"); 111 112 return builder.toString(); 113 } 114}