1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
53 /**Takes a source file, parses it once to get the warnings inside the file and |
53 /**Takes a source file, parses it once to get the warnings inside the file and |
54 * then for each and every declaration in the file, it tries to place |
54 * then for each and every declaration in the file, it tries to place |
55 * the @SuppressWarnings annotation on the declaration and verifies than no |
55 * the @SuppressWarnings annotation on the declaration and verifies than no |
56 * warnings are produced inside the declaration, but all are produced outside it. |
56 * warnings are produced inside the declaration, but all are produced outside it. |
57 * |
57 * |
58 * Currently only works with <code>unchecked,deprecation,cast</code> warnings. |
58 * Currently only works with <code>unchecked,deprecation,cast,divzero</code> warnings. |
59 */ |
59 */ |
60 public class VerifySuppressWarnings { |
60 public class VerifySuppressWarnings { |
61 |
61 |
62 private static final List<String> STANDARD_PARAMS = Arrays.asList("-Xlint:unchecked,deprecation,cast", "-Xjcov"); |
62 private static final List<String> STANDARD_PARAMS = |
|
63 Arrays.asList("-Xlint:unchecked,deprecation,cast,divzero"); |
63 |
64 |
64 public static void main(String... args) throws IOException, URISyntaxException { |
65 public static void main(String... args) throws IOException, URISyntaxException { |
65 if (args.length != 1) throw new IllegalStateException("Must provide class name!"); |
66 if (args.length != 1) throw new IllegalStateException("Must provide class name!"); |
66 String testContent = null; |
67 String testContent = null; |
67 List<File> sourcePath = new ArrayList<>(); |
68 List<File> sourcePath = new ArrayList<>(); |
131 declarationSpans.add(new int[] {(int) trees.getSourcePositions().getStartPosition(cut, node), endPos}); |
132 declarationSpans.add(new int[] {(int) trees.getSourcePositions().getStartPosition(cut, node), endPos}); |
132 } |
133 } |
133 }.scan(cut, null); |
134 }.scan(cut, null); |
134 |
135 |
135 for (final int[] declarationSpan : declarationSpans) { |
136 for (final int[] declarationSpan : declarationSpans) { |
136 final String suppressWarnings = "@SuppressWarnings({\"deprecation\", \"unchecked\", \"serial\"})"; |
137 final String suppressWarnings = |
|
138 "@SuppressWarnings({\"deprecation\", \"unchecked\", \"serial\", \"divzero\"})"; |
137 final String updatedContent = testContent.substring(0, declarationSpan[0]) + suppressWarnings + testContent.substring(declarationSpan[0]); |
139 final String updatedContent = testContent.substring(0, declarationSpan[0]) + suppressWarnings + testContent.substring(declarationSpan[0]); |
138 final List<Diagnostic<?>> foundErrors = new ArrayList<>(diagnostics); |
140 final List<Diagnostic<?>> foundErrors = new ArrayList<>(diagnostics); |
139 DiagnosticListener<JavaFileObject> verifyDiagnostics = new DiagnosticListener<JavaFileObject>() { |
141 DiagnosticListener<JavaFileObject> verifyDiagnostics = new DiagnosticListener<JavaFileObject>() { |
140 @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
142 @Override public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
141 long adjustedPos = diagnostic.getPosition(); |
143 long adjustedPos = diagnostic.getPosition(); |