Skip to content
Open
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ Till Brychcy <[email protected]>
Victor Williams Stafusa da Silva <[email protected]>
Yonatan Sherwin <[email protected]>
Yun Zhi Lin <[email protected]>
Dymitr "ay0ks" <[email protected]>

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.
51 changes: 28 additions & 23 deletions src/core/lombok/javac/handlers/HandleSuperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("<init>");
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("<init>")) 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<JCExpression> 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;
}
}