langtools/test/tools/javac/api/T6392782.java
changeset 27319 030080f03e4f
parent 7681 1f0819a3341f
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 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.
    36 
    36 
    37 public class T6392782 {
    37 public class T6392782 {
    38     public static void main(String... args) throws IOException {
    38     public static void main(String... args) throws IOException {
    39         String testSrc = System.getProperty("test.src", ".");
    39         String testSrc = System.getProperty("test.src", ".");
    40         JavacTool tool = JavacTool.create();
    40         JavacTool tool = JavacTool.create();
    41         StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    41         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
    42         Iterable<? extends JavaFileObject> files =
    42             Iterable<? extends JavaFileObject> files =
    43             fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
    43                 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6392782.class.getName()+".java")));
    44         JavacTask task = tool.getTask(null, fm, null, null, null, files);
    44             JavacTask task = tool.getTask(null, fm, null, null, null, files);
    45         Iterable<? extends Tree> trees = task.parse();
    45             Iterable<? extends Tree> trees = task.parse();
    46         TreeScanner<Integer,Void> scanner = new MyScanner();
    46             TreeScanner<Integer,Void> scanner = new MyScanner();
    47         check(scanner, 6, scanner.scan(trees, null));
    47             check(scanner, 6, scanner.scan(trees, null));
    48 
    48 
    49         CountNodes nodeCounter = new CountNodes();
    49             CountNodes nodeCounter = new CountNodes();
    50         // 359 nodes with the regular parser; 360 nodes with EndPosParser
    50             // 359 nodes with the regular parser; 360 nodes with EndPosParser
    51         // We automatically switch to EndPosParser when calling JavacTask.parse()
    51             // We automatically switch to EndPosParser when calling JavacTask.parse()
    52         check(nodeCounter, 360, nodeCounter.scan(trees, null));
    52             check(nodeCounter, 362, nodeCounter.scan(trees, null));
    53 
    53 
    54         CountIdentifiers idCounter = new CountIdentifiers();
    54             CountIdentifiers idCounter = new CountIdentifiers();
    55         check(idCounter, 107, idCounter.scan(trees, null));
    55             check(idCounter, 107, idCounter.scan(trees, null));
       
    56         }
    56     }
    57     }
    57 
    58 
    58     private static void check(TreeScanner<?,?> scanner, int expect, int found) {
    59     private static void check(TreeScanner<?,?> scanner, int expect, int found) {
    59         if (found != expect)
    60         if (found != expect)
    60             throw new AssertionError(scanner.getClass().getName() + ": expected: " + expect + " found: " + found);
    61             throw new AssertionError(scanner.getClass().getName() + ": expected: " + expect + " found: " + found);