Skip to content

Commit

Permalink
Partial fix for ASTConverterTest2.test0512 - missing return type with…
Browse files Browse the repository at this point in the history
… name matching compilation unit treat as constructor

Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed May 7, 2024
1 parent 3b8f7b8 commit 7792b16
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,26 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
if(isConstructor && !javacNameMatchesInitAndMethodNameMatchesTypeName) {
malformed = true;
}
if( javacNameMatchesInit && !isConstructor ) {
if( javacNameMatchesError || (javacNameMatchesInit && !isConstructor )) {
malformed = true;
}

if( javacNameMatchesError) {
malformed = true;
} else {
res.setName(this.ast.newSimpleName(methodDeclName));
}
JCTree retTypeTree = javac.getReturnType();
Type retType = null;
if( !javacNameMatchesError) {
res.setName(this.ast.newSimpleName(methodDeclName));
} else {
// javac name is an error, so let's treat the return type as the name
if( retTypeTree instanceof JCIdent jcid) {
res.setName(this.ast.newSimpleName(jcid.getName().toString()));
retTypeTree = null;
if( jcid.toString().equals(getNodeName(parent))) {
res.setConstructor(true);
isConstructor = true;
}
}
}

if( retTypeTree == null ) {
if( isConstructor && this.ast.apiLevel == AST.JLS2_INTERNAL ) {
retType = this.ast.newPrimitiveType(convert(TypeKind.VOID));
Expand Down Expand Up @@ -716,11 +725,10 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
}
}


if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
res.setReturnType2(retType);
} else {
if (retType != null) {
if( retType != null ) {
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
res.setReturnType2(retType);
} else {
res.internalSetReturnType(retType);
}
}
Expand Down

0 comments on commit 7792b16

Please sign in to comment.