diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 792e44cc1692..a2fef0e4046d 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList; @@ -386,7 +385,7 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl ourQNameToUnboxed = new HashMap<>(); @@ -165,18 +165,19 @@ public class TypesUtil { ourUnaryOperationsToOperatorNames.put(GroovyTokenTypes.mBNOT, BITWISE_NEGATE); } - private static final TObjectIntHashMap TYPE_TO_RANK = new TObjectIntHashMap<>(); + static final TObjectIntHashMap TYPE_TO_RANK = new TObjectIntHashMap<>(); static { - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_BYTE, 1); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_SHORT, 2); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_INTEGER, 3); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_LONG, 4); - TYPE_TO_RANK.put(GroovyCommonClassNames.JAVA_MATH_BIG_INTEGER, 5); - TYPE_TO_RANK.put(GroovyCommonClassNames.JAVA_MATH_BIG_DECIMAL, 6); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_FLOAT, 7); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_DOUBLE, 8); - TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_NUMBER, 9); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_BYTE, BYTE_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_CHARACTER, CHARACTER_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_SHORT, SHORT_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_INTEGER, INTEGER_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_LONG, LONG_RANK); + TYPE_TO_RANK.put(GroovyCommonClassNames.JAVA_MATH_BIG_INTEGER, BIG_INTEGER_RANK); + TYPE_TO_RANK.put(GroovyCommonClassNames.JAVA_MATH_BIG_DECIMAL, BIG_DECIMAL_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_FLOAT, FLOAT_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_DOUBLE, DOUBLE_RANK); + TYPE_TO_RANK.put(CommonClassNames.JAVA_LANG_NUMBER, 10); } private static final List LUB_NUMERIC_TYPES = ContainerUtil.newArrayList( @@ -277,6 +278,7 @@ public class TypesUtil { @NotNull PsiElement context, @NotNull ApplicableTo position) { if (!(context instanceof GroovyPsiElement)) return null; + if (targetType.equals(actualType)) return ConversionResult.OK; for (GrTypeConverter converter : GrTypeConverter.EP_NAME.getExtensions()) { if (!converter.isApplicableTo(position)) continue; final ConversionResult result = converter.isConvertibleEx(targetType, actualType, (GroovyPsiElement)context, position); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrBooleanTypeConverter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrBooleanTypeConverter.java index 444fe15ee619..fa63b55c0096 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrBooleanTypeConverter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrBooleanTypeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ public class GrBooleanTypeConverter extends GrTypeConverter { @Override public boolean isApplicableTo(@NotNull ApplicableTo position) { - return true; + return position != ApplicableTo.EXPLICIT_CAST; } @Nullable @@ -43,7 +43,6 @@ public class GrBooleanTypeConverter extends GrTypeConverter { switch (currentPosition) { case METHOD_PARAMETER: return null; - case EXPLICIT_CAST: case ASSIGNMENT: case RETURN_VALUE: return ConversionResult.OK; diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrCharConverter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrCharConverter.java index 495f8809af71..f2659b4f34e8 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrCharConverter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrCharConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ public class GrCharConverter extends GrTypeConverter { @Override public boolean isApplicableTo(@NotNull ApplicableTo position) { - return position == ApplicableTo.EXPLICIT_CAST || position == ApplicableTo.ASSIGNMENT || position == ApplicableTo.RETURN_VALUE; + return position == ApplicableTo.ASSIGNMENT || position == ApplicableTo.RETURN_VALUE; } @Nullable @@ -45,10 +45,9 @@ public class GrCharConverter extends GrTypeConverter { if (!PsiType.CHAR.equals(TypesUtil.unboxPrimitiveTypeWrapper(lType))) return null; if (PsiType.CHAR.equals(TypesUtil.unboxPrimitiveTypeWrapper(rType))) return ConversionResult.OK; - // can cast and assign numeric types to char + // can assign numeric types to char if (TypesUtil.isNumericType(rType)) { - if (rType instanceof PsiPrimitiveType || - currentPosition != ApplicableTo.EXPLICIT_CAST && TypesUtil.unboxPrimitiveTypeWrapper(rType) instanceof PsiPrimitiveType) { + if (rType instanceof PsiPrimitiveType || TypesUtil.unboxPrimitiveTypeWrapper(rType) instanceof PsiPrimitiveType) { return PsiType.CHAR.equals(lType) ? ConversionResult.OK : ConversionResult.ERROR; } else { @@ -78,8 +77,6 @@ public class GrCharConverter extends GrTypeConverter { if (PsiType.BOOLEAN.equals(TypesUtil.unboxPrimitiveTypeWrapper(rType))) { switch (currentPosition) { - case EXPLICIT_CAST: - return ConversionResult.ERROR; case ASSIGNMENT: case RETURN_VALUE: return ConversionResult.WARNING; @@ -96,8 +93,12 @@ public class GrCharConverter extends GrTypeConverter { // can cast and assign one-symbol strings to char if (!TypesUtil.isClassType(rType, CommonClassNames.JAVA_LANG_STRING)) return null; + return checkSingleSymbolLiteral(context) ? ConversionResult.OK : ConversionResult.ERROR; + } + + public static boolean checkSingleSymbolLiteral(GroovyPsiElement context) { final GrLiteral literal = getLiteral(context); final Object value = literal == null ? null : literal.getValue(); - return value == null ? null : value.toString().length() == 1 ? ConversionResult.OK : ConversionResult.ERROR; + return value != null && value.toString().length() == 1; } } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNullVoidConverter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNullVoidConverter.java index e8c0ae862070..dfb7363afba3 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNullVoidConverter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNullVoidConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ public class GrNullVoidConverter extends GrTypeConverter { @Override public boolean isApplicableTo(@NotNull ApplicableTo position) { switch (position) { - case EXPLICIT_CAST: case RETURN_VALUE: case ASSIGNMENT: case METHOD_PARAMETER: @@ -50,22 +49,7 @@ public class GrNullVoidConverter extends GrTypeConverter { final PsiClassType objectType = TypesUtil.getJavaLangObject(context); - if (currentPosition == ApplicableTo.EXPLICIT_CAST) { - if (PsiType.VOID.equals(TypesUtil.unboxPrimitiveTypeWrapper(targetType))) { // cast to V(v)oid - if (actualType.equals(objectType)) return ConversionResult.WARNING; // cast Object to V(v)oid compiles but fails at runtime - if (PsiType.VOID.equals(targetType)) { // cast to void - // can cast void to void only - return PsiType.VOID.equals(actualType) ? ConversionResult.OK : ConversionResult.ERROR; - } - else { // cast to Void - // can cast Void, void and null to Void - return actualType == PsiType.NULL || PsiType.VOID.equals(TypesUtil.unboxPrimitiveTypeWrapper(actualType)) - ? ConversionResult.OK - : ConversionResult.ERROR; - } - } - } - else if (currentPosition == ApplicableTo.RETURN_VALUE) { + if (currentPosition == ApplicableTo.RETURN_VALUE) { if (targetType.equals(objectType) && PsiType.VOID.equals(actualType)) { return ConversionResult.OK; // can return void from Object } @@ -73,8 +57,6 @@ public class GrNullVoidConverter extends GrTypeConverter { if (PsiType.VOID.equals(actualType)) { switch (currentPosition) { - case EXPLICIT_CAST: - return ConversionResult.ERROR; case RETURN_VALUE: { // we can return void values from method returning enum if (isEnum(targetType)) return ConversionResult.OK; diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNumberConverter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNumberConverter.java index b678568af18c..d1f58ace0f92 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNumberConverter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrNumberConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ public class GrNumberConverter extends GrTypeConverter { @Override public boolean isApplicableTo(@NotNull ApplicableTo position) { - return position == ApplicableTo.ASSIGNMENT || position == ApplicableTo.EXPLICIT_CAST || position == ApplicableTo.RETURN_VALUE; + return position == ApplicableTo.ASSIGNMENT || position == ApplicableTo.RETURN_VALUE; } @Nullable diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrPrimitiveCastConverter.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrPrimitiveCastConverter.kt new file mode 100644 index 000000000000..d9af3372698f --- /dev/null +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/typeEnhancers/GrPrimitiveCastConverter.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.lang.psi.typeEnhancers + +import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT +import com.intellij.psi.PsiPrimitiveType +import com.intellij.psi.PsiType +import com.intellij.psi.PsiType.* +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult.ERROR +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult.OK +import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypeConstants.* +import org.jetbrains.plugins.groovy.lang.psi.typeEnhancers.GrCharConverter.checkSingleSymbolLiteral + +class GrPrimitiveCastConverter : GrTypeConverter() { + + private companion object { + fun PsiType.unbox() = PsiPrimitiveType.getUnboxedType(this) + val numericRanks = arrayOf( + BYTE_RANK, SHORT_RANK, INTEGER_RANK, LONG_RANK, BIG_INTEGER_RANK, BIG_DECIMAL_RANK, FLOAT_RANK, DOUBLE_RANK + ) + } + + override fun isApplicableTo(position: ApplicableTo) = position == ApplicableTo.EXPLICIT_CAST + + override fun isConvertibleEx(lType: PsiType, rType: PsiType, context: GroovyPsiElement, position: ApplicableTo): ConversionResult? { + if (lType.unbox() == rType) return OK // boxing + if (rType.unbox() == lType) return OK // unboxing + + if (rType == VOID) return ERROR + if (lType.equalsToText(JAVA_LANG_OBJECT) || rType.equalsToText(JAVA_LANG_OBJECT)) return OK + if (lType == VOID) return ERROR + if (rType == NULL) return if (lType == BOOLEAN || lType !is PsiPrimitiveType) return OK else ERROR + if (lType.unbox() == VOID || rType.unbox() == VOID) return ERROR + if (lType == BOOLEAN || lType.unbox() == BOOLEAN || rType == BOOLEAN || rType.unbox() == BOOLEAN) return ERROR + if (lType.unbox() == CHAR || rType.unbox() == CHAR) return ERROR + + val lRank = getTypeRank(lType) + if (rType == CHAR) return if (lRank in numericRanks) OK else ERROR + val rRank = getTypeRank(rType) + if (lType == CHAR) return if (checkSingleSymbolLiteral(context) || rType is PsiPrimitiveType && rRank in numericRanks) OK else ERROR + + return if (lRank in numericRanks && rRank in numericRanks) OK else null + } +} \ No newline at end of file diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrReferenceResolveRunner.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrReferenceResolveRunner.kt index fcb9e70d383d..049d78d6b08f 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrReferenceResolveRunner.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/GrReferenceResolveRunner.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,6 +115,11 @@ class GrReferenceResolveRunner(val place: GrReferenceExpression, val processor: return processQualifierType(wildcard.extendsBound, state) } } + if (qualifierType is PsiWildcardType) { + if (qualifierType.isExtends) { + return processQualifierType(qualifierType.extendsBound, state) + } + } // Process trait type conjuncts in reversed order because last applied trait matters. if (qualifierType is GrTraitType) return qualifierType.conjuncts.findLast { !processQualifierType(it, state) } == null diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 6aa6c4df8f82..92addffd4b69 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -206,6 +206,7 @@ + diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrTypeCheckHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrTypeCheckHighlightingTest.groovy index e1ba0654f0fc..f9e02c807792 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrTypeCheckHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrTypeCheckHighlightingTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,7 @@ class GrTypeCheckHighlightingTest extends GrHighlightingTestBase { void testTypeCheckString() { doTest() } - void testCastToBuiltInPrimitiveTypes() { doTest() } - - void testCastToBuiltInBoxedTypes() { doTest() } + void testCastBuiltInTypes() { doTest() } void doTest() { addBigDecimal() diff --git a/plugins/groovy/testdata/highlighting/typecheck/CastBuiltInTypes.groovy b/plugins/groovy/testdata/highlighting/typecheck/CastBuiltInTypes.groovy new file mode 100644 index 000000000000..ca479f5f92f4 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/typecheck/CastBuiltInTypes.groovy @@ -0,0 +1,535 @@ +@groovy.transform.CompileStatic +class CastBuiltinTypes { + + def castObject(Object _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castNull() { + (void) null + (boolean) null + (byte) null + (short) null + (char) null + (int) null + (long) null + (float) null + (double) null + (Void) null + (Boolean) null + (Byte) null + (Short) null + (Character) null + (Integer) null + (Long) null + (Float) null + (Double) null + (BigInteger) null + (BigDecimal) null + (Object) null + } + + void foo() {} + + def castvoid() { + (void) foo() + (boolean) foo() + (byte) foo() + (short) foo() + (char) foo() + (int) foo() + (long) foo() + (float) foo() + (double) foo() + (Void) foo() + (Boolean) foo() + (Byte) foo() + (Short) foo() + (Character) foo() + (Integer) foo() + (Long) foo() + (Float) foo() + (Double) foo() + (BigInteger) foo() + (BigDecimal) foo() + (Object) foo() + } + + Void bar() {} + + def castVoid() { + (void) bar() + (boolean) bar() + (byte) bar() + (short) bar() + (char) bar() + (int) bar() + (long) bar() + (float) bar() + (double) bar() + (Void) bar() + (Boolean) bar() + (Byte) bar() + (Short) bar() + (Character) bar() + (Integer) bar() + (Long) bar() + (Float) bar() + (Double) bar() + (BigInteger) bar() + (BigDecimal) bar() + (Object) bar() + } + + def castboolean(boolean _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castBoolean(Boolean _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castCharacter(Character _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castChar(char _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castbyte(byte _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castshort(short _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castInt(int _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castlong(long _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castfloat(float _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castdouble(double _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castByte(Byte _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castShort(Short _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castInteger(Integer _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castLong(Long _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castFloat(Float _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castDouble(Double _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castBigInteger(BigInteger _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } + + def castBigDecimal(BigDecimal _) { + (void) _ + (boolean) _ + (byte) _ + (short) _ + (char) _ + (int) _ + (long) _ + (float) _ + (double) _ + (Void) _ + (Boolean) _ + (Byte) _ + (Short) _ + (Character) _ + (Integer) _ + (Long) _ + (Float) _ + (Double) _ + (BigInteger) _ + (BigDecimal) _ + (Object) _ + } +} \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInBoxedTypes.groovy b/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInBoxedTypes.groovy deleted file mode 100644 index 2b122afa30c0..000000000000 --- a/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInBoxedTypes.groovy +++ /dev/null @@ -1,280 +0,0 @@ -import groovy.transform.CompileStatic - -@CompileStatic -class FooCastToBuiltinBoxedTypes { - - def castToVoidB() { - (Void) null - (Void) 1 as void - (Void) 1 as boolean - (Void) 1 as byte - (Void) 1 as short - (Void) 1 as char - (Void) 1 as int - (Void) 1 as long - (Void) 1 as float - (Void) 1 as double - (Void) 1 as BigInteger - (Void) 1 as BigDecimal - (Void) 1 as Void - (Void) 1 as Boolean - (Void) 1 as Byte - (Void) 1 as Short - (Void) 1 as Character - (Void) 1 as Integer - (Void) 1 as Long - (Void) 1 as Float - (Void) 1 as Double - (Void) 1 as Object - } - - def castToBigInteger() { - (BigInteger) null - (BigInteger) 1 as void - (BigInteger) 1 as boolean - (BigInteger) 1 as byte - (BigInteger) 1 as short - (BigInteger) 1 as char - (BigInteger) 1 as int - (BigInteger) 1 as long - (BigInteger) 1 as float - (BigInteger) 1 as double - (BigInteger) 1 as BigInteger - (BigInteger) 1 as BigDecimal - (BigInteger) 1 as Void - (BigInteger) 1 as Boolean - (BigInteger) 1 as Byte - (BigInteger) 1 as Short - (BigInteger) 1 as Character - (BigInteger) 1 as Integer - (BigInteger) 1 as Long - (BigInteger) 1 as Float - (BigInteger) 1 as Double - (BigInteger) 1 as Object - } - - def castToBigDecimal() { - (BigDecimal) null - (BigDecimal) 1 as void - (BigDecimal) 1 as boolean - (BigDecimal) 1 as byte - (BigDecimal) 1 as short - (BigDecimal) 1 as char - (BigDecimal) 1 as int - (BigDecimal) 1 as long - (BigDecimal) 1 as float - (BigDecimal) 1 as double - (BigDecimal) 1 as BigInteger - (BigDecimal) 1 as BigDecimal - (BigDecimal) 1 as Void - (BigDecimal) 1 as Boolean - (BigDecimal) 1 as Byte - (BigDecimal) 1 as Short - (BigDecimal) 1 as Character - (BigDecimal) 1 as Integer - (BigDecimal) 1 as Long - (BigDecimal) 1 as Float - (BigDecimal) 1 as Double - (BigDecimal) 1 as Object - } - - def castToBoolean() { - (Boolean) null - (Boolean) 1 as void - (Boolean) 1 as boolean - (Boolean) 1 as byte - (Boolean) 1 as short - (Boolean) 1 as char - (Boolean) 1 as int - (Boolean) 1 as long - (Boolean) 1 as float - (Boolean) 1 as double - (Boolean) 1 as BigInteger - (Boolean) 1 as BigDecimal - (Boolean) 1 as Void - (Boolean) 1 as Boolean - (Boolean) 1 as Byte - (Boolean) 1 as Short - (Boolean) 1 as Character - (Boolean) 1 as Integer - (Boolean) 1 as Long - (Boolean) 1 as Float - (Boolean) 1 as Double - (Boolean) 1 as Object - } - - def castToByte() { - (Byte) null - (Byte) 1 as void - (Byte) 1 as boolean - (Byte) 1 as byte - (Byte) 1 as short - (Byte) 1 as char - (Byte) 1 as int - (Byte) 1 as long - (Byte) 1 as float - (Byte) 1 as double - (Byte) 1 as BigInteger - (Byte) 1 as BigDecimal - (Byte) 1 as Void - (Byte) 1 as Boolean - (Byte) 1 as Byte - (Byte) 1 as Short - (Byte) 1 as Character - (Byte) 1 as Integer - (Byte) 1 as Long - (Byte) 1 as Float - (Byte) 1 as Double - (Byte) 1 as Object - } - - def castToShort() { - (Short) null - (Short) 1 as void - (Short) 1 as boolean - (Short) 1 as byte - (Short) 1 as short - (Short) 1 as char - (Short) 1 as int - (Short) 1 as long - (Short) 1 as float - (Short) 1 as double - (Short) 1 as BigInteger - (Short) 1 as BigDecimal - (Short) 1 as Void - (Short) 1 as Boolean - (Short) 1 as Byte - (Short) 1 as Short - (Short) 1 as Character - (Short) 1 as Integer - (Short) 1 as Long - (Short) 1 as Float - (Short) 1 as Double - (Short) 1 as Object - } - - def castToChar() { - (Character) null - (Character) 1 as void - (Character) 1 as boolean - (Character) 1 as byte - (Character) 1 as short - (Character) 1 as char - (Character) 1 as int - (Character) 1 as long - (Character) 1 as float - (Character) 1 as double - (Character) 1 as BigInteger - (Character) 1 as BigDecimal - (Character) 1 as Void - (Character) 1 as Boolean - (Character) 1 as Byte - (Character) 1 as Short - (Character) 1 as Character - (Character) 1 as Integer - (Character) 1 as Long - (Character) 1 as Float - (Character) 1 as Double - (Character) 1 as Object - } - - def castToInt() { - (Integer) null - (Integer) 1 as void - (Integer) 1 as boolean - (Integer) 1 as byte - (Integer) 1 as short - (Integer) 1 as char - (Integer) 1 as int - (Integer) 1 as long - (Integer) 1 as float - (Integer) 1 as double - (Integer) 1 as BigInteger - (Integer) 1 as BigDecimal - (Integer) 1 as Void - (Integer) 1 as Boolean - (Integer) 1 as Byte - (Integer) 1 as Short - (Integer) 1 as Character - (Integer) 1 as Integer - (Integer) 1 as Long - (Integer) 1 as Float - (Integer) 1 as Double - (Integer) 1 as Object - } - - def castToLong() { - (Long) null - (Long) 1 as void - (Long) 1 as boolean - (Long) 1 as byte - (Long) 1 as short - (Long) 1 as char - (Long) 1 as int - (Long) 1 as long - (Long) 1 as float - (Long) 1 as double - (Long) 1 as BigInteger - (Long) 1 as BigDecimal - (Long) 1 as Void - (Long) 1 as Boolean - (Long) 1 as Byte - (Long) 1 as Short - (Long) 1 as Character - (Long) 1 as Integer - (Long) 1 as Long - (Long) 1 as Float - (Long) 1 as Double - (Long) 1 as Object - } - - def castToFloat() { - (Float) null - (Float) 1 as void - (Float) 1 as boolean - (Float) 1 as byte - (Float) 1 as short - (Float) 1 as char - (Float) 1 as int - (Float) 1 as long - (Float) 1 as float - (Float) 1 as double - (Float) 1 as BigInteger - (Float) 1 as BigDecimal - (Float) 1 as Void - (Float) 1 as Boolean - (Float) 1 as Byte - (Float) 1 as Short - (Float) 1 as Character - (Float) 1 as Integer - (Float) 1 as Long - (Float) 1 as Float - (Float) 1 as Double - (Float) 1 as Object - } - - def castToDouble() { - (Double) null - (Double) 1 as void - (Double) 1 as boolean - (Double) 1 as byte - (Double) 1 as short - (Double) 1 as char - (Double) 1 as int - (Double) 1 as long - (Double) 1 as float - (Double) 1 as double - (Double) 1 as BigInteger - (Double) 1 as BigDecimal - (Double) 1 as Void - (Double) 1 as Boolean - (Double) 1 as Byte - (Double) 1 as Short - (Double) 1 as Character - (Double) 1 as Integer - (Double) 1 as Long - (Double) 1 as Float - (Double) 1 as Double - (Double) 1 as Object - } -} diff --git a/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInPrimitiveTypes.groovy b/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInPrimitiveTypes.groovy deleted file mode 100644 index c6ce17022780..000000000000 --- a/plugins/groovy/testdata/highlighting/typecheck/CastToBuiltInPrimitiveTypes.groovy +++ /dev/null @@ -1,230 +0,0 @@ -import groovy.transform.CompileStatic - -@CompileStatic -class FooCastToBuiltinPrimitiveTypes { - - def castToVoid() { - (void) null - (void) 1 as void // no error, can cast void to void - (void) 1 as boolean - (void) 1 as byte - (void) 1 as short - (void) 1 as char - (void) 1 as int - (void) 1 as long - (void) 1 as float - (void) 1 as double - (void) 1 as BigInteger - (void) 1 as BigDecimal - (void) 1 as Void - (void) 1 as Boolean - (void) 1 as Byte - (void) 1 as Short - (void) 1 as Character - (void) 1 as Integer - (void) 1 as Long - (void) 1 as Float - (void) 1 as Double - (void) 1 as Object // no compile time, but will be runtime error - } - - def castToBoolean() { - (boolean) null - (boolean) 1 as void - (boolean) 1 as boolean - (boolean) 1 as byte - (boolean) 1 as short - (boolean) 1 as char - (boolean) 1 as int - (boolean) 1 as long - (boolean) 1 as float - (boolean) 1 as double - (boolean) 1 as BigInteger - (boolean) 1 as BigDecimal - (boolean) 1 as Void - (boolean) 1 as Boolean - (boolean) 1 as Byte - (boolean) 1 as Short - (boolean) 1 as Character - (boolean) 1 as Integer - (boolean) 1 as Long - (boolean) 1 as Float - (boolean) 1 as Double - (boolean) 1 as Object - } - - def castToByte() { - (byte) null - (byte) 1 as void - (byte) 1 as boolean - (byte) 1 as byte - (byte) 1 as short - (byte) 1 as char - (byte) 1 as int - (byte) 1 as long - (byte) 1 as float - (byte) 1 as double - (byte) 1 as BigInteger - (byte) 1 as BigDecimal - (byte) 1 as Void - (byte) 1 as Boolean - (byte) 1 as Byte - (byte) 1 as Short - (byte) 1 as Character - (byte) 1 as Integer - (byte) 1 as Long - (byte) 1 as Float - (byte) 1 as Double - (byte) 1 as Object - } - - def castToShort() { - (short) null - (short) 1 as void - (short) 1 as boolean - (short) 1 as byte - (short) 1 as short - (short) 1 as char - (short) 1 as int - (short) 1 as long - (short) 1 as float - (short) 1 as double - (short) 1 as BigInteger - (short) 1 as BigDecimal - (short) 1 as Void - (short) 1 as Boolean - (short) 1 as Byte - (short) 1 as Short - (short) 1 as Character - (short) 1 as Integer - (short) 1 as Long - (short) 1 as Float - (short) 1 as Double - (short) 1 as Object - } - - def castToChar() { - (char) null - (char) 1 as void - (char) 1 as boolean - (char) 1 as byte - (char) 1 as short - (char) 1 as char - (char) 1 as int - (char) 1 as long - (char) 1 as float - (char) 1 as double - (char) 1 as BigInteger - (char) 1 as BigDecimal - (char) 1 as Void - (char) 1 as Boolean - (char) 1 as Byte - (char) 1 as Short - (char) 1 as Character - (char) 1 as Integer - (char) 1 as Long - (char) 1 as Float - (char) 1 as Double - (char) 1 as Object - } - - def castToInt() { - (int) null - (int) 1 as void - (int) 1 as boolean - (int) 1 as byte - (int) 1 as short - (int) 1 as char - (int) 1 as int - (int) 1 as long - (int) 1 as float - (int) 1 as double - (int) 1 as BigInteger - (int) 1 as BigDecimal - (int) 1 as Void - (int) 1 as Boolean - (int) 1 as Byte - (int) 1 as Short - (int) 1 as Character - (int) 1 as Integer - (int) 1 as Long - (int) 1 as Float - (int) 1 as Double - (int) 1 as Object - } - - def castToLong() { - (long) null - (long) 1 as void - (long) 1 as boolean - (long) 1 as byte - (long) 1 as short - (long) 1 as char - (long) 1 as int - (long) 1 as long - (long) 1 as float - (long) 1 as double - (long) 1 as BigInteger - (long) 1 as BigDecimal - (long) 1 as Void - (long) 1 as Boolean - (long) 1 as Byte - (long) 1 as Short - (long) 1 as Character - (long) 1 as Integer - (long) 1 as Long - (long) 1 as Float - (long) 1 as Double - (long) 1 as Object - } - - def castToFloat() { - (float) null - (float) 1 as void - (float) 1 as boolean - (float) 1 as byte - (float) 1 as short - (float) 1 as char - (float) 1 as int - (float) 1 as long - (float) 1 as float - (float) 1 as double - (float) 1 as BigInteger - (float) 1 as BigDecimal - (float) 1 as Void - (float) 1 as Boolean - (float) 1 as Byte - (float) 1 as Short - (float) 1 as Character - (float) 1 as Integer - (float) 1 as Long - (float) 1 as Float - (float) 1 as Double - (float) 1 as Object - } - - def castToDouble() { - (double) null - (double) 1 as void - (double) 1 as boolean - (double) 1 as byte - (double) 1 as short - (double) 1 as char - (double) 1 as int - (double) 1 as long - (double) 1 as float - (double) 1 as double - (double) 1 as BigInteger - (double) 1 as BigDecimal - (double) 1 as Void - (double) 1 as Boolean - (double) 1 as Byte - (double) 1 as Short - (double) 1 as Character - (double) 1 as Integer - (double) 1 as Long - (double) 1 as Float - (double) 1 as Double - (double) 1 as Object - } -}