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.PsiAnnotationMethod;
020 import com.intellij.psi.PsiMethod;
021 import com.intellij.psi.PsiType;
022 import org.jetbrains.annotations.NotNull;
023 import org.jetbrains.kotlin.load.java.structure.JavaMethod;
024 import org.jetbrains.kotlin.load.java.structure.JavaType;
025 import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter;
026 import org.jetbrains.kotlin.load.java.structure.JavaValueParameter;
027 import org.jetbrains.kotlin.name.Name;
028
029 import java.util.List;
030
031 import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.typeParameters;
032 import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.valueParameters;
033
034 public class JavaMethodImpl extends JavaMemberImpl<PsiMethod> implements JavaMethod {
035 public JavaMethodImpl(@NotNull PsiMethod psiMethod) {
036 super(psiMethod);
037 assert !psiMethod.isConstructor() :
038 "PsiMethod which is a constructor should be wrapped in JavaConstructorImpl: " + psiMethod.getName();
039 }
040
041 @NotNull
042 @Override
043 public Name getName() {
044 return Name.identifier(getPsi().getName());
045 }
046
047 @NotNull
048 @Override
049 public List<JavaTypeParameter> getTypeParameters() {
050 return typeParameters(getPsi().getTypeParameters());
051 }
052
053 @Override
054 @NotNull
055 public List<JavaValueParameter> getValueParameters() {
056 return valueParameters(getPsi().getParameterList().getParameters());
057 }
058
059 @Override
060 public boolean getHasAnnotationParameterDefaultValue() {
061 PsiMethod psiMethod = getPsi();
062 return psiMethod instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) psiMethod).getDefaultValue() != null;
063 }
064
065 @Override
066 @NotNull
067 public JavaType getReturnType() {
068 PsiType psiType = getPsi().getReturnType();
069 assert psiType != null : "Method is not a constructor and has no return type: " + getName();
070 return JavaTypeImpl.create(psiType);
071 }
072 }