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        public DescriptorRendererBuilder setShortNames(boolean shortNames) {
052            this.shortNames = shortNames;
053            return this;
054        }
055    
056        public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) {
057            this.withDefinedIn = withDefinedIn;
058            return this;
059        }
060    
061        public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) {
062            this.modifiers = modifiers;
063            return this;
064        }
065    
066        public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) {
067            return setModifiers(ImmutableSet.copyOf(modifiers));
068        }
069    
070        public DescriptorRendererBuilder setStartFromName(boolean startFromName) {
071            this.startFromName = startFromName;
072            return this;
073        }
074    
075        public DescriptorRendererBuilder setDebugMode(boolean debugMode) {
076            this.debugMode = debugMode;
077            return this;
078        }
079    
080        public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) {
081            this.classWithPrimaryConstructor = classWithPrimaryConstructor;
082            return this;
083        }
084    
085        public DescriptorRendererBuilder setVerbose(boolean verbose) {
086            this.verbose = verbose;
087            return this;
088        }
089    
090        public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
091            this.unitReturnType = unitReturnType;
092            return this;
093        }
094    
095        public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
096            this.normalizedVisibilities = normalizedVisibilities;
097            return this;
098        }
099    
100        public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
101            this.showInternalKeyword = showInternalKeyword;
102            return this;
103        }
104    
105        public DescriptorRendererBuilder setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) {
106            this.overrideRenderingPolicy = overrideRenderingPolicy;
107            return this;
108        }
109    
110        public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
111            this.valueParametersHandler = valueParametersHandler;
112            return this;
113        }
114    
115        public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) {
116            this.textFormat = textFormat;
117            return this;
118        }
119    
120        public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
121            this.excludedAnnotationClasses = excludedAnnotationClasses;
122            return this;
123        }
124    
125        public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
126            this.prettyFunctionTypes = prettyFunctionTypes;
127            return this;
128        }
129    
130        public DescriptorRenderer build() {
131            return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
132                                              verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, prettyFunctionTypes,
133                                              overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses);
134        }
135    
136    }