mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 03:13:38 +00:00
Fixes #3564 - Duplicate StringBuffer calls to StringBuilder calls
Signed-off-by: Rob Stryker <rob@oxbeef.net>
This commit is contained in:
1 parent
d6ee06c534
commit
7830c73822
5 files changed
+41
-9
No files matched your search
@@ -183,7 +183,7 @@ public abstract class ConfigurationFile {
|
||||
|
||||
private static String replaceEnvironmentVariables(String fileName) {
|
||||
int start = 0;
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (fileName.startsWith("~")) {
|
||||
start = 1;
|
||||
result.append(System.getProperty("user.home", "~"));
|
||||
|
||||
@@ -1331,9 +1331,7 @@ public class EclipseHandlerUtil {
|
||||
expressions = new Expression[] { rhs };
|
||||
}
|
||||
if (expressions != null) for (Expression ex : expressions) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ex.print(0, sb);
|
||||
raws.add(sb.toString());
|
||||
raws.add(ex.toString());
|
||||
expressionValues.add(ex);
|
||||
guesses.add(calculateValue(ex));
|
||||
}
|
||||
|
||||
@@ -986,6 +986,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "printBody", "java.lang.StringBuilder", "int", "java.lang.StringBuilder"))
|
||||
.methodToReplace(new Hook("org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "print", "java.lang.StringBuilder", "int", "java.lang.StringBuilder"))
|
||||
.replacementMethod(new Hook("lombok.launch.PatchFixesHider$Javadoc", "printMethod", "java.lang.StringBuilder", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "int", "java.lang.StringBuilder", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration"))
|
||||
.requestExtra(StackRequest.THIS)
|
||||
.build());
|
||||
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "printBody", "java.lang.StringBuffer", "int", "java.lang.StringBuffer"))
|
||||
.methodToReplace(new Hook("org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "print", "java.lang.StringBuffer", "int", "java.lang.StringBuffer"))
|
||||
@@ -1050,7 +1057,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
sm.addScriptIfWitness(new String[] {"lombok/transform/TestWithEcj"}, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "print"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$Tests", "isImplicitCanonicalConstructor", "boolean", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "java.lang.Object"))
|
||||
.valueMethod(new Hook("lombok.launch.PatchFixesHider$Tests", "returnStringBuffer", "java.lang.StringBuffer", "java.lang.Object", "java.lang.StringBuffer"))
|
||||
.valueMethod(new Hook("lombok.launch.PatchFixesHider$Tests", "returnStringBuilder", "java.lang.StringBuilder", "java.lang.Object", "java.lang.StringBuilder"))
|
||||
.request(StackRequest.THIS, StackRequest.PARAM2)
|
||||
.transplant()
|
||||
.build());
|
||||
|
||||
@@ -65,6 +65,21 @@ public class PatchJavadoc {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StringBuilder printMethod(AbstractMethodDeclaration methodDeclaration, Integer tab, StringBuilder output, TypeDeclaration type) {
|
||||
Map<String, String> docs = CompilationUnit_javadoc.get(methodDeclaration.compilationResult.compilationUnit);
|
||||
if (docs != null) {
|
||||
String signature = EclipseHandlerUtil.getSignature(type, methodDeclaration);
|
||||
String rawJavadoc = docs.get(signature);
|
||||
if (rawJavadoc != null) {
|
||||
for (String line : rawJavadoc.split("\r?\n")) {
|
||||
ASTNode.printIndent(tab, output).append(line).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
return methodDeclaration.print(tab, output);
|
||||
}
|
||||
|
||||
|
||||
public static StringBuffer printMethod(AbstractMethodDeclaration methodDeclaration, Integer tab, StringBuffer output, TypeDeclaration type) {
|
||||
Map<String, String> docs = CompilationUnit_javadoc.get(methodDeclaration.compilationResult.compilationUnit);
|
||||
if (docs != null) {
|
||||
|
||||
@@ -427,20 +427,28 @@ 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;
|
||||
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 = Util.findMethod(shadowed, "printMethod", AbstractMethodDeclaration.class, Integer.class, StringBuffer.class, TypeDeclaration.class);
|
||||
try {
|
||||
PRINT_METHOD_NEW = Util.findMethod(shadowed, "printMethod", AbstractMethodDeclaration.class, Integer.class, StringBuilder.class, TypeDeclaration.class);
|
||||
} catch( RuntimeException e ) {
|
||||
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, methodDeclaration, tab, output, type);
|
||||
return (StringBuffer) Util.invokeMethod(PRINT_METHOD_OLD, methodDeclaration, tab, output, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,7 +985,11 @@ final class PatchFixesHider {
|
||||
return (method.bits & IsCanonicalConstructor) != 0 && (method.bits & IsImplicit) != 0;
|
||||
}
|
||||
|
||||
public static StringBuffer returnStringBuffer(Object p1, StringBuffer buffer) {
|
||||
public static StringBuilder returnStringBuffer(Object p1, StringBuffer buffer) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static StringBuilder returnStringBuilder(Object p1, StringBuilder buffer) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user