Skip to content

Commit

Permalink
Other IDE fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Oct 18, 2023
1 parent acd8f10 commit 1647f6b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public static TypeDeclaration FindTargetTypeDeclaration(
// The member is in the base class (because of single class inheritance in C#, there can be only one base
// class).
return memberReferenceExpression.FindFirstParentTypeDeclaration().BaseTypes
.Select(type => typeDeclarationLookupTable.Lookup(type))
.SingleOrDefault(typeDeclaration => typeDeclaration != null && typeDeclaration.ClassType == ClassType.Class);
.Select(typeDeclarationLookupTable.Lookup)
.SingleOrDefault(typeDeclaration => typeDeclaration is { ClassType: ClassType.Class });
}

if (target is IdentifierExpression or IndexerExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax;
public static class MethodDeclarationExtensions
{
public static bool IsConstructor(this MethodDeclaration methodDeclaration) =>
(methodDeclaration.GetMemberResolveResult()?.Member as IMethod)?.IsConstructor == true;
methodDeclaration.GetMemberResolveResult()?.Member is IMethod { IsConstructor: true };
}
21 changes: 6 additions & 15 deletions src/Hastlayer/Hast.Transformer/Models/IArraySizeHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,10 @@ public interface IArraySizeHolder

public static class ArraySizeHolderExtensions
{
public static IArraySize GetSizeOrThrow(this IArraySizeHolder arraySizeHolder, AstNode arrayHolder)
{
var size = arraySizeHolder.GetSize(arrayHolder);

if (size == null)
{
throw new NotSupportedException(
"The length of the array holder \"" + arrayHolder.GetFullName() + "\" couldn't be statically " +
"determined. Only arrays with dimensions defined at compile-time are supported. If the array size is " +
"actually static just Hastlayer can't figure it out for some reason then you can configure it " +
"manually via TransformerConfiguration by using the quoted full name.");
}

return size;
}
public static IArraySize GetSizeOrThrow(this IArraySizeHolder arraySizeHolder, AstNode arrayHolder) =>
arraySizeHolder.GetSize(arrayHolder) ?? throw new NotSupportedException(
$"The length of the array holder \"{arrayHolder.GetFullName()}\" couldn't be statically determined. Only " +
$"arrays with dimensions defined at compile-time are supported. If the array size is actually static " +
$"just Hastlayer can't figure it out for some reason then you can configure it manually via " +
$"TransformerConfiguration by using the quoted full name.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ void Replace(IType newType) =>
Replace(_knownTypeLookupTable.Lookup(KnownTypeCode.Int64));
}
else if (unaryOperatorExpression.Operator == UnaryOperatorType.Minus &&
((unaryOperatorExpression.Expression as CastExpression)?.Type as PrimitiveType)?.KnownTypeCode == KnownTypeCode.UInt32)
unaryOperatorExpression.Expression is CastExpression { Type: PrimitiveType { KnownTypeCode: KnownTypeCode.UInt32 } } castExpression)
{
// For an int value the AST can contain -(uint)value if the original code was (uint)-value. Fixing that
// here.
unaryOperatorExpression.Expression.ReplaceWith(((CastExpression)unaryOperatorExpression.Expression).Expression);
castExpression.ReplaceWith(castExpression.Expression);
}
}

Expand Down

0 comments on commit 1647f6b

Please sign in to comment.