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