langtools/test/tools/javac/T6665791.java
changeset 27319 030080f03e4f
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2010, 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.
    45 
    45 
    46     public static void main(String[] args) throws Exception {
    46     public static void main(String[] args) throws Exception {
    47         write(test_java, test);
    47         write(test_java, test);
    48 
    48 
    49         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    49         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    50         StandardJavaFileManager manager =
    50         try (StandardJavaFileManager manager =
    51                 compiler.getStandardFileManager(null, null, null);
    51                 compiler.getStandardFileManager(null, null, null)) {
    52         Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
    52             Iterable<? extends JavaFileObject> units = manager.getJavaFileObjects(test_java);
    53         final StringWriter sw = new StringWriter();
    53             final StringWriter sw = new StringWriter();
    54         JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
    54             JavacTask task = (JavacTask) compiler.getTask(sw, manager, null, null,
    55                 null, units);
    55                     null, units);
    56 
    56 
    57         new TreeScanner<Boolean, Void>() {
    57             new TreeScanner<Boolean, Void>() {
    58             @Override
    58                 @Override
    59             public Boolean visitClass(ClassTree arg0, Void arg1) {
    59                 public Boolean visitClass(ClassTree arg0, Void arg1) {
    60                 sw.write(arg0.toString());
    60                     sw.write(arg0.toString());
    61                 return super.visitClass(arg0, arg1);
    61                     return super.visitClass(arg0, arg1);
       
    62                 }
       
    63             }.scan(task.parse(), null);
       
    64 
       
    65             System.out.println("output:");
       
    66             System.out.println(sw.toString());
       
    67             String found = sw.toString().replaceAll("\\s+", " ").trim();
       
    68             String expect = test.replaceAll("\\s+", " ").trim();
       
    69             if (!expect.equals(found)) {
       
    70                 System.out.println("expect: " + expect);
       
    71                 System.out.println("found:  " + found);
       
    72                 throw new Exception("unexpected output");
    62             }
    73             }
    63         }.scan(task.parse(), null);
       
    64 
       
    65         System.out.println("output:");
       
    66         System.out.println(sw.toString());
       
    67         String found = sw.toString().replaceAll("\\s+", " ").trim();
       
    68         String expect = test.replaceAll("\\s+", " ").trim();
       
    69         if (!expect.equals(found)) {
       
    70             System.out.println("expect: " + expect);
       
    71             System.out.println("found:  " + found);
       
    72             throw new Exception("unexpected output");
       
    73         }
    74         }
    74     }
    75     }
    75 
    76 
    76     static void write(File file, String body) throws IOException {
    77     static void write(File file, String body) throws IOException {
    77         FileWriter out = new FileWriter(file);
    78         FileWriter out = new FileWriter(file);