001    /*
002     * Copyright 2010-2014 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;
018    
019    import com.google.common.collect.Multimap;
020    import com.google.common.collect.Sets;
021    import com.intellij.lang.ASTNode;
022    import org.jetbrains.annotations.NotNull;
023    import org.jetbrains.annotations.Nullable;
024    import org.jetbrains.jet.lang.descriptors.*;
025    import org.jetbrains.jet.lang.diagnostics.Errors;
026    import org.jetbrains.jet.lang.psi.*;
027    import org.jetbrains.jet.lang.types.*;
028    import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
029    import org.jetbrains.jet.lexer.JetModifierKeywordToken;
030    import org.jetbrains.jet.lexer.JetTokens;
031    
032    import javax.inject.Inject;
033    import java.util.*;
034    
035    import static org.jetbrains.jet.lang.diagnostics.Errors.*;
036    import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE;
037    import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE_PARAMETER;
038    
039    public class DeclarationsChecker {
040        @NotNull
041        private BindingTrace trace;
042        @NotNull
043        private ModifiersChecker modifiersChecker;
044        @NotNull
045        private DescriptorResolver descriptorResolver;
046    
047        @Inject
048        public void setTrace(@NotNull BindingTrace trace) {
049            this.trace = trace;
050            this.modifiersChecker = new ModifiersChecker(trace);
051        }
052    
053        @Inject
054        public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
055            this.descriptorResolver = descriptorResolver;
056        }
057    
058        public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
059            for (JetFile file : bodiesResolveContext.getFiles()) {
060                checkModifiersAndAnnotationsInPackageDirective(file);
061            }
062    
063            Map<JetClassOrObject, ClassDescriptorWithResolutionScopes> classes = bodiesResolveContext.getDeclaredClasses();
064            for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry : classes.entrySet()) {
065                JetClassOrObject classOrObject = entry.getKey();
066                ClassDescriptorWithResolutionScopes classDescriptor = entry.getValue();
067                if (!bodiesResolveContext.completeAnalysisNeeded(classOrObject)) continue;
068    
069                checkSupertypesForConsistency(classDescriptor);
070                checkTypesInClassHeader(classOrObject);
071    
072                if (classOrObject instanceof JetClass) {
073                    JetClass jetClass = (JetClass) classOrObject;
074                    checkClass(bodiesResolveContext, jetClass, classDescriptor);
075                    descriptorResolver.checkNamesInConstraints(
076                            jetClass, classDescriptor, classDescriptor.getScopeForClassHeaderResolution(), trace);
077                }
078                else if (classOrObject instanceof JetObjectDeclaration) {
079                    checkObject((JetObjectDeclaration) classOrObject);
080                }
081    
082                modifiersChecker.checkModifiersForDeclaration(classOrObject, classDescriptor);
083            }
084    
085            Map<JetNamedFunction, SimpleFunctionDescriptor> functions = bodiesResolveContext.getFunctions();
086            for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : functions.entrySet()) {
087                JetNamedFunction function = entry.getKey();
088                SimpleFunctionDescriptor functionDescriptor = entry.getValue();
089    
090                if (!bodiesResolveContext.completeAnalysisNeeded(function)) continue;
091                checkFunction(function, functionDescriptor);
092                modifiersChecker.checkModifiersForDeclaration(function, functionDescriptor);
093            }
094    
095            Map<JetProperty, PropertyDescriptor> properties = bodiesResolveContext.getProperties();
096            for (Map.Entry<JetProperty, PropertyDescriptor> entry : properties.entrySet()) {
097                JetProperty property = entry.getKey();
098                PropertyDescriptor propertyDescriptor = entry.getValue();
099    
100                if (!bodiesResolveContext.completeAnalysisNeeded(property)) continue;
101                checkProperty(property, propertyDescriptor);
102                modifiersChecker.checkModifiersForDeclaration(property, propertyDescriptor);
103            }
104    
105        }
106    
107        private void reportErrorIfHasIllegalModifier(JetModifierListOwner declaration) {
108            if (declaration.hasModifier(JetTokens.ENUM_KEYWORD)) {
109                trace.report(ILLEGAL_ENUM_ANNOTATION.on(declaration));
110            }
111            if (declaration.hasModifier(JetTokens.ANNOTATION_KEYWORD)) {
112                trace.report(ILLEGAL_ANNOTATION_KEYWORD.on(declaration));
113            }
114        }
115    
116        private void checkModifiersAndAnnotationsInPackageDirective(JetFile file) {
117            JetPackageDirective packageDirective = file.getPackageDirective();
118            if (packageDirective == null) return;
119    
120            JetModifierList modifierList = packageDirective.getModifierList();
121            if (modifierList == null) return;
122    
123            for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) {
124                JetConstructorCalleeExpression calleeExpression = annotationEntry.getCalleeExpression();
125                if (calleeExpression != null) {
126                    JetReferenceExpression reference = calleeExpression.getConstructorReferenceExpression();
127                    if (reference != null) {
128                        trace.report(UNRESOLVED_REFERENCE.on(reference, reference));
129                    }
130                }
131            }
132    
133            ModifiersChecker.reportIllegalModifiers(modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace);
134        }
135    
136        private void checkTypesInClassHeader(@NotNull JetClassOrObject classOrObject) {
137            for (JetDelegationSpecifier delegationSpecifier : classOrObject.getDelegationSpecifiers()) {
138                checkBoundsForTypeInClassHeader(delegationSpecifier.getTypeReference());
139            }
140    
141            if (!(classOrObject instanceof JetClass)) return;
142            JetClass jetClass = (JetClass) classOrObject;
143    
144            for (JetTypeParameter jetTypeParameter : jetClass.getTypeParameters()) {
145                checkBoundsForTypeInClassHeader(jetTypeParameter.getExtendsBound());
146                checkFinalUpperBounds(jetTypeParameter.getExtendsBound(), false);
147            }
148    
149            for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
150                checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
151                checkFinalUpperBounds(constraint.getBoundTypeReference(), constraint.isClassObjectConstraint());
152            }
153        }
154    
155        private void checkBoundsForTypeInClassHeader(@Nullable JetTypeReference typeReference) {
156            if (typeReference != null) {
157                JetType type = trace.getBindingContext().get(TYPE, typeReference);
158                if (type != null) {
159                    DescriptorResolver.checkBounds(typeReference, type, trace);
160                }
161            }
162        }
163    
164        private void checkFinalUpperBounds(@Nullable JetTypeReference typeReference, boolean isClassObjectConstraint) {
165            if (typeReference != null) {
166                JetType type = trace.getBindingContext().get(TYPE, typeReference);
167                if (type != null) {
168                    DescriptorResolver.checkUpperBoundType(typeReference, type, isClassObjectConstraint, trace);
169                }
170            }
171        }
172    
173        private void checkSupertypesForConsistency(@NotNull ClassDescriptor classDescriptor) {
174            Multimap<TypeConstructor, TypeProjection> multimap = SubstitutionUtils
175                    .buildDeepSubstitutionMultimap(classDescriptor.getDefaultType());
176            for (Map.Entry<TypeConstructor, Collection<TypeProjection>> entry : multimap.asMap().entrySet()) {
177                Collection<TypeProjection> projections = entry.getValue();
178                if (projections.size() > 1) {
179                    TypeConstructor typeConstructor = entry.getKey();
180                    DeclarationDescriptor declarationDescriptor = typeConstructor.getDeclarationDescriptor();
181                    assert declarationDescriptor instanceof TypeParameterDescriptor : declarationDescriptor;
182                    TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) declarationDescriptor;
183    
184                    // Immediate arguments of supertypes cannot be projected
185                    Set<JetType> conflictingTypes = Sets.newLinkedHashSet();
186                    for (TypeProjection projection : projections) {
187                        conflictingTypes.add(projection.getType());
188                    }
189                    switch (typeParameterDescriptor.getVariance()) {
190                        case INVARIANT:
191                            // Leave conflicting types as is
192                            break;
193                        case IN_VARIANCE:
194                            // Filter out those who have supertypes in this set (common supertype)
195                            Filter.REMOVE_IF_SUPERTYPE_IN_THE_SET.proceed(conflictingTypes);
196                            break;
197                        case OUT_VARIANCE:
198                            // Filter out those who have subtypes in this set (common subtype)
199                            Filter.REMOVE_IF_SUBTYPE_IN_THE_SET.proceed(conflictingTypes);
200                            break;
201                    }
202    
203                    if (conflictingTypes.size() > 1) {
204                        DeclarationDescriptor containingDeclaration = typeParameterDescriptor.getContainingDeclaration();
205                        assert containingDeclaration instanceof ClassDescriptor : containingDeclaration;
206                        JetClassOrObject psiElement = (JetClassOrObject) DescriptorToSourceUtils.classDescriptorToDeclaration(classDescriptor);
207                        JetDelegationSpecifierList delegationSpecifierList = psiElement.getDelegationSpecifierList();
208                        assert delegationSpecifierList != null;
209                        //                        trace.getErrorHandler().genericError(delegationSpecifierList.getNode(), "Type parameter " + typeParameterDescriptor.getName() + " of " + containingDeclaration.getName() + " has inconsistent values: " + conflictingTypes);
210                        trace.report(INCONSISTENT_TYPE_PARAMETER_VALUES
211                                             .on(delegationSpecifierList, typeParameterDescriptor, (ClassDescriptor) containingDeclaration,
212                                                 conflictingTypes));
213                    }
214                }
215            }
216        }
217    
218        private enum Filter {
219            REMOVE_IF_SUBTYPE_IN_THE_SET {
220                @Override
221                public boolean removeNeeded(JetType subject, JetType other) {
222                    return JetTypeChecker.DEFAULT.isSubtypeOf(other, subject);
223                }
224            },
225            REMOVE_IF_SUPERTYPE_IN_THE_SET {
226                @Override
227                public boolean removeNeeded(JetType subject, JetType other) {
228                    return JetTypeChecker.DEFAULT.isSubtypeOf(subject, other);
229                }
230            };
231    
232            private void proceed(Set<JetType> conflictingTypes) {
233                for (Iterator<JetType> iterator = conflictingTypes.iterator(); iterator.hasNext(); ) {
234                    JetType type = iterator.next();
235                    for (JetType otherType : conflictingTypes) {
236                        boolean subtypeOf = removeNeeded(type, otherType);
237                        if (type != otherType && subtypeOf) {
238                            iterator.remove();
239                            break;
240                        }
241                    }
242                }
243            }
244    
245            public abstract boolean removeNeeded(JetType subject, JetType other);
246        }
247    
248        private void checkObject(JetObjectDeclaration declaration) {
249            reportErrorIfHasIllegalModifier(declaration);
250        }
251    
252        private void checkClass(BodiesResolveContext c, JetClass aClass, ClassDescriptorWithResolutionScopes classDescriptor) {
253            checkOpenMembers(classDescriptor);
254            if (c.getTopDownAnalysisParameters().isLazyTopDownAnalysis()) {
255                checkTypeParameters(aClass);
256            }
257            if (aClass.isTrait()) {
258                checkTraitModifiers(aClass);
259                checkConstructorInTrait(aClass);
260            }
261            else if (aClass.isAnnotation()) {
262                checkAnnotationClassWithBody(aClass);
263                checkValOnAnnotationParameter(aClass);
264            }
265            else if (aClass.isEnum()) {
266                checkEnumModifiers(aClass);
267            }
268            else if (aClass instanceof JetEnumEntry) {
269                checkEnumEntry((JetEnumEntry) aClass, classDescriptor);
270            }
271        }
272    
273        private void checkTypeParameters(JetTypeParameterListOwner typeParameterListOwner) {
274            // TODO: Support annotation for type parameters
275            for (JetTypeParameter jetTypeParameter : typeParameterListOwner.getTypeParameters()) {
276                AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(jetTypeParameter, trace);
277    
278                TypeParameterDescriptor typeParameter = trace.get(TYPE_PARAMETER, jetTypeParameter);
279                if (typeParameter != null) {
280                    DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter);
281                }
282            }
283        }
284    
285        private void checkConstructorInTrait(JetClass klass) {
286            JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
287            if (primaryConstructorParameterList != null) {
288                trace.report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList));
289            }
290        }
291    
292        private void checkTraitModifiers(JetClass aClass) {
293            reportErrorIfHasIllegalModifier(aClass);
294            JetModifierList modifierList = aClass.getModifierList();
295            if (modifierList == null) return;
296            if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) {
297                trace.report(Errors.TRAIT_CAN_NOT_BE_FINAL.on(modifierList.getModifierNode(JetTokens.FINAL_KEYWORD).getPsi()));
298            }
299            if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
300                trace.report(Errors.ABSTRACT_MODIFIER_IN_TRAIT.on(aClass));
301            }
302            if (modifierList.hasModifier(JetTokens.OPEN_KEYWORD)) {
303                trace.report(Errors.OPEN_MODIFIER_IN_TRAIT.on(aClass));
304            }
305        }
306    
307        private void checkAnnotationClassWithBody(JetClassOrObject classOrObject) {
308            if (classOrObject.getBody() != null) {
309                trace.report(ANNOTATION_CLASS_WITH_BODY.on(classOrObject.getBody()));
310            }
311        }
312    
313        private void checkValOnAnnotationParameter(JetClass aClass) {
314            for (JetParameter parameter : aClass.getPrimaryConstructorParameters()) {
315                if (!parameter.hasValOrVarNode()) {
316                    trace.report(MISSING_VAL_ON_ANNOTATION_PARAMETER.on(parameter));
317                }
318            }
319        }
320    
321        private void checkOpenMembers(ClassDescriptorWithResolutionScopes classDescriptor) {
322            for (CallableMemberDescriptor memberDescriptor : classDescriptor.getDeclaredCallableMembers()) {
323                if (memberDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) continue;
324                JetNamedDeclaration member = (JetNamedDeclaration) DescriptorToSourceUtils.descriptorToDeclaration(memberDescriptor);
325                if (member != null && classDescriptor.getModality() == Modality.FINAL && member.hasModifier(JetTokens.OPEN_KEYWORD)) {
326                    trace.report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member));
327                }
328            }
329        }
330    
331        private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) {
332            reportErrorIfHasIllegalModifier(property);
333            DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
334            if (containingDeclaration instanceof ClassDescriptor) {
335                checkPropertyAbstractness(property, propertyDescriptor, (ClassDescriptor) containingDeclaration);
336            }
337            else {
338                modifiersChecker.checkIllegalModalityModifiers(property);
339            }
340            checkPropertyInitializer(property, propertyDescriptor);
341            checkAccessors(property, propertyDescriptor);
342            checkDeclaredTypeInPublicMember(property, propertyDescriptor);
343        }
344    
345        private void checkDeclaredTypeInPublicMember(JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) {
346            boolean hasDeferredType;
347            if (member instanceof JetProperty) {
348                hasDeferredType = ((JetProperty) member).getTypeRef() == null && DescriptorResolver.hasBody((JetProperty) member);
349            }
350            else {
351                assert member instanceof JetFunction;
352                JetFunction function = (JetFunction) member;
353                hasDeferredType = function.getReturnTypeRef() == null && function.hasBody() && !function.hasBlockBody();
354            }
355            if ((memberDescriptor.getVisibility().isPublicAPI()) && memberDescriptor.getOverriddenDescriptors().size() == 0 && hasDeferredType) {
356                trace.report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(member));
357            }
358        }
359    
360        private void checkPropertyAbstractness(
361                @NotNull JetProperty property,
362                @NotNull PropertyDescriptor propertyDescriptor,
363                @NotNull ClassDescriptor classDescriptor
364        ) {
365            JetPropertyAccessor getter = property.getGetter();
366            JetPropertyAccessor setter = property.getSetter();
367            JetModifierList modifierList = property.getModifierList();
368            ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null;
369    
370            if (abstractNode != null) { //has abstract modifier
371                if (!(classDescriptor.getModality() == Modality.ABSTRACT) && classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
372                    String name = property.getName();
373                    trace.report(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.on(property, name != null ? name : "", classDescriptor));
374                    return;
375                }
376                if (classDescriptor.getKind() == ClassKind.TRAIT) {
377                    trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(property));
378                }
379            }
380    
381            if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
382                JetType returnType = propertyDescriptor.getReturnType();
383                if (returnType instanceof DeferredType) {
384                    returnType = ((DeferredType) returnType).getDelegate();
385                }
386    
387                JetExpression initializer = property.getInitializer();
388                if (initializer != null) {
389                    trace.report(ABSTRACT_PROPERTY_WITH_INITIALIZER.on(initializer));
390                }
391                JetPropertyDelegate delegate = property.getDelegate();
392                if (delegate != null) {
393                    trace.report(ABSTRACT_DELEGATED_PROPERTY.on(delegate));
394                }
395                if (getter != null && getter.hasBody()) {
396                    trace.report(ABSTRACT_PROPERTY_WITH_GETTER.on(getter));
397                }
398                if (setter != null && setter.hasBody()) {
399                    trace.report(ABSTRACT_PROPERTY_WITH_SETTER.on(setter));
400                }
401            }
402        }
403    
404        private void checkPropertyInitializer(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
405            JetPropertyAccessor getter = property.getGetter();
406            JetPropertyAccessor setter = property.getSetter();
407            boolean hasAccessorImplementation = (getter != null && getter.hasBody()) ||
408                                                (setter != null && setter.hasBody());
409    
410            if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
411                if (!property.hasDelegateExpressionOrInitializer() && property.getTypeRef() == null) {
412                    trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
413                }
414                return;
415            }
416            DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
417            boolean inTrait = containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor)containingDeclaration).getKind() == ClassKind.TRAIT;
418            JetExpression initializer = property.getInitializer();
419            JetPropertyDelegate delegate = property.getDelegate();
420            boolean backingFieldRequired =
421                    Boolean.TRUE.equals(trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor));
422    
423            if (inTrait && backingFieldRequired && hasAccessorImplementation) {
424                trace.report(BACKING_FIELD_IN_TRAIT.on(property));
425            }
426    
427            if (initializer == null && delegate == null) {
428                boolean error = false;
429                if (backingFieldRequired && !inTrait &&
430                    Boolean.FALSE.equals(trace.getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor))) {
431                    if (!(containingDeclaration instanceof ClassDescriptor) || hasAccessorImplementation) {
432                        error = true;
433                        trace.report(MUST_BE_INITIALIZED.on(property));
434                    }
435                    else {
436                        error = true;
437                        trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property));
438                    }
439                }
440                if (!error && property.getTypeRef() == null) {
441                    trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
442                }
443                if (inTrait && property.hasModifier(JetTokens.FINAL_KEYWORD) && backingFieldRequired) {
444                    trace.report(FINAL_PROPERTY_IN_TRAIT.on(property));
445                }
446                return;
447            }
448    
449            if (inTrait) {
450                if (delegate != null) {
451                    trace.report(DELEGATED_PROPERTY_IN_TRAIT.on(delegate));
452                }
453                else {
454                    trace.report(PROPERTY_INITIALIZER_IN_TRAIT.on(initializer));
455                }
456            }
457            else if (delegate == null) {
458                if (!backingFieldRequired) {
459                    trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
460                }
461                else if (property.getReceiverTypeRef() != null) {
462                    trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer));
463                }
464            }
465        }
466    
467        protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
468            reportErrorIfHasIllegalModifier(function);
469            DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
470            boolean hasAbstractModifier = function.hasModifier(JetTokens.ABSTRACT_KEYWORD);
471            checkDeclaredTypeInPublicMember(function, functionDescriptor);
472            if (containingDescriptor instanceof ClassDescriptor) {
473                ClassDescriptor classDescriptor = (ClassDescriptor) containingDescriptor;
474                boolean inTrait = classDescriptor.getKind() == ClassKind.TRAIT;
475                boolean inEnum = classDescriptor.getKind() == ClassKind.ENUM_CLASS;
476                boolean inAbstractClass = classDescriptor.getModality() == Modality.ABSTRACT;
477                if (hasAbstractModifier && !inAbstractClass && !inEnum) {
478                    trace.report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName().asString(), classDescriptor));
479                }
480                if (hasAbstractModifier && inTrait) {
481                    trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(function));
482                }
483                boolean hasBody = function.hasBody();
484                if (hasBody && hasAbstractModifier) {
485                    trace.report(ABSTRACT_FUNCTION_WITH_BODY.on(function, functionDescriptor));
486                }
487                if (!hasBody && function.hasModifier(JetTokens.FINAL_KEYWORD) && inTrait) {
488                    trace.report(FINAL_FUNCTION_WITH_NO_BODY.on(function, functionDescriptor));
489                }
490                if (!hasBody && !hasAbstractModifier && !inTrait) {
491                    trace.report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(function, functionDescriptor));
492                }
493                return;
494            }
495            modifiersChecker.checkIllegalModalityModifiers(function);
496            if (!function.hasBody() && !hasAbstractModifier) {
497                trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
498            }
499        }
500    
501        private void checkAccessors(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
502            for (JetPropertyAccessor accessor : property.getAccessors()) {
503                modifiersChecker.checkIllegalModalityModifiers(accessor);
504            }
505            JetPropertyAccessor getter = property.getGetter();
506            PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
507            JetModifierList getterModifierList = getter != null ? getter.getModifierList() : null;
508            if (getterModifierList != null && getterDescriptor != null) {
509                Map<JetModifierKeywordToken, ASTNode> nodes = ModifiersChecker.getNodesCorrespondingToModifiers(getterModifierList, Sets
510                        .newHashSet(JetTokens.PUBLIC_KEYWORD, JetTokens.PROTECTED_KEYWORD, JetTokens.PRIVATE_KEYWORD,
511                                    JetTokens.INTERNAL_KEYWORD));
512                if (getterDescriptor.getVisibility() != propertyDescriptor.getVisibility()) {
513                    for (ASTNode node : nodes.values()) {
514                        trace.report(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.on(node.getPsi()));
515                    }
516                }
517                else {
518                    for (ASTNode node : nodes.values()) {
519                        trace.report(Errors.REDUNDANT_MODIFIER_IN_GETTER.on(node.getPsi()));
520                    }
521                }
522            }
523        }
524    
525        private void checkEnumModifiers(JetClass aClass) {
526            if (aClass.hasModifier(JetTokens.OPEN_KEYWORD)) {
527                trace.report(OPEN_MODIFIER_IN_ENUM.on(aClass));
528            }
529        }
530    
531        private void checkEnumEntry(@NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) {
532            DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
533            assert DescriptorUtils.isEnumClass(declaration) : "Enum entry should be declared in enum class: " + classDescriptor;
534            ClassDescriptor enumClass = (ClassDescriptor) declaration;
535    
536            List<JetDelegationSpecifier> delegationSpecifiers = enumEntry.getDelegationSpecifiers();
537            ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
538            assert constructor != null;
539            if (!constructor.getValueParameters().isEmpty() && delegationSpecifiers.isEmpty()) {
540                trace.report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(enumEntry, enumClass));
541            }
542    
543            for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
544                JetTypeReference typeReference = delegationSpecifier.getTypeReference();
545                if (typeReference != null) {
546                    JetType type = trace.getBindingContext().get(TYPE, typeReference);
547                    if (type != null) {
548                        JetType enumType = enumClass.getDefaultType();
549                        if (!type.getConstructor().equals(enumType.getConstructor())) {
550                            trace.report(ENUM_ENTRY_ILLEGAL_TYPE.on(typeReference, enumClass));
551                        }
552                    }
553                }
554            }
555        }
556    }