13693261870
2025-07-02 6708810c4de34dfb9513061432d656f91d56ee3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.ruoyi.buss.common.liquor;
 
 
import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import javax.tools.JavaFileObject;
import java.io.*;
import java.net.URI;
 
/**
 * This code mainly from: Arthas project
 * */
public class CustomJavaFileObject implements JavaFileObject {
    private final String className;
    private final URI uri;
 
    public CustomJavaFileObject(String className, URI uri) {
        this.uri = uri;
        this.className = className;
    }
 
    public URI toUri() {
        return uri;
    }
 
    public InputStream openInputStream() throws IOException {
        return uri.toURL().openStream();
    }
 
    public OutputStream openOutputStream() {
        throw new UnsupportedOperationException();
    }
 
    public String getName() {
        return this.className;
    }
 
    public Reader openReader(boolean ignoreEncodingErrors) {
        throw new UnsupportedOperationException();
    }
 
    public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        throw new UnsupportedOperationException();
    }
 
    public Writer openWriter() throws IOException {
        throw new UnsupportedOperationException();
    }
 
    public long getLastModified() {
        return 0;
    }
 
    public boolean delete() {
        throw new UnsupportedOperationException();
    }
 
    public Kind getKind() {
        return Kind.CLASS;
    }
 
    public boolean isNameCompatible(String simpleName, Kind kind) {
        return Kind.CLASS.equals(getKind())
                && this.className.endsWith(simpleName);
    }
 
    public NestingKind getNestingKind() {
        throw new UnsupportedOperationException();
    }
 
    public Modifier getAccessLevel() {
        throw new UnsupportedOperationException();
    }
 
    public String getClassName() {
        return this.className;
    }
 
 
    public String toString() {
        return this.getClass().getName() + "[" + this.toUri() + "]";
    }
}