Added annotation filtering in DescriptorRenderer.
This commit is contained in:
@@ -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<FqName> excludedAnnotationClasses = Collections.emptyList();
|
||||
|
||||
public DescriptorRendererBuilder() {
|
||||
}
|
||||
@@ -79,8 +86,13 @@ public class DescriptorRendererBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
private final ValueParametersHandler handler;
|
||||
@NotNull
|
||||
private final TextFormat textFormat;
|
||||
@NotNull
|
||||
private final Set<FqName> 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<FqName> 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(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user