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;
018
019 import com.intellij.lang.ASTNode;
020 import com.intellij.psi.tree.TokenSet;
021 import org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.jet.JetNodeTypes;
024 import org.jetbrains.jet.lexer.JetTokens;
025
026 import static org.jetbrains.jet.lexer.JetTokens.VAL_KEYWORD;
027 import static org.jetbrains.jet.lexer.JetTokens.VAR_KEYWORD;
028
029 public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed implements JetVariableDeclaration {
030 public JetMultiDeclarationEntry(@NotNull ASTNode node) {
031 super(node);
032 }
033
034 @Override
035 public JetTypeReference getTypeRef() {
036 return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
037 }
038
039 @Override
040 public void accept(@NotNull JetVisitorVoid visitor) {
041 visitor.visitMultiDeclarationEntry(this);
042 }
043
044 @Override
045 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
046 return visitor.visitMultiDeclarationEntry(this, data);
047 }
048
049 @Override
050 public boolean isVar() {
051 return getParentNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
052 }
053
054 @Nullable
055 @Override
056 public JetExpression getInitializer() {
057 return null;
058 }
059
060 @NotNull
061 private ASTNode getParentNode() {
062 ASTNode parent = getNode().getTreeParent();
063 assert parent.getElementType() == JetNodeTypes.MULTI_VARIABLE_DECLARATION;
064 return parent;
065 }
066
067 @Override
068 public ASTNode getValOrVarNode() {
069 return getParentNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
070 }
071 }