Skip to content

Commit

Permalink
Fix dom part of ASTConverter15JLS8Test.test0016 and others
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed May 2, 2024
1 parent 26964c4 commit 83a66bf
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ private Name toName(JCTree expression) {
if (expression instanceof JCAnnotatedType jcat) {
return toName(jcat.underlyingType);
}
if (expression instanceof JCTypeApply jcta) {
return toName(jcta.clazz);
}
throw new UnsupportedOperationException("toName for " + expression + " (" + expression.getClass().getName() + ")");
}

Expand Down Expand Up @@ -1111,7 +1114,9 @@ private Expression convertExpression(JCExpression javac) {
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
res.setType(convertToType(newClass.getIdentifier()));
} else {
res.setName(toName(newClass.clazz));
Name n = toName(newClass.clazz);
if( n != null )
res.setName(n);
}
if (newClass.getClassBody() != null && newClass.getClassBody() instanceof JCClassDecl javacAnon) {
AnonymousClassDeclaration anon = createAnonymousClassDeclaration(javacAnon, res);
Expand Down Expand Up @@ -1442,7 +1447,9 @@ private ConstructorInvocation convertThisConstructorInvocation(JCMethodInvocatio
ConstructorInvocation res = this.ast.newConstructorInvocation();
commonSettings(res, javac);
javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add);
javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
}
return res;
}

Expand Down Expand Up @@ -1567,7 +1574,9 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) {
VariableDeclarationStatement res = this.ast.newVariableDeclarationStatement(fragment);
commonSettings(res, javac);
if (jcVariableDecl.vartype != null) {
res.setType(convertToType(jcVariableDecl.vartype));
Type t = convertToType(jcVariableDecl.vartype);
if( t != null )
res.setType(t);
} else if( jcVariableDecl.declaredUsingVar() ) {
SimpleType st = this.ast.newSimpleType(this.ast.newSimpleName("var"));
st.setSourceRange(javac.getStartPosition(), 3);
Expand Down Expand Up @@ -1840,16 +1849,24 @@ private Type convertToType(JCTree javac) {
}
if (javac instanceof JCFieldAccess qualified) {
try {
Name qn = toName(qualified);
SimpleType res = this.ast.newSimpleType(qn);
commonSettings(res, qualified);
return res;
if( qualified.getExpression() == null ) {
Name qn = toName(qualified);
SimpleType res = this.ast.newSimpleType(qn);
commonSettings(res, qualified);
return res;
}
} catch (Exception ex) {
// case of not translatable name, eg because of generics
// TODO find a better check instead of relying on exception
}
// case of not translatable name, eg because of generics
// TODO find a better check instead of relying on exception
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
QualifiedType res = this.ast.newQualifiedType(convertToType(qualified.getExpression()), (SimpleName)convert(qualified.getIdentifier()));
commonSettings(res, qualified);
return res;
} else {
SimpleType res = this.ast.newSimpleType(toName(qualified));
commonSettings(res, javac);
return res;
}
}
if (javac instanceof JCPrimitiveTypeTree primitiveTypeTree) {
Expand Down

0 comments on commit 83a66bf

Please sign in to comment.