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.descriptors;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.kotlin.descriptors.*;
022    import org.jetbrains.kotlin.descriptors.annotations.Annotations;
023    import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
024    import org.jetbrains.kotlin.name.Name;
025    import org.jetbrains.kotlin.types.JetType;
026    
027    import java.util.List;
028    
029    public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements JavaCallableMemberDescriptor {
030        public JavaPropertyDescriptor(
031                @NotNull DeclarationDescriptor containingDeclaration,
032                @NotNull Annotations annotations,
033                @NotNull Visibility visibility,
034                boolean isVar,
035                @NotNull Name name,
036                @NotNull SourceElement source,
037                @Nullable PropertyDescriptor original
038        ) {
039            super(containingDeclaration, original, annotations, Modality.FINAL, visibility, isVar, name, Kind.DECLARATION, source, false);
040        }
041    
042        @Override
043        public boolean hasSynthesizedParameterNames() {
044            return false;
045        }
046    
047        @NotNull
048        @Override
049        public JavaCallableMemberDescriptor enhance(
050                @Nullable JetType enhancedReceiverType,
051                @NotNull List<JetType> enhancedValueParametersTypes,
052                @NotNull JetType enhancedReturnType
053        ) {
054            JavaPropertyDescriptor enhanced = new JavaPropertyDescriptor(
055                    getContainingDeclaration(),
056                    getAnnotations(),
057                    getVisibility(),
058                    isVar(),
059                    getName(),
060                    getSource(),
061                    getOriginal()
062            );
063            assert getGetter() == null : "Field must not have a getter: " + this;
064            assert getSetter() == null : "Field must not have a setter: " + this;
065            enhanced.initialize(null, null);
066            enhanced.setSetterProjectedOut(isSetterProjectedOut());
067            if (compileTimeInitializer != null) {
068                enhanced.setCompileTimeInitializer(compileTimeInitializer);
069            }
070            enhanced.setType(
071                    enhancedReturnType,
072                    getTypeParameters(), // TODO
073                    getDispatchReceiverParameter(),
074                    enhancedReceiverType
075            );
076            return enhanced;
077        }
078    }