diff --git a/AUTHORS b/AUTHORS index d83703dea..059210b0f 100755 --- a/AUTHORS +++ b/AUTHORS @@ -63,5 +63,6 @@ Till Brychcy Victor Williams Stafusa da Silva Yonatan Sherwin Yun Zhi Lin +Dymitr "ay0ks" <43708417+ay0ks@users.noreply.github.com> By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok in relation to all commits you add to Project Lombok, and you certify that you have the right to do so. diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index 11b3d39d4..d6f5c8ad9 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -1142,27 +1142,32 @@ private JCExpression copySelect(JavacTreeMaker maker, JCFieldAccess typeParam) { /** * Checks if there is a manual constructor in the given type with a single parameter (builder). */ - private boolean constructorExists(JavacNode type, String builderClassName) { - if (type != null && type.get() instanceof JCClassDecl) { - for (JCTree def : ((JCClassDecl)type.get()).defs) { - if (def instanceof JCMethodDecl) { - JCMethodDecl md = (JCMethodDecl) def; - String name = md.name.toString(); - boolean matches = name.equals(""); - if (isTolerate(type, md)) continue; - if (matches && md.params != null && md.params.length() == 1) { - // Cannot use typeMatches() here, because the parameter could be fully-qualified, partially-qualified, or not qualified. - // A string-compare of the last part should work. If it's a false-positive, users could still @Tolerate it. - String typeName = md.params.get(0).getType().toString(); - int lastIndexOfDot = typeName.lastIndexOf('.'); - if (lastIndexOfDot >= 0) { - typeName = typeName.substring(lastIndexOfDot + 1); - } - if ((builderClassName+"").equals(typeName)) return true; - } - } - } - } - return false; - } + private boolean constructorExists(JavacNode type, String builderClassName) { + if (type != null && type.get() instanceof JCClassDecl) { + for (JCTree def : ((JCClassDecl) type.get()).defs) { + if (def instanceof JCMethodDecl) { + JCMethodDecl md = (JCMethodDecl) def; + if (!md.name.contentEquals("")) continue; + if (isTolerate(type, md)) continue; + if (md.params != null && md.params.length() == 1) { + JCExpression paramType = md.params.get(0).vartype; + if (paramType instanceof JCTypeApply) { + JCTypeApply paramType_ = (JCTypeApply) paramType; + if (paramType_.clazz instanceof JCIdent && ((JCIdent) paramType_.clazz).name.contentEquals(builderClassName)) { + List paramArgs = paramType_.arguments; + if (paramArgs.size() >= 2) { + JCExpression argLast = paramArgs.get(paramArgs.size() - 1); + JCExpression argLast2 = paramArgs.get(paramArgs.size() - 2); + if (argLast instanceof JCWildcard && argLast2 instanceof JCWildcard) { + return true; + } + } + } + } + } + } + } + } + return false; + } }