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.resolve.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.jet.lang.resolve.java.structure.JavaMethod;
025    import org.jetbrains.jet.lang.resolve.java.structure.JavaType;
026    import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeParameter;
027    import org.jetbrains.jet.lang.resolve.java.structure.JavaValueParameter;
028    import org.jetbrains.jet.lang.resolve.name.Name;
029    
030    import java.util.Collection;
031    
032    import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.typeParameters;
033    import static org.jetbrains.jet.lang.resolve.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        }
039    
040        @NotNull
041        @Override
042        public Name getName() {
043            return Name.identifier(getPsi().getName());
044        }
045    
046        @NotNull
047        @Override
048        public Collection<JavaTypeParameter> getTypeParameters() {
049            return typeParameters(getPsi().getTypeParameters());
050        }
051    
052        @Override
053        @NotNull
054        public Collection<JavaValueParameter> getValueParameters() {
055            return valueParameters(getPsi().getParameterList().getParameters());
056        }
057    
058        @Override
059        public boolean hasAnnotationParameterDefaultValue() {
060            PsiMethod psiMethod = getPsi();
061            return psiMethod instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) psiMethod).getDefaultValue() != null;
062        }
063    
064        @Override
065        @Nullable
066        public JavaType getReturnType() {
067            PsiType psiType = getPsi().getReturnType();
068            return psiType == null ? null : JavaTypeImpl.create(psiType);
069        }
070    
071        @Override
072        public boolean isVararg() {
073            return getPsi().isVarArgs();
074        }
075    
076        @Override
077        public boolean isConstructor() {
078            // TODO: class JavaConstructor extends JavaMethod
079            return getPsi().isConstructor();
080        }
081    }