2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
19 package org.apidesign.bck2brwsr.dew;
22 import javax.lang.model.element.Modifier;
23 import javax.lang.model.element.NestingKind;
27 * @author Tomas Zezula
29 public abstract class BaseFileObject implements InferableJavaFileObject {
31 protected final String path;
32 protected final Kind kind;
37 if (!path.startsWith("/")) { //NOI18N
38 throw new IllegalArgumentException();
46 public String infer() {
47 return ClassLoaderFileManager.convertResourceToFQN(path);
51 public Kind getKind() {
56 public boolean isNameCompatible(String simpleName, Kind kind) {
57 return this.kind == kind &&
58 getSimpleName(path).equals(simpleName);
62 public NestingKind getNestingKind() {
67 public Modifier getAccessLevel() {
73 return URI.create(escape(path));
77 public String getName() {
83 protected static String getSimpleName(String path) {
84 int slashIndex = path.lastIndexOf('/');
85 assert slashIndex >= 0;
86 return (slashIndex + 1 < path.length()) ?
87 path.substring(slashIndex + 1) :
91 protected static Kind getKind(final String path) {
92 final String simpleName = getSimpleName(path);
93 final int dotIndex = simpleName.lastIndexOf('.'); //NOI18N
94 final String ext = dotIndex > 0 ?
95 simpleName.substring(dotIndex) :
97 for (Kind k : Kind.values()) {
98 if (k.extension.equals(ext)) {
105 private String escape(String path) {