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.PsiElement; 021 import com.intellij.util.IncorrectOperationException; 022 import org.jetbrains.annotations.NonNls; 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.JetStubElementTypes; 027 028 import java.util.Collections; 029 import java.util.List; 030 031 public class JetEnumEntry extends JetClass { 032 public JetEnumEntry(@NotNull ASTNode node) { 033 super(node); 034 } 035 036 public JetEnumEntry(@NotNull KotlinClassStub stub) { 037 super(stub); 038 } 039 040 @Override 041 public String getName() { 042 KotlinClassStub classStub = getStub(); 043 if (classStub != null) { 044 return classStub.getName(); 045 } 046 047 JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); 048 return nameAsDeclaration == null ? "<Anonymous>" : nameAsDeclaration.getName(); 049 } 050 051 @Override 052 public PsiElement getNameIdentifier() { 053 JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); 054 return nameAsDeclaration == null ? null : nameAsDeclaration.getNameIdentifier(); 055 } 056 057 @Override 058 public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { 059 JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); 060 return nameAsDeclaration == null ? null : nameAsDeclaration.setName(name); 061 } 062 063 @NotNull 064 @Override 065 public List<JetDelegationSpecifier> getDelegationSpecifiers() { 066 JetInitializerList initializerList = getInitializerList(); 067 if (initializerList == null) { 068 return Collections.emptyList(); 069 } 070 return initializerList.getInitializers(); 071 } 072 073 @Nullable 074 public JetInitializerList getInitializerList() { 075 return getStubOrPsiChild(JetStubElementTypes.INITIALIZER_LIST); 076 } 077 078 @Override 079 public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { 080 return visitor.visitEnumEntry(this, data); 081 } 082 }