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        private boolean renderDefaultValues = true;
055    
056        @NotNull
057        private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
058        @NotNull
059        private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
060        @NotNull
061        private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
062        @NotNull
063        private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
064        private boolean receiverAfterName = false;
065        private boolean renderClassObjectName = false;
066    
067        public DescriptorRendererBuilder() {
068        }
069    
070        @NotNull
071        public DescriptorRendererBuilder setShortNames(boolean shortNames) {
072            this.shortNames = shortNames;
073            return this;
074        }
075    
076        @NotNull
077        public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) {
078            this.withDefinedIn = withDefinedIn;
079            return this;
080        }
081    
082        @NotNull
083        public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) {
084            this.modifiers = modifiers;
085            return this;
086        }
087    
088        @NotNull
089        public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
090            return setModifiers(KotlinPackage.setOf(modifiers));
091        }
092    
093        @NotNull
094        public DescriptorRendererBuilder setStartFromName(boolean startFromName) {
095            this.startFromName = startFromName;
096            return this;
097        }
098    
099        @NotNull
100        public DescriptorRendererBuilder setDebugMode(boolean debugMode) {
101            this.debugMode = debugMode;
102            return this;
103        }
104    
105        @NotNull
106        public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) {
107            this.classWithPrimaryConstructor = classWithPrimaryConstructor;
108            return this;
109        }
110    
111        @NotNull
112        public DescriptorRendererBuilder setVerbose(boolean verbose) {
113            this.verbose = verbose;
114            return this;
115        }
116    
117        @NotNull
118        public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
119            this.unitReturnType = unitReturnType;
120            return this;
121        }
122    
123        @NotNull
124        public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
125            this.normalizedVisibilities = normalizedVisibilities;
126            return this;
127        }
128    
129        @NotNull
130        public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
131            this.showInternalKeyword = showInternalKeyword;
132            return this;
133        }
134    
135        @NotNull
136        public DescriptorRendererBuilder setOverrideRenderingPolicy(@NotNull DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) {
137            this.overrideRenderingPolicy = overrideRenderingPolicy;
138            return this;
139        }
140    
141        @NotNull
142        public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
143            this.valueParametersHandler = valueParametersHandler;
144            return this;
145        }
146    
147        @NotNull
148        public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) {
149            this.textFormat = textFormat;
150            return this;
151        }
152    
153        @NotNull
154        public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
155            this.excludedAnnotationClasses = excludedAnnotationClasses;
156            return this;
157        }
158    
159        @NotNull
160        public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
161            this.prettyFunctionTypes = prettyFunctionTypes;
162            return this;
163        }
164    
165        @NotNull
166        public DescriptorRendererBuilder setUninferredTypeParameterAsName(boolean uninferredTypeParameterAsName) {
167            this.uninferredTypeParameterAsName = uninferredTypeParameterAsName;
168            return this;
169        }
170    
171        @NotNull
172        public DescriptorRendererBuilder setIncludePropertyConstant(boolean includePropertyConstant) {
173            this.includePropertyConstant = includePropertyConstant;
174            return this;
175        }
176    
177        @NotNull
178        public DescriptorRendererBuilder setIncludeSynthesizedParameterNames(boolean includeSynthesizedParameterNames) {
179            this.includeSynthesizedParameterNames = includeSynthesizedParameterNames;
180            return this;
181        }
182    
183        @NotNull
184        public DescriptorRendererBuilder setWithoutTypeParameters(boolean withoutTypeParameters) {
185            this.withoutTypeParameters = withoutTypeParameters;
186            return this;
187        }
188    
189        @NotNull
190        public DescriptorRendererBuilder setWithoutFunctionParameterNames(boolean withoutFunctionParameterNames) {
191            this.withoutFunctionParameterNames = withoutFunctionParameterNames;
192            return this;
193        }
194    
195        @NotNull
196        public DescriptorRendererBuilder setReceiverAfterName(boolean receiverAfterName) {
197            this.receiverAfterName = receiverAfterName;
198            return this;
199        }
200    
201        @NotNull
202        public DescriptorRendererBuilder setRenderClassObjectName(boolean renderClassObjectName) {
203            this.renderClassObjectName = renderClassObjectName;
204            return this;
205        }
206    
207        @NotNull
208        public DescriptorRendererBuilder setWithoutSuperTypes(boolean withoutSuperTypes) {
209            this.withoutSuperTypes = withoutSuperTypes;
210            return this;
211        }
212    
213        public DescriptorRendererBuilder setRenderDefaultValues(boolean renderDefaultValues) {
214            this.renderDefaultValues = renderDefaultValues;
215            return this;
216        }
217    
218        @NotNull
219        public DescriptorRendererBuilder setTypeNormalizer(@NotNull Function1<JetType, JetType> typeNormalizer) {
220            this.typeNormalizer = typeNormalizer;
221            return this;
222        }
223    
224        @NotNull
225        public DescriptorRenderer build() {
226            return new DescriptorRendererImpl(
227                    shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType,
228                    normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
229                    overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
230                    includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName,
231                    renderClassObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues);
232        }
233    
234    }