Skip to content

Commit

Permalink
Fix Javadoc in Eclipse
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 authored and rspilker committed Mar 18, 2024
1 parent c93400d commit e4824cb
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 18 deletions.
7 changes: 1 addition & 6 deletions src/eclipseAgent/lombok/eclipse/agent/PatchJavadoc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 The Project Lombok Authors.
* Copyright (C) 2020-2024 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,20 +24,15 @@
import static lombok.eclipse.EcjAugments.CompilationUnit_javadoc;

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.SourceMethod;
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;

import lombok.eclipse.handlers.EclipseHandlerUtil;
import lombok.permit.Permit;

public class PatchJavadoc {
Expand Down
11 changes: 0 additions & 11 deletions src/eclipseAgent/lombok/launch/PatchFixesHider.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,26 +432,15 @@ public static Object modifyMethodPattern(Object original) {
/** Contains patch code to support Javadoc for generated methods */
public static final class Javadoc {
private static final Method GET_HTML;
private static final Method PRINT_METHOD_OLD;
private static final Method PRINT_METHOD_NEW;

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

public static String getHTMLContentFromSource(String original, IJavaElement member) {
return (String) Util.invokeMethod(GET_HTML, original, member);
}

public static StringBuilder printMethod(AbstractMethodDeclaration methodDeclaration, int tab, StringBuilder output, TypeDeclaration type) {
return (StringBuilder) Util.invokeMethod(PRINT_METHOD_NEW, methodDeclaration, tab, output, type);
}
public static StringBuffer printMethod(AbstractMethodDeclaration methodDeclaration, int tab, StringBuffer output, TypeDeclaration type) {
return (StringBuffer) Util.invokeMethod(PRINT_METHOD_OLD, methodDeclaration, tab, output, type);
}
}

/**
Expand Down
25 changes: 25 additions & 0 deletions test/eclipse/resource/javadoc/getterSetter/Javadoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pkg;

import lombok.Getter;
import lombok.Setter;

public class Javadoc {
/**
* Some text
*
* **SETTER**
* Setter section
* @param fieldName Hello, World3
* **GETTER**
* Getter section
* @return Sky is blue3
*/
@Getter
@Setter
private int field;

public void usage() {
getField();
setField(0);
}
}
3 changes: 2 additions & 1 deletion test/eclipse/src/lombok/eclipse/EclipseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import lombok.eclipse.cleanup.CleanupTest;
import lombok.eclipse.compile.NoErrorsTest;
import lombok.eclipse.edit.SelectTest;
import lombok.eclipse.misc.JavadocTest;
import lombok.eclipse.refactoring.ExtractInterfaceTest;
import lombok.eclipse.refactoring.InlineTest;
import lombok.eclipse.refactoring.RenameTest;
import lombok.eclipse.references.FindReferencesTest;

@RunWith(Suite.class)
@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class, FindReferencesTest.class, InlineTest.class, NoErrorsTest.class})
@SuiteClasses({ExtractInterfaceTest.class, RenameTest.class, SelectTest.class, CleanupTest.class, FindReferencesTest.class, InlineTest.class, NoErrorsTest.class, JavadocTest.class})
public class EclipseTests {

}
54 changes: 54 additions & 0 deletions test/eclipse/src/lombok/eclipse/misc/JavadocTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2024 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok.eclipse.misc;

import static org.junit.Assert.assertEquals;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import lombok.eclipse.EclipseRunner;
import lombok.eclipse.SetupSingleFileTest;

@RunWith(EclipseRunner.class)
public class JavadocTest {

@Rule
public SetupSingleFileTest setup = new SetupSingleFileTest();

@Test
public void getterSetter() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Javadoc.java");

IJavaElement getterInvocation = cu.codeSelect(306, 0)[0];
String getterHtmlContent = JavadocContentAccess2.getHTMLContent(getterInvocation, true);
assertEquals("Getter section<dl><dt>Returns:</dt><dd> Sky is blue3</dd></dl>", getterHtmlContent);

IJavaElement setterInvocation = cu.codeSelect(320, 0)[0];
String setterHtmlContent = JavadocContentAccess2.getHTMLContent(setterInvocation, true);
assertEquals("Setter section<dl><dt>Parameters:</dt><dd><b>fieldName</b> Hello, World3</dd><dd><b>field</b> </dd></dl>", setterHtmlContent);
}
}

0 comments on commit e4824cb

Please sign in to comment.