langtools/test/tools/javac/6457284/T6457284.java
changeset 26264 a09fedde76be
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
equal deleted inserted replaced
26263:5ce1fe94b270 26264:a09fedde76be
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2008, 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.
    30 
    30 
    31 import java.io.IOException;
    31 import java.io.IOException;
    32 import java.net.URI;
    32 import java.net.URI;
    33 import javax.lang.model.element.Element;
    33 import javax.lang.model.element.Element;
    34 
    34 
    35 import com.sun.tools.javac.api.JavacTaskImpl;
    35 import com.sun.source.util.JavacTask;
       
    36 import com.sun.tools.javac.api.JavacTool;
    36 import com.sun.tools.javac.util.Context;
    37 import com.sun.tools.javac.util.Context;
    37 import com.sun.tools.javac.util.List;
    38 import com.sun.tools.javac.util.List;
    38 import com.sun.tools.javac.util.JavacMessages;
    39 import com.sun.tools.javac.util.JavacMessages;
    39 
    40 
    40 import javax.tools.*;
    41 import javax.tools.*;
    47         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
    48         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
    48             return "class Test {}";
    49             return "class Test {}";
    49         }
    50         }
    50     }
    51     }
    51     public static void main(String[] args) throws IOException {
    52     public static void main(String[] args) throws IOException {
    52         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    53         Context context = new Context();
    53         JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, null, null, null, null,
    54         MyMessages.preRegister(context);
    54                                                              List.of(new MyFileObject()));
    55         JavacTool tool = JavacTool.create();
    55         MyMessages.preRegister(task.getContext());
    56         JavacTask task = tool.getTask(null, null, null, null, null,
       
    57                                       List.of(new MyFileObject()),
       
    58                                       context);
    56         task.parse();
    59         task.parse();
    57         for (Element e : task.analyze()) {
    60         for (Element e : task.analyze()) {
    58             if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package"))
    61             if (!e.getEnclosingElement().toString().equals("compiler.misc.unnamed.package"))
    59                 throw new AssertionError(e.getEnclosingElement());
    62                 throw new AssertionError(e.getEnclosingElement());
    60             System.out.println("OK: " + e.getEnclosingElement());
    63             System.out.println("OK: " + e.getEnclosingElement());