use of org.objectweb.asm.FieldVisitor in project groovy-core by groovy.
the class AsmClassGenerator method visitField.
public void visitField(FieldNode fieldNode) {
onLineNumber(fieldNode, "visitField: " + fieldNode.getName());
ClassNode t = fieldNode.getType();
String signature = BytecodeHelper.getGenericsBounds(t);
Expression initialValueExpression = fieldNode.getInitialValueExpression();
ConstantExpression cexp = initialValueExpression instanceof ConstantExpression ? (ConstantExpression) initialValueExpression : null;
if (cexp != null) {
cexp = Verifier.transformToPrimitiveConstantIfPossible(cexp);
}
Object value = cexp != null && ClassHelper.isStaticConstantInitializerType(cexp.getType()) && cexp.getType().equals(t) && fieldNode.isStatic() && fieldNode.isFinal() ? // GROOVY-5150
cexp.getValue() : null;
if (value != null) {
// byte, char and short require an extra cast
if (ClassHelper.byte_TYPE.equals(t) || ClassHelper.short_TYPE.equals(t)) {
value = ((Number) value).intValue();
} else if (ClassHelper.char_TYPE.equals(t)) {
value = Integer.valueOf((Character) value);
}
}
FieldVisitor fv = cv.visitField(fieldNode.getModifiers(), fieldNode.getName(), BytecodeHelper.getTypeDescription(t), signature, value);
visitAnnotations(fieldNode, fv);
fv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project gravel by gravel-st.
the class ASMClassWriter method createField.
private void createField(JVMField field) {
FieldVisitor fv = cw.visitField(ACC_PUBLIC | (field.isStatic() ? ACC_STATIC : 0), field.varName(), field.type().descriptorString(), null, null);
fv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project maple-ir by LLVM-but-worse.
the class FieldNode method accept.
/**
* Makes the given class visitor visit this field.
*
* @param cv
* a class visitor.
*/
public void accept(final ClassVisitor cv) {
FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
if (fv == null) {
return;
}
int i, n;
n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
for (i = 0; i < n; ++i) {
AnnotationNode an = visibleAnnotations.get(i);
an.accept(fv.visitAnnotation(an.desc, true));
}
n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
for (i = 0; i < n; ++i) {
AnnotationNode an = invisibleAnnotations.get(i);
an.accept(fv.visitAnnotation(an.desc, false));
}
n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
for (i = 0; i < n; ++i) {
TypeAnnotationNode an = visibleTypeAnnotations.get(i);
an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
}
n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
for (i = 0; i < n; ++i) {
TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
}
n = attrs == null ? 0 : attrs.size();
for (i = 0; i < n; ++i) {
fv.visitAttribute(attrs.get(i));
}
fv.visitEnd();
}
use of org.objectweb.asm.FieldVisitor in project maple-ir by LLVM-but-worse.
the class CheckClassAdapter method visitField.
@Override
public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) {
checkState();
checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE + Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
0x40000);
CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
CheckMethodAdapter.checkDesc(desc, false);
if (signature != null) {
checkFieldSignature(signature);
}
if (value != null) {
CheckMethodAdapter.checkConstant(value);
}
FieldVisitor av = super.visitField(access, name, desc, signature, value);
return new CheckFieldAdapter(av);
}
use of org.objectweb.asm.FieldVisitor in project neo4j by neo4j.
the class ByteCodeClassWriter method field.
@Override
public void field(FieldReference field, Expression value) {
// keep track of all static field->value, and initiate in <clinit> in done
if (Modifier.isStatic(field.modifiers()) && value != null) {
staticFields.put(field, value);
}
FieldVisitor fieldVisitor = classVisitor.visitField(field.modifiers(), field.name(), typeName(field.type()), signature(field.type()), null);
fieldVisitor.visitEnd();
}
Aggregations