Added annotation filtering in DescriptorRenderer.
This commit is contained in:
@@ -17,6 +17,11 @@
|
|||||||
package org.jetbrains.jet.renderer;
|
package org.jetbrains.jet.renderer;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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 {
|
public class DescriptorRendererBuilder {
|
||||||
private boolean shortNames = false;
|
private boolean shortNames = false;
|
||||||
@@ -30,6 +35,8 @@ public class DescriptorRendererBuilder {
|
|||||||
private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
|
private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
|
||||||
@NotNull
|
@NotNull
|
||||||
private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
|
private DescriptorRenderer.TextFormat textFormat = DescriptorRenderer.TextFormat.PLAIN;
|
||||||
|
@NotNull
|
||||||
|
private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
|
||||||
|
|
||||||
public DescriptorRendererBuilder() {
|
public DescriptorRendererBuilder() {
|
||||||
}
|
}
|
||||||
@@ -79,8 +86,13 @@ public class DescriptorRendererBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DescriptorRendererBuilder setExcludedAnnotationClasses(@NotNull Collection<FqName> excludedAnnotationClasses) {
|
||||||
|
this.excludedAnnotationClasses = excludedAnnotationClasses;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DescriptorRenderer build() {
|
public DescriptorRenderer build() {
|
||||||
return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
|
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;
|
private final ValueParametersHandler handler;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final TextFormat textFormat;
|
private final TextFormat textFormat;
|
||||||
|
@NotNull
|
||||||
|
private final Set<FqName> excludedAnnotationClasses;
|
||||||
|
|
||||||
/* package */ DescriptorRendererImpl(
|
/* package */ DescriptorRendererImpl(
|
||||||
boolean shortNames,
|
boolean shortNames,
|
||||||
@@ -70,7 +72,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
|||||||
boolean classWithPrimaryConstructor,
|
boolean classWithPrimaryConstructor,
|
||||||
boolean verbose,
|
boolean verbose,
|
||||||
@NotNull ValueParametersHandler handler,
|
@NotNull ValueParametersHandler handler,
|
||||||
@NotNull TextFormat textFormat
|
@NotNull TextFormat textFormat,
|
||||||
|
@NotNull Collection<FqName> excludedAnnotationClasses
|
||||||
) {
|
) {
|
||||||
this.shortNames = shortNames;
|
this.shortNames = shortNames;
|
||||||
this.withDefinedIn = withDefinedIn;
|
this.withDefinedIn = withDefinedIn;
|
||||||
@@ -81,6 +84,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
|||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
this.debugMode = debugMode;
|
this.debugMode = debugMode;
|
||||||
this.textFormat = textFormat;
|
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) {
|
private void renderAnnotations(@NotNull Annotated annotated, @NotNull StringBuilder builder) {
|
||||||
if (!modifiers) return;
|
if (!modifiers) return;
|
||||||
for (AnnotationDescriptor annotation : annotated.getAnnotations()) {
|
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