Skip to content

Commit

Permalink
fix override annotations emitting twice
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipdev committed Nov 16, 2023
1 parent 3482e13 commit 5662fc3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,24 @@ private boolean methodToJava(ClassNode node, StructMethod mt, int methodIndex, T

appendAnnotations(buffer, indent, mt, TypeAnnotation.METHOD_RETURN_TYPE);

StructAnnotationAttribute annotationAttribute = mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS);
boolean alreadyHasOverride = false;

if (annotationAttribute != null) {
alreadyHasOverride = annotationAttribute.getAnnotations().stream()
.anyMatch(annotation -> "java/lang/Override".equals(annotation.getClassName()));
}

boolean shouldApplyOverride = DecompilerContext.getOption(IFernflowerPreferences.OVERRIDE_ANNOTATION)
&& mt.getBytecodeVersion().hasOverride()
&& !CodeConstants.INIT_NAME.equals(mt.getName())
&& !CodeConstants.CLINIT_NAME.equals(mt.getName())
&& !mt.hasModifier(CodeConstants.ACC_STATIC)
&& !mt.hasModifier(CodeConstants.ACC_PRIVATE)
&& !alreadyHasOverride;

// Try append @Override after all other annotations
if (DecompilerContext.getOption(IFernflowerPreferences.OVERRIDE_ANNOTATION) && mt.getBytecodeVersion().hasOverride() && !CodeConstants.INIT_NAME.equals(mt.getName()) && !CodeConstants.CLINIT_NAME.equals(mt.getName()) && !mt.hasModifier(CodeConstants.ACC_STATIC) && !mt.hasModifier(CodeConstants.ACC_PRIVATE)) {
if (shouldApplyOverride) {
// Search superclasses for methods that match the name and descriptor of this one.
// Make sure not to search the current class otherwise it will return the current method itself!
// TODO: record overrides
Expand Down Expand Up @@ -1516,7 +1532,7 @@ public static List<String> getErrorComment() {
private static void appendComment(TextBuffer buffer, String comment, int indent) {
buffer.appendIndent(indent).append("// $VF: ").append(comment).appendLineSeparator();
}

private static void appendJavadoc(TextBuffer buffer, String javaDoc, int indent) {
if (javaDoc == null) return;
buffer.appendIndent(indent).append("/**").appendLineSeparator();
Expand Down

0 comments on commit 5662fc3

Please sign in to comment.