/** * Returns whether the two given classes have fields with the same * names and descriptors. */ private boolean haveAnyIdenticalFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the with the same name and descriptor in // the target class. clazz.fieldsAccept(new SimilarMemberVisitor(targetClass, true, false, false, false, counter)); return counter.getCount() > 0; }
/** * Returns whether the two given classes have fields with the same * names and descriptors. */ private boolean haveAnyIdenticalFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the with the same name and descriptor in // the target class. clazz.fieldsAccept(new SimilarMemberVisitor(targetClass, true, false, false, false, counter)); return counter.getCount() > 0; }
/** * Returns whether the two given classes have fields with the same * names and descriptors. */ private boolean haveAnyIdenticalFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the with the same name and descriptor in // the target class. clazz.fieldsAccept(new SimilarMemberVisitor(targetClass, true, false, false, false, counter)); return counter.getCount() > 0; }
/** * Returns whether the two given classes have class members with the same * name and descriptor. */ private boolean haveAnyIdenticalMethods(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are also // present in the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new SimilarMemberVisitor(targetClass, true, false, false, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, counter)))); return counter.getCount() > 0; }
/** * Returns whether the two given classes have class members with the same * name and descriptor. */ private boolean haveAnyIdenticalMethods(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are also // present in the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new SimilarMemberVisitor(targetClass, true, false, false, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, counter)))); return counter.getCount() > 0; }
/** * Returns whether the given class or its subclasses shadow any fields in * the given target class. */ private boolean shadowsAnyFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the ones that are shadowing non-private // fields in the class hierarchy of the target class. clazz.hierarchyAccept(true, false, false, true, new AllFieldVisitor( new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE, counter)))); return counter.getCount() > 0; }
/** * Returns whether the two given classes have class members with the same * name and descriptor. */ private boolean haveAnyIdenticalMethods(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are also // present in the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new SimilarMemberVisitor(targetClass, true, false, false, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, counter)))); return counter.getCount() > 0; }
/** * Returns whether the given class or its subclasses shadow any fields in * the given target class. */ private boolean shadowsAnyFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the ones that are shadowing non-private // fields in the class hierarchy of the target class. clazz.hierarchyAccept(true, false, false, true, new AllFieldVisitor( new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE, counter)))); return counter.getCount() > 0; }
/** * Returns whether the given class or its subclasses shadow any fields in * the given target class. */ private boolean shadowsAnyFields(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all fields, counting the ones that are shadowing non-private // fields in the class hierarchy of the target class. clazz.hierarchyAccept(true, false, false, true, new AllFieldVisitor( new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE, counter)))); return counter.getCount() > 0; }
/** * Returns whether the given class overrides any methods in the given * target class. */ private boolean overridesAnyMethods(Clazz clazz, ProgramClass targetClass) { // It's ok if the target class is never instantiated and does // not have any subclasses except for maybe the source class. if (!InstantiationClassMarker.isInstantiated(targetClass) && (targetClass.subClasses == null || isOnlySubClass(clazz, targetClass))) { return false; } MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are // overriding methods in the class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new InitializerMethodFilter(null, new SimilarMemberVisitor(targetClass, true, true, false, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE | ClassConstants.ACC_STATIC | ClassConstants.ACC_ABSTRACT, counter))))); return counter.getCount() > 0; }
/** * Returns whether the given class overrides any methods in the given * target class. */ private boolean overridesAnyMethods(Clazz clazz, ProgramClass targetClass) { // It's ok if the target class is never instantiated and does // not have any subclasses except for maybe the source class. if (!InstantiationClassMarker.isInstantiated(targetClass) && (targetClass.subClasses == null || isOnlySubClass(clazz, targetClass))) { return false; } MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are // overriding methods in the class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new InitializerMethodFilter(null, new SimilarMemberVisitor(targetClass, true, true, false, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE | ClassConstants.ACC_STATIC | ClassConstants.ACC_ABSTRACT, counter))))); return counter.getCount() > 0; }
/** * Returns whether the given class overrides any methods in the given * target class. */ private boolean overridesAnyMethods(Clazz clazz, ProgramClass targetClass) { // It's ok if the target class is never instantiated and does // not have any subclasses except for maybe the source class. if (!InstantiationClassMarker.isInstantiated(targetClass) && (targetClass.subClasses == null || isOnlySubClass(clazz, targetClass))) { return false; } MemberCounter counter = new MemberCounter(); // Visit all non-abstract methods, counting the ones that are // overriding methods in the class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, new InitializerMethodFilter(null, new SimilarMemberVisitor(targetClass, true, true, false, false, new MemberAccessFilter(0, ClassConstants.ACC_PRIVATE | ClassConstants.ACC_STATIC | ClassConstants.ACC_ABSTRACT, counter))))); return counter.getCount() > 0; }
/** * Returns whether the two given classes have initializers with the same * descriptors. */ private boolean haveAnyIdenticalInitializers(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // TODO: Currently checking shared methods, not just initializers. // TODO: Allow identical methods. // Visit all methods, counting the ones that are also present in the // target class. clazz.methodsAccept(//new MemberNameFilter(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_INIT), new SimilarMemberVisitor(targetClass, true, false, false, false, new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_ABSTRACT, counter))); return counter.getCount() > 0; }
private boolean isFunctionalInterface(Clazz clazz) { // Is it an interface? if ((clazz.getAccessFlags() & ClassConstants.ACC_INTERFACE) == 0) { return false; } // Count the abstract methods in the interface hierarchy. // Subtract any corresponding default methods, since only abstract // methods that don't have a default implementation count. // TODO: Find a better way to count default methods, since there may be more of them for a single abstract method, or we can find one via different paths. MemberCounter abstractMethodCounter = new MemberCounter(); MemberCounter defaultMethodCounter = new MemberCounter(); clazz.hierarchyAccept(true, false, true, false, new AllMethodVisitor( new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MultiMemberVisitor( abstractMethodCounter, new SimilarMemberVisitor(clazz, true, false, true, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, defaultMethodCounter)) )))); return abstractMethodCounter.getCount() - defaultMethodCounter.getCount() == 1; } }
private boolean isFunctionalInterface(Clazz clazz) { // Is it an interface? if ((clazz.getAccessFlags() & ClassConstants.ACC_INTERFACE) == 0) { return false; } // Count the abstract methods in the interface hierarchy. // Subtract any corresponding default methods, since only abstract // methods that don't have a default implementation count. // TODO: Find a better way to count default methods, since there may be more of them for a single abstract method, or we can find one via different paths. MemberCounter abstractMethodCounter = new MemberCounter(); MemberCounter defaultMethodCounter = new MemberCounter(); clazz.hierarchyAccept(true, false, true, false, new AllMethodVisitor( new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MultiMemberVisitor( abstractMethodCounter, new SimilarMemberVisitor(clazz, true, false, true, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, defaultMethodCounter)) )))); return abstractMethodCounter.getCount() - defaultMethodCounter.getCount() == 1; } }
private boolean isFunctionalInterface(Clazz clazz) { // Is it an interface? if ((clazz.getAccessFlags() & ClassConstants.ACC_INTERFACE) == 0) { return false; } // Count the abstract methods in the interface hierarchy. // Subtract any corresponding default methods, since only abstract // methods that don't have a default implementation count. // TODO: Find a better way to count default methods, since there may be more of them for a single abstract method, or we can find one via different paths. MemberCounter abstractMethodCounter = new MemberCounter(); MemberCounter defaultMethodCounter = new MemberCounter(); clazz.hierarchyAccept(true, false, true, false, new AllMethodVisitor( new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MultiMemberVisitor( abstractMethodCounter, new SimilarMemberVisitor(clazz, true, false, true, false, new MemberAccessFilter(0, ClassConstants.ACC_ABSTRACT, defaultMethodCounter)) )))); return abstractMethodCounter.getCount() - defaultMethodCounter.getCount() == 1; } }
/** * Returns whether the given class would introduce any abstract methods * in the target class. */ private boolean introducesUnwantedAbstractMethods(Clazz clazz, ProgramClass targetClass) { // It's ok if the target class is already abstract and does not // have any subclasses except for maybe the source class. if ((targetClass.getAccessFlags() & (ClassConstants.ACC_ABSTRACT | ClassConstants.ACC_INTERFACE)) != 0 && (targetClass.subClasses == null || isOnlySubClass(clazz, targetClass))) { return false; } MemberCounter counter = new MemberCounter(); Set targetSet = new HashSet(); // Collect all abstract methods, and similar abstract methods in the // class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MultiMemberVisitor( counter, new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MemberCollector(false, true, true, targetSet))) ))); return targetSet.size() < counter.getCount(); }
/** * Returns whether the given class would introduce any abstract methods * in the target class. */ private boolean introducesUnwantedAbstractMethods(Clazz clazz, ProgramClass targetClass) { // It's ok if the target class is already abstract and does not // have any subclasses except for maybe the source class. if ((targetClass.getAccessFlags() & (ClassConstants.ACC_ABSTRACT | ClassConstants.ACC_INTERFACE)) != 0 && (targetClass.subClasses == null || isOnlySubClass(clazz, targetClass))) { return false; } MemberCounter counter = new MemberCounter(); Set targetSet = new HashSet(); // Collect all abstract methods, and similar abstract methods in the // class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MultiMemberVisitor( counter, new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(ClassConstants.ACC_ABSTRACT, 0, new MemberCollector(false, true, true, targetSet))) ))); return targetSet.size() < counter.getCount(); }
/** * Returns whether the given class or its subclasses shadow any methods in * the given target class. */ private boolean shadowsAnyMethods(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all private methods, counting the ones that are shadowing // non-private methods in the class hierarchy of the target class. clazz.hierarchyAccept(true, false, false, true, new AllMethodVisitor( new MemberAccessFilter(ClassConstants.INTERNAL_ACC_PRIVATE, 0, new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_INIT)), new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE, counter)))))); // Visit all static methods, counting the ones that are shadowing // non-private methods in the class hierarchy of the target class. clazz.hierarchyAccept(true, false, false, true, new AllMethodVisitor( new MemberAccessFilter(ClassConstants.INTERNAL_ACC_STATIC, 0, new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)), new SimilarMemberVisitor(targetClass, true, true, true, false, new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE, counter)))))); return counter.getCount() > 0; }
/** * Returns whether the given class overrides any methods in the given * target class. */ private boolean overridesAnyMethods(Clazz clazz, Clazz targetClass) { MemberCounter counter = new MemberCounter(); // Visit all non-private non-static methods, counting the ones that are // being overridden in the class hierarchy of the target class. clazz.methodsAccept(new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE | ClassConstants.INTERNAL_ACC_STATIC | ClassConstants.INTERNAL_ACC_ABSTRACT, new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_CLINIT)), new MemberNameFilter(new NotMatcher(new FixedStringMatcher(ClassConstants.INTERNAL_METHOD_NAME_INIT)), new SimilarMemberVisitor(targetClass, true, true, false, false, new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE | ClassConstants.INTERNAL_ACC_STATIC | ClassConstants.INTERNAL_ACC_ABSTRACT, counter)))))); return counter.getCount() > 0; }