Skip to content

Commit

Permalink
Call to super constructor using wrong ast node
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed Apr 5, 2024
1 parent 74e070f commit cf02013
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;

import com.sun.source.tree.CaseTree.CaseKind;
import com.sun.source.tree.LambdaExpressionTree;
import com.sun.tools.javac.code.BoundKind;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.parser.Tokens.Comment;
Expand Down Expand Up @@ -1141,6 +1140,19 @@ private SuperMethodInvocation convertSuperMethodInvocation(JCMethodInvocation ja
}
return res;
}

private SuperConstructorInvocation convertSuperConstructorInvocation(JCMethodInvocation javac) {
SuperConstructorInvocation res = this.ast.newSuperConstructorInvocation();
commonSettings(res, javac);
javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add);

//res.setFlags(javac.getFlags() | ASTNode.MALFORMED);
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
}
return res;
}


private ConstructorInvocation convertThisConstructorInvocation(JCMethodInvocation javac) {
ConstructorInvocation res = this.ast.newConstructorInvocation();
Expand Down Expand Up @@ -1220,6 +1232,18 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) {
return substitute;
}
}
boolean uniqueCaseFound = false;
if (jcExpressionStatement.getExpression() instanceof JCMethodInvocation methodInvocation) {
JCExpression nameExpr = methodInvocation.getMethodSelect();
if (nameExpr instanceof JCIdent ident) {
if (Objects.equals(ident.getName(), Names.instance(this.context)._super)) {
uniqueCaseFound = true;
}
}
}
if( uniqueCaseFound ) {
return convertSuperConstructorInvocation((JCMethodInvocation)jcExpressionStatement.getExpression());
}
ExpressionStatement res = this.ast.newExpressionStatement(convertExpression(jcExpressionStatement.getExpression()));
commonSettings(res, javac);
return res;
Expand Down Expand Up @@ -1460,7 +1484,8 @@ private Type convertToType(JCTree javac) {
return res;
}
if (javac instanceof JCArrayTypeTree jcArrayType) {
ArrayType res = this.ast.newArrayType(convertToType(jcArrayType.getType()));
Type t = convertToType(jcArrayType.getType());
ArrayType res = this.ast.newArrayType(t);
commonSettings(res, javac);
return res;
}
Expand Down

0 comments on commit cf02013

Please sign in to comment.