001 /*
002 * Copyright 2010-2015 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.kotlin.psi;
018
019 import com.intellij.lang.ASTNode;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.annotations.Nullable;
022 import org.jetbrains.kotlin.KtNodeTypes;
023 import org.jetbrains.kotlin.parsing.KotlinParsing;
024
025 import java.util.Collections;
026 import java.util.List;
027
028 public class KtConstructorDelegationCall extends KtElementImpl implements KtCallElement {
029 public KtConstructorDelegationCall(@NotNull ASTNode node) {
030 super(node);
031 }
032
033 @Override
034 @Nullable
035 public KtValueArgumentList getValueArgumentList() {
036 return (KtValueArgumentList) findChildByType(KtNodeTypes.VALUE_ARGUMENT_LIST);
037 }
038
039 @Override
040 @NotNull
041 public List<? extends ValueArgument> getValueArguments() {
042 KtValueArgumentList list = getValueArgumentList();
043 return list != null ? list.getArguments() : Collections.<KtValueArgument>emptyList();
044 }
045
046 @NotNull
047 @Override
048 public List<KtLambdaArgument> getLambdaArguments() {
049 return Collections.emptyList();
050 }
051
052 @NotNull
053 @Override
054 public List<KtTypeProjection> getTypeArguments() {
055 return Collections.emptyList();
056 }
057
058 @Override
059 public KtTypeArgumentList getTypeArgumentList() {
060 return null;
061 }
062
063 @Nullable
064 @Override
065 public KtConstructorDelegationReferenceExpression getCalleeExpression() {
066 return findChildByClass(KtConstructorDelegationReferenceExpression.class);
067 }
068
069 /**
070 * @return true if this delegation call is not present in the source code. Note that we always parse delegation calls
071 * for secondary constructors, even if there's no explicit call in the source (see {@link KotlinParsing#parseSecondaryConstructor}).
072 *
073 * class Foo {
074 * constructor(name: String) // <--- implicit constructor delegation call (empty element after RPAR)
075 * }
076 */
077 public boolean isImplicit() {
078 KtConstructorDelegationReferenceExpression callee = getCalleeExpression();
079 return callee != null && callee.getFirstChild() == null;
080 }
081
082 public boolean isCallToThis() {
083 KtConstructorDelegationReferenceExpression callee = getCalleeExpression();
084 return callee != null && callee.isThis();
085 }
086 }