Search in sources :

Example 6 with ClassHierarchyTraverser

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

the class MethodInfo method getOverriders.

/**
     * Find all methods which override/implement this method.
     * Instance method are overridden by other instance methods and hidden by static methods.
     * 
     * @param checkAccess if false, find methods with the same signature in subclasses even if they
     *        do not override this method (i.e. private or static methods).
     * @return a list of all overriding methods.
     */
public Collection<MethodInfo> getOverriders(final boolean checkAccess) {
    final List<MethodInfo> overriders = new LinkedList<MethodInfo>();
    if (checkAccess && (isPrivate() || isStatic())) {
        return overriders;
    }
    ClassVisitor visitor = new ClassVisitor() {

        public boolean visitClass(ClassInfo classInfo) {
            MethodInfo overrider = classInfo.getMethodInfo(getMethodSignature());
            if (overrider != null) {
                if (overrider.isPrivate()) {
                    // found an overriding method which is private .. this is interesting..
                    logger.error("Found private method " + overrider.getMethodSignature() + " in " + classInfo.getClassName() + " overriding non-private method in " + getClassInfo().getClassName());
                }
                // signature, but is in a different package, it does NOT override this method.
                if (!checkAccess || overrider.overrides(MethodInfo.this, false)) {
                    overriders.add(overrider);
                }
            }
            return true;
        }

        public void finishClass(ClassInfo classInfo) {
        }
    };
    new ClassHierarchyTraverser(visitor).traverseDown(getClassInfo());
    return overriders;
}
Also used : ClassHierarchyTraverser(com.jopdesign.common.graphutils.ClassHierarchyTraverser) ClassVisitor(com.jopdesign.common.graphutils.ClassVisitor) LinkedList(java.util.LinkedList)

Example 7 with ClassHierarchyTraverser

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

the class ClassInfo method finishRemoveFromHierarchy.

protected void finishRemoveFromHierarchy() {
    // all extensions and inner classes of this class will now be incomplete
    if (fullyKnown == Ternary.TRUE) {
        ClassVisitor visitor = new ClassVisitor() {

            @SuppressWarnings({ "AccessingNonPublicFieldOfAnotherObject" })
            public boolean visitClass(ClassInfo classInfo) {
                classInfo.fullyKnown = Ternary.FALSE;
                return true;
            }

            public void finishClass(ClassInfo classInfo) {
            }
        };
        ClassHierarchyTraverser traverser = new ClassHierarchyTraverser(visitor);
        traverser.setVisitSubclasses(true, false);
        // we do not support nested classes without enclosing class, so no need to visit them
        // as they are removed too
        traverser.setVisitInnerClasses(false);
        traverser.traverseDown(this);
    }
}
Also used : ClassHierarchyTraverser(com.jopdesign.common.graphutils.ClassHierarchyTraverser) ClassVisitor(com.jopdesign.common.graphutils.ClassVisitor)

Aggregations

ClassHierarchyTraverser (com.jopdesign.common.graphutils.ClassHierarchyTraverser)7 ClassVisitor (com.jopdesign.common.graphutils.ClassVisitor)7 LinkedList (java.util.LinkedList)3 CallString (com.jopdesign.common.code.CallString)2 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)2 ClassInfo (com.jopdesign.common.ClassInfo)1 ClassMemberInfo (com.jopdesign.common.ClassMemberInfo)1 MethodInfo (com.jopdesign.common.MethodInfo)1 EmptyClassVisitor (com.jopdesign.common.graphutils.EmptyClassVisitor)1 MemberID (com.jopdesign.common.type.MemberID)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1