Revision: 7035
Author: [email protected]
Date: Thu Nov 19 13:48:42 2009
Log: In JsniChecker, suppressed warnings should cascade down to nested  
members.

FieldSerializerCreator suppresses deprecation warnings on generated field  
serializers, which silences warnings regarding the deprecated  
SerializableException.

Review by: bobv
http://code.google.com/p/google-web-toolkit/source/detail?r=7035

Modified:
  /trunk/dev/core/src/com/google/gwt/dev/javac/JsniChecker.java
  /trunk/dev/core/test/com/google/gwt/dev/javac/JsniCheckerTest.java
  /trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/JsniChecker.java       Thu Nov 
 
19 13:48:22 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/JsniChecker.java       Thu Nov 
 
19 13:48:42 2009
@@ -39,10 +39,13 @@
  import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
  import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  import org.eclipse.jdt.internal.compiler.ast.StringLiteral;
+import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  import org.eclipse.jdt.internal.compiler.ast.TypeReference;
  import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
  import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
+import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
  import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
  import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
  import org.eclipse.jdt.internal.compiler.lookup.NestedTypeBinding;
@@ -56,6 +59,7 @@
  import java.util.Locale;
  import java.util.Map;
  import java.util.Set;
+import java.util.Stack;

  /**
   * Tests for access to Java from JSNI. Issues a warning for:
@@ -90,6 +94,43 @@
            new JsniRefChecker(meth,  
hasUnsafeLongsAnnotation).check(jsniMethod.function());
          }
        }
+      suppressWarningsStack.pop();
+    }
+
+    public void endVisit(TypeDeclaration typeDeclaration, BlockScope  
scope) {
+      suppressWarningsStack.pop();
+    }
+
+    public void endVisit(TypeDeclaration typeDeclaration, ClassScope  
scope) {
+      suppressWarningsStack.pop();
+    }
+
+    public void endVisit(TypeDeclaration typeDeclaration,
+        CompilationUnitScope scope) {
+      suppressWarningsStack.pop();
+    }
+
+    @Override
+    public boolean visit(MethodDeclaration meth, ClassScope scope) {
+      suppressWarningsStack.push(getSuppressedWarnings(meth.annotations));
+      return true;
+    }
+
+    public boolean visit(TypeDeclaration typeDeclaration, BlockScope  
scope) {
+       
suppressWarningsStack.push(getSuppressedWarnings(typeDeclaration.annotations));
+      return true;
+    }
+
+    @Override
+    public boolean visit(TypeDeclaration typeDeclaration, ClassScope  
scope) {
+       
suppressWarningsStack.push(getSuppressedWarnings(typeDeclaration.annotations));
+      return true;
+    }
+
+    public boolean visit(TypeDeclaration typeDeclaration,
+        CompilationUnitScope scope) {
+       
suppressWarningsStack.push(getSuppressedWarnings(typeDeclaration.annotations));
+      return true;
      }

      private void checkDecl(MethodDeclaration meth, ClassScope scope) {
@@ -125,13 +166,11 @@
      private transient SourceInfo errorInfo;
      private final boolean hasUnsafeLongsAnnotation;
      private final MethodDeclaration method;
-    private final Set<String> suppressWarnings;

      public JsniRefChecker(MethodDeclaration method,
          boolean hasUnsafeLongsAnnotation) {
        this.method = method;
        this.hasUnsafeLongsAnnotation = hasUnsafeLongsAnnotation;
-      this.suppressWarnings = getSuppressedWarnings(method);
      }

      public void check(JsFunction function) {
@@ -281,9 +320,11 @@
      }

      private void emitWarning(String category, String msg) {
-      if (suppressWarnings.contains(category)
-          || suppressWarnings.contains("all")) {
-        return;
+      for (Set<String> suppressWarnings : suppressWarningsStack) {
+        if (suppressWarnings.contains(category)
+            || suppressWarnings.contains("all")) {
+          return;
+        }
        }
        JsniCollector.reportJsniWarning(errorInfo, method, msg);
      }
@@ -344,40 +385,6 @@
        }
        return null;
      }
-
-    private Set<String> getSuppressedWarnings(MethodDeclaration method) {
-      Annotation[] annotations = method.annotations;
-      if (annotations == null) {
-        return Sets.create();
-      }
-
-      for (Annotation a : annotations) {
-        if (SuppressWarnings.class.getName().equals(
-            CharOperation.toString(((ReferenceBinding)  
a.resolvedType).compoundName))) {
-          for (MemberValuePair pair : a.memberValuePairs()) {
-            if (String.valueOf(pair.name).equals("value")) {
-              Expression valueExpr = pair.value;
-              if (valueExpr instanceof StringLiteral) {
-                // @SuppressWarnings("Foo")
-                return Sets.create(((StringLiteral)  
valueExpr).constant.stringValue().toLowerCase(Locale.ENGLISH));
-              } else if (valueExpr instanceof ArrayInitializer) {
-                // @SuppressWarnings({ "Foo", "Bar"})
-                ArrayInitializer ai = (ArrayInitializer) valueExpr;
-                String[] values = new String[ai.expressions.length];
-                for (int i = 0, j = values.length; i < j; i++) {
-                  values[i] = ((StringLiteral)  
ai.expressions[i]).constant.stringValue().toLowerCase(Locale.ENGLISH);
-                }
-                return Sets.create(values);
-              } else {
-                throw new InternalCompilerException(
-                    "Unable to analyze SuppressWarnings annotation");
-              }
-            }
-          }
-        }
-      }
-      return Sets.create();
-    }

      private boolean looksLikeAnonymousClass(JsniRef jsniRef) {
        char[][] compoundName = getCompoundName(jsniRef);
@@ -419,9 +426,43 @@
        TypeResolver typeResolver) {
      new JsniChecker(cud, typeResolver, jsniMethods).check();
    }
+
+  static Set<String> getSuppressedWarnings(Annotation[] annotations) {
+    if (annotations != null) {
+      for (Annotation a : annotations) {
+        if (SuppressWarnings.class.getName().equals(
+            CharOperation.toString(((ReferenceBinding)  
a.resolvedType).compoundName))) {
+          for (MemberValuePair pair : a.memberValuePairs()) {
+            if (String.valueOf(pair.name).equals("value")) {
+              Expression valueExpr = pair.value;
+              if (valueExpr instanceof StringLiteral) {
+                // @SuppressWarnings("Foo")
+                return Sets.create(((StringLiteral)  
valueExpr).constant.stringValue().toLowerCase(
+                    Locale.ENGLISH));
+              } else if (valueExpr instanceof ArrayInitializer) {
+                // @SuppressWarnings({ "Foo", "Bar"})
+                ArrayInitializer ai = (ArrayInitializer) valueExpr;
+                String[] values = new String[ai.expressions.length];
+                for (int i = 0, j = values.length; i < j; i++) {
+                  values[i] = ((StringLiteral)  
ai.expressions[i]).constant.stringValue().toLowerCase(
+                      Locale.ENGLISH);
+                }
+                return Sets.create(values);
+              } else {
+                throw new InternalCompilerException(
+                    "Unable to analyze SuppressWarnings annotation");
+              }
+            }
+          }
+        }
+      }
+    }
+    return Sets.create();
+  }

    private final CompilationUnitDeclaration cud;
    private final Map<AbstractMethodDeclaration, JsniMethod> jsniMethods;
+  private final Stack<Set<String>> suppressWarningsStack = new  
Stack<Set<String>>();
    private final TypeResolver typeResolver;

    private JsniChecker(CompilationUnitDeclaration cud,
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/javac/JsniCheckerTest.java  Thu  
Nov 19 13:48:22 2009
+++ /trunk/dev/core/test/com/google/gwt/dev/javac/JsniCheckerTest.java  Thu  
Nov 19 13:48:42 2009
@@ -176,7 +176,28 @@
      code.append("    @D::bar;\n");
      code.append("  }-*/;\n");
      code.append("}\n");
-
+    shouldGenerateNoWarning(code);
+
+    // Check inherited suppress warnings.
+    code = new StringBuffer();
+    code.append("@Deprecated class D {\n");
+    code.append("  int bar;\n");
+    code.append("}\n");
+    code.append("@SuppressWarnings(\"deprecation\")\n");
+    code.append("class Buggy {\n");
+    code.append("  @Deprecated void foo(){}\n");
+    code.append("  @Deprecated int bar;\n");
+    code.append("  native void jsniMethod1() /*-{\n");
+    code.append("    @Buggy::foo();\n");
+    code.append("    @Buggy::bar;\n");
+    code.append("    @D::bar;\n");
+    code.append("  }-*/;\n");
+    code.append("  native void jsniMethod2() /*-{\n");
+    code.append("    @Buggy::foo();\n");
+    code.append("    @Buggy::bar;\n");
+    code.append("    @D::bar;\n");
+    code.append("  }-*/;\n");
+    code.append("}\n");
      shouldGenerateNoWarning(code);
    }

=======================================
---  
/trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java      
 
Wed Nov 18 07:57:10 2009
+++  
/trunk/user/src/com/google/gwt/user/rebind/rpc/FieldSerializerCreator.java      
 
Thu Nov 19 13:48:42 2009
@@ -155,7 +155,7 @@

      ClassSourceFileComposerFactory composerFactory = new  
ClassSourceFileComposerFactory(
          packageName, className);
-
+     
composerFactory.addAnnotationDeclaration("@SuppressWarnings(\"deprecation\")");
      return composerFactory.createSourceWriter(ctx, printWriter);
    }

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to