Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch SourceTypeConverter to avoid parsing empty strings #3749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ private static void patchFixSourceTypeConverter(ScriptManager sm) {
.target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "convertAnnotations", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "convertAnnotations", ANNOTATION_SIG + "[]", ANNOTATION_SIG + "[]", I_ANNOTATABLE_SIG))
.request(StackRequest.PARAM1, StackRequest.RETURN_VALUE).build());

sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
.target(new MethodTarget(SOURCE_TYPE_CONVERTER_SIG, "parseMemberValue", "org.eclipse.jdt.internal.compiler.ast.Expression", "char[]"))
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isEmpty", "boolean", "char[]"))
.valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnNullExpression", "org.eclipse.jdt.internal.compiler.ast.Expression", "java.lang.Object"))
.request(StackRequest.PARAM1)
.transplant()
.build());
}

private static void patchEclipseDebugPatches(ScriptManager sm) {
Expand Down
8 changes: 8 additions & 0 deletions src/eclipseAgent/lombok/launch/PatchFixesHider.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@ public static Annotation[] convertAnnotations(Annotation[] out, IAnnotatable ann
return replace;
}

public static boolean isEmpty(char[] array) {
return array.length == 0;
}

public static Expression returnNullExpression(Object string) {
return null;
}

public static String getRealNodeSource(String original, org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
if (!isGenerated(node)) return original;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pkg;

import lombok.Synchronized;

public class ClassWithSynchronized {
@Synchronized
public void test() {
}
}
10 changes: 10 additions & 0 deletions test/eclipse/resource/noerrors/synchronizedUsage/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pkg;

public class Usage {
private ClassWithSynchronized test;

// Prevent "The value of the field Usage.test is not used"
public void test() {
test.test();
}
}
15 changes: 12 additions & 3 deletions test/eclipse/src/lombok/eclipse/compile/NoErrorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
*/
package lombok.eclipse.compile;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jdt.core.ICompilationUnit;
Expand All @@ -49,15 +50,23 @@ public void fieldNameConstantsInAnnotation() throws Exception {
ICompilationUnit cu = setup.getPackageFragment().getCompilationUnit("Usage.java");

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
assertEquals(Collections.emptyList(), problems);
}

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

List<IProblem> problems = collectProblems(cu);
assertTrue(problems.isEmpty());
assertEquals(Collections.emptyList(), problems);
}

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

List<IProblem> problems = collectProblems(cu);
assertEquals(Collections.emptyList(), problems);
}

private List<IProblem> collectProblems(ICompilationUnit cu) throws JavaModelException {
Expand Down
Loading