27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 import java.net.URI; |
29 import java.net.URI; |
30 import java.net.URISyntaxException; |
30 import java.net.URISyntaxException; |
31 import java.nio.CharBuffer; |
31 import java.nio.CharBuffer; |
32 import java.nio.file.Path; |
|
33 import java.util.Arrays; |
32 import java.util.Arrays; |
34 import java.util.EnumSet; |
33 import java.util.EnumSet; |
35 import java.util.HashMap; |
34 import java.util.HashMap; |
36 import java.util.HashSet; |
35 import java.util.HashSet; |
37 import java.util.Map; |
36 import java.util.Map; |
38 import java.util.Set; |
37 import java.util.Set; |
|
38 |
|
39 import javax.lang.model.element.Modifier; |
|
40 import javax.lang.model.element.NestingKind; |
39 import javax.tools.JavaFileManager; |
41 import javax.tools.JavaFileManager; |
40 import javax.tools.JavaFileObject; |
42 import javax.tools.JavaFileObject; |
|
43 |
41 import com.sun.tools.javac.comp.Annotate; |
44 import com.sun.tools.javac.comp.Annotate; |
42 import com.sun.tools.javac.comp.Annotate.AnnotationTypeCompleter; |
45 import com.sun.tools.javac.comp.Annotate.AnnotationTypeCompleter; |
43 import com.sun.tools.javac.code.*; |
46 import com.sun.tools.javac.code.*; |
44 import com.sun.tools.javac.code.Lint.LintCategory; |
47 import com.sun.tools.javac.code.Lint.LintCategory; |
45 import com.sun.tools.javac.code.Scope.WriteableScope; |
48 import com.sun.tools.javac.code.Scope.WriteableScope; |
46 import com.sun.tools.javac.code.Symbol.*; |
49 import com.sun.tools.javac.code.Symbol.*; |
47 import com.sun.tools.javac.code.Symtab; |
50 import com.sun.tools.javac.code.Symtab; |
48 import com.sun.tools.javac.code.Type.*; |
51 import com.sun.tools.javac.code.Type.*; |
49 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
52 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata; |
50 import com.sun.tools.javac.file.BaseFileObject; |
53 import com.sun.tools.javac.file.BaseFileManager; |
|
54 import com.sun.tools.javac.file.PathFileObject; |
51 import com.sun.tools.javac.jvm.ClassFile.NameAndType; |
55 import com.sun.tools.javac.jvm.ClassFile.NameAndType; |
52 import com.sun.tools.javac.jvm.ClassFile.Version; |
56 import com.sun.tools.javac.jvm.ClassFile.Version; |
53 import com.sun.tools.javac.util.*; |
57 import com.sun.tools.javac.util.*; |
54 import com.sun.tools.javac.util.DefinedBy.Api; |
58 import com.sun.tools.javac.util.DefinedBy.Api; |
55 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
59 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
2463 * A subclass of JavaFileObject for the sourcefile attribute found in a classfile. |
2467 * A subclass of JavaFileObject for the sourcefile attribute found in a classfile. |
2464 * The attribute is only the last component of the original filename, so is unlikely |
2468 * The attribute is only the last component of the original filename, so is unlikely |
2465 * to be valid as is, so operations other than those to access the name throw |
2469 * to be valid as is, so operations other than those to access the name throw |
2466 * UnsupportedOperationException |
2470 * UnsupportedOperationException |
2467 */ |
2471 */ |
2468 private static class SourceFileObject extends BaseFileObject { |
2472 private static class SourceFileObject implements JavaFileObject { |
2469 |
2473 |
2470 /** The file's name. |
2474 /** The file's name. |
2471 */ |
2475 */ |
2472 private Name name; |
2476 private final Name name; |
2473 private Name flatname; |
2477 private final Name flatname; |
2474 |
2478 |
2475 public SourceFileObject(Name name, Name flatname) { |
2479 public SourceFileObject(Name name, Name flatname) { |
2476 super(null); // no file manager; never referenced for this file object |
|
2477 this.name = name; |
2480 this.name = name; |
2478 this.flatname = flatname; |
2481 this.flatname = flatname; |
2479 } |
2482 } |
2480 |
2483 |
2481 @Override @DefinedBy(Api.COMPILER) |
2484 @Override @DefinedBy(Api.COMPILER) |
2482 public URI toUri() { |
2485 public URI toUri() { |
2483 try { |
2486 try { |
2484 return new URI(null, name.toString(), null); |
2487 return new URI(null, name.toString(), null); |
2485 } catch (URISyntaxException e) { |
2488 } catch (URISyntaxException e) { |
2486 throw new CannotCreateUriError(name.toString(), e); |
2489 throw new PathFileObject.CannotCreateUriError(name.toString(), e); |
2487 } |
2490 } |
2488 } |
2491 } |
2489 |
2492 |
2490 @Override @DefinedBy(Api.COMPILER) |
2493 @Override @DefinedBy(Api.COMPILER) |
2491 public String getName() { |
2494 public String getName() { |
2492 return name.toString(); |
2495 return name.toString(); |
2493 } |
2496 } |
2494 |
2497 |
2495 @Override |
|
2496 public String getShortName() { |
|
2497 return getName(); |
|
2498 } |
|
2499 |
|
2500 @Override @DefinedBy(Api.COMPILER) |
2498 @Override @DefinedBy(Api.COMPILER) |
2501 public JavaFileObject.Kind getKind() { |
2499 public JavaFileObject.Kind getKind() { |
2502 return getKind(getName()); |
2500 return BaseFileManager.getKind(getName()); |
2503 } |
2501 } |
2504 |
2502 |
2505 @Override @DefinedBy(Api.COMPILER) |
2503 @Override @DefinedBy(Api.COMPILER) |
2506 public InputStream openInputStream() { |
2504 public InputStream openInputStream() { |
2507 throw new UnsupportedOperationException(); |
2505 throw new UnsupportedOperationException(); |
2535 @Override @DefinedBy(Api.COMPILER) |
2533 @Override @DefinedBy(Api.COMPILER) |
2536 public boolean delete() { |
2534 public boolean delete() { |
2537 throw new UnsupportedOperationException(); |
2535 throw new UnsupportedOperationException(); |
2538 } |
2536 } |
2539 |
2537 |
2540 @Override |
|
2541 protected String inferBinaryName(Iterable<? extends Path> path) { |
|
2542 return flatname.toString(); |
|
2543 } |
|
2544 |
|
2545 @Override @DefinedBy(Api.COMPILER) |
2538 @Override @DefinedBy(Api.COMPILER) |
2546 public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) { |
2539 public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) { |
2547 return true; // fail-safe mode |
2540 return true; // fail-safe mode |
|
2541 } |
|
2542 |
|
2543 @Override @DefinedBy(Api.COMPILER) |
|
2544 public NestingKind getNestingKind() { |
|
2545 return null; |
|
2546 } |
|
2547 |
|
2548 @Override @DefinedBy(Api.COMPILER) |
|
2549 public Modifier getAccessLevel() { |
|
2550 return null; |
2548 } |
2551 } |
2549 |
2552 |
2550 /** |
2553 /** |
2551 * Check if two file objects are equal. |
2554 * Check if two file objects are equal. |
2552 * SourceFileObjects are just placeholder objects for the value of a |
2555 * SourceFileObjects are just placeholder objects for the value of a |