private final Class _cl;
private final Class[] _inner;
public ReflectiveMeta() {
- this(MG.class,
- new Class[] {
- MG.Grammar.class,
- MG.AnonUn.class,
- MG.Range.class,
- MG.El.class,
- MG.Seq.class,
- MG.NonTerminal.class,
- MG.NonTerminalReference.class,
- MG.StringLiteral.class,
- MG.XTree.class,
- MG.CharClass.class
- });
+ this(MG.class);
+ }
+ public ReflectiveMeta(Class c) {
+ this._cl = c;
+ this._inner = c.getDeclaredClasses();
}
public ReflectiveMeta(Class c, Class[] inner) {
this._cl = c;
}
public static abstract class Target {
- public abstract int[] buildSequence(Production p);
+ public int[] buildSequence(Production p) {
+ Annotation[][] annotations = _bindable.getArgAnnotations();
+ String[] names = _bindable.getArgNames();
+ String name = _bindable.getSimpleName();
+ int len = annotations.length;
+ int ofs = 0;
+ bind.arg[] argtags = new bind.arg[len];
+ for(int i=0; i<names.length; i++)
+ for(Annotation a : annotations[i+ofs])
+ if (a instanceof bind.arg)
+ argtags[i+ofs] = (bind.arg)a;
+ return Target.this.buildSequence(p, names, argtags);
+ }
private Reflection.Bindable _bindable;
public Target(Reflection.Bindable b) { this._bindable = b; }
for(int i=0; i<o.length; i++) o2[map[i]] = o[i];
return plant(o2);
}
- public int[] buildSequence(Production p) {
- Annotation[][] annotations = _bindable.getArgAnnotations();
- String[] names = _bindable.getArgNames();
- String name = _bindable.getSimpleName();
- int len = annotations.length;
- int ofs = 0;
- bind.arg[] argtags = new bind.arg[len];
- for(int i=0; i<names.length; i++)
- for(Annotation a : annotations[i+ofs])
- if (a instanceof bind.arg)
- argtags[i+ofs] = (bind.arg)a;
- return Target.this.buildSequence(p, names, argtags);
- }
}
}
public static class TargetClass extends Target {
public final Class _class;
public TargetClass(Class _class) { super(Reflection.Bindable.create(_class)); this._class = _class; }
- public int[] buildSequence(Production p) {
- Field[] f = _class.getDeclaredFields();
- String[] names = new String[f.length];
- bind.arg[] argtags = new bind.arg[f.length];
- for(int i=0; i<f.length; i++) {
- names[i] = f[i].getName();
- argtags[i] = f[i].getAnnotation(bind.arg.class);
- }
- int[] ret = buildSequence(p, names, argtags);
- if (ret!=null) return ret;
- for(Constructor c : _class.getConstructors())
- if (new TargetConstructor(c).buildSequence(p)!=null)
- return new TargetConstructor(c).buildSequence(p);
- return null;
- }
}
public static class TargetConstructor extends Target {
public final Constructor _ctor;
public TargetConstructor(Constructor _ctor) { super(Reflection.Bindable.create(_ctor)); this._ctor = _ctor; }
- public int[] buildSequence(Production p) {
- Annotation[][] annotations = _ctor.getParameterAnnotations();
- int len = annotations.length;
- int ofs = 0;
- String name = _ctor.getDeclaringClass().getName();
- /*
- if (name.indexOf('$') > name.lastIndexOf('.')) {
- len--;
- ofs++;
- }
- */
- String[] names = new String[len];
- bind.arg[] argtags = new bind.arg[len];
- for(int i=0; i<names.length; i++)
- for(Annotation a : annotations[i+ofs])
- if (a instanceof bind.arg)
- argtags[i+ofs] = (bind.arg)a;
- return buildSequence(p, names, argtags);
- }
}
public static class TargetMethod extends Target {
public final Method _method;
public TargetMethod(Method _method) { super(Reflection.Bindable.create(_method)); this._method = _method; }
- public int[] buildSequence(Production p) {
- Annotation[][] annotations = _method.getParameterAnnotations();
- String[] names = new String[annotations.length];
- bind.arg[] argtags = new bind.arg[annotations.length];
- for(int i=0; i<names.length; i++)
- for(Annotation a : annotations[i])
- if (a instanceof bind.arg)
- argtags[i] = (bind.arg)a;
- int[] ret = buildSequence(p, names, argtags);
- return ret;
- }
}
public static Union cached = null;