From e235ec2dcc109b74e78ed04ce3e4af9ff36b95ed Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Wed, 14 Feb 2024 19:21:19 +0100 Subject: [PATCH] verifying that new expression have non or the correct amount of type parameters. --- .../semantics/HaxeTypeAnnotator.java | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeTypeAnnotator.java b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeTypeAnnotator.java index 94f9d21d6..9f6d5edb5 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeTypeAnnotator.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/annotator/semantics/HaxeTypeAnnotator.java @@ -54,31 +54,43 @@ public void run() { static public void checkValidTypeParameters(final HaxeType type, final AnnotationHolder holder) { PsiElement context = type.getContext(); - if (context != null && context.getParent() instanceof HaxeTypeTag) { + if (context == null || context.getParent() == null) return; + if (context instanceof HaxeNewExpression) { + if (type.getTypeParam() != null) { + checkTypeParametersForType(type, holder); + } + } + else if (context.getParent() instanceof HaxeTypeTag) { if (context.getParent().getParent() instanceof HaxeParameter) { // if HaxeType is part of a method parameter then type specifics are possibly inherited // this check is currently only checking assignment to variables and arguments when calling methods return; } - SpecificHaxeClassReference haxeClassReference = HaxeTypeResolver.getTypeFromType(type).getClassType(); - if (haxeClassReference != null) { - if (HaxeTypeResolver.isTypeParameter(type.getReferenceExpression())) { - // ignoring check if type is Type Parameter itself. - return; - } - HaxeClass haxeClass = haxeClassReference.getHaxeClass(); - if (haxeClass != null) { - // Dynamic is special and does not require Type parameter to de specified - if (DYNAMIC.equalsIgnoreCase(haxeClass.getName())) return; - int typeParameterCount = type.getTypeParam() == null ? 0 : type.getTypeParam().getTypeList().getTypeListPartList().size(); - int classParameterCount = countTypeParameters(haxeClass); + checkTypeParametersForType(type, holder); + } + } - if (typeParameterCount != classParameterCount) { - String typeName = getTypeName(type.getReferenceExpression().getIdentifier()); - holder.newAnnotation(HighlightSeverity.ERROR, HaxeBundle.message("haxe.inspections.parameter.count.mismatch.description", typeName, classParameterCount, typeParameterCount)) - .range(type) - .create(); - } + private static void checkTypeParametersForType(HaxeType type, AnnotationHolder holder) { + SpecificHaxeClassReference haxeClassReference = HaxeTypeResolver.getTypeFromType(type).getClassType(); + if (haxeClassReference != null) { + if (HaxeTypeResolver.isTypeParameter(type.getReferenceExpression())) { + // ignoring check if type is Type Parameter itself. + return; + } + HaxeClass haxeClass = haxeClassReference.getHaxeClass(); + if (haxeClass != null) { + // Dynamic is special and does not require Type parameter to de specified + if (DYNAMIC.equalsIgnoreCase(haxeClass.getName())) return; + int typeParameterCount = type.getTypeParam() == null ? 0 : type.getTypeParam().getTypeList().getTypeListPartList().size(); + int classParameterCount = countTypeParameters(haxeClass); + + if (typeParameterCount != classParameterCount) { + String typeName = getTypeName(type.getReferenceExpression().getIdentifier()); + holder.newAnnotation(HighlightSeverity.ERROR, + HaxeBundle.message("haxe.inspections.parameter.count.mismatch.description", typeName, classParameterCount, + typeParameterCount)) + .range(type) + .create(); } } }