Search in sources :

Example 1 with ClassMemberInfo

use of com.jopdesign.common.ClassMemberInfo in project jop by jop-devel.

the class InlineHelper method makePublic.

private void makePublic(ClassMemberInfo member) {
    boolean wasPrivate = member.isPrivate();
    // If we need to make it public, check if we need to make the class and all enclosing classes public too
    ClassInfo cls = member.getClassInfo();
    while (cls != null) {
        if (!cls.isPublic()) {
            cls.setAccessType(AccessType.ACC_PUBLIC);
        }
        cls = cls.getEnclosingClassInfo();
    }
    if (wasPrivate && member instanceof MethodInfo) {
        // we are done here. if the method was private, there are no conflicting
        // methods or we needed to rename it anyway.
        member.setAccessType(AccessType.ACC_PUBLIC);
        return;
    }
    // if we make a non-private method or any field public, need to go down to find all overriding
    // members and make them public too
    final MemberID memberID = member.getMemberID();
    ClassVisitor visitor = new EmptyClassVisitor() {

        @Override
        public boolean visitClass(ClassInfo classInfo) {
            ClassMemberInfo m = classInfo.getMemberInfo(memberID);
            if (m == null) {
                return true;
            }
            if (m.isPublic()) {
                // we do not need to go further down if we find a public member
                return false;
            }
            m.setAccessType(AccessType.ACC_PUBLIC);
            return true;
        }
    };
    new ClassHierarchyTraverser(visitor).traverseDown(member.getClassInfo());
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassMemberInfo(com.jopdesign.common.ClassMemberInfo) MethodInfo(com.jopdesign.common.MethodInfo) ClassHierarchyTraverser(com.jopdesign.common.graphutils.ClassHierarchyTraverser) EmptyClassVisitor(com.jopdesign.common.graphutils.EmptyClassVisitor) ClassVisitor(com.jopdesign.common.graphutils.ClassVisitor) EmptyClassVisitor(com.jopdesign.common.graphutils.EmptyClassVisitor) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

ClassInfo (com.jopdesign.common.ClassInfo)1 ClassMemberInfo (com.jopdesign.common.ClassMemberInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 ClassHierarchyTraverser (com.jopdesign.common.graphutils.ClassHierarchyTraverser)1 ClassVisitor (com.jopdesign.common.graphutils.ClassVisitor)1 EmptyClassVisitor (com.jopdesign.common.graphutils.EmptyClassVisitor)1 MemberID (com.jopdesign.common.type.MemberID)1