Jump to content

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


Botre

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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