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.psi.stubs.impl;
018    
019    import com.intellij.psi.stubs.StubElement;
020    import com.intellij.util.io.StringRef;
021    import org.jetbrains.annotations.Nullable;
022    import org.jetbrains.jet.lang.psi.JetProperty;
023    import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
024    import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
025    import org.jetbrains.jet.lang.resolve.name.FqName;
026    
027    public class PsiJetPropertyStubImpl extends JetStubBaseImpl<JetProperty> implements PsiJetPropertyStub {
028        private final StringRef name;
029        private final boolean isVar;
030        private final boolean isTopLevel;
031        private final boolean hasDelegate;
032        private final boolean hasDelegateExpression;
033        private final boolean hasInitializer;
034        private final boolean hasReceiverTypeRef;
035        private final boolean hasReturnTypeRef;
036        private final FqName fqName;
037    
038        public PsiJetPropertyStubImpl(
039                StubElement parent,
040                StringRef name,
041                boolean isVar,
042                boolean isTopLevel,
043                boolean hasDelegate,
044                boolean hasDelegateExpression,
045                boolean hasInitializer,
046                boolean hasReceiverTypeRef,
047                boolean hasReturnTypeRef,
048                @Nullable FqName fqName
049        ) {
050            super(parent, JetStubElementTypes.PROPERTY);
051    
052            if (isTopLevel && fqName == null) {
053                throw new IllegalArgumentException("fqName shouldn't be null for top level properties");
054            }
055            if (hasDelegateExpression && !hasDelegate) {
056                throw new IllegalArgumentException("Can't have delegate expression without delegate");
057            }
058    
059            this.name = name;
060            this.isVar = isVar;
061            this.isTopLevel = isTopLevel;
062            this.hasDelegate = hasDelegate;
063            this.hasDelegateExpression = hasDelegateExpression;
064            this.hasInitializer = hasInitializer;
065            this.hasReceiverTypeRef = hasReceiverTypeRef;
066            this.hasReturnTypeRef = hasReturnTypeRef;
067            this.fqName = fqName;
068        }
069    
070        @Override
071        public boolean isVar() {
072            return isVar;
073        }
074    
075        @Override
076        public boolean isTopLevel() {
077            return isTopLevel;
078        }
079    
080        @Override
081        public boolean hasDelegate() {
082            return hasDelegate;
083        }
084    
085        @Override
086        public boolean hasDelegateExpression() {
087            return hasDelegateExpression;
088        }
089    
090        @Override
091        public boolean hasInitializer() {
092            return hasInitializer;
093        }
094    
095        @Override
096        public boolean hasReceiverTypeRef() {
097            return hasReceiverTypeRef;
098        }
099    
100        @Override
101        public boolean hasReturnTypeRef() {
102            return hasReturnTypeRef;
103        }
104    
105        @Nullable
106        @Override
107        public FqName getFqName() {
108            return fqName;
109        }
110    
111        @Override
112        public String getName() {
113            return StringRef.toString(name);
114        }
115    }