private CtField[] collectPersistentFields(CtClass managedCtClass) { List<CtField> persistentFieldList = new ArrayList<CtField>(); for ( CtField ctField : managedCtClass.getDeclaredFields() ) { // skip static fields and skip fields added by enhancement and outer reference in inner classes if ( ctField.getName().startsWith( "$$_hibernate_" ) || "this$0".equals( ctField.getName() ) ) { continue; } if ( !Modifier.isStatic( ctField.getModifiers() ) && enhancementContext.isPersistentField( ctField ) ) { persistentFieldList.add( ctField ); } } // HHH-10646 Add fields inherited from @MappedSuperclass // HHH-10981 There is no need to do it for @MappedSuperclass if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) { persistentFieldList.addAll( collectInheritPersistentFields( managedCtClass ) ); } CtField[] orderedFields = enhancementContext.order( persistentFieldList.toArray( new CtField[0] ) ); log.debugf( "Persistent fields for entity %s: %s", managedCtClass.getName(), Arrays.toString( orderedFields ) ); return orderedFields; }
public void setModifiers(int mod) { ClassFile cf = getClassFile2(); if (Modifier.isStatic(mod)) { int flags = cf.getInnerAccessFlags(); if (flags != -1 && (flags & AccessFlag.STATIC) != 0) mod = mod & ~Modifier.STATIC; else throw new RuntimeException("cannot change " + getName() + " into a static class"); } checkModify(); cf.setAccessFlags(AccessFlag.of(mod)); }
private List<CtField> collectCollectionFields(CtClass managedCtClass) { List<CtField> collectionList = new ArrayList<>(); for ( CtField ctField : managedCtClass.getDeclaredFields() ) { // skip static fields and skip fields added by enhancement if ( Modifier.isStatic( ctField.getModifiers() ) || ctField.getName().startsWith( "$$_hibernate_" ) ) { continue; } if ( enhancementContext.isPersistentField( ctField ) && !enhancementContext.isMappedCollection( ctField ) ) { if ( PersistentAttributesHelper.isAssignable( ctField, Collection.class.getName() ) || PersistentAttributesHelper.isAssignable( ctField, Map.class.getName() ) ) { collectionList.add( ctField ); } } } // HHH-10646 Add fields inherited from @MappedSuperclass // HHH-10981 There is no need to do it for @MappedSuperclass if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) { collectionList.addAll( collectInheritCollectionFields( managedCtClass ) ); } return collectionList; }
private static boolean isMainMethod(MethodInfo method) { int flags = method.getAccessFlags(); return method.getName().equals("main") && Modifier.isPublic(flags) && Modifier.isStatic(flags) && U.eq(method.getDescriptor(), "([Ljava/lang/String;)V"); // TODO find more elegant solution }
if (Modifier.isPublic(mod)) { CtMethod body; if (Modifier.isStatic(mod)) body = forwardStaticMethod; else
static Bytecode makeBody(CtClass clazz, ClassFile classfile, CtMethod wrappedBody, CtClass[] parameters, CtClass returnType, ConstParameter cparam) throws CannotCompileException { boolean isStatic = Modifier.isStatic(wrappedBody.getModifiers()); Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0); int stacksize = makeBody0(clazz, classfile, wrappedBody, isStatic, parameters, returnType, cparam, code); code.setMaxStack(stacksize); code.setMaxLocals(isStatic, parameters, 0); return code; }
/** * Inserts a new parameter, which becomes the first parameter. */ public void insertParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.insertParameter(type, desc); try { addParameter2(Modifier.isStatic(getModifiers()) ? 0 : 1, type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
static Bytecode makeBody(CtClass clazz, ClassFile classfile, CtMethod wrappedBody, CtClass[] parameters, CtClass returnType, ConstParameter cparam) throws CannotCompileException { boolean isStatic = Modifier.isStatic(wrappedBody.getModifiers()); Bytecode code = new Bytecode(classfile.getConstPool(), 0, 0); int stacksize = makeBody0(clazz, classfile, wrappedBody, isStatic, parameters, returnType, cparam, code); code.setMaxStack(stacksize); code.setMaxLocals(isStatic, parameters, 0); return code; }
private int makeFieldInitializer(Bytecode code, CtClass[] parameters) throws CannotCompileException, NotFoundException { int stacksize = 0; Javac jv = new Javac(code, this); try { jv.recordParams(parameters, false); } catch (CompileError e) { throw new CannotCompileException(e); } for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (!Modifier.isStatic(f.getModifiers())) { int s = fi.init.compile(f.getType(), f.getName(), code, parameters, jv); if (stacksize < s) stacksize = s; } } return stacksize; }
/** * Appends a new parameter, which becomes the last parameter. */ public void addParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.appendParameter(type, desc); int offset = Modifier.isStatic(getModifiers()) ? 0 : 1; try { addParameter2(offset + Descriptor.paramSize(desc), type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
private void modifyClassConstructor(ClassFile cf) throws CannotCompileException, NotFoundException { if (fieldInitializers == null) return; Bytecode code = new Bytecode(cf.getConstPool(), 0, 0); Javac jv = new Javac(code, this); int stacksize = 0; boolean doInit = false; for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (Modifier.isStatic(f.getModifiers())) { doInit = true; int s = fi.init.compileIfStatic(f.getType(), f.getName(), code, jv); if (stacksize < s) stacksize = s; } } if (doInit) // need an initializer for static fileds. modifyClassConstructor(cf, code, stacksize, 0); }
/** * Inserts a new parameter, which becomes the first parameter. */ public void insertParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.insertParameter(type, desc); try { addParameter2(Modifier.isStatic(getModifiers()) ? 0 : 1, type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
/** * Appends a new parameter, which becomes the last parameter. */ public void addParameter(CtClass type) throws CannotCompileException { declaringClass.checkModify(); String desc = methodInfo.getDescriptor(); String desc2 = Descriptor.appendParameter(type, desc); int offset = Modifier.isStatic(getModifiers()) ? 0 : 1; try { addParameter2(offset + Descriptor.paramSize(desc), type, desc); } catch (BadBytecode e) { throw new CannotCompileException(e); } methodInfo.setDescriptor(desc2); }
+ "_" + name); if (Modifier.isStatic(mod)) body = trapStaticMethod; else
recordParams(method.getParameterTypes(), Modifier.isStatic(mod));
init.check(f.getSignature()); int mod = f.getModifiers(); if (Modifier.isStatic(mod) && Modifier.isFinal(mod)) try { ConstPool cp = getClassFile2().getConstPool();
boolean isStatic = Modifier.isStatic(delegate.getModifiers()); CtClass deleClass = delegate.getDeclaringClass(); CtClass[] params = delegate.getParameterTypes();
try { int nvars = jv.recordParams(getParameterTypes(), Modifier.isStatic(getModifiers())); jv.recordParamNames(ca, nvars); jv.recordLocalVariables(ca, 0);
CtClass[] plist = gen.makeParamList(md); CtClass[] tlist = gen.makeThrowsList(md); recordParams(plist, Modifier.isStatic(mod)); md = p.parseMethod2(stable, md); try {