Mon, 08 Apr 2013 15:53:08 +0100
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
Summary: Ignore indy entries in LineNumberTable
Reviewed-by: jjg
duke@1 | 1 | /* |
duke@1 | 2 | * @test /nodynamiccopyright/ |
duke@1 | 3 | * @bug 6406771 |
duke@1 | 4 | * @summary CompilationUnitTree needs access to a line map |
duke@1 | 5 | */ |
duke@1 | 6 | |
duke@1 | 7 | // WARNING: White-space and layout is important in this file, especially tab characters. |
duke@1 | 8 | |
duke@1 | 9 | import java.io.*; |
duke@1 | 10 | import java.util.*; |
duke@1 | 11 | import javax.annotation.processing.*; |
duke@1 | 12 | import javax.lang.model.*; |
duke@1 | 13 | import javax.lang.model.element.*; |
duke@1 | 14 | import javax.tools.*; |
duke@1 | 15 | import com.sun.tools.javac.api.*; |
duke@1 | 16 | import com.sun.source.tree.*; |
duke@1 | 17 | import com.sun.source.util.*; |
duke@1 | 18 | import com.sun.tools.javac.tree.JCTree; |
duke@1 | 19 | |
darcy@495 | 20 | |
duke@1 | 21 | @SupportedAnnotationTypes("*") |
duke@1 | 22 | public class T6406771 extends AbstractProcessor { |
duke@1 | 23 | String[] tests = { |
duke@1 | 24 | "line:24", |
duke@1 | 25 | "line:25", |
duke@1 | 26 | "line:26", "line:26", |
duke@1 | 27 | // 1 2 3 4 5 6 |
duke@1 | 28 | //3456789012345678901234567890123456789012345678901234567890 |
duke@1 | 29 | "col:7", "col:16", "col:26", // this line uses spaces |
duke@1 | 30 | "col:9", "col:25", "col:41", // this line uses tabs |
duke@1 | 31 | "col:20", "col:43" // this line uses a mixture |
duke@1 | 32 | }; |
duke@1 | 33 | |
duke@1 | 34 | // White-space after this point does not matter |
duke@1 | 35 | |
duke@1 | 36 | public static void main(String[] args) { |
duke@1 | 37 | String self = T6406771.class.getName(); |
duke@1 | 38 | String testSrc = System.getProperty("test.src"); |
duke@1 | 39 | String testClasses = System.getProperty("test.classes"); |
duke@1 | 40 | |
duke@1 | 41 | JavacTool tool = JavacTool.create(); |
duke@1 | 42 | StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
duke@1 | 43 | JavaFileObject f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, self+".java"))).iterator().next(); |
duke@1 | 44 | |
duke@1 | 45 | List<String> opts = Arrays.asList("-d", ".", "-processorpath", testClasses, "-processor", self, "-proc:only"); |
duke@1 | 46 | |
duke@1 | 47 | JavacTask task = tool.getTask(null, fm, null, opts, null, Arrays.asList(f)); |
duke@1 | 48 | |
duke@1 | 49 | if (!task.call()) |
duke@1 | 50 | throw new AssertionError("failed"); |
duke@1 | 51 | } |
duke@1 | 52 | |
duke@1 | 53 | public boolean process(Set<? extends TypeElement> elems, RoundEnvironment rEnv) { |
duke@1 | 54 | final String LINE = "line" + ':'; // avoid matching this string |
duke@1 | 55 | final String COLUMN = "col" + ':'; |
duke@1 | 56 | final Messager messager = processingEnv.getMessager(); |
duke@1 | 57 | final Trees trees = Trees.instance(processingEnv); |
duke@1 | 58 | |
duke@1 | 59 | TreeScanner<Void,LineMap> s = new TreeScanner<Void,LineMap>() { |
duke@1 | 60 | public Void visitLiteral(LiteralTree tree, LineMap lineMap) { |
duke@1 | 61 | if (tree.getKind() == Tree.Kind.STRING_LITERAL) { |
duke@1 | 62 | String s = (String) tree.getValue(); |
duke@1 | 63 | int pos = ((JCTree) tree).pos; // can't get through public api, bug 6412669 filed |
duke@1 | 64 | String prefix; |
duke@1 | 65 | long found; |
duke@1 | 66 | if (s.startsWith(LINE)) { |
duke@1 | 67 | prefix = LINE; |
duke@1 | 68 | found = lineMap.getLineNumber(pos); |
duke@1 | 69 | } |
duke@1 | 70 | else if (s.startsWith(COLUMN)) { |
duke@1 | 71 | prefix = COLUMN; |
duke@1 | 72 | found = lineMap.getColumnNumber(pos); |
duke@1 | 73 | } |
duke@1 | 74 | else |
duke@1 | 75 | return null; |
duke@1 | 76 | int expect = Integer.parseInt(s.substring(prefix.length())); |
duke@1 | 77 | if (expect != found) { |
duke@1 | 78 | messager.printMessage(Diagnostic.Kind.ERROR, |
duke@1 | 79 | "Error: " + prefix + " pos=" + pos |
duke@1 | 80 | + " expect=" + expect + " found=" + found); |
duke@1 | 81 | } |
duke@1 | 82 | } |
duke@1 | 83 | return null; |
duke@1 | 84 | } |
duke@1 | 85 | }; |
duke@1 | 86 | |
duke@1 | 87 | for (Element e: rEnv.getRootElements()) { |
duke@1 | 88 | System.err.println(e); |
duke@1 | 89 | Tree t = trees.getTree(e); |
duke@1 | 90 | TreePath p = trees.getPath(e); |
duke@1 | 91 | s.scan(p.getLeaf(), p.getCompilationUnit().getLineMap()); |
duke@1 | 92 | |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | return true; |
duke@1 | 96 | } |
duke@1 | 97 | |
darcy@495 | 98 | @Override |
darcy@495 | 99 | public SourceVersion getSupportedSourceVersion() { |
darcy@495 | 100 | return SourceVersion.latest(); |
darcy@495 | 101 | } |
duke@1 | 102 | } |