当前位置: 首页>>代码示例>>Java>>正文


Java FieldAccess类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:Dagger2Extension.java

示例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());
            }
        }
    });
}
 
开发者ID:deephacks,项目名称:confit,代码行数:23,代码来源:ConfigProxyGenerator.java

示例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())
	);
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:8,代码来源:EntryFactory.java

示例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();
}
 
开发者ID:ChrisRM,项目名称:material-theme-jetbrains,代码行数:39,代码来源:MTTabsPainterPatcherComponent.java

示例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);
    }
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:12,代码来源:CodeProcessor.java

示例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();
}
 
开发者ID:evandor,项目名称:unitprofiler,代码行数:13,代码来源:ProfilingExprEditor.java

示例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;
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:69,代码来源:JarIndex.java

示例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()));
}
 
开发者ID:OpenModLoader,项目名称:Enigma,代码行数:4,代码来源:EntryFactory.java

示例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()));
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-Enigma,代码行数:7,代码来源:EntryFactory.java

示例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);
    }
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:52,代码来源:CodeProcessor.java

示例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);
        }
    }
 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:57,代码来源:FSTByteArrayUnsafeStructGeneration.java

示例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 + "\";");
    }
}
 
开发者ID:SSEHUB,项目名称:spassMeter,代码行数:14,代码来源:ConfigurationFieldEditor.java

示例13: edit

import javassist.expr.FieldAccess; //导入依赖的package包/类
public void edit(FieldAccess e) throws CannotCompileException { } 
开发者ID:petablox-project,项目名称:petablox,代码行数:2,代码来源:BasicInstrumentor.java

示例14: defineStructWriteAccess

import javassist.expr.FieldAccess; //导入依赖的package包/类
void defineStructWriteAccess(FieldAccess f, CtClass type, FSTClazzInfo.FSTFieldInfo fieldInfo); 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:2,代码来源:FSTStructGeneration.java

示例15: defineStructReadAccess

import javassist.expr.FieldAccess; //导入依赖的package包/类
void defineStructReadAccess(FieldAccess f, CtClass type, FSTClazzInfo.FSTFieldInfo fieldInfo); 
开发者ID:RuedigerMoeller,项目名称:fast-serialization,代码行数:2,代码来源:FSTStructGeneration.java


注:本文中的javassist.expr.FieldAccess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。