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