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