001package org.crsh.lang.java; 002 003import javax.lang.model.element.NestingKind; 004import javax.tools.JavaFileObject; 005import java.io.IOException; 006import java.io.InputStream; 007import java.io.OutputStream; 008import java.io.Reader; 009import java.io.Writer; 010import javax.lang.model.element.Modifier; 011import java.net.URI; 012 013/** @author Julien Viet */ 014class URIJavaFileObject implements JavaFileObject { 015 016 /** . */ 017 final String binaryName; 018 019 /** . */ 020 private final URI uri; 021 022 /** . */ 023 private final String name; 024 025 /** . */ 026 private final long lastModified; 027 028 public URIJavaFileObject(String binaryName, URI uri, long lastModified) { 029 this.uri = uri; 030 this.binaryName = binaryName; 031 this.name = uri.getPath() == null ? uri.getSchemeSpecificPart() : uri.getPath(); 032 this.lastModified = lastModified; 033 } 034 035 public URI toUri() { 036 return uri; 037 } 038 039 public String getName() { 040 return name; 041 } 042 043 public long getLastModified() { 044 return lastModified; 045 } 046 047 public InputStream openInputStream() throws IOException { 048 return uri.toURL().openStream(); 049 } 050 051 public OutputStream openOutputStream() throws IOException { 052 throw new UnsupportedOperationException(); 053 } 054 055 public Reader openReader(boolean ignoreEncodingErrors) throws IOException { 056 throw new UnsupportedOperationException(); 057 } 058 059 public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 060 throw new UnsupportedOperationException(); 061 } 062 063 public Writer openWriter() throws IOException { 064 throw new UnsupportedOperationException(); 065 } 066 067 public boolean delete() { 068 return false; 069 } 070 071 public Kind getKind() { 072 return Kind.CLASS; 073 } 074 075 public boolean isNameCompatible(String simpleName, Kind kind) { 076 String baseName = simpleName + kind.extension; 077 return kind.equals(getKind()) 078 && (baseName.equals(getName()) 079 || getName().endsWith("/" + baseName)); 080 } 081 082 public NestingKind getNestingKind() { 083 return null; 084 } 085 086 public Modifier getAccessLevel() { 087 return null; 088 } 089 090 @Override 091 public String toString() { 092 return getClass().getSimpleName() + "[uri=" + uri + "]"; 093 } 094}