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