public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); }
Map findCommonInterfaces(Map typeMap, Map alterMap) { Iterator i = alterMap.keySet().iterator(); while (i.hasNext()) { if (! typeMap.containsKey(i.next())) i.remove(); } // Reduce to subinterfaces // This does not need to be recursive since we make a copy, // and that copy contains all super types for the whole hierarchy i = new ArrayList(alterMap.values()).iterator(); while (i.hasNext()) { CtClass intf = (CtClass) i.next(); CtClass[] interfaces; try { interfaces = intf.getInterfaces(); } catch (NotFoundException e) { throw new RuntimeException(e); } for (int c = 0; c < interfaces.length; c++) alterMap.remove(interfaces[c].getName()); } return alterMap; }
public static CtClass getSuperInterface(CtClass c, String interfaceName) throws CompileError { try { CtClass[] intfs = c.getInterfaces(); for (int i = 0; i < intfs.length; i++) if (intfs[i].getName().equals(interfaceName)) return intfs[i]; } catch (NotFoundException e) {} throw new CompileError("cannot find the super inetrface " + interfaceName + " of " + c.getName()); }
Map getDeclaredInterfaces(CtClass clazz, Map map) { if (map == null) map = new HashMap(); if (clazz.isInterface()) map.put(clazz.getName(), clazz); CtClass[] interfaces; try { interfaces = clazz.getInterfaces(); } catch (NotFoundException e) { throw new RuntimeException(e); } for (int i = 0; i < interfaces.length; i++) { CtClass intf = interfaces[i]; map.put(intf.getName(), intf); getDeclaredInterfaces(intf, map); } return map; }
Map<String,CtClass> findCommonInterfaces(Map<String,CtClass> typeMap, Map<String,CtClass> alterMap) { if (alterMap == null) alterMap = new HashMap<String,CtClass>(); if (typeMap == null||typeMap.isEmpty()) alterMap.clear(); for (String name:alterMap.keySet()) if (!typeMap.containsKey(name)) alterMap.remove(name); // Reduce to subinterfaces // This does not need to be recursive since we make a copy, // and that copy contains all super types for the whole hierarchy for (CtClass intf:alterMap.values()) { CtClass[] interfaces; try { interfaces = intf.getInterfaces(); } catch (NotFoundException e) { throw new RuntimeException(e); } for (CtClass c:interfaces) alterMap.remove(c.getName()); } return alterMap; }
Map getAllInterfaces(CtClass clazz, Map map) { if (map == null) map = new HashMap(); if (clazz.isInterface()) map.put(clazz.getName(), clazz); do { try { CtClass[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { CtClass intf = interfaces[i]; map.put(intf.getName(), intf); getAllInterfaces(intf, map); } clazz = clazz.getSuperclass(); } catch (NotFoundException e) { throw new RuntimeException(e); } } while (clazz != null); return map; }
Map<String,CtClass> getDeclaredInterfaces(CtClass clazz, Map<String,CtClass> map) { if (map == null) map = new HashMap<String,CtClass>(); if (clazz.isInterface()) map.put(clazz.getName(), clazz); CtClass[] interfaces; try { interfaces = clazz.getInterfaces(); } catch (NotFoundException e) { throw new RuntimeException(e); } for (CtClass intf:interfaces) { map.put(intf.getName(), intf); getDeclaredInterfaces(intf, map); } return map; }
Map<String,CtClass> getAllInterfaces(CtClass clazz, Map<String,CtClass> map) { if (map == null) map = new HashMap<String,CtClass>(); if (clazz.isInterface()) map.put(clazz.getName(), clazz); do { try { CtClass[] interfaces = clazz.getInterfaces(); for (CtClass intf:interfaces) { map.put(intf.getName(), intf); getAllInterfaces(intf, map); } clazz = clazz.getSuperclass(); } catch (NotFoundException e) { throw new RuntimeException(e); } } while (clazz != null); return map; }
private boolean alreadyEnhanced(CtClass managedCtClass) { try { for ( CtClass declaredInterface : managedCtClass.getInterfaces() ) { if ( PersistentAttributesHelper.isAssignable( declaredInterface, Managed.class.getName() ) ) { return true; } } return false; } catch ( NotFoundException e ) { throw new HibernateException( "Unable to transform class: " + e.getMessage() , e ); } }
public static boolean isAssignable(CtClass thisCtClass, String targetClassName) { if ( thisCtClass == null ) { return false; } if ( thisCtClass.getName().equals( targetClassName ) ) { return true; } try { // check if extends if ( isAssignable( thisCtClass.getSuperclass(), targetClassName ) ) { return true; } // check if implements for ( CtClass interfaceCtClass : thisCtClass.getInterfaces() ) { if ( isAssignable( interfaceCtClass, targetClassName ) ) { return true; } } } catch (NotFoundException e) { // keep going } return false; }
private void addCompositeOwnerInterface(CtClass managedCtClass) throws NotFoundException, CannotCompileException { CtClass compositeOwnerCtClass = managedCtClass.getClassPool().get( CompositeOwner.class.getName() ); // HHH-10540 only add the interface once for ( CtClass i : managedCtClass.getInterfaces() ) { if ( i.subclassOf( compositeOwnerCtClass ) ) { return; } } managedCtClass.addInterface( compositeOwnerCtClass ); if ( enhancementContext.isCompositeClass( managedCtClass ) ) { // if a composite have a embedded field we need to implement the TRACKER_CHANGER_NAME method as well MethodWriter.write( managedCtClass, "public void %1$s(String name) {%n" + " if (%2$s != null) { %2$s.callOwner(\".\" + name); }%n}", EnhancerConstants.TRACKER_CHANGER_NAME, EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME ); } }
for ( CtClass ctClass : currentValue.getType().getInterfaces() ) { if ( ctClass.getName().equals( Collection.class.getName() ) ) {
for ( CtClass interfaceCtClass : ctClass.getInterfaces() ) { method = getterOrNull( interfaceCtClass, propertyName ); if ( method != null ) {
CtClass[] ifs = cc.getInterfaces(); int size = ifs.length; for (int i = 0; i < size; ++i) {
private static void getFields(ArrayList alist, CtClass cc) { int i, num; if (cc == null) return; try { getFields(alist, cc.getSuperclass()); } catch (NotFoundException e) {} try { CtClass[] ifs = cc.getInterfaces(); num = ifs.length; for (i = 0; i < num; ++i) getFields(alist, ifs[i]); } catch (NotFoundException e) {} CtMember.Cache memCache = ((CtClassType)cc).getMembers(); CtMember field = memCache.fieldHead(); CtMember tail = memCache.lastField(); while (field != tail) { field = field.next(); if (!Modifier.isPrivate(field.getModifiers())) alist.add(field); } }
private static void getMethods0(HashMap h, CtClass cc) { try { CtClass[] ifs = cc.getInterfaces(); int size = ifs.length; for (int i = 0; i < size; ++i) getMethods0(h, ifs[i]); } catch (NotFoundException e) {} try { CtClass s = cc.getSuperclass(); if (s != null) getMethods0(h, s); } catch (NotFoundException e) {} if (cc instanceof CtClassType) { CtMember.Cache memCache = ((CtClassType)cc).getMembers(); CtMember mth = memCache.methodHead(); CtMember mthTail = memCache.lastMethod(); while (mth != mthTail) { mth = mth.next(); if (!Modifier.isPrivate(mth.getModifiers())) h.put(((CtMethod)mth).getStringRep(), mth); } } }
private static void getFields(List<CtMember> alist, CtClass cc) { if (cc == null) return; try { getFields(alist, cc.getSuperclass()); } catch (NotFoundException e) {} try { CtClass[] ifs = cc.getInterfaces(); for (CtClass ctc : ifs) getFields(alist, ctc); } catch (NotFoundException e) {} CtMember.Cache memCache = ((CtClassType)cc).getMembers(); CtMember field = memCache.fieldHead(); CtMember tail = memCache.lastField(); while (field != tail) { field = field.next(); if (!Modifier.isPrivate(field.getModifiers())) alist.add(field); } }
CtClass[] ifs = cc.getInterfaces(); for (CtClass ctc : ifs) { CtMethod m = getMethod0(ctc, name, desc);
CtClass[] ifs = clazz.getInterfaces(); int size = ifs.length; for (int i = 0; i < size; ++i) {
private static void getMethods0(Map<String,CtMember> h, CtClass cc) { try { CtClass[] ifs = cc.getInterfaces(); for (CtClass ctc : ifs) getMethods0(h, ctc); } catch (NotFoundException e) {} try { CtClass s = cc.getSuperclass(); if (s != null) getMethods0(h, s); } catch (NotFoundException e) {} if (cc instanceof CtClassType) { CtMember.Cache memCache = ((CtClassType)cc).getMembers(); CtMember mth = memCache.methodHead(); CtMember mthTail = memCache.lastMethod(); while (mth != mthTail) { mth = mth.next(); if (!Modifier.isPrivate(mth.getModifiers())) h.put(((CtMethod)mth).getStringRep(), mth); } } }