org.jetbrains.kotlin.psi.JetAnnotationEntry Maven / Gradle / Ivy
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.JetNodeTypes;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.stubs.KotlinAnnotationEntryStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
import java.util.Collections;
import java.util.List;
public class JetAnnotationEntry extends JetElementImplStub implements JetCallElement {
public JetAnnotationEntry(@NotNull ASTNode node) {
super(node);
}
public JetAnnotationEntry(@NotNull KotlinAnnotationEntryStub stub) {
super(stub, JetStubElementTypes.ANNOTATION_ENTRY);
}
@Override
public R accept(@NotNull JetVisitor visitor, D data) {
return visitor.visitAnnotationEntry(this, data);
}
@Nullable @IfNotParsed
public JetTypeReference getTypeReference() {
JetConstructorCalleeExpression calleeExpression = getCalleeExpression();
if (calleeExpression == null) {
return null;
}
return calleeExpression.getTypeReference();
}
@Override
public JetConstructorCalleeExpression getCalleeExpression() {
return getStubOrPsiChild(JetStubElementTypes.CONSTRUCTOR_CALLEE);
}
@Override
public JetValueArgumentList getValueArgumentList() {
KotlinAnnotationEntryStub stub = getStub();
if (stub != null && !stub.hasValueArguments()) {
return null;
}
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
}
@NotNull
@Override
public List getValueArguments() {
JetValueArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.emptyList();
}
@NotNull
@Override
public List getFunctionLiteralArguments() {
return Collections.emptyList();
}
@NotNull
@Override
public List getTypeArguments() {
JetTypeArgumentList typeArgumentList = getTypeArgumentList();
if (typeArgumentList == null) {
return Collections.emptyList();
}
return typeArgumentList.getArguments();
}
@Override
public JetTypeArgumentList getTypeArgumentList() {
JetTypeReference typeReference = getTypeReference();
if (typeReference == null) {
return null;
}
JetTypeElement typeElement = typeReference.getTypeElement();
if (typeElement instanceof JetUserType) {
JetUserType userType = (JetUserType) typeElement;
return userType.getTypeArgumentList();
}
return null;
}
@Nullable
public PsiElement getAtSymbol() {
return findChildByType(JetTokens.AT);
}
@Nullable
public JetAnnotationUseSiteTarget getUseSiteTarget() {
JetAnnotationUseSiteTarget target = getStubOrPsiChild(JetStubElementTypes.ANNOTATION_TARGET);
if (target == null) {
PsiElement parent = getStubOrPsiParent();
if (parent instanceof JetAnnotation) {
return ((JetAnnotation) parent).getUseSiteTarget();
}
}
return target;
}
}