"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

StaticTypeCheckingSupport.java  (apache-groovy-src-3.0.8):StaticTypeCheckingSupport.java  (apache-groovy-src-3.0.9)
skipping to change at line 647 skipping to change at line 647
*/ */
public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right) { public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right) {
return checkCompatibleAssignmentTypes(left, right, null); return checkCompatibleAssignmentTypes(left, right, null);
} }
public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right, final Expression rightExpression) { public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right, final Expression rightExpression) {
return checkCompatibleAssignmentTypes(left, right, rightExpression, true ); return checkCompatibleAssignmentTypes(left, right, rightExpression, true );
} }
public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right, final Expression rightExpression, final boolean allowConst ructorCoercion) { public static boolean checkCompatibleAssignmentTypes(final ClassNode left, f inal ClassNode right, final Expression rightExpression, final boolean allowConst ructorCoercion) {
if (!isPrimitiveType(left) && isNullConstant(rightExpression)) {
return true;
}
ClassNode leftRedirect = left.redirect(); ClassNode leftRedirect = left.redirect();
ClassNode rightRedirect = right.redirect(); ClassNode rightRedirect = right.redirect();
if (leftRedirect == rightRedirect) return true; if (leftRedirect == rightRedirect) return true;
if (leftRedirect.isArray() && rightRedirect.isArray()) { if (leftRedirect.isArray() && rightRedirect.isArray()) {
return checkCompatibleAssignmentTypes(leftRedirect.getComponentType( ), rightRedirect.getComponentType(), rightExpression, false); return checkCompatibleAssignmentTypes(leftRedirect.getComponentType( ), rightRedirect.getComponentType(), rightExpression, false);
} }
if (right == VOID_TYPE || right == void_WRAPPER_TYPE) { if (right == VOID_TYPE || right == void_WRAPPER_TYPE) {
return left == VOID_TYPE || left == void_WRAPPER_TYPE; return left == VOID_TYPE || left == void_WRAPPER_TYPE;
skipping to change at line 669 skipping to change at line 673
if (isNumberType(rightRedirect) || WideningCategories.isNumberCategory(r ightRedirect)) { if (isNumberType(rightRedirect) || WideningCategories.isNumberCategory(r ightRedirect)) {
if (BigDecimal_TYPE == leftRedirect || Number_TYPE == leftRedirect) { if (BigDecimal_TYPE == leftRedirect || Number_TYPE == leftRedirect) {
// any number can be assigned to BigDecimal or Number // any number can be assigned to BigDecimal or Number
return true; return true;
} }
if (BigInteger_TYPE == leftRedirect) { if (BigInteger_TYPE == leftRedirect) {
return WideningCategories.isBigIntCategory(getUnwrapper(rightRed irect)) || rightRedirect.isDerivedFrom(BigInteger_TYPE); return WideningCategories.isBigIntCategory(getUnwrapper(rightRed irect)) || rightRedirect.isDerivedFrom(BigInteger_TYPE);
} }
} }
// if rightExpression is null and leftExpression is not a primitive type // anything can be assigned to an Object, String, [Bb]oolean or Class re
, it's ok ceiver; except null to boolean
boolean rightExpressionIsNull = isNullConstant(rightExpression); if (isWildcardLeftHandSide(leftRedirect) && !(boolean_TYPE.equals(left)
if (rightExpressionIsNull && !isPrimitiveType(left)) { && isNullConstant(rightExpression))) return true;
return true;
}
// on an assignment everything that can be done by a GroovyCast is allow
ed
// anything can be assigned to an Object, String, Boolean or Class typed
variable
if (isWildcardLeftHandSide(leftRedirect) && !(boolean_TYPE.equals(left)
&& rightExpressionIsNull)) return true;
// char as left expression if (leftRedirect == char_TYPE && rightRedirect == Character_TYPE) return
if (leftRedirect == char_TYPE && rightRedirect == STRING_TYPE) { true;
if (rightExpression instanceof ConstantExpression) { if (leftRedirect == Character_TYPE && rightRedirect == char_TYPE) return
String value = rightExpression.getText(); true;
return value.length() == 1; if ((leftRedirect == char_TYPE || leftRedirect == Character_TYPE) && rig
} htRedirect == STRING_TYPE) {
} return rightExpression instanceof ConstantExpression && rightExpress
if (leftRedirect == Character_TYPE && (rightRedirect == STRING_TYPE || r ion.getText().length() == 1;
ightExpressionIsNull)) {
return rightExpressionIsNull || (rightExpression instanceof Constant
Expression && rightExpression.getText().length() == 1);
} }
// if left is Enum and right is String or GString we do valueOf // if left is Enum and right is String or GString we do valueOf
if (leftRedirect.isDerivedFrom(Enum_Type) && (rightRedirect == GSTRING_T YPE || rightRedirect == STRING_TYPE)) { if (leftRedirect.isDerivedFrom(Enum_Type) && (rightRedirect == GSTRING_T YPE || rightRedirect == STRING_TYPE)) {
return true; return true;
} }
// if right is array, map or collection we try invoking the constructor // if right is array, map or collection we try invoking the constructor
if (allowConstructorCoercion && isGroovyConstructorCompatible(rightExpre ssion)) { if (allowConstructorCoercion && isGroovyConstructorCompatible(rightExpre ssion)) {
// TODO: in case of the array we could maybe make a partial check // TODO: in case of the array we could maybe make a partial check
skipping to change at line 1375 skipping to change at line 1366
return true; return true;
} }
static void addMethodLevelDeclaredGenerics(final MethodNode method, final Ma p<GenericsTypeName, GenericsType> resolvedPlaceholders) { static void addMethodLevelDeclaredGenerics(final MethodNode method, final Ma p<GenericsTypeName, GenericsType> resolvedPlaceholders) {
ClassNode dummy = OBJECT_TYPE.getPlainNodeReference(); ClassNode dummy = OBJECT_TYPE.getPlainNodeReference();
dummy.setGenericsTypes(method.getGenericsTypes()); dummy.setGenericsTypes(method.getGenericsTypes());
GenericsUtils.extractPlaceholders(dummy, resolvedPlaceholders); GenericsUtils.extractPlaceholders(dummy, resolvedPlaceholders);
} }
protected static boolean typeCheckMethodsWithGenerics(final ClassNode receiv er, final ClassNode[] argumentTypes, final MethodNode candidateMethod) { protected static boolean typeCheckMethodsWithGenerics(final ClassNode receiv er, final ClassNode[] argumentTypes, final MethodNode candidateMethod) {
boolean isExtensionMethod = candidateMethod instanceof ExtensionMethodNo if (candidateMethod instanceof ExtensionMethodNode) {
de; ClassNode[] realTypes = new ClassNode[argumentTypes.length + 1];
if (!isExtensionMethod realTypes[0] = receiver; // object expression is implicit argument
&& receiver.isUsingGenerics() System.arraycopy(argumentTypes, 0, realTypes, 1, argumentTypes.lengt
h);
MethodNode realMethod = ((ExtensionMethodNode) candidateMethod).getE
xtensionMethodNode();
return typeCheckMethodsWithGenerics(realMethod.getDeclaringClass(),
realTypes, realMethod, true);
}
if (receiver.isUsingGenerics()
&& receiver.equals(CLASS_Type) && receiver.equals(CLASS_Type)
&& !candidateMethod.getDeclaringClass().equals(CLASS_Type)) { && !candidateMethod.getDeclaringClass().equals(CLASS_Type)) {
return typeCheckMethodsWithGenerics(receiver.getGenericsTypes()[0].g etType(), argumentTypes, candidateMethod); return typeCheckMethodsWithGenerics(receiver.getGenericsTypes()[0].g etType(), argumentTypes, candidateMethod);
} }
// both candidate method and receiver have generic information so a chec
k is possible return typeCheckMethodsWithGenerics(receiver, argumentTypes, candidateMe
GenericsType[] genericsTypes = candidateMethod.getGenericsTypes(); thod, false);
boolean methodUsesGenerics = (genericsTypes != null && genericsTypes.len
gth > 0);
if (isExtensionMethod && methodUsesGenerics) {
ClassNode[] dgmArgs = new ClassNode[argumentTypes.length + 1];
dgmArgs[0] = receiver;
System.arraycopy(argumentTypes, 0, dgmArgs, 1, argumentTypes.length)
;
MethodNode extensionMethodNode = ((ExtensionMethodNode) candidateMet
hod).getExtensionMethodNode();
return typeCheckMethodsWithGenerics(extensionMethodNode.getDeclaring
Class(), dgmArgs, extensionMethodNode, true);
} else {
return typeCheckMethodsWithGenerics(receiver, argumentTypes, candida
teMethod, false);
}
} }
private static boolean typeCheckMethodsWithGenerics(final ClassNode receiver , final ClassNode[] argumentTypes, final MethodNode candidateMethod, final boole an isExtensionMethod) { private static boolean typeCheckMethodsWithGenerics(final ClassNode receiver , final ClassNode[] argumentTypes, final MethodNode candidateMethod, final boole an isExtensionMethod) {
boolean failure = false; boolean failure = false;
// correct receiver for inner class // correct receiver for inner class
// we assume the receiver is an instance of the declaring class of the // we assume the receiver is an instance of the declaring class of the
// candidate method, but findMethod returns also outer class methods // candidate method, but findMethod returns also outer class methods
// for that receiver. For now we skip receiver based checks in that case // for that receiver. For now we skip receiver based checks in that case
// TODO: correct generics for when receiver is to be skipped // TODO: correct generics for when receiver is to be skipped
 End of changes. 5 change blocks. 
47 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)