All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.pointer.InstanceMethodPointer Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.pointer;

import org.qbicc.type.definition.classfile.ClassFile;
import org.qbicc.type.definition.element.InstanceMethodElement;

/**
 * An exact pointer to an instance method.
 */
public final class InstanceMethodPointer extends RootPointer implements ExecutableElementPointer {
    private final InstanceMethodElement instanceMethod;

    InstanceMethodPointer(InstanceMethodElement instanceMethod) {
        super(instanceMethod.getType().getPointer());
        this.instanceMethod = instanceMethod;
    }

    public static InstanceMethodPointer of(final InstanceMethodElement methodElement) {
        return methodElement.getOrCreateInstanceMethodPointer(InstanceMethodPointer::new);
    }

    @Deprecated
    public InstanceMethodElement getInstanceMethod() {
        return getExecutableElement();
    }

    public InstanceMethodElement getExecutableElement() {
        return instanceMethod;
    }

    @Override
    public int hashCode() {
        return super.hashCode() * 19 + instanceMethod.hashCode();
    }

    @Override
    public boolean equals(final RootPointer other) {
        return other instanceof InstanceMethodPointer imp && equals(imp);
    }

    public boolean equals(final InstanceMethodPointer other) {
        return this == other || super.equals(other) && instanceMethod == other.instanceMethod;
    }

    @Override
    public StringBuilder toString(StringBuilder b) {
        return b.append('&').append(instanceMethod);
    }

    public boolean isNoThrow() {
        return getExecutableElement().hasNoModifiersOf(ClassFile.I_ACC_NO_THROW);
    }

    @Override
    public boolean isNoSafePoints() {
        return getExecutableElement().hasNoModifiersOf(ClassFile.I_ACC_NO_SAFEPOINTS);
    }

    @Override
    public boolean isNoReturn() {
        return getExecutableElement().hasNoModifiersOf(ClassFile.I_ACC_NO_RETURN);
    }

    @Override
    public boolean isNoSideEffect() {
        return getExecutableElement().hasNoModifiersOf(ClassFile.I_ACC_NO_SIDE_EFFECTS);
    }

    public  R accept(final Visitor visitor, final T t) {
        return visitor.visit(t, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy