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