/** * Returns the field with the specified name. The returned field * may be a private field declared in a super class or interface. */ public CtField getField(String name) throws NotFoundException { return getField(name, null); }
/** * Returns the field with the specified name. The returned field * may be a private field declared in a super class or interface. */ public CtField getField(String name) throws NotFoundException { return getField(name, null); }
public JavassistDynamicField(DynamicBean dynamicBean, CtClass clazz, ConstPool cpool, String fieldName) { try { this.dynamicBean = dynamicBean; this.cpool = cpool; this.cfield = clazz.getField(fieldName); attr = new AnnotationsAttribute(cpool, AnnotationsAttribute.visibleTag); } catch (NotFoundException e) { log.error(fieldName + " not found"); } }
static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) { if (!clazz.subclassOf(fclass)) return false; try { CtField f = clazz.getField(fname); return f.getDeclaringClass() == fclass; } catch (NotFoundException e) {} return false; }
private void exposeRawEnumArray(CtClass cc) throws NotFoundException, CannotCompileException { CtField field; try { field = cc.getField("$VALUES"); } catch( NotFoundException nfe ) { // Eclipse apparently stores this in a different place. field = cc.getField("ENUM$VALUES"); } String body = "public static "+cc.getName()+" raw_enum(int i) { return i==255?null:"+field.getName()+"[i]; } "; try { cc.addMethod(CtNewMethod.make(body,cc)); } catch( CannotCompileException ce ) { Log.warn(Sys.WATER,"--- Compilation failure while compiler raw_enum for "+cc.getName()+"\n"+body+"\n------",ce); throw ce; } }
static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) { if (!clazz.subclassOf(fclass)) return false; try { CtField f = clazz.getField(fname); return f.getDeclaringClass() == fclass; } catch (NotFoundException e) {} return false; }
/** * duplicated here to take CtClass instead of Class * @see org.hibernate.internal.util.ReflectHelper#locateField */ private static CtField findFieldOrNull(CtClass ctClass, String propertyName) { if ( ctClass == null ) { return null; } try { return ctClass.getField( propertyName ); } catch ( NotFoundException nsfe ) { try { return findFieldOrNull( ctClass.getSuperclass(), propertyName ); } catch (NotFoundException e) { return null; } } }
public static CtMethod addGetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing getter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.getter( name, target.getField( field ) ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.getter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
public static CtMethod addSetter(CtClass target, String field, String name) { CtField actualField = null; try { actualField = target.getField( field ); log.debugf( "Writing setter method [%s] into [%s] for field [%s]", name, target.getName(), field ); CtMethod method = CtNewMethod.setter( name, actualField ); target.addMethod( method ); return method; } catch (CannotCompileException cce) { try { // Fall back to create a getter from delegation. CtMethod method = CtNewMethod.delegator( CtNewMethod.setter( name, actualField ), target ); target.addMethod( method ); return method; } catch (CannotCompileException ignored) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, cce ); } } catch (NotFoundException nfe) { String msg = String.format( "Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field ); throw new EnhancementException( msg, nfe ); } }
/** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); }
@Override public DynamicBean removeField(String fieldName) { try { clazz.removeField(clazz.getField(fieldName)); clazz.removeMethod(clazz.getDeclaredMethod("get" + StringUtils.capitalize(fieldName))); clazz.removeMethod(clazz.getDeclaredMethod("set" + StringUtils.capitalize(fieldName))); } catch (NotFoundException e) { e.printStackTrace(); log.error("can't remove field : " + fieldName); } return this; }
/** * Returns the field accessed by this expression. */ public CtField getField() throws NotFoundException { CtClass cc = getCtClass(); int index = iterator.u16bitAt(currentPos + 1); ConstPool cp = getConstPool(); return cc.getField(cp.getFieldrefName(index), cp.getFieldrefType(index)); }
/** * @param className a qualified class name. e.g. java.lang.String */ public CtField lookupField(String className, Symbol fieldName) throws CompileError { CtClass cc = lookupClass(className, false); try { return cc.getField(fieldName.get()); } catch (NotFoundException e) {} throw new CompileError("no such field: " + fieldName.get()); }
/** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } }
/** * Returns the field accessed by this expression. */ public CtField getField() throws NotFoundException { CtClass cc = getCtClass(); int index = iterator.u16bitAt(currentPos + 1); ConstPool cp = getConstPool(); return cc.getField(cp.getFieldrefName(index), cp.getFieldrefType(index)); }
/** * Only used by fieldAccess() in MemberCodeGen and TypeChecker. * * @param jvmClassName a JVM class name. e.g. java/lang/String * @see #lookupClass(String, boolean) */ public CtField lookupFieldByJvmName2(String jvmClassName, Symbol fieldSym, ASTree expr) throws NoFieldException { String field = fieldSym.get(); CtClass cc = null; try { cc = lookupClass(jvmToJavaName(jvmClassName), true); } catch (CompileError e) { // EXPR might be part of a qualified class name. throw new NoFieldException(jvmClassName + "/" + field, expr); } try { return cc.getField(field); } catch (NotFoundException e) { // maybe an inner class. jvmClassName = javaToJvmName(cc.getName()); throw new NoFieldException(jvmClassName + "$" + field, expr); } }
/** * 如果当前属性不存在先创建属性以及setter/getter方法和注解。 如果已经属性返回当前属性 */ @Override public DynamicField field(String fieldName, CtClass fieldType) { try { clazz.getField(fieldName); } catch (NotFoundException e) { try { CtField f = new CtField(fieldType, fieldName, clazz); clazz.addField(f); getter(fieldName, f); setter(fieldName, f); } catch (CannotCompileException ex) { ex.printStackTrace(); } } return new JavassistDynamicField(this, clazz, cpool, fieldName); }
|| !enhancementContext.isPersistentField( targetCtClass.getField( fieldName ) ) || PersistentAttributesHelper.hasAnnotation( targetCtClass, fieldName, Id.class ) || "this$0".equals( fieldName ) ) {
CtField f = null; try { f = thisClass.getField(name);
String name = mem.get(); try { CtField f = thisClass.getField(name); if (Modifier.isStatic(f.getModifiers())) mem.setField(f);