author | Jaroslav Tulach <jtulach@netbeans.org> |
Thu, 03 Oct 2013 10:03:22 +0200 | |
branch | javac |
changeset 1327 | 217ca48c5b80 |
parent 1324 | 263482b074e9 |
permissions | -rw-r--r-- |
jtulach@1326 | 1 |
/** |
jtulach@1326 | 2 |
* Back 2 Browser Bytecode Translator |
jtulach@1326 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jtulach@1326 | 4 |
* |
jtulach@1326 | 5 |
* This program is free software: you can redistribute it and/or modify |
jtulach@1326 | 6 |
* it under the terms of the GNU General Public License as published by |
jtulach@1326 | 7 |
* the Free Software Foundation, version 2 of the License. |
jtulach@1326 | 8 |
* |
jtulach@1326 | 9 |
* This program is distributed in the hope that it will be useful, |
jtulach@1326 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jtulach@1326 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jtulach@1326 | 12 |
* GNU General Public License for more details. |
jtulach@1326 | 13 |
* |
jtulach@1326 | 14 |
* You should have received a copy of the GNU General Public License |
jtulach@1326 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jtulach@1326 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
tzezula@1324 | 17 |
*/ |
tzezula@1324 | 18 |
|
tzezula@1324 | 19 |
package org.apidesign.bck2brwsr.dew; |
tzezula@1324 | 20 |
|
tzezula@1324 | 21 |
import java.net.URI; |
tzezula@1324 | 22 |
import javax.lang.model.element.Modifier; |
tzezula@1324 | 23 |
import javax.lang.model.element.NestingKind; |
tzezula@1324 | 24 |
|
tzezula@1324 | 25 |
/** |
tzezula@1324 | 26 |
* |
jtulach@1326 | 27 |
* @author Tomas Zezula |
tzezula@1324 | 28 |
*/ |
tzezula@1324 | 29 |
public abstract class BaseFileObject implements InferableJavaFileObject { |
tzezula@1324 | 30 |
|
tzezula@1324 | 31 |
protected final String path; |
tzezula@1324 | 32 |
protected final Kind kind; |
tzezula@1324 | 33 |
|
tzezula@1324 | 34 |
BaseFileObject( |
tzezula@1324 | 35 |
String path, |
tzezula@1324 | 36 |
Kind kind) { |
tzezula@1324 | 37 |
if (!path.startsWith("/")) { //NOI18N |
tzezula@1324 | 38 |
throw new IllegalArgumentException(); |
tzezula@1324 | 39 |
} |
tzezula@1324 | 40 |
this.path = path; |
tzezula@1324 | 41 |
this.kind = kind; |
tzezula@1324 | 42 |
} |
tzezula@1324 | 43 |
|
tzezula@1324 | 44 |
|
tzezula@1324 | 45 |
@Override |
tzezula@1324 | 46 |
public String infer() { |
tzezula@1324 | 47 |
return ClassLoaderFileManager.convertResourceToFQN(path); |
tzezula@1324 | 48 |
} |
tzezula@1324 | 49 |
|
tzezula@1324 | 50 |
@Override |
tzezula@1324 | 51 |
public Kind getKind() { |
tzezula@1324 | 52 |
return kind; |
tzezula@1324 | 53 |
} |
tzezula@1324 | 54 |
|
tzezula@1324 | 55 |
@Override |
tzezula@1324 | 56 |
public boolean isNameCompatible(String simpleName, Kind kind) { |
tzezula@1324 | 57 |
return this.kind == kind && |
tzezula@1324 | 58 |
getSimpleName(path).equals(simpleName); |
tzezula@1324 | 59 |
} |
tzezula@1324 | 60 |
|
tzezula@1324 | 61 |
@Override |
tzezula@1324 | 62 |
public NestingKind getNestingKind() { |
tzezula@1324 | 63 |
return null; |
tzezula@1324 | 64 |
} |
tzezula@1324 | 65 |
|
tzezula@1324 | 66 |
@Override |
tzezula@1324 | 67 |
public Modifier getAccessLevel() { |
tzezula@1324 | 68 |
return null; |
tzezula@1324 | 69 |
} |
tzezula@1324 | 70 |
|
tzezula@1324 | 71 |
@Override |
tzezula@1324 | 72 |
public URI toUri() { |
tzezula@1324 | 73 |
return URI.create(escape(path)); |
tzezula@1324 | 74 |
} |
tzezula@1324 | 75 |
|
tzezula@1324 | 76 |
@Override |
tzezula@1324 | 77 |
public String getName() { |
tzezula@1324 | 78 |
return path; |
tzezula@1324 | 79 |
} |
tzezula@1324 | 80 |
|
tzezula@1324 | 81 |
|
tzezula@1324 | 82 |
|
tzezula@1324 | 83 |
protected static String getSimpleName(String path) { |
tzezula@1324 | 84 |
int slashIndex = path.lastIndexOf('/'); |
tzezula@1324 | 85 |
assert slashIndex >= 0; |
tzezula@1324 | 86 |
return (slashIndex + 1 < path.length()) ? |
tzezula@1324 | 87 |
path.substring(slashIndex + 1) : |
tzezula@1324 | 88 |
""; //NOI18N |
tzezula@1324 | 89 |
} |
tzezula@1324 | 90 |
|
tzezula@1324 | 91 |
protected static Kind getKind(final String path) { |
tzezula@1324 | 92 |
final String simpleName = getSimpleName(path); |
tzezula@1324 | 93 |
final int dotIndex = simpleName.lastIndexOf('.'); //NOI18N |
tzezula@1324 | 94 |
final String ext = dotIndex > 0 ? |
tzezula@1324 | 95 |
simpleName.substring(dotIndex) : |
tzezula@1324 | 96 |
""; |
tzezula@1324 | 97 |
for (Kind k : Kind.values()) { |
tzezula@1324 | 98 |
if (k.extension.equals(ext)) { |
tzezula@1324 | 99 |
return k; |
tzezula@1324 | 100 |
} |
tzezula@1324 | 101 |
} |
tzezula@1324 | 102 |
return Kind.OTHER; |
tzezula@1324 | 103 |
} |
tzezula@1324 | 104 |
|
tzezula@1324 | 105 |
private String escape(String path) { |
tzezula@1324 | 106 |
return path; |
tzezula@1324 | 107 |
} |
tzezula@1324 | 108 |
|
tzezula@1324 | 109 |
|
tzezula@1324 | 110 |
} |