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.load.java.structure.impl;
018    
019    import com.intellij.psi.PsiAnnotationOwner;
020    import com.intellij.psi.PsiClass;
021    import com.intellij.psi.PsiDocCommentOwner;
022    import com.intellij.psi.PsiMember;
023    import org.jetbrains.annotations.NotNull;
024    import org.jetbrains.annotations.Nullable;
025    import org.jetbrains.kotlin.descriptors.Visibility;
026    import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
027    import org.jetbrains.kotlin.load.java.structure.JavaClass;
028    import org.jetbrains.kotlin.load.java.structure.JavaMember;
029    import org.jetbrains.kotlin.name.FqName;
030    import org.jetbrains.kotlin.name.Name;
031    
032    import java.util.Collection;
033    
034    public abstract class JavaMemberImpl<Psi extends PsiMember> extends JavaElementImpl<Psi>
035            implements JavaMember, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
036        protected JavaMemberImpl(@NotNull Psi psiMember) {
037            super(psiMember);
038        }
039    
040        @Nullable
041        @Override
042        public PsiAnnotationOwner getAnnotationOwnerPsi() {
043            return getPsi().getModifierList();
044        }
045    
046        @NotNull
047        @Override
048        public Name getName() {
049            String name = getPsi().getName();
050            assert name != null && Name.isValidIdentifier(name) : "Member must have a name: " + getPsi().getText();
051            return Name.identifier(name);
052        }
053    
054        @NotNull
055        @Override
056        public JavaClass getContainingClass() {
057            PsiClass psiClass = getPsi().getContainingClass();
058            assert psiClass != null : "Member must have a containing class: " + getPsi();
059            return new JavaClassImpl(psiClass);
060        }
061    
062        @Override
063        public boolean isAbstract() {
064            return JavaElementUtil.isAbstract(this);
065        }
066    
067        @Override
068        public boolean isStatic() {
069            return JavaElementUtil.isStatic(this);
070        }
071    
072        @Override
073        public boolean isFinal() {
074            return JavaElementUtil.isFinal(this);
075        }
076    
077        @NotNull
078        @Override
079        public Visibility getVisibility() {
080            return JavaElementUtil.getVisibility(this);
081        }
082    
083        @NotNull
084        @Override
085        public Collection<JavaAnnotation> getAnnotations() {
086            return JavaElementUtil.getAnnotations(this);
087        }
088    
089        @Nullable
090        @Override
091        public JavaAnnotation findAnnotation(@NotNull FqName fqName) {
092            return JavaElementUtil.findAnnotation(this, fqName);
093        }
094    
095        @Override
096        public boolean isDeprecatedInJavaDoc() {
097            PsiMember psi = getPsi();
098            return psi instanceof PsiDocCommentOwner && ((PsiDocCommentOwner) psi).isDeprecated();
099        }
100    }