langtools/test/tools/javac/positions/TreeEndPosTest.java
changeset 27319 030080f03e4f
parent 27121 36889255488f
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 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.
   135         ByteArrayOutputStream ba = new ByteArrayOutputStream();
   135         ByteArrayOutputStream ba = new ByteArrayOutputStream();
   136         PrintWriter writer = new PrintWriter(ba);
   136         PrintWriter writer = new PrintWriter(ba);
   137         File tempDir = new File(".");
   137         File tempDir = new File(".");
   138         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
   138         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
   139         DiagnosticCollector dc = new DiagnosticCollector();
   139         DiagnosticCollector dc = new DiagnosticCollector();
   140         JavaFileManager javaFileManager = getJavaFileManager(compiler, dc);
   140         try (JavaFileManager javaFileManager = getJavaFileManager(compiler, dc)) {
   141         List<String> options = new ArrayList<>();
   141             List<String> options = new ArrayList<>();
   142         options.add("-cp");
   142             options.add("-cp");
   143         options.add(tempDir.getPath());
   143             options.add(tempDir.getPath());
   144         options.add("-d");
   144             options.add("-d");
   145         options.add(tempDir.getPath());
   145             options.add(tempDir.getPath());
   146         options.add("-XDshouldStopPolicy=GENERATE");
   146             options.add("-XDshouldStopPolicy=GENERATE");
   147 
   147 
   148         List<JavaFileObject> sources = new ArrayList<>();
   148             List<JavaFileObject> sources = new ArrayList<>();
   149         sources.add(src);
   149             sources.add(src);
   150         JavaCompiler.CompilationTask task =
   150             JavaCompiler.CompilationTask task =
   151                 compiler.getTask(writer, javaFileManager,
   151                     compiler.getTask(writer, javaFileManager,
   152                 dc, options, null,
   152                     dc, options, null,
   153                 sources);
   153                     sources);
   154         task.call();
   154             task.call();
   155         for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
   155             for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
   156             long actualStart = diagnostic.getStartPosition();
   156                 long actualStart = diagnostic.getStartPosition();
   157             long actualEnd = diagnostic.getEndPosition();
   157                 long actualEnd = diagnostic.getEndPosition();
   158             System.out.println("Source: " + src.source);
   158                 System.out.println("Source: " + src.source);
   159             System.out.println("Diagnostic: " + diagnostic);
   159                 System.out.println("Diagnostic: " + diagnostic);
   160             System.out.print("Start position: Expected: " + src.startPos);
   160                 System.out.print("Start position: Expected: " + src.startPos);
   161             System.out.println(", Actual: " + actualStart);
   161                 System.out.println(", Actual: " + actualStart);
   162             System.out.print("End position: Expected: " + src.endPos);
   162                 System.out.print("End position: Expected: " + src.endPos);
   163             System.out.println(", Actual: " + actualEnd);
   163                 System.out.println(", Actual: " + actualEnd);
   164             if (src.startPos != actualStart || src.endPos != actualEnd) {
   164                 if (src.startPos != actualStart || src.endPos != actualEnd) {
   165                 throw new RuntimeException("error: trees don't match");
   165                     throw new RuntimeException("error: trees don't match");
       
   166                 }
   166             }
   167             }
   167         }
   168         }
   168     }
   169     }
   169 }
   170 }