001 /* 002 * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered 003 * by the modified BSD License. You should have received a copy of the 004 * modified BSD license with this compiler. 005 * 006 * Copyright (c) 2011, Jesper Öqvist 007 * All rights reserved. 008 */ 009 010 /** 011 * JLS $5.1.9 012 * 013 * Add unchecked conversion warnings to the type checking 014 * of assignments, declaration initializers and cast expressions. 015 * 016 * TODO: The unchecked conversion warning can be suppressed with 017 * the SuppressWarnings annotation. 018 */ 019 aspect UncheckedConversion { 020 public void VariableDeclaration.checkWarnings() { 021 if (hasInit() && !suppressWarnings("unchecked")) 022 checkUncheckedConversion(getInit().type(), type()); 023 } 024 025 public void FieldDeclaration.checkWarnings() { 026 if (hasInit() && !suppressWarnings("unchecked")) 027 checkUncheckedConversion(getInit().type(), type()); 028 } 029 030 public void AssignSimpleExpr.checkWarnings() { 031 if (!withinSuppressWarnings("unchecked")) 032 checkUncheckedConversion(getSource().type(), getDest().type()); 033 } 034 035 public void CastExpr.checkWarnings() { 036 if (!withinSuppressWarnings("unchecked")) 037 checkUncheckedConversion(getExpr().type(), getTypeAccess().type()); 038 } 039 040 public void ASTNode.checkUncheckedConversion(TypeDecl source, TypeDecl dest) { 041 if (source.isUncheckedConversionTo(dest)) 042 warning("unchecked conversion from raw type "+source.typeName()+ 043 " to generic type "+dest.typeName()); 044 } 045 046 /** 047 * An unchecked conversion occurs when converting from a 048 * raw type G to a generic type G<T1, ..., Tn>. 049 */ 050 syn boolean TypeDecl.isUncheckedConversionTo(TypeDecl dest) = 051 (!dest.isRawType()) && this.isRawType(); 052 }