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        private boolean includePropertyConstant = false;
040        @NotNull
041        private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
042        @NotNull
043        private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
044        @NotNull
045        private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
046        @NotNull
047        private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
048    
049        public DescriptorRendererBuilder() {
050        }
051    
052        @NotNull
053        public DescriptorRendererBuilder setShortNames(boolean shortNames) {
054            this.shortNames = shortNames;
055            return this;
056        }
057    
058        @NotNull
059        public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) {
060            this.withDefinedIn = withDefinedIn;
061            return this;
062        }
063    
064        @NotNull
065        public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) {
066            this.modifiers = modifiers;
067            return this;
068        }
069    
070        @NotNull
071        public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
072            return setModifiers(ImmutableSet.copyOf(modifiers));
073        }
074    
075        @NotNull
076        public DescriptorRendererBuilder setStartFromName(boolean startFromName) {
077            this.startFromName = startFromName;
078            return this;
079        }
080    
081        @NotNull
082        public DescriptorRendererBuilder setDebugMode(boolean debugMode) {
083            this.debugMode = debugMode;
084            return this;
085        }
086    
087        @NotNull
088        public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) {
089            this.classWithPrimaryConstructor = classWithPrimaryConstructor;
090            return this;
091        }
092    
093        @NotNull
094        public DescriptorRendererBuilder setVerbose(boolean verbose) {
095            this.verbose = verbose;
096            return this;
097        }
098    
099        @NotNull
100        public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
101            this.unitReturnType = unitReturnType;
102            return this;
103        }
104    
105        @NotNull
106        public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
107            this.normalizedVisibilities = normalizedVisibilities;
108            return this;
109        }
110    
111        @NotNull
112        public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
113            this.showInternalKeyword = showInternalKeyword;
114            return this;
115        }
116    
117        @NotNull
118        public DescriptorRendererBuilder setOverrideRenderingPolicy(@NotNull DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) {
119            this.overrideRenderingPolicy = overrideRenderingPolicy;
120            return this;
121        }
122    
123        @NotNull
124        public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
125            this.valueParametersHandler = valueParametersHandler;
126            return this;
127        }
128    
129        @NotNull
130        public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) {
131            this.textFormat = textFormat;
132            return this;
133        }
134    
135        @NotNull
136        public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
137            this.excludedAnnotationClasses = excludedAnnotationClasses;
138            return this;
139        }
140    
141        @NotNull
142        public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
143            this.prettyFunctionTypes = prettyFunctionTypes;
144            return this;
145        }
146    
147        public DescriptorRendererBuilder setIncludePropertyConstant(boolean includePropertyConstant) {
148            this.includePropertyConstant = includePropertyConstant;
149            return this;
150        }
151    
152        @NotNull
153        public DescriptorRenderer build() {
154            return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
155                                              verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, prettyFunctionTypes,
156                                              overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses,
157                                              includePropertyConstant);
158        }
159    
160    }