-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize multi-lingual support of Stapler to include routing
Originally this capability was added to support JRuby, and so far it was only used to find @PostConstruct method. But if we expand this Klass and KlassNavigator abstraction to request routing, then we can use this to build a parallel type hierarchy. See issue #76
- Loading branch information
Showing
8 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
core/src/main/java/org/kohsuke/stapler/KlassDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.kohsuke.stapler; | ||
|
||
import org.kohsuke.stapler.lang.FieldRef; | ||
import org.kohsuke.stapler.lang.Klass; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Reflection information of a {@link Klass} that drives the request routing. | ||
* | ||
* <p> | ||
* Born as a generalization of {@link ClassDescriptor} to {@link Klass}. | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
class KlassDescriptor<C> { | ||
final Klass<C> clazz; | ||
final FunctionList methods; | ||
final List<FieldRef> fields; | ||
|
||
/** | ||
* @param klazz | ||
* The class to build a descriptor around. | ||
*/ | ||
public KlassDescriptor(Klass<C> klazz) { | ||
this.clazz = klazz; | ||
this.fields = klazz.getFields(); | ||
this.methods = new FunctionList(klazz.getFunctions()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/kohsuke/stapler/lang/AnnotatedRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.kohsuke.stapler.lang; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
/** | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public abstract class AnnotatedRef { | ||
// no subtyping outside the package | ||
/*package*/ AnnotatedRef() {} | ||
|
||
public abstract <T extends Annotation> T getAnnotation(Class<T> type); | ||
|
||
public boolean hasAnnotation(Class<? extends Annotation> type) { | ||
return getAnnotation(type)!=null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.kohsuke.stapler.lang; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public abstract class FieldRef extends AnnotatedRef { | ||
/** | ||
* Name of the method. | ||
* | ||
* @see Field#getName() | ||
*/ | ||
public abstract String getName(); | ||
|
||
/** | ||
* Obtains the value of the field of the instance. | ||
*/ | ||
public abstract Object get(Object instance) throws IllegalAccessException; | ||
|
||
/** | ||
* Gets a fully qualified name of this field that includes the declaring type. | ||
*/ | ||
public abstract String getQualifiedName(); | ||
|
||
public static FieldRef wrap(final Field f) { | ||
f.setAccessible(true); | ||
|
||
return new FieldRef() { | ||
@Override | ||
public <T extends Annotation> T getAnnotation(Class<T> type) { | ||
return f.getAnnotation(type); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return f.getName(); | ||
} | ||
|
||
@Override | ||
public Object get(Object instance) throws IllegalAccessException { | ||
return f.get(instance); | ||
} | ||
|
||
@Override | ||
public String getQualifiedName() { | ||
return f.getDeclaringClass().getName()+"."+getName(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters