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.PsiElement;
021 import org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.jet.lexer.JetToken;
024 import org.jetbrains.jet.lexer.JetTokens;
025
026 public abstract class JetQualifiedExpression extends JetExpressionImpl {
027 public JetQualifiedExpression(@NotNull ASTNode node) {
028 super(node);
029 }
030
031 @NotNull
032 public JetExpression getReceiverExpression() {
033 JetExpression left = findChildByClass(JetExpression.class);
034 assert left != null;
035 return left;
036 }
037
038 @Nullable @IfNotParsed
039 public JetExpression getSelectorExpression() {
040 ASTNode node = getOperationTokenNode();
041 while (node != null) {
042 PsiElement psi = node.getPsi();
043 if (psi instanceof JetExpression) {
044 return (JetExpression) psi;
045 }
046 node = node.getTreeNext();
047 }
048
049 return null;
050 }
051 @NotNull
052 public ASTNode getOperationTokenNode() {
053 ASTNode operationNode = getNode().findChildByType(JetTokens.OPERATIONS);
054 assert operationNode != null;
055 return operationNode;
056 }
057
058 @NotNull
059 public JetToken getOperationSign() {
060 return (JetToken) getOperationTokenNode().getElementType();
061 }
062 }