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.renderer;
018    
019    import kotlin.Function1;
020    import kotlin.KotlinPackage;
021    import org.jetbrains.annotations.NotNull;
022    import org.jetbrains.jet.lang.resolve.name.FqName;
023    import org.jetbrains.jet.lang.types.JetType;
024    
025    import java.util.Collection;
026    import java.util.Collections;
027    import java.util.EnumSet;
028    import java.util.Set;
029    
030    public class DescriptorRendererBuilder {
031        private boolean shortNames = false;
032        private boolean withDefinedIn = true;
033        private Set<DescriptorRenderer.Modifier> modifiers = EnumSet.allOf(DescriptorRenderer.Modifier.class);
034        private boolean startFromName = false;
035        private boolean debugMode = false;
036        private boolean classWithPrimaryConstructor = false;
037        private boolean verbose = false;
038        private boolean unitReturnType = true;
039        private boolean normalizedVisibilities = false;
040        private boolean showInternalKeyword = true;
041        private boolean prettyFunctionTypes = true;
042        private boolean uninferredTypeParameterAsName = false;
043        private boolean includePropertyConstant = false;
044        private boolean includeSynthesizedParameterNames = true;
045        private boolean withoutFunctionParameterNames = false;
046        private boolean withoutTypeParameters = false;
047        private boolean withoutSuperTypes = false;
048        private Function1<JetType, JetType> typeNormalizer = new Function1<JetType, JetType>() {
049            @Override
050            public JetType invoke(JetType type) {
051                return type;
052            }
053        };
054    
055        @NotNull
056        private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
057        @NotNull
058        private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
059        @NotNull
060        private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
061        @NotNull
062        private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
063        private boolean receiverAfterName = false;
064        private boolean renderClassObjectName = false;
065    
066        public DescriptorRendererBuilder() {
067        }
068    
069        @NotNull
070        public DescriptorRendererBuilder setShortNames(boolean shortNames) {
071            this.shortNames = shortNames;
072            return this;
073        }
074    
075        @NotNull
076        public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) {
077            this.withDefinedIn = withDefinedIn;
078            return this;
079        }
080    
081        @NotNull
082        public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) {
083            this.modifiers = modifiers;
084            return this;
085        }
086    
087        @NotNull
088        public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
089            return setModifiers(KotlinPackage.setOf(modifiers));
090        }
091    
092        @NotNull
093        public DescriptorRendererBuilder setStartFromName(boolean startFromName) {
094            this.startFromName = startFromName;
095            return this;
096        }
097    
098        @NotNull
099        public DescriptorRendererBuilder setDebugMode(boolean debugMode) {
100            this.debugMode = debugMode;
101            return this;
102        }
103    
104        @NotNull
105        public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) {
106            this.classWithPrimaryConstructor = classWithPrimaryConstructor;
107            return this;
108        }
109    
110        @NotNull
111        public DescriptorRendererBuilder setVerbose(boolean verbose) {
112            this.verbose = verbose;
113            return this;
114        }
115    
116        @NotNull
117        public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
118            this.unitReturnType = unitReturnType;
119            return this;
120        }
121    
122        @NotNull
123        public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
124            this.normalizedVisibilities = normalizedVisibilities;
125            return this;
126        }
127    
128        @NotNull
129        public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
130            this.showInternalKeyword = showInternalKeyword;
131            return this;
132        }
133    
134        @NotNull
135        public DescriptorRendererBuilder setOverrideRenderingPolicy(@NotNull DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) {
136            this.overrideRenderingPolicy = overrideRenderingPolicy;
137            return this;
138        }
139    
140        @NotNull
141        public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
142            this.valueParametersHandler = valueParametersHandler;
143            return this;
144        }
145    
146        @NotNull
147        public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) {
148            this.textFormat = textFormat;
149            return this;
150        }
151    
152        @NotNull
153        public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
154            this.excludedAnnotationClasses = excludedAnnotationClasses;
155            return this;
156        }
157    
158        @NotNull
159        public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
160            this.prettyFunctionTypes = prettyFunctionTypes;
161            return this;
162        }
163    
164        @NotNull
165        public DescriptorRendererBuilder setUninferredTypeParameterAsName(boolean uninferredTypeParameterAsName) {
166            this.uninferredTypeParameterAsName = uninferredTypeParameterAsName;
167            return this;
168        }
169    
170        public DescriptorRendererBuilder setIncludePropertyConstant(boolean includePropertyConstant) {
171            this.includePropertyConstant = includePropertyConstant;
172            return this;
173        }
174    
175        public DescriptorRendererBuilder setIncludeSynthesizedParameterNames(boolean includeSynthesizedParameterNames) {
176            this.includeSynthesizedParameterNames = includeSynthesizedParameterNames;
177            return this;
178        }
179    
180        public DescriptorRendererBuilder setWithoutTypeParameters(boolean withoutTypeParameters) {
181            this.withoutTypeParameters = withoutTypeParameters;
182            return this;
183        }
184    
185        public DescriptorRendererBuilder setWithoutFunctionParameterNames(boolean withoutFunctionParameterNames) {
186            this.withoutFunctionParameterNames = withoutFunctionParameterNames;
187            return this;
188        }
189    
190        public DescriptorRendererBuilder setReceiverAfterName(boolean receiverAfterName) {
191            this.receiverAfterName = receiverAfterName;
192            return this;
193        }
194    
195        public DescriptorRendererBuilder setRenderClassObjectName(boolean renderClassObjectName) {
196            this.renderClassObjectName = renderClassObjectName;
197            return this;
198        }
199    
200        public DescriptorRendererBuilder setWithoutSuperTypes(boolean withoutSuperTypes) {
201            this.withoutSuperTypes = withoutSuperTypes;
202            return this;
203        }
204    
205        @NotNull
206        public DescriptorRendererBuilder setTypeNormalizer(@NotNull Function1<JetType, JetType> typeNormalizer) {
207            this.typeNormalizer = typeNormalizer;
208            return this;
209        }
210    
211        @NotNull
212        public DescriptorRenderer build() {
213            return new DescriptorRendererImpl(
214                    shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType,
215                    normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
216                    overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
217                    includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName,
218                    renderClassObjectName, withoutSuperTypes, typeNormalizer);
219        }
220    
221    }