001 /* 002 * Copyright 2010-2014 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 uninferredTypeParameterAsName = false; 040 private boolean includePropertyConstant = false; 041 private boolean includeSynthesizedParameterNames = true; 042 private boolean withoutFunctionParameterNames = false; 043 private boolean withoutTypeParameters = false; 044 private boolean withoutSuperTypes = false; 045 046 @NotNull 047 private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN; 048 @NotNull 049 private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler(); 050 @NotNull 051 private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN; 052 @NotNull 053 private Collection<FqName> excludedAnnotationClasses = Collections.emptyList(); 054 private boolean receiverAfterName = false; 055 private boolean renderClassObjectName = false; 056 057 public DescriptorRendererBuilder() { 058 } 059 060 @NotNull 061 public DescriptorRendererBuilder setShortNames(boolean shortNames) { 062 this.shortNames = shortNames; 063 return this; 064 } 065 066 @NotNull 067 public DescriptorRendererBuilder setWithDefinedIn(boolean withDefinedIn) { 068 this.withDefinedIn = withDefinedIn; 069 return this; 070 } 071 072 @NotNull 073 public DescriptorRendererBuilder setModifiers(Set<DescriptorRenderer.Modifier> modifiers) { 074 this.modifiers = modifiers; 075 return this; 076 } 077 078 @NotNull 079 public DescriptorRendererBuilder setModifiers(DescriptorRenderer.Modifier... modifiers) { 080 return setModifiers(ImmutableSet.copyOf(modifiers)); 081 } 082 083 @NotNull 084 public DescriptorRendererBuilder setStartFromName(boolean startFromName) { 085 this.startFromName = startFromName; 086 return this; 087 } 088 089 @NotNull 090 public DescriptorRendererBuilder setDebugMode(boolean debugMode) { 091 this.debugMode = debugMode; 092 return this; 093 } 094 095 @NotNull 096 public DescriptorRendererBuilder setClassWithPrimaryConstructor(boolean classWithPrimaryConstructor) { 097 this.classWithPrimaryConstructor = classWithPrimaryConstructor; 098 return this; 099 } 100 101 @NotNull 102 public DescriptorRendererBuilder setVerbose(boolean verbose) { 103 this.verbose = verbose; 104 return this; 105 } 106 107 @NotNull 108 public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) { 109 this.unitReturnType = unitReturnType; 110 return this; 111 } 112 113 @NotNull 114 public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) { 115 this.normalizedVisibilities = normalizedVisibilities; 116 return this; 117 } 118 119 @NotNull 120 public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) { 121 this.showInternalKeyword = showInternalKeyword; 122 return this; 123 } 124 125 @NotNull 126 public DescriptorRendererBuilder setOverrideRenderingPolicy(@NotNull DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy) { 127 this.overrideRenderingPolicy = overrideRenderingPolicy; 128 return this; 129 } 130 131 @NotNull 132 public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) { 133 this.valueParametersHandler = valueParametersHandler; 134 return this; 135 } 136 137 @NotNull 138 public DescriptorRendererBuilder setTextFormat(@NotNull DescriptorRenderer.TextFormat textFormat) { 139 this.textFormat = textFormat; 140 return this; 141 } 142 143 @NotNull 144 public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) { 145 this.excludedAnnotationClasses = excludedAnnotationClasses; 146 return this; 147 } 148 149 @NotNull 150 public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) { 151 this.prettyFunctionTypes = prettyFunctionTypes; 152 return this; 153 } 154 155 @NotNull 156 public DescriptorRendererBuilder setUninferredTypeParameterAsName(boolean uninferredTypeParameterAsName) { 157 this.uninferredTypeParameterAsName = uninferredTypeParameterAsName; 158 return this; 159 } 160 161 public DescriptorRendererBuilder setIncludePropertyConstant(boolean includePropertyConstant) { 162 this.includePropertyConstant = includePropertyConstant; 163 return this; 164 } 165 166 public DescriptorRendererBuilder setIncludeSynthesizedParameterNames(boolean includeSynthesizedParameterNames) { 167 this.includeSynthesizedParameterNames = includeSynthesizedParameterNames; 168 return this; 169 } 170 171 public DescriptorRendererBuilder setWithoutTypeParameters(boolean withoutTypeParameters) { 172 this.withoutTypeParameters = withoutTypeParameters; 173 return this; 174 } 175 176 public DescriptorRendererBuilder setWithoutFunctionParameterNames(boolean withoutFunctionParameterNames) { 177 this.withoutFunctionParameterNames = withoutFunctionParameterNames; 178 return this; 179 } 180 181 public DescriptorRendererBuilder setReceiverAfterName(boolean receiverAfterName) { 182 this.receiverAfterName = receiverAfterName; 183 return this; 184 } 185 186 public DescriptorRendererBuilder setRenderClassObjectName(boolean renderClassObjectName) { 187 this.renderClassObjectName = renderClassObjectName; 188 return this; 189 } 190 191 public DescriptorRendererBuilder setWithoutSuperTypes(boolean withoutSuperTypes) { 192 this.withoutSuperTypes = withoutSuperTypes; 193 return this; 194 } 195 196 @NotNull 197 public DescriptorRenderer build() { 198 return new DescriptorRendererImpl( 199 shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType, 200 normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName, 201 overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant, 202 includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName, 203 renderClassObjectName, withoutSuperTypes); 204 } 205 206 }