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 <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
041            return visitor.visitMultiDeclarationEntry(this, data);
042        }
043    
044        @Override
045        public boolean isVar() {
046            return getParentNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
047        }
048    
049        @Nullable
050        @Override
051        public JetExpression getInitializer() {
052            return null;
053        }
054    
055        @NotNull
056        private ASTNode getParentNode() {
057            ASTNode parent = getNode().getTreeParent();
058            assert parent.getElementType() == JetNodeTypes.MULTI_VARIABLE_DECLARATION;
059            return parent;
060        }
061    
062        @Override
063        public ASTNode getValOrVarNode() {
064            return getParentNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
065        }
066    }