From df11628fb0583b6c8449af4b596672e4c9cc446e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 25 Dec 2012 03:26:24 +0400 Subject: [PATCH] Added annotation filtering in DescriptorRenderer. --- .../jet/renderer/DescriptorRendererBuilder.java | 14 +++++++++++++- .../jet/renderer/DescriptorRendererImpl.java | 13 +++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererBuilder.java b/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererBuilder.java index 02c1c0a7ee8..10b826a1936 100644 --- a/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererBuilder.java @@ -17,6 +17,11 @@ package org.jetbrains.jet.renderer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.name.FqName; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; public class DescriptorRendererBuilder { private boolean shortNames = false; @@ -30,6 +35,8 @@ public class DescriptorRendererBuilder { private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler(); @NotNull private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN; + @NotNull + private Collection excludedAnnotationClasses = Collections.emptyList(); public DescriptorRendererBuilder() { } @@ -79,8 +86,13 @@ public class DescriptorRendererBuilder { return this; } + public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection excludedAnnotationClasses) { + this.excludedAnnotationClasses = excludedAnnotationClasses; + return this; + } + public DescriptorRenderer build() { return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, - verbose, valueParametersHandler, textFormat); + verbose, valueParametersHandler, textFormat, excludedAnnotationClasses); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java b/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java index e727fb79e4b..ddec3719656 100644 --- a/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java @@ -60,6 +60,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer { private final ValueParametersHandler handler; @NotNull private final TextFormat textFormat; + @NotNull + private final Set excludedAnnotationClasses; /* package */ DescriptorRendererImpl( boolean shortNames, @@ -70,7 +72,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer { boolean classWithPrimaryConstructor, boolean verbose, @NotNull ValueParametersHandler handler, - @NotNull TextFormat textFormat + @NotNull TextFormat textFormat, + @NotNull Collection excludedAnnotationClasses ) { this.shortNames = shortNames; this.withDefinedIn = withDefinedIn; @@ -81,6 +84,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer { this.verbose = verbose; this.debugMode = debugMode; this.textFormat = textFormat; + this.excludedAnnotationClasses = Sets.newHashSet(excludedAnnotationClasses); } @@ -285,7 +289,12 @@ public class DescriptorRendererImpl implements DescriptorRenderer { private void renderAnnotations(@NotNull Annotated annotated, @NotNull StringBuilder builder) { if (!modifiers) return; for (AnnotationDescriptor annotation : annotated.getAnnotations()) { - builder.append(renderType(annotation.getType())).append(" "); + ClassDescriptor annotationClass = (ClassDescriptor) annotation.getType().getConstructor().getDeclarationDescriptor(); + assert annotationClass != null; + + if (!excludedAnnotationClasses.contains(DescriptorUtils.getFQName(annotationClass).toSafe())) { + builder.append(renderType(annotation.getType())).append(" "); + } } }