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.wrapper;
018    
019    import com.intellij.psi.PsiMethod;
020    import com.intellij.psi.PsiModifier;
021    import com.intellij.psi.PsiParameter;
022    import com.intellij.psi.PsiType;
023    import org.jetbrains.annotations.NotNull;
024    import org.jetbrains.annotations.Nullable;
025    import org.jetbrains.jet.lang.resolve.java.kt.JetConstructorAnnotation;
026    import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation;
027    
028    import java.util.ArrayList;
029    import java.util.List;
030    
031    public class PsiMethodWrapper extends PsiMemberWrapper {
032    
033        public PsiMethodWrapper(@NotNull PsiMethod psiMethod) {
034            super(psiMethod);
035        }
036        
037        private List<PsiParameterWrapper> parameters;
038        @NotNull
039        public List<PsiParameterWrapper> getParameters() {
040            if (parameters == null) {
041                PsiParameter[] psiParameters = getPsiMethod().getParameterList().getParameters();
042                parameters = new ArrayList<PsiParameterWrapper>(psiParameters.length);
043                for (PsiParameter psiParameter : psiParameters) {
044                    parameters.add(new PsiParameterWrapper(psiParameter));
045                }
046            }
047            return parameters;
048        }
049    
050        @NotNull
051        public PsiParameterWrapper getParameter(int i) {
052            return getParameters().get(i);
053        }
054    
055        private JetMethodAnnotation jetMethodAnnotation;
056        @NotNull
057        public JetMethodAnnotation getJetMethodAnnotation() {
058            if (jetMethodAnnotation == null) {
059                jetMethodAnnotation = JetMethodAnnotation.get(getPsiMethod());
060            }
061            return jetMethodAnnotation;
062        }
063    
064        private JetConstructorAnnotation jetConstructorAnnotation;
065        @NotNull
066        public JetConstructorAnnotation getJetConstructorAnnotation() {
067            if (jetConstructorAnnotation == null) {
068                jetConstructorAnnotation = JetConstructorAnnotation.get(getPsiMethod());
069            }
070            return jetConstructorAnnotation;
071        }
072    
073        @Override
074        public boolean isAbstract() {
075            return psiMember.hasModifierProperty(PsiModifier.ABSTRACT);
076        }
077    
078        @NotNull
079        public PsiMethod getPsiMethod() {
080            return (PsiMethod) psiMember;
081        }
082    
083        @Nullable
084        public PsiType getReturnType() {
085            return getPsiMethod().getReturnType();
086        }
087    }