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.renderer;
018    
019    import com.google.common.collect.ImmutableSet;
020    import org.jetbrains.annotations.NotNull;
021    import org.jetbrains.jet.lang.resolve.name.FqName;
022    
023    import java.util.Collection;
024    import java.util.Collections;
025    import java.util.Set;
026    
027    public class DescriptorRendererBuilder {
028        private boolean shortNames = false;
029        private boolean withDefinedIn = true;
030        private Set<DescriptorRenderer.Modifier> modifiers = ImmutableSet.copyOf(DescriptorRenderer.Modifier.values());
031        private boolean startFromName = false;
032        private boolean debugMode = false;
033        private boolean classWithPrimaryConstructor = false;
034        private boolean verbose = false;
035        private boolean unitReturnType = true;
036        private boolean normalizedVisibilities = false;
037        private boolean showInternalKeyword = true;
038        private boolean prettyFunctionTypes = true;
039        @NotNull
040        private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
041        @NotNull
042        private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
043        @NotNull
044        private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
045        @NotNull
046        private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
047    
048        public DescriptorRendererBuilder() {
049        }
050    
051        @NotNull
052        public DescriptorRendererBuilder setShortNames(boolean shortNames) {
053            this.shortNames = shortNames;
054            return this;
055        }
056    
057        @NotNull
058        public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) {
059            this.withDefinedIn = withDefinedIn;
060            return this;
061        }
062    
063        @NotNull
064        public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) {
065            this.modifiers = modifiers;
066            return this;
067        }
068    
069        @NotNull
070        public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
071            return setModifiers(ImmutableSet.copyOf(modifiers));
072        }
073    
074        @NotNull
075        public DescriptorRendererBuilder setStartFromName(boolean startFromName) {
076            this.startFromName = startFromName;
077            return this;
078        }
079    
080        @NotNull
081        public DescriptorRendererBuilder setDebugMode(boolean debugMode) {
082            this.debugMode = debugMode;
083            return this;
084        }
085    
086        @NotNull
087        public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) {
088            this.classWithPrimaryConstructor = classWithPrimaryConstructor;
089            return this;
090        }
091    
092        @NotNull
093        public DescriptorRendererBuilder setVerbose(boolean verbose) {
094            this.verbose = verbose;
095            return this;
096        }
097    
098        @NotNull
099        public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
100            this.unitReturnType = unitReturnType;
101            return this;
102        }
103    
104        @NotNull
105        public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
106            this.normalizedVisibilities = normalizedVisibilities;
107            return this;
108        }
109    
110        @NotNull
111        public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
112            this.showInternalKeyword = showInternalKeyword;
113            return this;
114        }
115    
116        @NotNull
117        public DescriptorRendererBuilder setOverrideRenderingPolicy(@NotNull DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) {
118            this.overrideRenderingPolicy = overrideRenderingPolicy;
119            return this;
120        }
121    
122        @NotNull
123        public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
124            this.valueParametersHandler = valueParametersHandler;
125            return this;
126        }
127    
128        @NotNull
129        public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) {
130            this.textFormat = textFormat;
131            return this;
132        }
133    
134        @NotNull
135        public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
136            this.excludedAnnotationClasses = excludedAnnotationClasses;
137            return this;
138        }
139    
140        @NotNull
141        public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
142            this.prettyFunctionTypes = prettyFunctionTypes;
143            return this;
144        }
145    
146        @NotNull
147        public DescriptorRenderer build() {
148            return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
149                                              verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, prettyFunctionTypes,
150                                              overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses);
151        }
152    
153    }