2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
7 package org.apidesign.bck2brwsr.dew;
10 import javax.lang.model.element.Modifier;
11 import javax.lang.model.element.NestingKind;
17 public abstract class BaseFileObject implements InferableJavaFileObject {
19 protected final String path;
20 protected final Kind kind;
25 if (!path.startsWith("/")) { //NOI18N
26 throw new IllegalArgumentException();
34 public String infer() {
35 return ClassLoaderFileManager.convertResourceToFQN(path);
39 public Kind getKind() {
44 public boolean isNameCompatible(String simpleName, Kind kind) {
45 return this.kind == kind &&
46 getSimpleName(path).equals(simpleName);
50 public NestingKind getNestingKind() {
55 public Modifier getAccessLevel() {
61 return URI.create(escape(path));
65 public String getName() {
71 protected static String getSimpleName(String path) {
72 int slashIndex = path.lastIndexOf('/');
73 assert slashIndex >= 0;
74 return (slashIndex + 1 < path.length()) ?
75 path.substring(slashIndex + 1) :
79 protected static Kind getKind(final String path) {
80 final String simpleName = getSimpleName(path);
81 final int dotIndex = simpleName.lastIndexOf('.'); //NOI18N
82 final String ext = dotIndex > 0 ?
83 simpleName.substring(dotIndex) :
85 for (Kind k : Kind.values()) {
86 if (k.extension.equals(ext)) {
93 private String escape(String path) {