langtools/test/tools/javac/tree/TreePosRoundsTest.java
changeset 27319 030080f03e4f
parent 6717 0103d76cfe48
child 27991 8f4b68523da3
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.
    52 public class TreePosRoundsTest extends AbstractProcessor {
    52 public class TreePosRoundsTest extends AbstractProcessor {
    53     public static void main(String... args) throws Exception {
    53     public static void main(String... args) throws Exception {
    54         String testSrc = System.getProperty("test.src");
    54         String testSrc = System.getProperty("test.src");
    55         String testClasses = System.getProperty("test.classes");
    55         String testClasses = System.getProperty("test.classes");
    56         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    56         JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    57         StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
    57         try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) {
    58         String thisName = TreePosRoundsTest.class.getName();
    58             String thisName = TreePosRoundsTest.class.getName();
    59         File thisFile = new File(testSrc, thisName + ".java");
    59             File thisFile = new File(testSrc, thisName + ".java");
    60         Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
    60             Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
    61         List<String> options = Arrays.asList(
    61             List<String> options = Arrays.asList(
    62                 "-proc:only",
    62                     "-proc:only",
    63                 "-processor", thisName,
    63                     "-processor", thisName,
    64                 "-processorpath", testClasses);
    64                     "-processorpath", testClasses);
    65         CompilationTask t = c.getTask(null, fm, null, options, null, files);
    65             CompilationTask t = c.getTask(null, fm, null, options, null, files);
    66         boolean ok = t.call();
    66             boolean ok = t.call();
    67         if (!ok)
    67             if (!ok)
    68             throw new Exception("processing failed");
    68                 throw new Exception("processing failed");
       
    69         }
    69     }
    70     }
    70 
    71 
    71     Filer filer;
    72     Filer filer;
    72     Messager messager;
    73     Messager messager;
    73     Trees trees;
    74     Trees trees;
   153                 // so deal with that manually...
   154                 // so deal with that manually...
   154                 Tree.Kind enclKind = tp.getParentPath().getLeaf().getKind();
   155                 Tree.Kind enclKind = tp.getParentPath().getLeaf().getKind();
   155                 //System.err.println("  encl: " +enclKind);
   156                 //System.err.println("  encl: " +enclKind);
   156                 if (enclKind == Tree.Kind.CLASS || enclKind == Tree.Kind.BLOCK)
   157                 if (enclKind == Tree.Kind.CLASS || enclKind == Tree.Kind.BLOCK)
   157                     expect += ";";
   158                     expect += ";";
       
   159                 // t-w-r- adds implicit final: remove it
       
   160                 if (enclKind == Tree.Kind.TRY && expect.startsWith("final "))
       
   161                     expect = expect.substring(6);
   158             }
   162             }
   159             //System.err.println("expect: " + expect);
   163             //System.err.println("expect: " + expect);
   160 
   164 
   161             int start = (int)sourcePositions.getStartPosition(unit, tree);
   165             int start = (int)sourcePositions.getStartPosition(unit, tree);
   162             if (start == Diagnostic.NOPOS) {
   166             if (start == Diagnostic.NOPOS) {