001 /*
002 * Copyright 2010-2015 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.kotlin.psi;
018
019 import com.intellij.lang.ASTNode;
020 import com.intellij.psi.PsiElement;
021 import com.intellij.psi.search.LocalSearchScope;
022 import com.intellij.psi.search.SearchScope;
023 import com.intellij.psi.tree.TokenSet;
024 import org.jetbrains.annotations.NotNull;
025 import org.jetbrains.annotations.Nullable;
026 import org.jetbrains.kotlin.JetNodeTypes;
027 import org.jetbrains.kotlin.lexer.JetTokens;
028 import org.jetbrains.kotlin.name.FqName;
029 import org.jetbrains.kotlin.psi.typeRefHelpers.TypeRefHelpersPackage;
030
031 import java.util.Collections;
032 import java.util.List;
033
034 import static org.jetbrains.kotlin.lexer.JetTokens.VAL_KEYWORD;
035 import static org.jetbrains.kotlin.lexer.JetTokens.VAR_KEYWORD;
036
037 public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed implements JetVariableDeclaration {
038 public JetMultiDeclarationEntry(@NotNull ASTNode node) {
039 super(node);
040 }
041
042 @Override
043 public JetTypeReference getTypeReference() {
044 return TypeRefHelpersPackage.getTypeReference(this);
045 }
046
047 @Override
048 @Nullable
049 public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
050 return TypeRefHelpersPackage.setTypeReference(this, getNameIdentifier(), typeRef);
051 }
052
053 @Nullable
054 @Override
055 public PsiElement getColon() {
056 return findChildByType(JetTokens.COLON);
057 }
058
059 @Nullable
060 @Override
061 public JetParameterList getValueParameterList() {
062 return null;
063 }
064
065 @NotNull
066 @Override
067 public List<JetParameter> getValueParameters() {
068 return Collections.emptyList();
069 }
070
071 @Nullable
072 @Override
073 public JetTypeReference getReceiverTypeReference() {
074 return null;
075 }
076
077 @Nullable
078 @Override
079 public JetTypeParameterList getTypeParameterList() {
080 return null;
081 }
082
083 @Nullable
084 @Override
085 public JetTypeConstraintList getTypeConstraintList() {
086 return null;
087 }
088
089 @NotNull
090 @Override
091 public List<JetTypeConstraint> getTypeConstraints() {
092 return Collections.emptyList();
093 }
094
095 @NotNull
096 @Override
097 public List<JetTypeParameter> getTypeParameters() {
098 return Collections.emptyList();
099 }
100
101 @Override
102 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
103 return visitor.visitMultiDeclarationEntry(this, data);
104 }
105
106 @Override
107 public boolean isVar() {
108 return getParentNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
109 }
110
111 @Nullable
112 @Override
113 public JetExpression getInitializer() {
114 return null;
115 }
116
117 @Override
118 public boolean hasInitializer() {
119 return false;
120 }
121
122 @NotNull
123 private ASTNode getParentNode() {
124 ASTNode parent = getNode().getTreeParent();
125 assert parent.getElementType() == JetNodeTypes.MULTI_VARIABLE_DECLARATION;
126 return parent;
127 }
128
129 @Override
130 public PsiElement getValOrVarKeyword() {
131 ASTNode node = getParentNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
132 if (node == null) return null;
133 return node.getPsi();
134 }
135
136 @Nullable
137 @Override
138 public FqName getFqName() {
139 return null;
140 }
141
142 @NotNull
143 @Override
144 public SearchScope getUseScope() {
145 JetElement enclosingBlock = JetPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
146 if (enclosingBlock != null) return new LocalSearchScope(enclosingBlock);
147
148 return super.getUseScope();
149 }
150 }