Skip to content

Commit e4824cb

Browse files
Rawi01rspilker
authored andcommitted
Fix Javadoc in Eclipse
1 parent c93400d commit e4824cb

File tree

5 files changed

+82
-18
lines changed

5 files changed

+82
-18
lines changed

src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 The Project Lombok Authors.
2+
* Copyright (C) 2020-2024 The Project Lombok Authors.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -24,20 +24,15 @@
2424
import static lombok.eclipse.EcjAugments.CompilationUnit_javadoc;
2525

2626
import java.lang.reflect.Method;
27-
import java.lang.reflect.InvocationTargetException;
2827
import java.util.Map;
2928

3029
import org.eclipse.jdt.core.ICompilationUnit;
3130
import org.eclipse.jdt.core.IJavaElement;
3231
import org.eclipse.jdt.core.IMember;
33-
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
34-
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
35-
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
3632
import org.eclipse.jdt.internal.core.CompilationUnit;
3733
import org.eclipse.jdt.internal.core.SourceMethod;
3834
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
3935

40-
import lombok.eclipse.handlers.EclipseHandlerUtil;
4136
import lombok.permit.Permit;
4237

4338
public class PatchJavadoc {

src/eclipseAgent/lombok/launch/PatchFixesHider.java

-11
Original file line numberDiff line numberDiff line change
@@ -432,26 +432,15 @@ public static Object modifyMethodPattern(Object original) {
432432
/** Contains patch code to support Javadoc for generated methods */
433433
public static final class Javadoc {
434434
private static final Method GET_HTML;
435-
private static final Method PRINT_METHOD_OLD;
436-
private static final Method PRINT_METHOD_NEW;
437435

438436
static {
439437
Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchJavadoc");
440438
GET_HTML = Util.findMethod(shadowed, "getHTMLContentFromSource", String.class, Object.class);
441-
PRINT_METHOD_NEW = Util.findMethod(shadowed, "printMethod", AbstractMethodDeclaration.class, Integer.class, StringBuilder.class, TypeDeclaration.class);
442-
PRINT_METHOD_OLD = Util.findMethod(shadowed, "printMethod", AbstractMethodDeclaration.class, Integer.class, StringBuffer.class, TypeDeclaration.class);
443439
}
444440

445441
public static String getHTMLContentFromSource(String original, IJavaElement member) {
446442
return (String) Util.invokeMethod(GET_HTML, original, member);
447443
}
448-
449-
public static StringBuilder printMethod(AbstractMethodDeclaration methodDeclaration, int tab, StringBuilder output, TypeDeclaration type) {
450-
return (StringBuilder) Util.invokeMethod(PRINT_METHOD_NEW, methodDeclaration, tab, output, type);
451-
}
452-
public static StringBuffer printMethod(AbstractMethodDeclaration methodDeclaration, int tab, StringBuffer output, TypeDeclaration type) {
453-
return (StringBuffer) Util.invokeMethod(PRINT_METHOD_OLD, methodDeclaration, tab, output, type);
454-
}
455444
}
456445

457446
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package pkg;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
public class Javadoc {
7+
/**
8+
* Some text
9+
*
10+
* **SETTER**
11+
* Setter section
12+
* @param fieldName Hello, World3
13+
* **GETTER**
14+
* Getter section
15+
* @return Sky is blue3
16+
*/
17+
@Getter
18+
@Setter
19+
private int field;
20+
21+
public void usage() {
22+
getField();
23+
setField(0);
24+
}
25+
}

test/eclipse/src/lombok/eclipse/EclipseTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import lombok.eclipse.cleanup.CleanupTest;
2929
import lombok.eclipse.compile.NoErrorsTest;
3030
import lombok.eclipse.edit.SelectTest;
31+
import lombok.eclipse.misc.JavadocTest;
3132
import lombok.eclipse.refactoring.ExtractInterfaceTest;
3233
import lombok.eclipse.refactoring.InlineTest;
3334
import lombok.eclipse.refactoring.RenameTest;
3435
import lombok.eclipse.references.FindReferencesTest;
3536

3637
@RunWith(Suite.class)
37-
@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class, FindReferencesTest.class, InlineTest.class, NoErrorsTest.class})
38+
@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class, FindReferencesTest.class, InlineTest.class, NoErrorsTest.class, JavadocTest.class})
3839
public class EclipseTests {
3940

4041
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2024 The Project Lombok Authors.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package lombok.eclipse.misc;
23+
24+
import static org.junit.Assert.assertEquals;
25+
26+
import org.eclipse.jdt.core.ICompilationUnit;
27+
import org.eclipse.jdt.core.IJavaElement;
28+
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
29+
import org.junit.Rule;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
33+
import lombok.eclipse.EclipseRunner;
34+
import lombok.eclipse.SetupSingleFileTest;
35+
36+
@RunWith(EclipseRunner.class)
37+
public class JavadocTest {
38+
39+
@Rule
40+
public SetupSingleFileTest setup = new SetupSingleFileTest();
41+
42+
@Test
43+
public void getterSetter() throws Exception {
44+
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Javadoc.java");
45+
46+
IJavaElement getterInvocation = cu.codeSelect(306, 0)[0];
47+
String getterHtmlContent = JavadocContentAccess2.getHTMLContent(getterInvocation, true);
48+
assertEquals("Getter section<dl><dt>Returns:</dt><dd> Sky is blue3</dd></dl>", getterHtmlContent);
49+
50+
IJavaElement setterInvocation = cu.codeSelect(320, 0)[0];
51+
String setterHtmlContent = JavadocContentAccess2.getHTMLContent(setterInvocation, true);
52+
assertEquals("Setter section<dl><dt>Parameters:</dt><dd><b>fieldName</b> Hello, World3</dd><dd><b>field</b> </dd></dl>", setterHtmlContent);
53+
}
54+
}

0 commit comments

Comments
 (0)