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
jjg@458 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@458 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@458 | 4 | * |
jjg@458 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@458 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@458 | 7 | * published by the Free Software Foundation. |
jjg@458 | 8 | * |
jjg@458 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@458 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@458 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@458 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@458 | 13 | * accompanied this code). |
jjg@458 | 14 | * |
jjg@458 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@458 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@458 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@458 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
jjg@458 | 22 | */ |
jjg@458 | 23 | |
jjg@458 | 24 | /* |
jjg@458 | 25 | * @test |
jjg@458 | 26 | * @bug 6855236 |
jjg@458 | 27 | * @summary Compiler Tree API TreePath class generates NullPointerException from Iterator |
jjg@458 | 28 | * @compile T6855236.java |
jjg@458 | 29 | * @compile -processor T6855236 -proc:only T6855236.java |
jjg@458 | 30 | */ |
jjg@458 | 31 | |
jjg@458 | 32 | import java.util.*; |
jjg@458 | 33 | |
jjg@458 | 34 | import javax.annotation.processing.*; |
jjg@458 | 35 | import javax.lang.model.*; |
jjg@458 | 36 | import javax.lang.model.element.*; |
jjg@458 | 37 | |
jjg@458 | 38 | import com.sun.source.tree.*; |
jjg@458 | 39 | import com.sun.source.util.*; |
jjg@458 | 40 | |
jjg@458 | 41 | @SupportedAnnotationTypes("*") |
jjg@458 | 42 | public class T6855236 extends AbstractProcessor { |
jjg@458 | 43 | |
jjg@458 | 44 | private Trees trees; |
jjg@458 | 45 | |
jjg@458 | 46 | @Override |
jjg@458 | 47 | public void init(ProcessingEnvironment pe) { |
jjg@458 | 48 | super.init(pe); |
jjg@458 | 49 | trees = Trees.instance(pe); |
jjg@458 | 50 | } |
jjg@458 | 51 | |
jjg@458 | 52 | @Override |
jjg@458 | 53 | public boolean process(Set<? extends TypeElement> arg0, RoundEnvironment roundEnvironment) { |
jjg@458 | 54 | // Scanner class to scan through various component elements |
jjg@458 | 55 | CodeVisitor visitor = new CodeVisitor(); |
jjg@458 | 56 | |
jjg@458 | 57 | for (Element e : roundEnvironment.getRootElements()) { |
jjg@458 | 58 | TreePath tp = trees.getPath(e); |
jjg@458 | 59 | visitor.scan(tp, trees); |
jjg@458 | 60 | } |
jjg@458 | 61 | |
jjg@458 | 62 | return true; |
jjg@458 | 63 | } |
jjg@458 | 64 | |
darcy@495 | 65 | @Override |
darcy@495 | 66 | public SourceVersion getSupportedSourceVersion() { |
darcy@495 | 67 | return SourceVersion.latest(); |
darcy@495 | 68 | } |
darcy@495 | 69 | |
jjg@458 | 70 | class CodeVisitor extends TreePathScanner<Object, Trees> { |
jjg@458 | 71 | |
jjg@458 | 72 | @Override |
jjg@458 | 73 | public Object visitMethodInvocation(MethodInvocationTree node, Trees p) { |
jjg@683 | 74 | System.out.println("current path: "); |
jjg@458 | 75 | for (Tree t : getCurrentPath()) { |
jjg@683 | 76 | System.out.println(" " + t.getKind() + ": " + trim(t, 64)); |
jjg@683 | 77 | } |
jjg@458 | 78 | System.out.println("parent path: " + getCurrentPath().getParentPath()); |
jjg@458 | 79 | System.out.println("method select: " + node.getMethodSelect().toString()); |
jjg@458 | 80 | for (ExpressionTree arg : node.getArguments()) { |
jjg@458 | 81 | System.out.println("argument: " + arg.toString()); |
jjg@458 | 82 | } |
jjg@458 | 83 | return super.visitMethodInvocation(node, p); |
jjg@458 | 84 | } |
jjg@458 | 85 | |
jjg@458 | 86 | @Override |
jjg@458 | 87 | public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) { |
jjg@458 | 88 | ExpressionTree t = node.getExpression(); |
jjg@683 | 89 | System.out.println(); |
jjg@683 | 90 | System.out.println("expression statement: " + trim(t, 64)); |
jjg@458 | 91 | return super.visitExpressionStatement(node, p); |
jjg@458 | 92 | } |
jjg@458 | 93 | |
jjg@458 | 94 | } |
jjg@458 | 95 | |
jjg@683 | 96 | private String trim(Tree t, int len) { |
jjg@683 | 97 | String s = t.toString().trim().replaceAll("\\s+", " "); |
jjg@683 | 98 | if (s.length() > len) |
jjg@683 | 99 | s = s.substring(0, len) + "..."; |
jjg@683 | 100 | return s; |
jjg@683 | 101 | } |
jjg@683 | 102 | |
jjg@458 | 103 | } |
jjg@458 | 104 | |
jjg@458 | 105 |