# HG changeset patch # Parent a9720c9ba66cff9258a2733f73056faf7c25cf00 # User Jesse Glick #104757: inline formatting of @Override. diff --git a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java b/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java --- a/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java +++ b/java.source/src/org/netbeans/modules/java/source/save/Reformatter.java @@ -390,6 +390,7 @@ private int lastBlankLinesTokenIndex; private Diff lastBlankLinesDiff; private boolean afterAnnotation; + private boolean lastAnnoWasOverride; private boolean wrapAnnotation; private boolean checkWrap; private boolean fieldGroup; @@ -1027,6 +1028,8 @@ if (afterAnnotation) { if (!isStandalone) { spaces(1, true); + } else if (lastAnnoWasOverride) { + spaces(1); } else { switch (cs.wrapAnnotations()) { case WRAP_ALWAYS: @@ -1062,14 +1065,16 @@ lastBlankLinesTokenIndex = lblti; lastBlankLinesDiff = lbld; wrapAnnotation = cs.wrapAnnotations() == CodeStyle.WrapStyle.WRAP_ALWAYS; + AnnotationTree nextAnno = annotations.next(); if (!isStandalone || !afterAnnotation) { - scan(annotations.next(), p); + scan(nextAnno, p); } else { - wrapTree(cs.wrapAnnotations(), -1, 0, annotations.next()); + wrapTree(cs.wrapAnnotations(), -1, 0, nextAnno); } wrapAnnotation = false; afterAnnotation = true; - ret = false; + lastAnnoWasOverride = nextAnno.getAnnotationType().toString().matches("(java[.]lang[.])?Override"); // NOI18N + ret = lastAnnoWasOverride; continue; } afterAnnotation = false; diff --git a/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java b/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java --- a/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java +++ b/java.source/test/unit/src/org/netbeans/modules/java/source/save/FormatingTest.java @@ -3379,6 +3379,32 @@ reformat(doc, content, golden); } + public void testInlineOverride104757() throws Exception { + testFile = new File(getWorkDir(), "C.java"); + Document doc = DataObject.find(FileUtil.toFileObject(testFile)).getCookie(EditorCookie.class).openDocument(); + doc.putProperty(Language.class, JavaTokenId.language()); + String content = + "package p;\n\n" + + "public class C {\n\n" + + " @SuppressWarnings(\"whatever\")\n" + + " @Override\n" + + " public void m() {\n" + + " }\n\n" + + " public @Override void n() {\n" + + " }\n" + + "}\n"; + String golden = + "package p;\n\n" + + "public class C {\n\n" + + " @SuppressWarnings(\"whatever\")\n" + + " @Override public void m() {\n" + + " }\n\n" + + " public @Override void n() {\n" + + " }\n" + + "}\n"; + reformat(doc, content, golden); + } + private void reformat(Document doc, String content, String golden) throws Exception { reformat(doc, content, golden, 0, content.length()); }