Search in sources :

Example 1 with ClassParameter

use of dyvilx.tools.compiler.ast.parameter.ClassParameter in project Dyvil by Dyvil.

the class ExternalClass method visitField.

public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    IType type = ClassFormat.readFieldType(signature == null ? desc : signature);
    if (this.classParameters != null && this.classParameters.contains(name)) {
        final ClassParameter param = new ExternalClassParameter(this, Name.fromQualified(name), desc, type, readModifiers(access));
        this.parameters.add(param);
        return new SimpleFieldVisitor(param);
    }
    final ExternalField field = new ExternalField(this, Name.fromQualified(name), desc, type, readModifiers(access));
    if (value != null) {
        field.setConstantValue(value);
    }
    this.body.addDataMember(field);
    return new SimpleFieldVisitor(field);
}
Also used : ClassParameter(dyvilx.tools.compiler.ast.parameter.ClassParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with ClassParameter

use of dyvilx.tools.compiler.ast.parameter.ClassParameter in project Dyvil by Dyvil.

the class CaseClassMetadata method resolveTypesPre.

@Override
public void resolveTypesPre(MarkerList markers, IContext context) {
    super.resolveTypesPre(markers, context);
    for (IParameter param : this.theClass.getParameters()) {
        final ClassParameter classParameter = (ClassParameter) param;
        if (classParameter.isOverride() || classParameter.getProperty() != null) {
            // Ignore override class parameters and class parameters that already have a property
            continue;
        }
        // Create a property with getter
        final IProperty property = classParameter.createProperty();
        property.getAttributes().addFlag(Modifiers.GENERATED);
        property.initGetter();
        if (!classParameter.hasModifier(Modifiers.FINAL)) {
            // and setter, for non-final class parameters
            property.initSetter();
        }
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IProperty(dyvilx.tools.compiler.ast.field.IProperty) ClassParameter(dyvilx.tools.compiler.ast.parameter.ClassParameter)

Example 3 with ClassParameter

use of dyvilx.tools.compiler.ast.parameter.ClassParameter in project Dyvil by Dyvil.

the class ExternalClass method visitMethod.

public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ((access & Modifiers.SYNTHETIC) != 0) {
        return null;
    }
    switch(name) {
        case "<clinit>":
            return null;
        case "<init>":
            if (this.hasModifier(Modifiers.ENUM)) {
                return null;
            }
            final ExternalConstructor ctor = new ExternalConstructor(this, readModifiers(access));
            if (signature != null) {
                readConstructorType(signature, ctor);
            } else {
                readConstructorType(desc, ctor);
                if (exceptions != null) {
                    readExceptions(exceptions, ctor.getExceptions());
                }
            }
            if ((access & Modifiers.ACC_VARARGS) != 0) {
                final ParameterList parameterList = ctor.getExternalParameterList();
                parameterList.get(parameterList.size() - 1).setVarargs();
            }
            this.body.addConstructor(ctor);
            return new SimpleMethodVisitor(ctor);
    }
    if (this.isAnnotation() && (access & Modifiers.STATIC) == 0) {
        final ClassParameter param = new ExternalClassParameter(this, Name.fromQualified(name), desc.substring(2), readReturnType(desc), readModifiers(access));
        this.parameters.add(param);
        return new AnnotationClassVisitor(param);
    }
    final ExternalMethod method = new ExternalMethod(this, name, desc, signature, readModifiers(access));
    if (signature != null) {
        readMethodType(signature, method);
    } else {
        readMethodType(desc, method);
        if (exceptions != null) {
            readExceptions(exceptions, method.getExceptions());
        }
    }
    if ((access & Modifiers.ACC_VARARGS) != 0) {
        final ParameterList parameterList = method.getExternalParameterList();
        parameterList.get(parameterList.size() - 1).setVarargs();
    }
    this.body.addMethod(method);
    return new SimpleMethodVisitor(method);
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ClassParameter(dyvilx.tools.compiler.ast.parameter.ClassParameter)

Aggregations

ClassParameter (dyvilx.tools.compiler.ast.parameter.ClassParameter)3 IProperty (dyvilx.tools.compiler.ast.field.IProperty)1 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)1 IType (dyvilx.tools.compiler.ast.type.IType)1