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