mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 00:17:45 +00:00
Fix Javadoc in Eclipse
This commit is contained in:
1 parent
c93400d9f4
commit
e4824cbe14
5 files changed
+82
-18
No files matched your search
@@ -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
|
||||
@@ -24,20 +24,15 @@ package lombok.eclipse.agent;
|
||||
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 {
|
||||
|
||||
@@ -432,26 +432,15 @@ final class PatchFixesHider {
|
||||
/** 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,14 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
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 {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user