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 com.intellij.psi.PsiClass;
021 import com.intellij.psi.PsiElement;
022 import com.intellij.psi.PsiEnumConstant;
023 import org.jetbrains.annotations.NotNull;
024 import org.jetbrains.annotations.Nullable;
025 import org.jetbrains.kotlin.psi.stubs.KotlinClassStub;
026 import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
027
028 import java.util.Collections;
029 import java.util.List;
030
031 public class KtEnumEntry extends KtClass {
032 public KtEnumEntry(@NotNull ASTNode node) {
033 super(node);
034 }
035
036 public KtEnumEntry(@NotNull KotlinClassStub stub) {
037 super(stub);
038 }
039
040 @NotNull
041 @Override
042 public List<KtSuperTypeListEntry> getSuperTypeListEntries() {
043 KtInitializerList initializerList = getInitializerList();
044 if (initializerList == null) {
045 return Collections.emptyList();
046 }
047 return initializerList.getInitializers();
048 }
049
050 public boolean hasInitializer() {
051 return !getSuperTypeListEntries().isEmpty();
052 }
053
054 @Nullable
055 public KtInitializerList getInitializerList() {
056 return getStubOrPsiChild(KtStubElementTypes.INITIALIZER_LIST);
057 }
058
059 @Override
060 public <R, D> R accept(@NotNull KtVisitor<R, D> visitor, D data) {
061 return visitor.visitEnumEntry(this, data);
062 }
063
064 @Override
065 public boolean isEquivalentTo(@Nullable PsiElement another) {
066 if (another instanceof PsiEnumConstant) {
067 PsiEnumConstant enumConstant = (PsiEnumConstant) another;
068 PsiClass containingClass = enumConstant.getContainingClass();
069 if (containingClass != null) {
070 String containingClassQName = containingClass.getQualifiedName();
071 if (containingClassQName != null && enumConstant.getName() != null) {
072 String theirFQName = containingClassQName + "." + enumConstant.getName();
073 if (theirFQName.equals(getQualifiedName())) {
074 return true;
075 }
076 }
077 }
078 }
079 return super.isEquivalentTo(another);
080 }
081 }