test/tools/javac/api/EndPositions.java

changeset 1521
71f35e4b93a5
parent 1323
1a7c11b22192
child 2525
2eb010b6cb22
equal deleted inserted replaced
1520:5c956be64b9e 1521:71f35e4b93a5
1 /* 1 /*
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2010, 2013, 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.
26 * @bug 7196760 26 * @bug 7196760
27 * @summary javac doesn't report Diagnostic end positions properly when 27 * @summary javac doesn't report Diagnostic end positions properly when
28 * an annotation processor is present 28 * an annotation processor is present
29 */ 29 */
30 30
31 import com.sun.source.tree.ClassTree;
32 import com.sun.source.tree.CompilationUnitTree;
33 import com.sun.source.tree.Tree;
34 import com.sun.source.util.JavacTask; 31 import com.sun.source.util.JavacTask;
35 import com.sun.source.util.Trees;
36 import java.io.IOException; 32 import java.io.IOException;
37 import java.net.URI; 33 import java.net.URI;
38 import java.util.Arrays; 34 import java.util.Arrays;
39 import java.util.Collections; 35 import java.util.Collections;
40 import java.util.List; 36 import java.util.List;
70 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); 66 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
71 List<String> options = Arrays.asList("-processor", EndPositions.class.getCanonicalName()); 67 List<String> options = Arrays.asList("-processor", EndPositions.class.getCanonicalName());
72 JavacTask task = (JavacTask)javac.getTask(null, null, diagnostics, options, null, compilationUnits); 68 JavacTask task = (JavacTask)javac.getTask(null, null, diagnostics, options, null, compilationUnits);
73 boolean valid = task.call(); 69 boolean valid = task.call();
74 if (valid) 70 if (valid)
75 throw new AssertionError("Compilation succeeded unexpectedly"); 71 throw new AssertionError("Expected one error, but found none.");
76 72
77 List<Diagnostic<? extends JavaFileObject>> errors = diagnostics.getDiagnostics(); 73 List<Diagnostic<? extends JavaFileObject>> errors = diagnostics.getDiagnostics();
78 if (errors.size() != 1) 74 if (errors.size() != 1)
79 throw new AssertionError("Expected one error only, but found " + errors.size() + " errors"); 75 throw new AssertionError("Expected one error only, but found " + errors.size() + "; errors: " + errors);
80 76
81 Diagnostic<?> error = errors.get(0); 77 Diagnostic<?> error = errors.get(0);
82 if (error.getStartPosition() >= error.getEndPosition()) 78 if (error.getStartPosition() >= error.getEndPosition())
83 throw new AssertionError("Expected start to be less than end position: start [" + 79 throw new AssertionError("Expected start to be less than end position: start [" +
84 error.getStartPosition() + "], end [" + error.getEndPosition() +"]"); 80 error.getStartPosition() + "], end [" + error.getEndPosition() +"]" +
81 "; diagnostics code: " + error.getCode());
85 82
86 System.out.println("All is good!"); 83 System.out.println("All is good!");
87 } 84 }
88 85
89 @Override 86 @Override

mercurial