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.google.common.collect.Lists;
020 import com.intellij.lang.ASTNode;
021 import com.intellij.openapi.util.TextRange;
022 import com.intellij.psi.PsiElement;
023 import com.intellij.psi.PsiReference;
024 import com.intellij.psi.PsiReferenceService;
025 import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
026 import com.intellij.psi.util.PsiTreeUtil;
027 import org.jetbrains.annotations.NotNull;
028 import org.jetbrains.annotations.Nullable;
029 import org.jetbrains.jet.JetNodeTypes;
030 import org.jetbrains.jet.lexer.JetTokens;
031
032 import java.util.Collections;
033 import java.util.List;
034
035 public class JetArrayAccessExpression extends JetReferenceExpression {
036 public JetArrayAccessExpression(@NotNull ASTNode node) {
037 super(node);
038 }
039
040 @Override
041 public void accept(@NotNull JetVisitorVoid visitor) {
042 visitor.visitArrayAccessExpression(this);
043 }
044
045 @Override
046 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
047 return visitor.visitArrayAccessExpression(this, data);
048 }
049
050 @Nullable @IfNotParsed
051 public JetExpression getArrayExpression() {
052 return findChildByClass(JetExpression.class);
053 }
054
055 @NotNull
056 public List<JetExpression> getIndexExpressions() {
057 return PsiTreeUtil.getChildrenOfTypeAsList(getIndicesNode(), JetExpression.class);
058 }
059
060 @NotNull
061 public JetContainerNode getIndicesNode() {
062 JetContainerNode indicesNode = (JetContainerNode) findChildByType(JetNodeTypes.INDICES);
063 assert indicesNode != null : "Can't be null because of parser";
064 return indicesNode;
065 }
066
067 @NotNull
068 public List<TextRange> getBracketRanges() {
069 PsiElement lBracket = getIndicesNode().findChildByType(JetTokens.LBRACKET);
070 PsiElement rBracket = getIndicesNode().findChildByType(JetTokens.RBRACKET);
071 if (lBracket == null || rBracket == null) {
072 return Collections.emptyList();
073 }
074 return Lists.newArrayList(lBracket.getTextRange(), rBracket.getTextRange());
075 }
076 }