本文整理了Java中org.codehaus.groovy.ast.FieldNode.setSynthetic()
方法的一些代码示例,展示了FieldNode.setSynthetic()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FieldNode.setSynthetic()
方法的具体详情如下:
包路径:org.codehaus.groovy.ast.FieldNode
类名称:FieldNode
方法名:setSynthetic
暂无
代码示例来源:origin: org.codehaus.groovy/groovy
private static FieldNode setMetaClassFieldIfNotExists(ClassNode node, FieldNode metaClassField) {
if (metaClassField != null) return metaClassField;
final String classInternalName = BytecodeHelper.getClassInternalName(node);
metaClassField =
node.addField("metaClass", ACC_PRIVATE | ACC_TRANSIENT | ACC_SYNTHETIC, ClassHelper.METACLASS_TYPE,
new BytecodeExpression(ClassHelper.METACLASS_TYPE) {
public void visit(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, classInternalName, "$getStaticMetaClass", "()Lgroovy/lang/MetaClass;", false);
}
});
metaClassField.setSynthetic(true);
return metaClassField;
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static void addFastPathHelperFieldsAndHelperMethod(ClassNode node, final String classInternalName, boolean knownSpecialCase) {
if (node.getNodeMetaData(ClassNodeSkip.class) != null) return;
FieldNode stMCB = checkFieldDoesNotExist(node, STATIC_METACLASS_BOOL);
if (stMCB == null) {
stMCB = node.addField(
STATIC_METACLASS_BOOL,
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC | ACC_TRANSIENT,
ClassHelper.boolean_TYPE, null);
stMCB.setSynthetic(true);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
protected void addTimeStamp(ClassNode node) {
if (node.getDeclaredField(Verifier.__TIMESTAMP) == null) { // in case if verifier visited the call already
FieldNode timeTagField = new FieldNode(
Verifier.__TIMESTAMP,
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
ClassHelper.long_TYPE,
//"",
node,
new ConstantExpression(System.currentTimeMillis()));
// alternatively, FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
timeTagField = new FieldNode(
Verifier.__TIMESTAMP__ + String.valueOf(System.currentTimeMillis()),
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
ClassHelper.long_TYPE,
//"",
node,
new ConstantExpression((long) 0));
// alternatively, FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private void setConstField(ConstantExpression constantExpression) {
final Object n = constantExpression.getValue();
if (!(n instanceof Number)) return;
if (n instanceof Integer || n instanceof Double) return;
if (n instanceof Long && (0L == (Long) n || 1L == (Long) n)) return; // LCONST_0, LCONST_1
boolean isPrimitive = isPrimitiveType(constantExpression.getType());
FieldNode field = isPrimitive ? const2Prims.get(n) : const2Objects.get(n);
if (field != null) {
constantExpression.setConstantName(field.getName());
return;
}
String name;
do {
name = "$const$" + index++;
} while (currentClass.getDeclaredField(name) != null);
// TODO consider moving initcode to <clinit> and remaking field final
field = new FieldNode(name,
Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC,
constantExpression.getType(),
currentClass,
constantExpression);
field.setSynthetic(true);
missingFields.add(field);
constantExpression.setConstantName(field.getName());
if (isPrimitive) {
const2Prims.put(n, field);
} else {
const2Objects.put(n, field);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
staticMetaClassField.setSynthetic(true);
代码示例来源:origin: org.codehaus.groovy/groovy
private void completeEnum(ClassNode enumClass) {
boolean isAic = isAnonymousInnerClass(enumClass);
// create MIN_VALUE and MAX_VALUE fields
FieldNode minValue = null, maxValue = null, values = null;
if (!isAic) {
ClassNode enumRef = enumClass.getPlainNodeReference();
// create values field
values = new FieldNode("$VALUES", PRIVATE_FS | Opcodes.ACC_SYNTHETIC, enumRef.makeArray(), enumClass, null);
values.setSynthetic(true);
addMethods(enumClass, values);
checkForAbstractMethods(enumClass);
// create MIN_VALUE and MAX_VALUE fields
minValue = new FieldNode("MIN_VALUE", PUBLIC_FS, enumRef, enumClass, null);
maxValue = new FieldNode("MAX_VALUE", PUBLIC_FS, enumRef, enumClass, null);
}
addInit(enumClass, minValue, maxValue, values, isAic);
}
代码示例来源:origin: org.codehaus.groovy/groovy
private Variable findClassMember(ClassNode cn, String name) {
if (cn == null) return null;
if (cn.isScript()) {
return new DynamicVariable(name, false);
}
for (FieldNode fn : cn.getFields()) {
if (fn.getName().equals(name)) return fn;
}
for (MethodNode mn : cn.getMethods()) {
String pName = getPropertyName(mn);
if (name.equals(pName)) {
PropertyNode property = new PropertyNode(name, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
property.getField().setHasNoRealSourcePosition(true);
property.getField().setSynthetic(true);
property.getField().setDeclaringClass(cn);
property.setDeclaringClass(cn);
return property;
}
}
for (PropertyNode pn : cn.getProperties()) {
if (pn.getName().equals(name)) return pn;
}
Variable ret = findClassMember(cn.getSuperClass(), name);
if (ret != null) return ret;
return findClassMember(cn.getOuterClass(), name);
}
代码示例来源:origin: org.codehaus.groovy/groovy
fieldNode.setSynthetic(true);
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
private FieldNode setMetaClassFieldIfNotExists(ClassNode node, FieldNode metaClassField) {
if (metaClassField != null) return metaClassField;
final String classInternalName = BytecodeHelper.getClassInternalName(node);
metaClassField =
node.addField("metaClass", ACC_PRIVATE | ACC_TRANSIENT | ACC_SYNTHETIC, ClassHelper.METACLASS_TYPE,
new BytecodeExpression(ClassHelper.METACLASS_TYPE) {
public void visit(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, classInternalName, "$getStaticMetaClass", "()Lgroovy/lang/MetaClass;");
}});
metaClassField.setSynthetic(true);
return metaClassField;
}
代码示例来源:origin: org.kohsuke.droovy/groovy
private FieldNode setMetaClassFieldIfNotExists(ClassNode node, FieldNode metaClassField){
if (metaClassField != null) return metaClassField;
final String classInternalName = BytecodeHelper.getClassInternalName(node);
metaClassField =
node.addField("metaClass", ACC_PRIVATE | ACC_TRANSIENT | ACC_SYNTHETIC, ClassHelper.METACLASS_TYPE, new BytecodeExpression() {
public void visit(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKEVIRTUAL, classInternalName, "$getStaticMetaClass", "()Lgroovy/lang/MetaClass;");
mv.visitFieldInsn(PUTFIELD, classInternalName, "metaClass", "Lgroovy/lang/MetaClass;");
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, classInternalName, "metaClass", "Lgroovy/lang/MetaClass;");
}
public ClassNode getType() {
return ClassHelper.METACLASS_TYPE;
}
});
metaClassField.setSynthetic(true);
return metaClassField;
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
private FieldNode setMetaClassFieldIfNotExists(ClassNode node, FieldNode metaClassField){
if (metaClassField != null) return metaClassField;
final String classInternalName = BytecodeHelper.getClassInternalName(node);
metaClassField =
node.addField("metaClass", ACC_PRIVATE | ACC_TRANSIENT | ACC_SYNTHETIC, ClassHelper.METACLASS_TYPE, new BytecodeExpression() {
public void visit(MethodVisitor mv) {
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKEVIRTUAL, classInternalName, "$getStaticMetaClass", "()Lgroovy/lang/MetaClass;");
mv.visitFieldInsn(PUTFIELD, classInternalName, "metaClass", "Lgroovy/lang/MetaClass;");
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, classInternalName, "metaClass", "Lgroovy/lang/MetaClass;");
}
public ClassNode getType() {
return ClassHelper.METACLASS_TYPE;
}
});
metaClassField.setSynthetic(true);
return metaClassField;
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
protected void addTimeStamp(ClassNode node) {
FieldNode timeTagField = new FieldNode(
Verifier.__TIMESTAMP,
Modifier.PUBLIC | Modifier.STATIC,
ClassHelper.Long_TYPE,
//"",
node,
new ConstantExpression(new Long(System.currentTimeMillis())));
// alternatively , FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
timeTagField = new FieldNode(
Verifier.__TIMESTAMP__ + String.valueOf(System.currentTimeMillis()),
Modifier.PUBLIC | Modifier.STATIC,
ClassHelper.Long_TYPE,
//"",
node,
new ConstantExpression(new Long(0)));
// alternatively , FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
private void addFastPathHelperFieldsAndHelperMethod(ClassNode node, final String classInternalName, boolean knownSpecialCase) {
if (node.getNodeMetaData(ClassNodeSkip.class)!=null) return;
FieldNode stMCB = checkFieldDoesNotExist(node,STATIC_METACLASS_BOOL);
if (stMCB==null) {
stMCB = node.addField(
STATIC_METACLASS_BOOL,
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC | ACC_TRANSIENT,
ClassHelper.boolean_TYPE, null);
stMCB.setSynthetic(true);
}
}
代码示例来源:origin: org.kohsuke.droovy/groovy
protected void addTimeStamp(ClassNode node) {
FieldNode timeTagField = new FieldNode(
Verifier.__TIMESTAMP,
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
ClassHelper.Long_TYPE,
//"",
node,
new ConstantExpression(System.currentTimeMillis()));
// alternatively , FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
timeTagField = new FieldNode(
Verifier.__TIMESTAMP__ + String.valueOf(System.currentTimeMillis()),
ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC,
ClassHelper.Long_TYPE,
//"",
node,
new ConstantExpression((long) 0));
// alternatively , FieldNode timeTagField = SourceUnit.createFieldNode("public static final long __timeStamp = " + System.currentTimeMillis() + "L");
timeTagField.setSynthetic(true);
node.addField(timeTagField);
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
private void setConstField(ConstantExpression constantExpression) {
final Object n = constantExpression.getValue();
if (!(n instanceof Number || n instanceof Character)) return;
FieldNode field = (FieldNode) const2Var.get(n);
if (field!=null) {
constantExpression.setConstantName(field.getName());
return;
}
final String name = "$const$" + const2Var.size();
//TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already,
// then is this code still valid?
field = currentClass.getDeclaredField(name);
if (field==null) {
field = new FieldNode(name,
Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL,
constantExpression.getType(),
currentClass,
constantExpression
);
field.setSynthetic(true);
missingFields.add(field);
}
constantExpression.setConstantName(field.getName());
const2Var.put(n, field);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
private void setConstField(ConstantExpression constantExpression) {
final Object n = constantExpression.getValue();
if (!(n instanceof Number || n instanceof Character)) return;
FieldNode field = (FieldNode) const2Var.get(n);
if (field!=null) {
constantExpression.setConstantName(field.getName());
return;
}
final String name = "$const$" + const2Var.size();
//TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already,
// then is this code still valid?
field = currentClass.getDeclaredField(name);
if (field==null) {
field = new FieldNode(name,
Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL,
constantExpression.getType(),
currentClass,
constantExpression
);
field.setSynthetic(true);
missingFields.add(field);
}
constantExpression.setConstantName(field.getName());
const2Var.put(n, field);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
private void setConstField(ConstantExpression constantExpression) {
final Object n = constantExpression.getValue();
if (!(n instanceof Number || n instanceof Character)) return;
if (n instanceof Integer || n instanceof Double) return;
FieldNode field = (FieldNode) const2Var.get(n);
if (field!=null) {
constantExpression.setConstantName(field.getName());
return;
}
final String name = "$const$" + const2Var.size();
//TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already,
// then is this code still valid?
field = currentClass.getDeclaredField(name);
if (field==null) {
field = new FieldNode(name,
Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL,
constantExpression.getType(),
currentClass,
constantExpression
);
field.setSynthetic(true);
missingFields.add(field);
}
constantExpression.setConstantName(field.getName());
const2Var.put(n, field);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
/**
* @param name is the full name of the class
* @param modifiers the modifiers,
* @param superClass the base class name - use "java.lang.Object" if no direct
* base class
* @see org.objectweb.asm.Opcodes
*/
public ClassNode(String name, int modifiers, ClassNode superClass, ClassNode[] interfaces, MixinNode[] mixins) {
this.name = name;
this.modifiers = modifiers;
this.superClass = superClass;
this.interfaces = interfaces;
this.mixins = mixins;
isPrimaryNode = true;
if (superClass!=null) {
usesGenerics = superClass.isUsingGenerics();
}
if (!usesGenerics && interfaces!=null) {
for (int i = 0; i < interfaces.length; i++) {
usesGenerics = usesGenerics || interfaces[i].isUsingGenerics();
}
}
if ((modifiers & ACC_INTERFACE) == 0)
addField("$ownClass", ACC_STATIC|ACC_PUBLIC|ACC_FINAL|ACC_SYNTHETIC, ClassHelper.CLASS_Type, new ClassExpression(this)).setSynthetic(true);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
private void completeEnum(ClassNode enumClass) {
boolean isAic = isAnonymousInnerClass(enumClass);
// create MIN_VALUE and MAX_VALUE fields
FieldNode minValue = null, maxValue = null, values = null;
if (!isAic) {
ClassNode enumRef = enumClass.getPlainNodeReference();
// create values field
values = new FieldNode("$VALUES", PRIVATE_FS | Opcodes.ACC_SYNTHETIC, enumRef.makeArray(), enumClass, null);
values.setSynthetic(true);
addMethods(enumClass, values);
// create MIN_VALUE and MAX_VALUE fields
minValue = new FieldNode("MIN_VALUE", PUBLIC_FS, enumRef, enumClass, null);
maxValue = new FieldNode("MAX_VALUE", PUBLIC_FS, enumRef, enumClass, null);
}
addInit(enumClass, minValue, maxValue, values, isAic);
}
代码示例来源:origin: org.gcontracts/gcontracts-core
/**
* Adds an instance field which allows to control whether GContract assertions
* are enabled or not. Before assertions are evaluated this field will be checked.
*
* @see Configurator
*
* @param type the current {@link ClassNode}
*/
public void init(final ClassNode type) {
Validate.notNull(type);
StaticMethodCallExpression checkAssertionsEnabledMethodCall = new StaticMethodCallExpression(ClassHelper.makeWithoutCaching(Configurator.class), "checkAssertionsEnabled", new ArgumentListExpression(new ConstantExpression(type.getName())));
final FieldNode fieldNode = type.addField(BaseVisitor.GCONTRACTS_ENABLED_VAR, Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL, ClassHelper.boolean_TYPE, checkAssertionsEnabledMethodCall);
fieldNode.setSynthetic(true);
}
}
内容来源于网络,如有侵权,请联系作者删除!