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.PsiAnnotationOwner;
020    import com.intellij.psi.PsiParameter;
021    import com.intellij.psi.impl.compiled.ClsParameterImpl;
022    import com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl;
023    import org.jetbrains.annotations.NotNull;
024    import org.jetbrains.annotations.Nullable;
025    import org.jetbrains.kotlin.descriptors.Visibilities;
026    import org.jetbrains.kotlin.descriptors.Visibility;
027    import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
028    import org.jetbrains.kotlin.load.java.structure.JavaType;
029    import org.jetbrains.kotlin.load.java.structure.JavaValueParameter;
030    import org.jetbrains.kotlin.name.FqName;
031    import org.jetbrains.kotlin.name.Name;
032    
033    import java.util.Collection;
034    
035    public class JavaValueParameterImpl extends JavaElementImpl<PsiParameter>
036            implements JavaValueParameter, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
037        public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) {
038            super(psiParameter);
039        }
040    
041        @Nullable
042        @Override
043        public PsiAnnotationOwner getAnnotationOwnerPsi() {
044            return getPsi().getModifierList();
045        }
046    
047        @Override
048        public boolean isAbstract() {
049            return false;
050        }
051    
052        @Override
053        public boolean isStatic() {
054            return false;
055        }
056    
057        @Override
058        public boolean isFinal() {
059            return false;
060        }
061    
062        @NotNull
063        @Override
064        public Visibility getVisibility() {
065            return Visibilities.LOCAL;
066        }
067    
068        @NotNull
069        @Override
070        public Collection<JavaAnnotation> getAnnotations() {
071            return JavaElementUtil.getAnnotations(this);
072        }
073    
074        @Nullable
075        @Override
076        public JavaAnnotation findAnnotation(@NotNull FqName fqName) {
077            return JavaElementUtil.findAnnotation(this, fqName);
078        }
079    
080        @Override
081        public boolean isDeprecatedInJavaDoc() {
082            return false;
083        }
084    
085        @Override
086        @Nullable
087        public Name getName() {
088            PsiParameter psi = getPsi();
089            if (isParameterWithAutoGeneratedName(psi)) {
090                return null;
091            }
092    
093            String name = psi.getName();
094            return name == null ? null : Name.identifier(name);
095        }
096    
097        private static boolean isParameterWithAutoGeneratedName(PsiParameter psi) {
098            // see com.intellij.psi.impl.compiled.ClsParameterImpl.calcName()
099            return psi instanceof ClsParameterImpl && ((PsiParameterStubImpl) ((ClsParameterImpl) psi).getStub()).isAutoGeneratedName();
100        }
101    
102        @Override
103        @NotNull
104        public JavaType getType() {
105            return JavaTypeImpl.create(getPsi().getType());
106        }
107    
108        @Override
109        public boolean isVararg() {
110            return getPsi().isVarArgs();
111        }
112    }