Jump to content

[Snippet] Check if a class overrides all overridable methods from a super class


Recommended Posts

Posted (edited)

Checks if all overridable methods from a class are indeed overriden.

Useful for writing decorator classes / wrappers.

 

Example:

public class InteractableObjectDecorator extends InteractableObject {

	static {
		ReflectionUtil.checkOverrides(InteractableObjectDecorator.class, InteractableObject.class);
	}
	
	public InteractableObjectDecorator(XInteractableObject instance) {
		super(instance);
	}

}
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public java.lang.String org.osbot.rs07.api.model.InteractableObject.getName() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public java.lang.String[] org.osbot.rs07.api.model.InteractableObject.getActions() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getId() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getType() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.def.EntityDefinition org.osbot.rs07.api.model.InteractableObject.getDefinition() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.def.ObjectDefinition org.osbot.rs07.api.model.InteractableObject.getDefinition() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.exists() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getLocalY() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getGridY() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getOrientation() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.isOnScreen() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getZ() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int[] org.osbot.rs07.api.model.InteractableObject.getModelIds() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.map.Area org.osbot.rs07.api.model.InteractableObject.getArea(int) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getUID() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getLocalX() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getGridX() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.hasAction(java.lang.String[]) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.map.Position org.osbot.rs07.api.model.InteractableObject.getPosition() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.isPlayer() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.isNPC() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.model.Animable org.osbot.rs07.api.model.InteractableObject.getAnimable() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getY() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getSizeY() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.isVisible() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.interact(java.lang.String[]) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getX() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.hover() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getSizeX() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.InteractableObject.getConfig() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.isGameObject() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.InteractableObject.examine() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public void org.osbot.rs07.api.model.Modeled.setPrioritized(boolean) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.rs07.api.model.Modeled.isPrioritized() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public void org.osbot.rs07.api.model.Modeled.updateModel(org.osbot.rs07.api.model.Model) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.model.Model org.osbot.rs07.api.model.Modeled.getModel() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public int org.osbot.rs07.api.model.Modeled.getHeight() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.script.MethodProvider org.osbot.rs07.api.RS07Wrapper.getMethods() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.api.Client org.osbot.rs07.api.RS07Wrapper.getClient() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.core.AbstractBot org.osbot.rs07.api.RS07Wrapper.getBot() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public org.osbot.rs07.Bot org.osbot.rs07.api.RS07Wrapper.getBot() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public boolean org.osbot.core.api.Wrapper.equals(java.lang.Object) from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public java.lang.String java.lang.Object.toString() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
java.lang.NoSuchMethodException: class test.InteractableObjectDecorator does not override public native int java.lang.Object.hashCode() from class org.osbot.rs07.api.model.InteractableObject
	at reflection.ReflectionUtil.checkOverrides(ReflectionUtil.java:71)
	at test.InteractableObjectDecorator.<clinit>(InteractableObjectDecorator.java:11)
 

Snippet

	public static void checkOverrides(Class<?> subClass, Class<?> superClass) {
		for (Method superMethod : superClass.getMethods()) {
			if(Modifier.isStatic(superMethod.getModifiers())) continue;
			if(Modifier.isFinal(superMethod.getModifiers())) continue;
			try {
				Method subMethod = subClass.getMethod(superMethod.getName(), superMethod.getParameterTypes());
				if(subMethod.getDeclaringClass().equals(superMethod.getDeclaringClass())) {
					throw new NoSuchMethodException(subClass + " does not override " + superMethod + " from " + superClass);
				}
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			}			
		}
	}
Edited by Botre

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...