Skip to content

Commit

Permalink
Don't add null convertToType result to lists
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon authored and mickaelistria committed May 31, 2024
1 parent 85254a3 commit 9b12d71
Showing 1 changed file with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ private AbstractTypeDeclaration convertClassDecl(JCClassDecl javacClassDecl, AST
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
javacClassDecl.getImplementsClause().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(typeDeclaration.superInterfaceTypes()::add);
} else {
Iterator<JCExpression> it = javacClassDecl.getImplementsClause().iterator();
Expand Down Expand Up @@ -471,6 +472,7 @@ private AbstractTypeDeclaration convertClassDecl(JCClassDecl javacClassDecl, AST
if( this.ast.apiLevel >= AST.JLS17_INTERNAL) {
javacClassDecl.getPermitsClause().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(typeDeclaration.permittedTypes()::add);
if (!javacClassDecl.getPermitsClause().isEmpty()) {
int permitsOffset = this.rawText.substring(javacClassDecl.pos).indexOf("permits") + javacClassDecl.pos;
Expand Down Expand Up @@ -804,7 +806,10 @@ private MethodDeclaration convertMethodDecl(JCMethodDecl javac, ASTNode parent)
if (this.ast.apiLevel < AST.JLS8_INTERNAL) {
res.thrownExceptions().add(toName(thrown));
} else {
res.thrownExceptionTypes().add(convertToType(thrown));
Type type = convertToType(thrown);
if (type != null) {
res.thrownExceptionTypes().add(type);
}
}
}
if( malformed ) {
Expand Down Expand Up @@ -1086,7 +1091,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
commonSettings(res2, javac);
methodInvocation.getArguments().stream().map(this::convertExpression).forEach(res2.arguments()::add);
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
methodInvocation.getTypeArguments().stream().map(this::convertToType).forEach(res2.typeArguments()::add);
methodInvocation.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res2.typeArguments()::add);
}
if( superCall1 ) {
res2.setQualifier(toName(fa.getExpression()));
Expand Down Expand Up @@ -1114,7 +1122,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
commonSettings(res2, javac);
methodInvocation.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add);
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
methodInvocation.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
methodInvocation.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
if( superCall1 ) {
res2.setQualifier(toName(fa.getExpression()));
Expand All @@ -1134,7 +1145,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
}
if (methodInvocation.getTypeArguments() != null) {
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
methodInvocation.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
methodInvocation.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
}
return res;
Expand Down Expand Up @@ -1311,7 +1325,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
commonSettings(res, javac);
res.setType(convertToType(qualifierExpression));
if (jcMemberReference.getTypeArguments() != null) {
jcMemberReference.getTypeArguments().map(this::convertToType).forEach(res.typeArguments()::add);
jcMemberReference.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
return res;
} else if (qualifierExpression.getKind() == Kind.PARAMETERIZED_TYPE || qualifierExpression.getKind() == Kind.ARRAY_TYPE) {
Expand All @@ -1320,7 +1337,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
res.setType(convertToType(qualifierExpression));
res.setName((SimpleName)convertName(jcMemberReference.getName()));
if (jcMemberReference.getTypeArguments() != null) {
jcMemberReference.getTypeArguments().map(this::convertToType).forEach(res.typeArguments()::add);
jcMemberReference.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
return res;
} else {
Expand All @@ -1329,7 +1349,10 @@ private Expression convertExpressionImpl(JCExpression javac) {
res.setExpression(convertExpression(jcMemberReference.getQualifierExpression()));
res.setName((SimpleName)convertName(jcMemberReference.getName()));
if (jcMemberReference.getTypeArguments() != null) {
jcMemberReference.getTypeArguments().map(this::convertToType).forEach(res.typeArguments()::add);
jcMemberReference.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
return res;
}
Expand Down Expand Up @@ -1570,7 +1593,10 @@ private SuperConstructorInvocation convertSuperConstructorInvocation(JCMethodInv

//res.setFlags(javac.getFlags() | ASTNode.MALFORMED);
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
javac.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
if( javac.getMethodSelect() instanceof JCFieldAccess jcfa && jcfa.selected != null ) {
res.setExpression(convertExpression(jcfa.selected));
Expand All @@ -1584,7 +1610,10 @@ private ConstructorInvocation convertThisConstructorInvocation(JCMethodInvocatio
commonSettings(res, javac);
javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add);
if( this.ast.apiLevel > AST.JLS2_INTERNAL) {
javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
javac.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
}
return res;
}
Expand Down Expand Up @@ -2162,7 +2191,10 @@ Type convertToType(JCTree javac) {
if (javac instanceof JCTypeUnion union) {
UnionType res = this.ast.newUnionType();
commonSettings(res, javac);
union.getTypeAlternatives().stream().map(this::convertToType).forEach(res.types()::add);
union.getTypeAlternatives().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.types()::add);
return res;
}
if (javac instanceof JCArrayTypeTree jcArrayType) {
Expand All @@ -2184,7 +2216,10 @@ Type convertToType(JCTree javac) {
if( this.ast.apiLevel != AST.JLS2_INTERNAL) {
ParameterizedType res = this.ast.newParameterizedType(convertToType(jcTypeApply.getType()));
commonSettings(res, javac);
jcTypeApply.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add);
jcTypeApply.getTypeArguments().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.typeArguments()::add);
return res;
} else {
return convertToType(jcTypeApply.clazz);
Expand All @@ -2205,7 +2240,10 @@ Type convertToType(JCTree javac) {
if (javac instanceof JCTypeIntersection jcTypeIntersection) {
IntersectionType res = this.ast.newIntersectionType();
commonSettings(res, javac);
jcTypeIntersection.getBounds().stream().map(this::convertToType).forEach(res.types()::add);
jcTypeIntersection.getBounds().stream()
.map(this::convertToType)
.filter(Objects::nonNull)
.forEach(res.types()::add);
return res;
}
if (javac instanceof JCAnnotatedType jcAnnotatedType) {
Expand Down

0 comments on commit 9b12d71

Please sign in to comment.