Mon, 17 Oct 2011 12:54:33 +0100
7097436: Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs
Summary: Duplicate aliasing check during subtyping leads to spurious varargs diagnostic
Reviewed-by: jjg
mcimadamore@676 | 1 | /* |
mcimadamore@676 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@676 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@676 | 4 | * |
mcimadamore@676 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@676 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@676 | 7 | * published by the Free Software Foundation. |
mcimadamore@676 | 8 | * |
mcimadamore@676 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@676 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@676 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@676 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@676 | 13 | * accompanied this code). |
mcimadamore@676 | 14 | * |
mcimadamore@676 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@676 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@676 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@676 | 18 | * |
mcimadamore@676 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@676 | 20 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@676 | 21 | * questions. |
mcimadamore@676 | 22 | */ |
mcimadamore@676 | 23 | |
mcimadamore@676 | 24 | import com.sun.source.util.TaskEvent; |
mcimadamore@676 | 25 | import java.awt.BorderLayout; |
mcimadamore@676 | 26 | import java.awt.Color; |
mcimadamore@676 | 27 | import java.awt.Dimension; |
mcimadamore@676 | 28 | import java.awt.EventQueue; |
mcimadamore@676 | 29 | import java.awt.Font; |
mcimadamore@676 | 30 | import java.awt.GridBagConstraints; |
mcimadamore@676 | 31 | import java.awt.GridBagLayout; |
mcimadamore@676 | 32 | import java.awt.Rectangle; |
mcimadamore@676 | 33 | import java.awt.event.ActionEvent; |
mcimadamore@676 | 34 | import java.awt.event.ActionListener; |
mcimadamore@676 | 35 | import java.awt.event.MouseAdapter; |
mcimadamore@676 | 36 | import java.awt.event.MouseEvent; |
mcimadamore@676 | 37 | import javax.swing.DefaultComboBoxModel; |
mcimadamore@676 | 38 | import javax.swing.JComboBox; |
mcimadamore@676 | 39 | import javax.swing.JComponent; |
mcimadamore@676 | 40 | import javax.swing.JFrame; |
mcimadamore@676 | 41 | import javax.swing.JLabel; |
mcimadamore@676 | 42 | import javax.swing.JPanel; |
mcimadamore@676 | 43 | import javax.swing.JScrollPane; |
mcimadamore@676 | 44 | import javax.swing.JTextArea; |
mcimadamore@676 | 45 | import javax.swing.JTextField; |
mcimadamore@676 | 46 | import javax.swing.SwingUtilities; |
mcimadamore@676 | 47 | import javax.swing.event.CaretEvent; |
mcimadamore@676 | 48 | import javax.swing.event.CaretListener; |
mcimadamore@676 | 49 | import javax.swing.text.BadLocationException; |
mcimadamore@676 | 50 | import javax.swing.text.DefaultHighlighter; |
mcimadamore@676 | 51 | import javax.swing.text.Highlighter; |
mcimadamore@676 | 52 | import java.io.File; |
mcimadamore@676 | 53 | import java.io.IOException; |
mcimadamore@676 | 54 | import java.io.PrintStream; |
mcimadamore@676 | 55 | import java.io.PrintWriter; |
mcimadamore@676 | 56 | import java.io.StringWriter; |
mcimadamore@676 | 57 | import java.lang.reflect.Field; |
mcimadamore@676 | 58 | import java.lang.reflect.Modifier; |
mcimadamore@676 | 59 | import java.nio.charset.Charset; |
mcimadamore@676 | 60 | import java.util.ArrayList; |
mcimadamore@676 | 61 | import java.util.HashMap; |
mcimadamore@676 | 62 | import java.util.List; |
mcimadamore@676 | 63 | import java.util.Map; |
mcimadamore@676 | 64 | import javax.tools.Diagnostic; |
mcimadamore@676 | 65 | import javax.tools.DiagnosticListener; |
mcimadamore@676 | 66 | import javax.tools.JavaFileObject; |
mcimadamore@676 | 67 | import javax.tools.StandardJavaFileManager; |
mcimadamore@676 | 68 | |
mcimadamore@676 | 69 | import com.sun.source.tree.CompilationUnitTree; |
mcimadamore@676 | 70 | import com.sun.source.util.JavacTask; |
mcimadamore@676 | 71 | import com.sun.source.util.TaskListener; |
mcimadamore@676 | 72 | import com.sun.tools.javac.api.JavacTool; |
mcimadamore@676 | 73 | import com.sun.tools.javac.code.Symbol; |
mcimadamore@676 | 74 | import com.sun.tools.javac.code.Type; |
mcimadamore@676 | 75 | import com.sun.tools.javac.tree.JCTree; |
mcimadamore@676 | 76 | import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
mcimadamore@676 | 77 | import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; |
mcimadamore@676 | 78 | import com.sun.tools.javac.tree.JCTree.JCImport; |
mcimadamore@676 | 79 | import com.sun.tools.javac.tree.TreeInfo; |
mcimadamore@676 | 80 | import com.sun.tools.javac.tree.TreeScanner; |
mcimadamore@676 | 81 | import com.sun.tools.javac.util.Pair; |
mcimadamore@676 | 82 | |
mcimadamore@676 | 83 | import java.util.Arrays; |
mcimadamore@676 | 84 | import java.util.HashSet; |
mcimadamore@676 | 85 | import java.util.Set; |
mcimadamore@676 | 86 | import javax.lang.model.element.Element; |
mcimadamore@676 | 87 | |
mcimadamore@676 | 88 | /** |
mcimadamore@676 | 89 | * Utility and test program to check validity of tree positions for tree nodes. |
mcimadamore@676 | 90 | * The program can be run standalone, or as a jtreg test. In standalone mode, |
mcimadamore@676 | 91 | * errors can be displayed in a gui viewer. For info on command line args, |
mcimadamore@676 | 92 | * run program with no args. |
mcimadamore@676 | 93 | * |
mcimadamore@676 | 94 | * <p> |
mcimadamore@676 | 95 | * jtreg: Note that by using the -r switch in the test description below, this test |
mcimadamore@676 | 96 | * will process all java files in the langtools/test directory, thus implicitly |
mcimadamore@676 | 97 | * covering any new language features that may be tested in this test suite. |
mcimadamore@676 | 98 | */ |
mcimadamore@676 | 99 | |
mcimadamore@676 | 100 | /* |
mcimadamore@676 | 101 | * @test |
mcimadamore@676 | 102 | * @bug 6970584 |
mcimadamore@676 | 103 | * @summary assorted position errors in compiler syntax trees |
mcimadamore@676 | 104 | * @run main CheckAttributedTree -q -r -et ERRONEOUS . |
mcimadamore@676 | 105 | */ |
mcimadamore@676 | 106 | public class CheckAttributedTree { |
mcimadamore@676 | 107 | /** |
mcimadamore@676 | 108 | * Main entry point. |
mcimadamore@676 | 109 | * If test.src is set, program runs in jtreg mode, and will throw an Error |
mcimadamore@676 | 110 | * if any errors arise, otherwise System.exit will be used, unless the gui |
mcimadamore@676 | 111 | * viewer is being used. In jtreg mode, the default base directory for file |
mcimadamore@676 | 112 | * args is the value of ${test.src}. In jtreg mode, the -r option can be |
mcimadamore@676 | 113 | * given to change the default base directory to the root test directory. |
mcimadamore@676 | 114 | */ |
mcimadamore@676 | 115 | public static void main(String... args) { |
mcimadamore@676 | 116 | String testSrc = System.getProperty("test.src"); |
mcimadamore@676 | 117 | File baseDir = (testSrc == null) ? null : new File(testSrc); |
mcimadamore@676 | 118 | boolean ok = new CheckAttributedTree().run(baseDir, args); |
mcimadamore@676 | 119 | if (!ok) { |
mcimadamore@676 | 120 | if (testSrc != null) // jtreg mode |
mcimadamore@676 | 121 | throw new Error("failed"); |
mcimadamore@676 | 122 | else |
mcimadamore@676 | 123 | System.exit(1); |
mcimadamore@676 | 124 | } |
mcimadamore@676 | 125 | } |
mcimadamore@676 | 126 | |
mcimadamore@676 | 127 | /** |
mcimadamore@676 | 128 | * Run the program. A base directory can be provided for file arguments. |
mcimadamore@676 | 129 | * In jtreg mode, the -r option can be given to change the default base |
mcimadamore@676 | 130 | * directory to the test root directory. For other options, see usage(). |
mcimadamore@676 | 131 | * @param baseDir base directory for any file arguments. |
mcimadamore@676 | 132 | * @param args command line args |
mcimadamore@676 | 133 | * @return true if successful or in gui mode |
mcimadamore@676 | 134 | */ |
mcimadamore@676 | 135 | boolean run(File baseDir, String... args) { |
mcimadamore@676 | 136 | if (args.length == 0) { |
mcimadamore@676 | 137 | usage(System.out); |
mcimadamore@676 | 138 | return true; |
mcimadamore@676 | 139 | } |
mcimadamore@676 | 140 | |
mcimadamore@676 | 141 | List<File> files = new ArrayList<File>(); |
mcimadamore@676 | 142 | for (int i = 0; i < args.length; i++) { |
mcimadamore@676 | 143 | String arg = args[i]; |
mcimadamore@676 | 144 | if (arg.equals("-encoding") && i + 1 < args.length) |
mcimadamore@676 | 145 | encoding = args[++i]; |
mcimadamore@676 | 146 | else if (arg.equals("-gui")) |
mcimadamore@676 | 147 | gui = true; |
mcimadamore@676 | 148 | else if (arg.equals("-q")) |
mcimadamore@676 | 149 | quiet = true; |
mcimadamore@676 | 150 | else if (arg.equals("-v")) |
mcimadamore@676 | 151 | verbose = true; |
mcimadamore@676 | 152 | else if (arg.equals("-t") && i + 1 < args.length) |
mcimadamore@676 | 153 | tags.add(args[++i]); |
mcimadamore@676 | 154 | else if (arg.equals("-ef") && i + 1 < args.length) |
mcimadamore@676 | 155 | excludeFiles.add(new File(baseDir, args[++i])); |
mcimadamore@676 | 156 | else if (arg.equals("-et") && i + 1 < args.length) |
mcimadamore@676 | 157 | excludeTags.add(args[++i]); |
mcimadamore@676 | 158 | else if (arg.equals("-r")) { |
mcimadamore@676 | 159 | if (excludeFiles.size() > 0) |
mcimadamore@676 | 160 | throw new Error("-r must be used before -ef"); |
mcimadamore@676 | 161 | File d = baseDir; |
mcimadamore@676 | 162 | while (!new File(d, "TEST.ROOT").exists()) { |
mcimadamore@676 | 163 | if (d == null) |
mcimadamore@676 | 164 | throw new Error("cannot find TEST.ROOT"); |
mcimadamore@676 | 165 | d = d.getParentFile(); |
mcimadamore@676 | 166 | } |
mcimadamore@676 | 167 | baseDir = d; |
mcimadamore@676 | 168 | } |
mcimadamore@676 | 169 | else if (arg.startsWith("-")) |
mcimadamore@676 | 170 | throw new Error("unknown option: " + arg); |
mcimadamore@676 | 171 | else { |
mcimadamore@676 | 172 | while (i < args.length) |
mcimadamore@676 | 173 | files.add(new File(baseDir, args[i++])); |
mcimadamore@676 | 174 | } |
mcimadamore@676 | 175 | } |
mcimadamore@676 | 176 | |
mcimadamore@676 | 177 | for (File file: files) { |
mcimadamore@676 | 178 | if (file.exists()) |
mcimadamore@676 | 179 | test(file); |
mcimadamore@676 | 180 | else |
mcimadamore@676 | 181 | error("File not found: " + file); |
mcimadamore@676 | 182 | } |
mcimadamore@676 | 183 | |
mcimadamore@676 | 184 | if (fileCount != 1) |
mcimadamore@676 | 185 | System.err.println(fileCount + " files read"); |
mcimadamore@676 | 186 | if (errors > 0) |
mcimadamore@676 | 187 | System.err.println(errors + " errors"); |
mcimadamore@676 | 188 | |
mcimadamore@676 | 189 | return (gui || errors == 0); |
mcimadamore@676 | 190 | } |
mcimadamore@676 | 191 | |
mcimadamore@676 | 192 | /** |
mcimadamore@676 | 193 | * Print command line help. |
mcimadamore@676 | 194 | * @param out output stream |
mcimadamore@676 | 195 | */ |
mcimadamore@676 | 196 | void usage(PrintStream out) { |
mcimadamore@676 | 197 | out.println("Usage:"); |
mcimadamore@676 | 198 | out.println(" java CheckAttributedTree options... files..."); |
mcimadamore@676 | 199 | out.println(""); |
mcimadamore@676 | 200 | out.println("where options include:"); |
mcimadamore@676 | 201 | out.println("-q Quiet: don't report on inapplicable files"); |
mcimadamore@676 | 202 | out.println("-gui Display returns in a GUI viewer"); |
mcimadamore@676 | 203 | out.println("-v Verbose: report on files as they are being read"); |
mcimadamore@676 | 204 | out.println("-t tag Limit checks to tree nodes with this tag"); |
mcimadamore@676 | 205 | out.println(" Can be repeated if desired"); |
mcimadamore@676 | 206 | out.println("-ef file Exclude file or directory"); |
mcimadamore@676 | 207 | out.println("-et tag Exclude tree nodes with given tag name"); |
mcimadamore@676 | 208 | out.println(""); |
mcimadamore@676 | 209 | out.println("files may be directories or files"); |
mcimadamore@676 | 210 | out.println("directories will be scanned recursively"); |
mcimadamore@676 | 211 | out.println("non java files, or java files which cannot be parsed, will be ignored"); |
mcimadamore@676 | 212 | out.println(""); |
mcimadamore@676 | 213 | } |
mcimadamore@676 | 214 | |
mcimadamore@676 | 215 | /** |
mcimadamore@676 | 216 | * Test a file. If the file is a directory, it will be recursively scanned |
mcimadamore@676 | 217 | * for java files. |
mcimadamore@676 | 218 | * @param file the file or directory to test |
mcimadamore@676 | 219 | */ |
mcimadamore@676 | 220 | void test(File file) { |
mcimadamore@676 | 221 | if (excludeFiles.contains(file)) { |
mcimadamore@676 | 222 | if (!quiet) |
mcimadamore@676 | 223 | error("File " + file + " excluded"); |
mcimadamore@676 | 224 | return; |
mcimadamore@676 | 225 | } |
mcimadamore@676 | 226 | |
mcimadamore@676 | 227 | if (file.isDirectory()) { |
mcimadamore@676 | 228 | for (File f: file.listFiles()) { |
mcimadamore@676 | 229 | test(f); |
mcimadamore@676 | 230 | } |
mcimadamore@676 | 231 | return; |
mcimadamore@676 | 232 | } |
mcimadamore@676 | 233 | |
mcimadamore@676 | 234 | if (file.isFile() && file.getName().endsWith(".java")) { |
mcimadamore@676 | 235 | try { |
mcimadamore@676 | 236 | if (verbose) |
mcimadamore@676 | 237 | System.err.println(file); |
mcimadamore@676 | 238 | fileCount++; |
mcimadamore@676 | 239 | NPETester p = new NPETester(); |
mcimadamore@676 | 240 | p.test(read(file)); |
mcimadamore@676 | 241 | } catch (AttributionException e) { |
mcimadamore@676 | 242 | if (!quiet) { |
mcimadamore@676 | 243 | error("Error attributing " + file + "\n" + e.getMessage()); |
mcimadamore@676 | 244 | } |
mcimadamore@676 | 245 | } catch (IOException e) { |
mcimadamore@676 | 246 | error("Error reading " + file + ": " + e); |
mcimadamore@676 | 247 | } |
mcimadamore@676 | 248 | return; |
mcimadamore@676 | 249 | } |
mcimadamore@676 | 250 | |
mcimadamore@676 | 251 | if (!quiet) |
mcimadamore@676 | 252 | error("File " + file + " ignored"); |
mcimadamore@676 | 253 | } |
mcimadamore@676 | 254 | |
jjh@808 | 255 | // See CR: 6982992 Tests CheckAttributedTree.java, JavacTreeScannerTest.java, and SourceTreeeScannerTest.java timeout |
jjh@808 | 256 | StringWriter sw = new StringWriter(); |
jjh@808 | 257 | PrintWriter pw = new PrintWriter(sw); |
jjh@808 | 258 | Reporter r = new Reporter(pw); |
jjh@808 | 259 | JavacTool tool = JavacTool.create(); |
jjh@808 | 260 | StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null); |
jjh@808 | 261 | |
mcimadamore@676 | 262 | /** |
mcimadamore@676 | 263 | * Read a file. |
mcimadamore@676 | 264 | * @param file the file to be read |
mcimadamore@676 | 265 | * @return the tree for the content of the file |
mcimadamore@676 | 266 | * @throws IOException if any IO errors occur |
mcimadamore@676 | 267 | * @throws TreePosTest.ParseException if any errors occur while parsing the file |
mcimadamore@676 | 268 | */ |
mcimadamore@676 | 269 | List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException { |
mcimadamore@676 | 270 | JavacTool tool = JavacTool.create(); |
jjh@808 | 271 | r.errors = 0; |
mcimadamore@676 | 272 | Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); |
mcimadamore@676 | 273 | String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" }; |
mcimadamore@676 | 274 | JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files); |
mcimadamore@676 | 275 | final List<Element> analyzedElems = new ArrayList<>(); |
mcimadamore@676 | 276 | task.setTaskListener(new TaskListener() { |
mcimadamore@676 | 277 | public void started(TaskEvent e) { |
mcimadamore@676 | 278 | if (e.getKind() == TaskEvent.Kind.ANALYZE) |
mcimadamore@676 | 279 | analyzedElems.add(e.getTypeElement()); |
mcimadamore@676 | 280 | } |
mcimadamore@676 | 281 | public void finished(TaskEvent e) { } |
mcimadamore@676 | 282 | }); |
mcimadamore@676 | 283 | |
mcimadamore@676 | 284 | try { |
mcimadamore@676 | 285 | Iterable<? extends CompilationUnitTree> trees = task.parse(); |
mcimadamore@676 | 286 | task.analyze(); |
mcimadamore@676 | 287 | List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>(); |
jjg@683 | 288 | //System.out.println("Try to add pairs. Elems are " + analyzedElems); |
mcimadamore@676 | 289 | for (CompilationUnitTree t : trees) { |
mcimadamore@676 | 290 | JCCompilationUnit cu = (JCCompilationUnit)t; |
mcimadamore@676 | 291 | for (JCTree def : cu.defs) { |
mcimadamore@676 | 292 | if (def.getTag() == JCTree.CLASSDEF && |
mcimadamore@676 | 293 | analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { |
jjg@683 | 294 | //System.out.println("Adding pair..."); |
mcimadamore@676 | 295 | res.add(new Pair<>(cu, def)); |
mcimadamore@676 | 296 | } |
mcimadamore@676 | 297 | } |
mcimadamore@676 | 298 | } |
mcimadamore@676 | 299 | return res; |
mcimadamore@676 | 300 | } |
mcimadamore@676 | 301 | catch (Throwable t) { |
mcimadamore@676 | 302 | throw new AttributionException("Exception while attributing file: " + file); |
mcimadamore@676 | 303 | } |
mcimadamore@676 | 304 | } |
mcimadamore@676 | 305 | |
mcimadamore@676 | 306 | /** |
mcimadamore@676 | 307 | * Report an error. When the program is complete, the program will either |
mcimadamore@676 | 308 | * exit or throw an Error if any errors have been reported. |
mcimadamore@676 | 309 | * @param msg the error message |
mcimadamore@676 | 310 | */ |
mcimadamore@676 | 311 | void error(String msg) { |
mcimadamore@676 | 312 | System.err.println(msg); |
mcimadamore@676 | 313 | errors++; |
mcimadamore@676 | 314 | } |
mcimadamore@676 | 315 | |
mcimadamore@676 | 316 | /** Number of files that have been analyzed. */ |
mcimadamore@676 | 317 | int fileCount; |
mcimadamore@676 | 318 | /** Number of errors reported. */ |
mcimadamore@676 | 319 | int errors; |
mcimadamore@676 | 320 | /** Flag: don't report irrelevant files. */ |
mcimadamore@676 | 321 | boolean quiet; |
mcimadamore@676 | 322 | /** Flag: show errors in GUI viewer. */ |
mcimadamore@676 | 323 | boolean gui; |
mcimadamore@676 | 324 | /** The GUI viewer for errors. */ |
mcimadamore@676 | 325 | Viewer viewer; |
mcimadamore@676 | 326 | /** Flag: report files as they are processed. */ |
mcimadamore@676 | 327 | boolean verbose; |
mcimadamore@676 | 328 | /** Option: encoding for test files. */ |
mcimadamore@676 | 329 | String encoding; |
mcimadamore@676 | 330 | /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes |
mcimadamore@676 | 331 | * are analyzed. */ |
mcimadamore@676 | 332 | Set<String> tags = new HashSet<String>(); |
mcimadamore@676 | 333 | /** Set of files and directories to be excluded from analysis. */ |
mcimadamore@676 | 334 | Set<File> excludeFiles = new HashSet<File>(); |
mcimadamore@676 | 335 | /** Set of tag names to be excluded from analysis. */ |
mcimadamore@676 | 336 | Set<String> excludeTags = new HashSet<String>(); |
mcimadamore@676 | 337 | /** Utility class for trees */ |
mcimadamore@676 | 338 | TreeUtil treeUtil = new TreeUtil(); |
mcimadamore@676 | 339 | |
mcimadamore@676 | 340 | /** |
mcimadamore@676 | 341 | * Main class for testing assertions concerning types/symbol |
mcimadamore@676 | 342 | * left uninitialized after attribution |
mcimadamore@676 | 343 | */ |
mcimadamore@676 | 344 | private class NPETester extends TreeScanner { |
mcimadamore@676 | 345 | void test(List<Pair<JCCompilationUnit, JCTree>> trees) { |
mcimadamore@676 | 346 | for (Pair<JCCompilationUnit, JCTree> p : trees) { |
mcimadamore@676 | 347 | sourcefile = p.fst.sourcefile; |
mcimadamore@676 | 348 | endPosTable = p.fst.endPositions; |
mcimadamore@676 | 349 | encl = new Info(p.snd, endPosTable); |
mcimadamore@676 | 350 | p.snd.accept(this); |
mcimadamore@676 | 351 | } |
mcimadamore@676 | 352 | } |
mcimadamore@676 | 353 | |
mcimadamore@676 | 354 | @Override |
mcimadamore@676 | 355 | public void scan(JCTree tree) { |
mcimadamore@676 | 356 | if (tree == null || |
mcimadamore@676 | 357 | excludeTags.contains(treeUtil.nameFromTag(tree.getTag()))) { |
mcimadamore@676 | 358 | return; |
mcimadamore@676 | 359 | } |
mcimadamore@676 | 360 | |
mcimadamore@676 | 361 | Info self = new Info(tree, endPosTable); |
mcimadamore@676 | 362 | check(!mandatoryType(tree) || |
mcimadamore@676 | 363 | (tree.type != null && |
mcimadamore@676 | 364 | checkFields(tree)), |
mcimadamore@676 | 365 | "'null' found in tree ", |
mcimadamore@676 | 366 | self); |
mcimadamore@676 | 367 | |
mcimadamore@676 | 368 | Info prevEncl = encl; |
mcimadamore@676 | 369 | encl = self; |
mcimadamore@676 | 370 | tree.accept(this); |
mcimadamore@676 | 371 | encl = prevEncl; |
mcimadamore@676 | 372 | } |
mcimadamore@676 | 373 | |
mcimadamore@676 | 374 | private boolean mandatoryType(JCTree that) { |
mcimadamore@676 | 375 | return that instanceof JCTree.JCExpression || |
mcimadamore@676 | 376 | that.getTag() == JCTree.VARDEF || |
mcimadamore@676 | 377 | that.getTag() == JCTree.METHODDEF || |
mcimadamore@676 | 378 | that.getTag() == JCTree.CLASSDEF; |
mcimadamore@676 | 379 | } |
mcimadamore@676 | 380 | |
mcimadamore@676 | 381 | private final List<String> excludedFields = Arrays.asList("varargsElement"); |
mcimadamore@676 | 382 | |
mcimadamore@676 | 383 | void check(boolean ok, String label, Info self) { |
mcimadamore@676 | 384 | if (!ok) { |
mcimadamore@676 | 385 | if (gui) { |
mcimadamore@676 | 386 | if (viewer == null) |
mcimadamore@676 | 387 | viewer = new Viewer(); |
mcimadamore@676 | 388 | viewer.addEntry(sourcefile, label, encl, self); |
mcimadamore@676 | 389 | } |
mcimadamore@676 | 390 | error(label + self.toString() + " encl: " + encl.toString() + " in file: " + sourcefile + " " + self.tree); |
mcimadamore@676 | 391 | } |
mcimadamore@676 | 392 | } |
mcimadamore@676 | 393 | |
mcimadamore@676 | 394 | boolean checkFields(JCTree t) { |
mcimadamore@676 | 395 | List<Field> fieldsToCheck = treeUtil.getFieldsOfType(t, |
mcimadamore@676 | 396 | excludedFields, |
mcimadamore@676 | 397 | Symbol.class, |
mcimadamore@676 | 398 | Type.class); |
mcimadamore@676 | 399 | for (Field f : fieldsToCheck) { |
mcimadamore@676 | 400 | try { |
mcimadamore@676 | 401 | if (f.get(t) == null) { |
mcimadamore@676 | 402 | return false; |
mcimadamore@676 | 403 | } |
mcimadamore@676 | 404 | } |
mcimadamore@676 | 405 | catch (IllegalAccessException e) { |
mcimadamore@676 | 406 | System.err.println("Cannot read field: " + f); |
mcimadamore@676 | 407 | //swallow it |
mcimadamore@676 | 408 | } |
mcimadamore@676 | 409 | } |
mcimadamore@676 | 410 | return true; |
mcimadamore@676 | 411 | } |
mcimadamore@676 | 412 | |
mcimadamore@676 | 413 | @Override |
mcimadamore@676 | 414 | public void visitImport(JCImport tree) { } |
mcimadamore@676 | 415 | |
mcimadamore@676 | 416 | @Override |
mcimadamore@676 | 417 | public void visitTopLevel(JCCompilationUnit tree) { |
mcimadamore@676 | 418 | scan(tree.defs); |
mcimadamore@676 | 419 | } |
mcimadamore@676 | 420 | |
mcimadamore@676 | 421 | JavaFileObject sourcefile; |
mcimadamore@676 | 422 | Map<JCTree, Integer> endPosTable; |
mcimadamore@676 | 423 | Info encl; |
mcimadamore@676 | 424 | } |
mcimadamore@676 | 425 | |
mcimadamore@676 | 426 | /** |
mcimadamore@676 | 427 | * Utility class providing easy access to position and other info for a tree node. |
mcimadamore@676 | 428 | */ |
mcimadamore@676 | 429 | private class Info { |
mcimadamore@676 | 430 | Info() { |
mcimadamore@676 | 431 | tree = null; |
mcimadamore@676 | 432 | tag = JCTree.ERRONEOUS; |
mcimadamore@676 | 433 | start = 0; |
mcimadamore@676 | 434 | pos = 0; |
mcimadamore@676 | 435 | end = Integer.MAX_VALUE; |
mcimadamore@676 | 436 | } |
mcimadamore@676 | 437 | |
mcimadamore@676 | 438 | Info(JCTree tree, Map<JCTree, Integer> endPosTable) { |
mcimadamore@676 | 439 | this.tree = tree; |
mcimadamore@676 | 440 | tag = tree.getTag(); |
mcimadamore@676 | 441 | start = TreeInfo.getStartPos(tree); |
mcimadamore@676 | 442 | pos = tree.pos; |
mcimadamore@676 | 443 | end = TreeInfo.getEndPos(tree, endPosTable); |
mcimadamore@676 | 444 | } |
mcimadamore@676 | 445 | |
mcimadamore@676 | 446 | @Override |
mcimadamore@676 | 447 | public String toString() { |
mcimadamore@676 | 448 | return treeUtil.nameFromTag(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; |
mcimadamore@676 | 449 | } |
mcimadamore@676 | 450 | |
mcimadamore@676 | 451 | final JCTree tree; |
mcimadamore@676 | 452 | final int tag; |
mcimadamore@676 | 453 | final int start; |
mcimadamore@676 | 454 | final int pos; |
mcimadamore@676 | 455 | final int end; |
mcimadamore@676 | 456 | } |
mcimadamore@676 | 457 | |
mcimadamore@676 | 458 | /** |
mcimadamore@676 | 459 | * Names for tree tags. |
mcimadamore@676 | 460 | * javac does not provide an API to convert tag values to strings, so this class uses |
mcimadamore@676 | 461 | * reflection to determine names of public static final int values in JCTree. |
mcimadamore@676 | 462 | */ |
mcimadamore@676 | 463 | private static class TreeUtil { |
mcimadamore@676 | 464 | String nameFromTag(int tag) { |
mcimadamore@676 | 465 | if (names == null) { |
mcimadamore@676 | 466 | names = new HashMap<Integer, String>(); |
mcimadamore@676 | 467 | Class c = JCTree.class; |
mcimadamore@676 | 468 | for (Field f : c.getDeclaredFields()) { |
mcimadamore@676 | 469 | if (f.getType().equals(int.class)) { |
mcimadamore@676 | 470 | int mods = f.getModifiers(); |
mcimadamore@676 | 471 | if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { |
mcimadamore@676 | 472 | try { |
mcimadamore@676 | 473 | names.put(f.getInt(null), f.getName()); |
mcimadamore@676 | 474 | } catch (IllegalAccessException e) { |
mcimadamore@676 | 475 | } |
mcimadamore@676 | 476 | } |
mcimadamore@676 | 477 | } |
mcimadamore@676 | 478 | } |
mcimadamore@676 | 479 | } |
mcimadamore@676 | 480 | String name = names.get(tag); |
mcimadamore@676 | 481 | return (name == null) ? "??" : name; |
mcimadamore@676 | 482 | } |
mcimadamore@676 | 483 | |
mcimadamore@676 | 484 | List<Field> getFieldsOfType(JCTree t, List<String> excludeNames, Class<?>... types) { |
mcimadamore@676 | 485 | List<Field> buf = new ArrayList<Field>(); |
mcimadamore@676 | 486 | for (Field f : t.getClass().getDeclaredFields()) { |
mcimadamore@676 | 487 | if (!excludeNames.contains(f.getName())) { |
mcimadamore@676 | 488 | for (Class<?> type : types) { |
mcimadamore@676 | 489 | if (type.isAssignableFrom(f.getType())) { |
mcimadamore@676 | 490 | f.setAccessible(true); |
mcimadamore@676 | 491 | buf.add(f); |
mcimadamore@676 | 492 | break; |
mcimadamore@676 | 493 | } |
mcimadamore@676 | 494 | } |
mcimadamore@676 | 495 | } |
mcimadamore@676 | 496 | } |
mcimadamore@676 | 497 | return buf; |
mcimadamore@676 | 498 | } |
mcimadamore@676 | 499 | |
mcimadamore@676 | 500 | private Map<Integer, String> names; |
mcimadamore@676 | 501 | } |
mcimadamore@676 | 502 | |
mcimadamore@676 | 503 | /** |
mcimadamore@676 | 504 | * Thrown when errors are found parsing a java file. |
mcimadamore@676 | 505 | */ |
mcimadamore@676 | 506 | private static class ParseException extends Exception { |
mcimadamore@676 | 507 | ParseException(String msg) { |
mcimadamore@676 | 508 | super(msg); |
mcimadamore@676 | 509 | } |
mcimadamore@676 | 510 | } |
mcimadamore@676 | 511 | |
mcimadamore@676 | 512 | private static class AttributionException extends Exception { |
mcimadamore@676 | 513 | AttributionException(String msg) { |
mcimadamore@676 | 514 | super(msg); |
mcimadamore@676 | 515 | } |
mcimadamore@676 | 516 | } |
mcimadamore@676 | 517 | |
mcimadamore@676 | 518 | /** |
mcimadamore@676 | 519 | * DiagnosticListener to report diagnostics and count any errors that occur. |
mcimadamore@676 | 520 | */ |
mcimadamore@676 | 521 | private static class Reporter implements DiagnosticListener<JavaFileObject> { |
mcimadamore@676 | 522 | Reporter(PrintWriter out) { |
mcimadamore@676 | 523 | this.out = out; |
mcimadamore@676 | 524 | } |
mcimadamore@676 | 525 | |
mcimadamore@676 | 526 | public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
mcimadamore@676 | 527 | out.println(diagnostic); |
mcimadamore@676 | 528 | switch (diagnostic.getKind()) { |
mcimadamore@676 | 529 | case ERROR: |
mcimadamore@676 | 530 | errors++; |
mcimadamore@676 | 531 | } |
mcimadamore@676 | 532 | } |
mcimadamore@676 | 533 | int errors; |
mcimadamore@676 | 534 | PrintWriter out; |
mcimadamore@676 | 535 | } |
mcimadamore@676 | 536 | |
mcimadamore@676 | 537 | /** |
mcimadamore@676 | 538 | * GUI viewer for issues found by TreePosTester. The viewer provides a drop |
mcimadamore@676 | 539 | * down list for selecting error conditions, a header area providing details |
mcimadamore@676 | 540 | * about an error, and a text area with the ranges of text highlighted as |
mcimadamore@676 | 541 | * appropriate. |
mcimadamore@676 | 542 | */ |
mcimadamore@676 | 543 | private class Viewer extends JFrame { |
mcimadamore@676 | 544 | /** |
mcimadamore@676 | 545 | * Create a viewer. |
mcimadamore@676 | 546 | */ |
mcimadamore@676 | 547 | Viewer() { |
mcimadamore@676 | 548 | initGUI(); |
mcimadamore@676 | 549 | } |
mcimadamore@676 | 550 | |
mcimadamore@676 | 551 | /** |
mcimadamore@676 | 552 | * Add another entry to the list of errors. |
mcimadamore@676 | 553 | * @param file The file containing the error |
mcimadamore@676 | 554 | * @param check The condition that was being tested, and which failed |
mcimadamore@676 | 555 | * @param encl the enclosing tree node |
mcimadamore@676 | 556 | * @param self the tree node containing the error |
mcimadamore@676 | 557 | */ |
mcimadamore@676 | 558 | void addEntry(JavaFileObject file, String check, Info encl, Info self) { |
mcimadamore@676 | 559 | Entry e = new Entry(file, check, encl, self); |
mcimadamore@676 | 560 | DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel(); |
mcimadamore@676 | 561 | m.addElement(e); |
mcimadamore@676 | 562 | if (m.getSize() == 1) |
mcimadamore@676 | 563 | entries.setSelectedItem(e); |
mcimadamore@676 | 564 | } |
mcimadamore@676 | 565 | |
mcimadamore@676 | 566 | /** |
mcimadamore@676 | 567 | * Initialize the GUI window. |
mcimadamore@676 | 568 | */ |
mcimadamore@676 | 569 | private void initGUI() { |
mcimadamore@676 | 570 | JPanel head = new JPanel(new GridBagLayout()); |
mcimadamore@676 | 571 | GridBagConstraints lc = new GridBagConstraints(); |
mcimadamore@676 | 572 | GridBagConstraints fc = new GridBagConstraints(); |
mcimadamore@676 | 573 | fc.anchor = GridBagConstraints.WEST; |
mcimadamore@676 | 574 | fc.fill = GridBagConstraints.HORIZONTAL; |
mcimadamore@676 | 575 | fc.gridwidth = GridBagConstraints.REMAINDER; |
mcimadamore@676 | 576 | |
mcimadamore@676 | 577 | entries = new JComboBox(); |
mcimadamore@676 | 578 | entries.addActionListener(new ActionListener() { |
mcimadamore@676 | 579 | public void actionPerformed(ActionEvent e) { |
mcimadamore@676 | 580 | showEntry((Entry) entries.getSelectedItem()); |
mcimadamore@676 | 581 | } |
mcimadamore@676 | 582 | }); |
mcimadamore@676 | 583 | fc.insets.bottom = 10; |
mcimadamore@676 | 584 | head.add(entries, fc); |
mcimadamore@676 | 585 | fc.insets.bottom = 0; |
mcimadamore@676 | 586 | head.add(new JLabel("check:"), lc); |
mcimadamore@676 | 587 | head.add(checkField = createTextField(80), fc); |
mcimadamore@676 | 588 | fc.fill = GridBagConstraints.NONE; |
mcimadamore@676 | 589 | head.add(setBackground(new JLabel("encl:"), enclColor), lc); |
mcimadamore@676 | 590 | head.add(enclPanel = new InfoPanel(), fc); |
mcimadamore@676 | 591 | head.add(setBackground(new JLabel("self:"), selfColor), lc); |
mcimadamore@676 | 592 | head.add(selfPanel = new InfoPanel(), fc); |
mcimadamore@676 | 593 | add(head, BorderLayout.NORTH); |
mcimadamore@676 | 594 | |
mcimadamore@676 | 595 | body = new JTextArea(); |
mcimadamore@676 | 596 | body.setFont(Font.decode(Font.MONOSPACED)); |
mcimadamore@676 | 597 | body.addCaretListener(new CaretListener() { |
mcimadamore@676 | 598 | public void caretUpdate(CaretEvent e) { |
mcimadamore@676 | 599 | int dot = e.getDot(); |
mcimadamore@676 | 600 | int mark = e.getMark(); |
mcimadamore@676 | 601 | if (dot == mark) |
mcimadamore@676 | 602 | statusText.setText("dot: " + dot); |
mcimadamore@676 | 603 | else |
mcimadamore@676 | 604 | statusText.setText("dot: " + dot + ", mark:" + mark); |
mcimadamore@676 | 605 | } |
mcimadamore@676 | 606 | }); |
mcimadamore@676 | 607 | JScrollPane p = new JScrollPane(body, |
mcimadamore@676 | 608 | JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |
mcimadamore@676 | 609 | JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
mcimadamore@676 | 610 | p.setPreferredSize(new Dimension(640, 480)); |
mcimadamore@676 | 611 | add(p, BorderLayout.CENTER); |
mcimadamore@676 | 612 | |
mcimadamore@676 | 613 | statusText = createTextField(80); |
mcimadamore@676 | 614 | add(statusText, BorderLayout.SOUTH); |
mcimadamore@676 | 615 | |
mcimadamore@676 | 616 | pack(); |
mcimadamore@676 | 617 | setLocationRelativeTo(null); // centered on screen |
mcimadamore@676 | 618 | setVisible(true); |
mcimadamore@676 | 619 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
mcimadamore@676 | 620 | } |
mcimadamore@676 | 621 | |
mcimadamore@676 | 622 | /** Show an entry that has been selected. */ |
mcimadamore@676 | 623 | private void showEntry(Entry e) { |
mcimadamore@676 | 624 | try { |
mcimadamore@676 | 625 | // update simple fields |
mcimadamore@676 | 626 | setTitle(e.file.getName()); |
mcimadamore@676 | 627 | checkField.setText(e.check); |
mcimadamore@676 | 628 | enclPanel.setInfo(e.encl); |
mcimadamore@676 | 629 | selfPanel.setInfo(e.self); |
mcimadamore@676 | 630 | // show file text with highlights |
mcimadamore@676 | 631 | body.setText(e.file.getCharContent(true).toString()); |
mcimadamore@676 | 632 | Highlighter highlighter = body.getHighlighter(); |
mcimadamore@676 | 633 | highlighter.removeAllHighlights(); |
mcimadamore@676 | 634 | addHighlight(highlighter, e.encl, enclColor); |
mcimadamore@676 | 635 | addHighlight(highlighter, e.self, selfColor); |
mcimadamore@676 | 636 | scroll(body, getMinPos(enclPanel.info, selfPanel.info)); |
mcimadamore@676 | 637 | } catch (IOException ex) { |
mcimadamore@676 | 638 | body.setText("Cannot read " + e.file.getName() + ": " + e); |
mcimadamore@676 | 639 | } |
mcimadamore@676 | 640 | } |
mcimadamore@676 | 641 | |
mcimadamore@676 | 642 | /** Create a test field. */ |
mcimadamore@676 | 643 | private JTextField createTextField(int width) { |
mcimadamore@676 | 644 | JTextField f = new JTextField(width); |
mcimadamore@676 | 645 | f.setEditable(false); |
mcimadamore@676 | 646 | f.setBorder(null); |
mcimadamore@676 | 647 | return f; |
mcimadamore@676 | 648 | } |
mcimadamore@676 | 649 | |
mcimadamore@676 | 650 | /** Add a highlighted region based on the positions in an Info object. */ |
mcimadamore@676 | 651 | private void addHighlight(Highlighter h, Info info, Color c) { |
mcimadamore@676 | 652 | int start = info.start; |
mcimadamore@676 | 653 | int end = info.end; |
mcimadamore@676 | 654 | if (start == -1 && end == -1) |
mcimadamore@676 | 655 | return; |
mcimadamore@676 | 656 | if (start == -1) |
mcimadamore@676 | 657 | start = end; |
mcimadamore@676 | 658 | if (end == -1) |
mcimadamore@676 | 659 | end = start; |
mcimadamore@676 | 660 | try { |
mcimadamore@676 | 661 | h.addHighlight(info.start, info.end, |
mcimadamore@676 | 662 | new DefaultHighlighter.DefaultHighlightPainter(c)); |
mcimadamore@676 | 663 | if (info.pos != -1) { |
mcimadamore@676 | 664 | Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40% |
mcimadamore@676 | 665 | h.addHighlight(info.pos, info.pos + 1, |
mcimadamore@676 | 666 | new DefaultHighlighter.DefaultHighlightPainter(c2)); |
mcimadamore@676 | 667 | } |
mcimadamore@676 | 668 | } catch (BadLocationException e) { |
mcimadamore@676 | 669 | e.printStackTrace(); |
mcimadamore@676 | 670 | } |
mcimadamore@676 | 671 | } |
mcimadamore@676 | 672 | |
mcimadamore@676 | 673 | /** Get the minimum valid position in a set of info objects. */ |
mcimadamore@676 | 674 | private int getMinPos(Info... values) { |
mcimadamore@676 | 675 | int i = Integer.MAX_VALUE; |
mcimadamore@676 | 676 | for (Info info: values) { |
mcimadamore@676 | 677 | if (info.start >= 0) i = Math.min(i, info.start); |
mcimadamore@676 | 678 | if (info.pos >= 0) i = Math.min(i, info.pos); |
mcimadamore@676 | 679 | if (info.end >= 0) i = Math.min(i, info.end); |
mcimadamore@676 | 680 | } |
mcimadamore@676 | 681 | return (i == Integer.MAX_VALUE) ? 0 : i; |
mcimadamore@676 | 682 | } |
mcimadamore@676 | 683 | |
mcimadamore@676 | 684 | /** Set the background on a component. */ |
mcimadamore@676 | 685 | private JComponent setBackground(JComponent comp, Color c) { |
mcimadamore@676 | 686 | comp.setOpaque(true); |
mcimadamore@676 | 687 | comp.setBackground(c); |
mcimadamore@676 | 688 | return comp; |
mcimadamore@676 | 689 | } |
mcimadamore@676 | 690 | |
mcimadamore@676 | 691 | /** Scroll a text area to display a given position near the middle of the visible area. */ |
mcimadamore@676 | 692 | private void scroll(final JTextArea t, final int pos) { |
mcimadamore@676 | 693 | // Using invokeLater appears to give text a chance to sort itself out |
mcimadamore@676 | 694 | // before the scroll happens; otherwise scrollRectToVisible doesn't work. |
mcimadamore@676 | 695 | // Maybe there's a better way to sync with the text... |
mcimadamore@676 | 696 | EventQueue.invokeLater(new Runnable() { |
mcimadamore@676 | 697 | public void run() { |
mcimadamore@676 | 698 | try { |
mcimadamore@676 | 699 | Rectangle r = t.modelToView(pos); |
mcimadamore@676 | 700 | JScrollPane p = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, t); |
mcimadamore@676 | 701 | r.y = Math.max(0, r.y - p.getHeight() * 2 / 5); |
mcimadamore@676 | 702 | r.height += p.getHeight() * 4 / 5; |
mcimadamore@676 | 703 | t.scrollRectToVisible(r); |
mcimadamore@676 | 704 | } catch (BadLocationException ignore) { |
mcimadamore@676 | 705 | } |
mcimadamore@676 | 706 | } |
mcimadamore@676 | 707 | }); |
mcimadamore@676 | 708 | } |
mcimadamore@676 | 709 | |
mcimadamore@676 | 710 | private JComboBox entries; |
mcimadamore@676 | 711 | private JTextField checkField; |
mcimadamore@676 | 712 | private InfoPanel enclPanel; |
mcimadamore@676 | 713 | private InfoPanel selfPanel; |
mcimadamore@676 | 714 | private JTextArea body; |
mcimadamore@676 | 715 | private JTextField statusText; |
mcimadamore@676 | 716 | |
mcimadamore@676 | 717 | private Color selfColor = new Color(0.f, 1.f, 0.f, 0.2f); // 20% green |
mcimadamore@676 | 718 | private Color enclColor = new Color(1.f, 0.f, 0.f, 0.2f); // 20% red |
mcimadamore@676 | 719 | |
mcimadamore@676 | 720 | /** Panel to display an Info object. */ |
mcimadamore@676 | 721 | private class InfoPanel extends JPanel { |
mcimadamore@676 | 722 | InfoPanel() { |
mcimadamore@676 | 723 | add(tagName = createTextField(20)); |
mcimadamore@676 | 724 | add(new JLabel("start:")); |
mcimadamore@676 | 725 | add(addListener(start = createTextField(6))); |
mcimadamore@676 | 726 | add(new JLabel("pos:")); |
mcimadamore@676 | 727 | add(addListener(pos = createTextField(6))); |
mcimadamore@676 | 728 | add(new JLabel("end:")); |
mcimadamore@676 | 729 | add(addListener(end = createTextField(6))); |
mcimadamore@676 | 730 | } |
mcimadamore@676 | 731 | |
mcimadamore@676 | 732 | void setInfo(Info info) { |
mcimadamore@676 | 733 | this.info = info; |
mcimadamore@676 | 734 | tagName.setText(treeUtil.nameFromTag(info.tag)); |
mcimadamore@676 | 735 | start.setText(String.valueOf(info.start)); |
mcimadamore@676 | 736 | pos.setText(String.valueOf(info.pos)); |
mcimadamore@676 | 737 | end.setText(String.valueOf(info.end)); |
mcimadamore@676 | 738 | } |
mcimadamore@676 | 739 | |
mcimadamore@676 | 740 | JTextField addListener(final JTextField f) { |
mcimadamore@676 | 741 | f.addMouseListener(new MouseAdapter() { |
mcimadamore@676 | 742 | @Override |
mcimadamore@676 | 743 | public void mouseClicked(MouseEvent e) { |
mcimadamore@676 | 744 | body.setCaretPosition(Integer.valueOf(f.getText())); |
mcimadamore@676 | 745 | body.getCaret().setVisible(true); |
mcimadamore@676 | 746 | } |
mcimadamore@676 | 747 | }); |
mcimadamore@676 | 748 | return f; |
mcimadamore@676 | 749 | } |
mcimadamore@676 | 750 | |
mcimadamore@676 | 751 | Info info; |
mcimadamore@676 | 752 | JTextField tagName; |
mcimadamore@676 | 753 | JTextField start; |
mcimadamore@676 | 754 | JTextField pos; |
mcimadamore@676 | 755 | JTextField end; |
mcimadamore@676 | 756 | } |
mcimadamore@676 | 757 | |
mcimadamore@676 | 758 | /** Object to record information about an error to be displayed. */ |
mcimadamore@676 | 759 | private class Entry { |
mcimadamore@676 | 760 | Entry(JavaFileObject file, String check, Info encl, Info self) { |
mcimadamore@676 | 761 | this.file = file; |
mcimadamore@676 | 762 | this.check = check; |
mcimadamore@676 | 763 | this.encl = encl; |
mcimadamore@676 | 764 | this.self= self; |
mcimadamore@676 | 765 | } |
mcimadamore@676 | 766 | |
mcimadamore@676 | 767 | @Override |
mcimadamore@676 | 768 | public String toString() { |
mcimadamore@676 | 769 | return file.getName() + " " + check + " " + getMinPos(encl, self); |
mcimadamore@676 | 770 | } |
mcimadamore@676 | 771 | |
mcimadamore@676 | 772 | final JavaFileObject file; |
mcimadamore@676 | 773 | final String check; |
mcimadamore@676 | 774 | final Info encl; |
mcimadamore@676 | 775 | final Info self; |
mcimadamore@676 | 776 | } |
mcimadamore@676 | 777 | } |
mcimadamore@676 | 778 | } |