xapi.source.read.JavaVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
The newest version!
package xapi.source.read;
public class JavaVisitor {
// There is not a java.lang.reflect.Modifier field for default methods, so we use this unused value instead.
public static final int MODIFIER_DEFAULT = 0x00010000;
/**
* The default TypeData object is used to deserialize source-compatible type names.
*
* Lexing package names and inner classes requires the use java convention naming:
* lowercase.packages.Uppercase.Classes
*
* packagename with uppercase first-chars in fragments will be lexed incorrectly.
*
* Because these types can be lexed incorrectly, you may directly use the constructors provided.
* Just be sure to provide the fully qualified class name (inner classes must be enclosed).
*
* @author "James X. Nelson ([email protected])"
*
*/
public static class TypeData {
public static final TypeData NONE = new TypeData("");
public TypeData(String pkgName, String enclosingClass) {
this(enclosingClass);
this.pkgName = pkgName;
}
public TypeData(String className) {
clsName = className;
int end = className.lastIndexOf('.');
if (end == -1) {
simpleName = clsName;
} else {
simpleName = clsName.substring(end+1);
}
}
/**
* The prefix of lowercase package fragments.
* Might be "super" or "this"
*/
public String pkgName = "";
/**
* The fully qualified class (including parent classes, if any)
*/
public String clsName;
/**
* The last class fragment
*/
public String simpleName;
/**
* Any generics string, including enclosing < > characters.
*/
public String generics = "";
/**
* The number of array dimensions, if any, for this type.
*/
public int arrayDepth;
@Override
public String toString() {
StringBuilder b = new StringBuilder();
if (pkgName.length() > 0) {
b.append(pkgName).append('.');
}
b.append(clsName).append(generics);
b.append(getArrayDefinition());
return b.toString();
}
protected String getArrayDefinition() {
StringBuilder b = new StringBuilder();
int i = arrayDepth;
while (i --> 0) {
b.append("[]");
}
return b.toString();
}
public String getImportName() {
int index = clsName.indexOf('.');
return (pkgName.length()==0?"":pkgName+"."
+(index == -1 ? clsName : clsName.substring(0, index)));
}
public String getQualifiedName() {
return (pkgName.length()==0?"":pkgName+".")+clsName;
}
public String getSimpleName() {
return clsName
+ (generics.length() > 0 ? generics : "")
+ getArrayDefinition()
;
}
}
public static interface JavadocVisitor {
void visitJavadoc(String javadoc, Param receiver);
}
public static interface ModifierVisitor {
void visitModifier(int modifier, Param receiver);
}
public static interface TypeVisitor extends ModifierVisitor {
// void visitType(String type, Param receiver);
}
public static interface AnnotationVisitor {
AnnotationMemberVisitor visitAnnotation(String annoName, String annoBody, Param receiver);
}
public static interface AnnotationMemberVisitor {
void visitMember(String name, String value, Param receiver);
}
public static interface GenericVisitor {
void visitGeneric(String generic, Param receiver);
}
public static interface MemberVisitor
extends AnnotationVisitor,
GenericVisitor,
JavadocVisitor,
ModifierVisitor
{
}
public static interface FieldVisitor
extends MemberVisitor {
void visitName(String type, Param receiver);
void visitInitializer(String initializer, Param receiver);
}
public static interface ParameterVisitor
extends AnnotationVisitor, ModifierVisitor {
void visitType(TypeData type, String name, boolean varargs, Param receiver);
}
public static interface ExecutableVisitor
extends MemberVisitor {
ParameterVisitor visitParameter();
void visitException(String type, Param receiver);
}
public static interface ConstructorVisitor
extends ExecutableVisitor {
}
public static interface MethodVisitor
extends ExecutableVisitor {
void visitReturnType(TypeData returnType, Param receiver);
void visitName(String name, Param receiver);
}
public static interface ImportVisitor {
void visitImport(String name, boolean isStatic, Param receiver);
}
public static interface ClassVisitor
extends MemberVisitor,
ImportVisitor
{
/**
* Called on a javadoc comment found before the package statement.
* @param copyright - The copyright javadoc
* @param receiver - An object you want to pass to your visitor
*/
void visitCopyright(String copyright, Param receiver);
void visitPackage(String pkg, Param receiver);
void visitName(String name, Param receiver);
void visitType(String type, Param receiver);
void visitSuperclass(String superClass, Param receiver);
void visitInterface(String iface, Param receiver);
ClassBodyVisitor visitBody(String body, Param receiver);
}
public static interface EnumVisitor
extends ClassVisitor {
EnumDefinitionVisitor visitItem(String definition, Param param);
}
public static interface EnumDefinitionVisitor
extends ClassVisitor {
ParameterVisitor visitParams(String params, Param param);
@Override
ClassBodyVisitor visitBody(String body, Param param);
}
public static interface ClassBodyVisitor {
void visitCodeBlock(String block, boolean isStatic, Param param);
FieldVisitor visitField(String definition, Param param);
MethodVisitor visitMethod(String definition, Param param);
ClassVisitor visitInnerClass(String definition, Param param);
}
}