29 import java.net.URI; |
29 import java.net.URI; |
30 import javax.lang.model.element.Modifier; |
30 import javax.lang.model.element.Modifier; |
31 import javax.lang.model.element.NestingKind; |
31 import javax.lang.model.element.NestingKind; |
32 import javax.tools.JavaFileObject; |
32 import javax.tools.JavaFileObject; |
33 |
33 |
|
34 import com.sun.tools.javac.util.DefinedBy; |
|
35 import com.sun.tools.javac.util.DefinedBy.Api; |
|
36 |
34 /** |
37 /** |
35 * The SmartFileObject will return an outputstream that cache the written data |
38 * The SmartFileObject will return an outputstream that cache the written data |
36 * and compare the new content with the old content on disk. Only if they differ, |
39 * and compare the new content with the old content on disk. Only if they differ, |
37 * will the file be updated. |
40 * will the file be updated. |
38 * |
41 * |
59 @Override |
62 @Override |
60 public int hashCode() { |
63 public int hashCode() { |
61 return file.hashCode(); |
64 return file.hashCode(); |
62 } |
65 } |
63 |
66 |
|
67 @DefinedBy(Api.COMPILER) |
64 public Kind getKind() { |
68 public Kind getKind() { |
65 return file.getKind(); |
69 return file.getKind(); |
66 } |
70 } |
67 |
71 |
|
72 @DefinedBy(Api.COMPILER) |
68 public boolean isNameCompatible(String simpleName, Kind kind) { |
73 public boolean isNameCompatible(String simpleName, Kind kind) { |
69 return file.isNameCompatible(simpleName, kind); |
74 return file.isNameCompatible(simpleName, kind); |
70 } |
75 } |
71 |
76 |
|
77 @DefinedBy(Api.COMPILER) |
72 public URI toUri() { |
78 public URI toUri() { |
73 return file.toUri(); |
79 return file.toUri(); |
74 } |
80 } |
75 |
81 |
|
82 @DefinedBy(Api.COMPILER) |
76 public String getName() { |
83 public String getName() { |
77 return file.getName(); |
84 return file.getName(); |
78 } |
85 } |
79 |
86 |
|
87 @DefinedBy(Api.COMPILER) |
80 public InputStream openInputStream() throws IOException { |
88 public InputStream openInputStream() throws IOException { |
81 return file.openInputStream(); |
89 return file.openInputStream(); |
82 } |
90 } |
83 |
91 |
|
92 @DefinedBy(Api.COMPILER) |
84 public OutputStream openOutputStream() throws IOException { |
93 public OutputStream openOutputStream() throws IOException { |
85 return file.openOutputStream(); |
94 return file.openOutputStream(); |
86 } |
95 } |
87 |
96 |
|
97 @DefinedBy(Api.COMPILER) |
88 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
98 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
89 return file.getCharContent(ignoreEncodingErrors); |
99 return file.getCharContent(ignoreEncodingErrors); |
90 } |
100 } |
91 |
101 |
92 static String lineseparator = System.getProperty("line.separator"); |
102 static String lineseparator = System.getProperty("line.separator"); |
93 |
103 |
|
104 @DefinedBy(Api.COMPILER) |
94 public Writer openWriter() throws IOException { |
105 public Writer openWriter() throws IOException { |
95 StringBuilder s = new StringBuilder(); |
106 StringBuilder s = new StringBuilder(); |
96 try (BufferedReader r = new BufferedReader(file.openReader(true))) { |
107 try (BufferedReader r = new BufferedReader(file.openReader(true))) { |
97 while (r.ready()) { |
108 while (r.ready()) { |
98 s.append(r.readLine()+lineseparator); |
109 s.append(r.readLine()+lineseparator); |
101 // Perfectly ok. |
112 // Perfectly ok. |
102 } |
113 } |
103 return new SmartWriter(file, s.toString(), file.getName(), stdout); |
114 return new SmartWriter(file, s.toString(), file.getName(), stdout); |
104 } |
115 } |
105 |
116 |
|
117 @DefinedBy(Api.COMPILER) |
106 public long getLastModified() { |
118 public long getLastModified() { |
107 return file.getLastModified(); |
119 return file.getLastModified(); |
108 } |
120 } |
109 |
121 |
|
122 @DefinedBy(Api.COMPILER) |
110 public boolean delete() { |
123 public boolean delete() { |
111 return file.delete(); |
124 return file.delete(); |
112 } |
125 } |
113 |
126 |
|
127 @DefinedBy(Api.COMPILER) |
114 public Modifier getAccessLevel() { |
128 public Modifier getAccessLevel() { |
115 return file.getAccessLevel(); |
129 return file.getAccessLevel(); |
116 } |
130 } |
117 |
131 |
|
132 @DefinedBy(Api.COMPILER) |
118 public NestingKind getNestingKind() { |
133 public NestingKind getNestingKind() { |
119 return file.getNestingKind(); |
134 return file.getNestingKind(); |
120 } |
135 } |
121 |
136 |
|
137 @DefinedBy(Api.COMPILER) |
122 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
138 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { |
123 return file.openReader(ignoreEncodingErrors); |
139 return file.openReader(ignoreEncodingErrors); |
124 } |
140 } |
125 |
141 |
126 } |
142 } |