本文整理汇总了Java中javassist.expr.FieldAccess类的典型用法代码示例。如果您正苦于以下问题:Java FieldAccess类的具体用法?Java FieldAccess怎么用?Java FieldAccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldAccess类属于javassist.expr包,在下文中一共展示了FieldAccess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replacePresenterWithPresenterProvider
import javassist.expr.FieldAccess; //导入依赖的package包/类
private void replacePresenterWithPresenterProvider(CtClass membersInjectorClass,
final String presenterFieldName,
final String presenterProviderField)
throws NotFoundException, CannotCompileException {
CtMethod injectMembers = membersInjectorClass.getDeclaredMethod("injectMembers");
final int[] injectedPresenterLineNumber = {-1};
injectMembers.instrument(new ExprEditor() {
@Override
public void edit(FieldAccess f) throws CannotCompileException {
if (f.isWriter() && f.getFieldName().equals(presenterFieldName)) {
injectedPresenterLineNumber[0] = f.getLineNumber();
}
}
});
if (injectedPresenterLineNumber[0] != -1) {
deleteLine(injectMembers, injectedPresenterLineNumber[0]);
fillPresenterProviderInView(injectMembers, presenterProviderField, injectedPresenterLineNumber[0]);
viewDelegateBinder.log("DaggerExtension",
"Remove presenter injection from " +
membersInjectorClass.getSimpleName() +
" and replace with our presenterProvider ");
viewDelegateBinder.writeClass(membersInjectorClass);
}
}
示例2: instrument
import javassist.expr.FieldAccess; //导入依赖的package包/类
/**
* Instrument a single reference field, using the ConfigReferenceHolder to fetch the real
* reference from the cache and replace it with a real object.
*/
private void instrument(CtClass proxy, final SchemaPropertyRef ref) throws Exception {
final Schema schema = schemas.get(ref.getSchemaName());
checkNotNull(schema, "Schema not found for SchemaPropertyRef ["+ref+"]");
final String fieldName = ref.getFieldName();
// for help on javassist syntax, see chapter around javassist.expr.FieldAccess at
// http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/tutorial/tutorial2.html#before
proxy.instrument(new ExprEditor() {
public void edit(FieldAccess f) throws CannotCompileException {
if (f.getFieldName().equals(ref.getFieldName())) {
StringBuilder code = new StringBuilder();
code.append("{");
code.append("$_=("+schema.getType()+") this."+PROXY_FIELD_NAME+".getObjectReference(\""+fieldName+"\", \""+schema.getName()+"\");");
code.append("}");
f.replace(code.toString());
}
}
});
}
示例3: getFieldEntry
import javassist.expr.FieldAccess; //导入依赖的package包/类
public static FieldEntry getFieldEntry(FieldAccess call) {
return new FieldEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
call.getFieldName(),
new Type(call.getSignature())
);
}
示例4: hackTabsGetHeight
import javassist.expr.FieldAccess; //导入依赖的package包/类
/**
* Hack TabsUtil,getHeight to override SDK
*/
private void hackTabsGetHeight() throws
NotFoundException,
CannotCompileException {
final ClassPool cp = new ClassPool(true);
cp.insertClassPath(new ClassClassPath(TabInfo.class));
final CtClass ctClass = cp.get("com.intellij.ui.tabs.impl.TabLabel");
final CtMethod ctMethod = ctClass.getDeclaredMethod("getPreferredSize");
ctMethod.instrument(new ExprEditor() {
@Override
public void edit(final MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("com.intellij.ui.tabs.TabsUtil") && m.getMethodName().equals("getTabsHeight")) {
final String code = String.format("com.intellij.ide.util.PropertiesComponent.getInstance().getInt(\"%s\", 25)", TABS_HEIGHT);
final String isDebugTab = "myInfo.getTabActionPlace() != null ? myInfo.getTabActionPlace().contains(\"debugger\") : true";
m.replace(String.format("{ $_ = com.intellij.util.ui.JBUI.scale(%s); }", code));
}
}
});
ctClass.toClass();
// Hack JBRunnerTabs
final CtClass tabLabelClass = cp.get("com.intellij.execution.ui.layout.impl.JBRunnerTabs$MyTabLabel");
final CtMethod ctMethod2 = tabLabelClass.getDeclaredMethod("getPreferredSize");
ctMethod2.instrument(new ExprEditor() {
@Override
public void edit(final FieldAccess f) throws CannotCompileException {
if (f.getFieldName().equals("height") && f.isReader()) {
f.replace("{ $_ = com.intellij.util.ui.JBUI.scale(25); }");
}
}
});
tabLabelClass.toClass();
}
示例5: edit
import javassist.expr.FieldAccess; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public void edit(FieldAccess fi) throws CannotCompileException {
try {
addTypeIf(innerClassPrefix, fi.getField().getType(),
targetClassName, inner);
} catch (NotFoundException e) {
throw new CannotCompileException(e);
}
}
示例6: edit
import javassist.expr.FieldAccess; //导入依赖的package包/类
@Override
public void edit(FieldAccess f) throws CannotCompileException {
logger.warn(" >>> FieldAccess: {}, {}, {}", new Object[] {f.getEnclosingClass().getName(), f.getFieldName(), f.getLineNumber()});
f.getSignature();
try {
f.getField();
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
f.where();
}
示例7: isIllegalConstructor
import javassist.expr.FieldAccess; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private boolean isIllegalConstructor(Set<String> syntheticFieldTypes, CtConstructor constructor) {
// illegal constructors only set synthetic member fields, then call super()
String className = constructor.getDeclaringClass().getName();
// collect all the field accesses, constructor calls, and method calls
final List<FieldAccess> illegalFieldWrites = Lists.newArrayList();
final List<ConstructorCall> constructorCalls = Lists.newArrayList();
try {
constructor.instrument(new ExprEditor() {
@Override
public void edit(FieldAccess fieldAccess) {
if (fieldAccess.isWriter() && constructorCalls.isEmpty()) {
illegalFieldWrites.add(fieldAccess);
}
}
@Override
public void edit(ConstructorCall constructorCall) {
constructorCalls.add(constructorCall);
}
});
} catch (CannotCompileException ex) {
// we're not compiling anything... this is stupid
throw new Error(ex);
}
// are there any illegal field writes?
if (illegalFieldWrites.isEmpty()) {
return false;
}
// are all the writes to synthetic fields?
for (FieldAccess fieldWrite : illegalFieldWrites) {
// all illegal writes have to be to the local class
if (!fieldWrite.getClassName().equals(className)) {
System.err.println(String.format("WARNING: illegal write to non-member field %s.%s", fieldWrite.getClassName(), fieldWrite.getFieldName()));
return false;
}
// find the field
FieldInfo fieldInfo = null;
for (FieldInfo info : (List<FieldInfo>)constructor.getDeclaringClass().getClassFile().getFields()) {
if (info.getName().equals(fieldWrite.getFieldName()) && info.getDescriptor().equals(fieldWrite.getSignature())) {
fieldInfo = info;
break;
}
}
if (fieldInfo == null) {
// field is in a superclass or something, can't be a local synthetic member
return false;
}
// is this field synthetic?
boolean isSynthetic = (fieldInfo.getAccessFlags() & AccessFlag.SYNTHETIC) != 0;
if (isSynthetic) {
syntheticFieldTypes.add(fieldInfo.getDescriptor());
} else {
System.err.println(String.format("WARNING: illegal write to non synthetic field %s %s.%s", fieldInfo.getDescriptor(), className, fieldInfo.getName()));
return false;
}
}
// we passed all the tests!
return true;
}
示例8: getFieldEntry
import javassist.expr.FieldAccess; //导入依赖的package包/类
public static FieldEntry getFieldEntry(FieldAccess call) {
return new FieldEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), call.getFieldName(), new Type(call.getSignature()));
}
示例9: getFieldEntry
import javassist.expr.FieldAccess; //导入依赖的package包/类
public static FieldEntry getFieldEntry(FieldAccess call)
{
return new FieldEntry(new ClassEntry(Descriptor.toJvmName(call
.getClassName())), call.getFieldName(), new Type(
call.getSignature()));
}
示例10: edit
import javassist.expr.FieldAccess; //导入依赖的package包/类
/**
* Is called when a field access occurs. Replaces field accesses to
* attributes scheduled for removal by the value expression specified
* in the annotation or by the default value. Replaces initial values
* in case of {@link SetValue}.
*
* @param access the field access to be processed
* @throws CannotCompileException in case of errors in the generated
* byte code
*/
@Override
public void edit(FieldAccess access) throws CannotCompileException {
try {
CtField field = access.getField();
if ((removals.containsKey(getSignature(field))
|| classesForRemoval.contains(field.getDeclaringClass()))
&& !access.getEnclosingClass().equals(
field.getDeclaringClass())) { // do not delete in self
Variability var = Annotations.getAnnotationRec(field,
Variability.class, config.checkRecursively());
if (access.isWriter()) {
access.replace(";");
} else {
String override = null;
if (null != var) {
override = var.value();
}
access.replace("$_ = " + Types.getDefaultValue(
field.getType(), override) + ";");
}
} else {
if (access.isStatic() && access.isWriter()) {
SetValue set = Annotations.getAnnotationRec(
field, SetValue.class, config.checkRecursively());
if (null != set) {
String binding = bindings.get(set.id());
if (null != binding) {
access.replace(
field.getDeclaringClass().getName()
+ "." + field.getName() + " = "
+ bindings.get(set.id()) + ";");
System.out.println("- modified value of "
+ field.getName());
}
}
}
}
} catch (NotFoundException ex) {
throw new CannotCompileException(ex);
}
}
示例11: defineStructReadAccess
import javassist.expr.FieldAccess; //导入依赖的package包/类
@Override
public void defineStructReadAccess(FieldAccess f, CtClass type, FSTClazzInfo.FSTFieldInfo fieldInfo) {
boolean vola = fieldInfo.isVolatile();
validateAnnotations(fieldInfo,vola);
String insert = "";
String statement = "";
if ( vola ) {
insert = "Volatile";
}
int off = fieldInfo.getStructOffset();
try {
if ( type == CtPrimitiveType.booleanType ) {
f.replace("$_ = ___bytes.getBool"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.byteType ) {
f.replace("$_ = ___bytes.get"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.charType ) {
f.replace("$_ = ___bytes.getChar"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.shortType ) {
f.replace("$_ = ___bytes.getShort"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.intType ) {
f.replace("$_ = ___bytes.getInt"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.longType ) {
f.replace("$_ = ___bytes.getLong"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.floatType ) {
f.replace("$_ = ___bytes.getFloat"+insert+"("+off+"+___offset);");
} else
if ( type == CtPrimitiveType.doubleType ) {
f.replace("$_ = ___bytes.getDouble"+insert+"("+off+"+___offset);");
} else { // object ref or obje array
String typeString = type.getName();
if ( type.isArray() ) {
throw new RuntimeException("invalid direct access to array in struct code. Use arrayaccessor name convention as documented."+fieldInfo);
}
if ( ! FSTStruct.class.isAssignableFrom(Class.forName( typeString) ) ) {
throw new RuntimeException("invalid type, require at least FSTStruct "+fieldInfo);
}
statement = "{ int tmpIdx = ___bytes.getInt( " + off + " + ___offset); if (tmpIdx < 0) return null;" +
"long __tmpOff = ___offset + tmpIdx; " +
"" + typeString + " tmp = (" + typeString + ")___fac.getStructPointerByOffset(___bytes,__tmpOff); " +
"if ( tmp == null ) return null;" +
(trackChanges ? "tmp.tracker = new org.nustaq.offheap.structs.FSTStructChange(tracker,\"" + fieldInfo.getName() + "\"); " : "")+
"$_ = tmp; " +
"}";
f.replace(statement);
// f.replace("{ Object _o = unsafe.toString(); $_ = _o; }");
}
} catch (Exception ex) {
throw new RuntimeException(""+fieldInfo+" "+statement,ex);
}
}
示例12: edit
import javassist.expr.FieldAccess; //导入依赖的package包/类
/**
* Instruments a field access for notifying the recorder about value
* changes.
*
* @param fa the field access
* @throws CannotCompileException in case that the new code does not compile
*/
public void edit(FieldAccess fa) throws CannotCompileException {
if (null != args && fa.isWriter() && fa.isStatic()
&& fa.getFieldName().equals("cmdArgs")) {
fa.replace("cmdArgs = \"" + args + "\";");
}
}
示例13: edit
import javassist.expr.FieldAccess; //导入依赖的package包/类
public void edit(FieldAccess e) throws CannotCompileException { }
示例14: defineStructWriteAccess
import javassist.expr.FieldAccess; //导入依赖的package包/类
void defineStructWriteAccess(FieldAccess f, CtClass type, FSTClazzInfo.FSTFieldInfo fieldInfo);
示例15: defineStructReadAccess
import javassist.expr.FieldAccess; //导入依赖的package包/类
void defineStructReadAccess(FieldAccess f, CtClass type, FSTClazzInfo.FSTFieldInfo fieldInfo);