Search in sources :

Example 11 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class AbstractClass method addMethods.

private static void addMethods(Collection<IMethod> methods, IProperty property) {
    final IMethod getter = property.getGetter();
    if (getter != null) {
        methods.add(getter);
    }
    final IMethod setter = property.getSetter();
    if (setter != null) {
        methods.add(setter);
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 12 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class ClassBody method checkProperty.

public static void checkProperty(IProperty property, MarkerList markers, IClass checkedClass, ITypeContext typeContext) {
    final IMethod getter = property.getGetter();
    if (getter != null) {
        checkMethod(getter, markers, checkedClass, typeContext);
    }
    final IMethod setter = property.getSetter();
    if (setter != null) {
        checkMethod(setter, markers, checkedClass, typeContext);
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 13 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class CodeClass method checkFunctional.

public void checkFunctional(MarkerList markers) {
    final boolean hasAnnotation = this.hasModifier(Modifiers.FUNCTIONAL);
    if (hasAnnotation && !this.isInterface()) {
        // FunctionalInterface annotation on class or object
        markers.add(Markers.semanticError(this.position, "interface.functional.class"));
        return;
    }
    if (this.body == null) {
        if (hasAnnotation) {
            // No abstract method
            markers.add(Markers.semanticError(this.position, "interface.functional.not_found", this.name));
        }
        return;
    }
    // Partial copy in ExternalClass.getFunctionalMethod
    IMethod functionalMethod = null;
    for (IMethod method : this.body.allMethods()) {
        if (!method.isFunctional()) {
            continue;
        }
        if (functionalMethod == null) {
            functionalMethod = method;
            continue;
        }
        if (!hasAnnotation) {
            return;
        }
        // Multiple abstract methods
        markers.add(Markers.semanticError(this.position, "interface.functional.multiple", this.name));
        return;
    }
    if (functionalMethod != null) {
        this.metadata.setFunctionalMethod(functionalMethod);
        return;
    }
    if (hasAnnotation) {
        // No abstract method
        markers.add(Markers.semanticError(this.position, "interface.functional.not_found", this.name));
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 14 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class HeaderContext method getImplicitMatches.

@Override
public void getImplicitMatches(MatchList<IMethod> list, IValue value, IType targetType) {
    // See comment in getMethodMatches for rationale
    this.header.getImplicitMatches(list, value, targetType);
    if (list.hasCandidate()) {
        return;
    }
    final ImportDeclaration[] imports = this.header.importDeclarations;
    for (int i = 0; i < this.header.importCount; i++) {
        final IImportContext importContext = imports[i].getContext();
        final MatchList<IMethod> subList = list.emptyCopy();
        importContext.getImplicitMatches(subList, value, targetType);
        list.addAll(subList);
    }
}
Also used : IImportContext(dyvilx.tools.compiler.ast.imports.IImportContext) ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 15 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class StatementList method addMethod.

protected void addMethod(MemberStatement memberStatement, MarkerList markers) {
    final IClassMember member = memberStatement.member;
    final MemberKind memberKind = member.getKind();
    if (memberKind != MemberKind.METHOD) {
        markers.add(Markers.semantic(member.getPosition(), "statementlist.declaration.invalid", Util.memberNamed(member)));
        return;
    }
    final IMethod method = (IMethod) member;
    if (this.methods == null) {
        this.methods = new ArrayList<>();
        this.methods.add(method);
        return;
    }
    final Name methodName = method.getName();
    final int parameterCount = method.getParameters().size();
    final String desc = method.getDescriptor();
    for (IMethod candidate : this.methods) {
        if (// same name
        candidate.getName() == methodName && candidate.getParameters().size() == parameterCount && candidate.getDescriptor().equals(desc)) {
            markers.add(Markers.semanticError(memberStatement.getPosition(), "method.duplicate", methodName, desc));
        }
    }
    this.methods.add(method);
}
Also used : MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IClassMember(dyvilx.tools.compiler.ast.member.IClassMember) Name(dyvil.lang.Name)

Aggregations

IMethod (dyvilx.tools.compiler.ast.method.IMethod)31 IValue (dyvilx.tools.compiler.ast.expression.IValue)6 IField (dyvilx.tools.compiler.ast.field.IField)4 IProperty (dyvilx.tools.compiler.ast.field.IProperty)4 IType (dyvilx.tools.compiler.ast.type.IType)3 TreeSet (dyvil.collection.mutable.TreeSet)2 Name (dyvil.lang.Name)2 SourcePosition (dyvil.source.position.SourcePosition)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)2 IImportContext (dyvilx.tools.compiler.ast.imports.IImportContext)2 ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)2 MatchList (dyvilx.tools.compiler.ast.method.MatchList)2 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)2 PrintStream (java.io.PrintStream)2 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)1 IImplicitContext (dyvilx.tools.compiler.ast.context.IImplicitContext)1