Search in sources :

Example 1 with NonNull

use of dyvil.annotation.internal.NonNull in project Dyvil by Dyvil.

the class FileUtils method readLines.

@DyvilModifiers(Modifiers.INFIX)
@NonNull
public static List<@NonNull String> readLines(@NonNull File file) throws IOException {
    try (BufferedReader reader = Files.newBufferedReader(file.toPath())) {
        final List<String> result = new ArrayList<>();
        for (; ; ) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            result.add(line);
        }
        return result;
    }
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(dyvil.collection.mutable.ArrayList) NonNull(dyvil.annotation.internal.NonNull) DyvilModifiers(dyvil.annotation.internal.DyvilModifiers)

Example 2 with NonNull

use of dyvil.annotation.internal.NonNull in project Dyvil by Dyvil.

the class LambdaExpr method makeType.

@NonNull
private LambdaType makeType() {
    final int count = this.parameters.size();
    final LambdaType lambdaType = new LambdaType();
    final TypeList arguments = lambdaType.getArguments();
    for (int i = 0; i < count; i++) {
        arguments.add(this.parameters.get(i).getType());
    }
    arguments.add(this.returnType != null ? this.returnType : Types.UNKNOWN);
    this.flags |= LAMBDA_TYPE_INFERRED;
    return lambdaType;
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) TypeList(dyvilx.tools.compiler.ast.type.TypeList) NonNull(dyvil.annotation.internal.NonNull)

Example 3 with NonNull

use of dyvil.annotation.internal.NonNull in project Dyvil by Dyvil.

the class ClassFormat method readReferenceType.

@NonNull
private static IType readReferenceType(String desc, int start, int end) {
    int index = desc.indexOf('<', start);
    if (index >= 0 && index < end) {
        final GenericType type = new InternalGenericType(desc.substring(start, index));
        final TypeList arguments = type.getArguments();
        index++;
        while (desc.charAt(index) != '>') {
            index = readTyped(desc, index, arguments, true);
        }
        return type;
    }
    return new InternalType(desc.substring(start, end));
}
Also used : InternalType(dyvilx.tools.compiler.ast.type.raw.InternalType) GenericType(dyvilx.tools.compiler.ast.type.generic.GenericType) InternalGenericType(dyvilx.tools.compiler.ast.type.generic.InternalGenericType) InternalGenericType(dyvilx.tools.compiler.ast.type.generic.InternalGenericType) TypeList(dyvilx.tools.compiler.ast.type.TypeList) NonNull(dyvil.annotation.internal.NonNull)

Example 4 with NonNull

use of dyvil.annotation.internal.NonNull in project Dyvil by Dyvil.

the class ForEachStatement method toIteratorLoop.

@NonNull
public IValue toIteratorLoop(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
    final IType iteratorType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERATOR_TYPE);
    if (varType == Types.UNKNOWN) {
        this.inferVariableType(markers, iteratorType);
    } else if (!Types.isAssignable(varType, iteratorType)) {
        final Marker marker = Markers.semanticError(value.getPosition(), "for.iterator.type");
        marker.addInfo(Markers.getSemantic("iterator.type", iteratorType));
        marker.addInfo(Markers.getSemantic("variable.type", varType));
        markers.add(marker);
    }
    this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERATOR, null, markers, context, null));
    final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, true);
    iterableForStatement.resolveAction(this.action, markers, context);
    return iterableForStatement;
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType) NonNull(dyvil.annotation.internal.NonNull)

Example 5 with NonNull

use of dyvil.annotation.internal.NonNull in project Dyvil by Dyvil.

the class ForEachStatement method toIterable.

@NonNull
public IValue toIterable(MarkerList markers, IContext context, IType varType, IValue value, IType valueType) {
    final IType iterableType = Types.resolveTypeSafely(valueType, IterableForStatement.LazyFields.ITERABLE_TYPE);
    if (varType == Types.UNKNOWN) {
        this.inferVariableType(markers, iterableType);
    } else if (!Types.isAssignable(varType, iterableType)) {
        final Marker marker = Markers.semanticError(value.getPosition(), "for.iterable.type");
        marker.addInfo(Markers.getSemantic("iterable.type", iterableType));
        marker.addInfo(Markers.getSemantic("variable.type", varType));
        markers.add(marker);
    }
    this.variable.setValue(TypeChecker.convertValue(value, IterableForStatement.LazyFields.ITERABLE, null, markers, context, null));
    final IterableForStatement iterableForStatement = new IterableForStatement(this.position, this.variable, false);
    iterableForStatement.resolveAction(this.action, markers, context);
    return iterableForStatement;
}
Also used : Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType) NonNull(dyvil.annotation.internal.NonNull)

Aggregations

NonNull (dyvil.annotation.internal.NonNull)9 ArrayList (dyvil.collection.mutable.ArrayList)2 IType (dyvilx.tools.compiler.ast.type.IType)2 TypeList (dyvilx.tools.compiler.ast.type.TypeList)2 Marker (dyvilx.tools.parsing.marker.Marker)2 Constructor (java.lang.reflect.Constructor)2 DyvilModifiers (dyvil.annotation.internal.DyvilModifiers)1 List (dyvil.collection.List)1 LambdaType (dyvilx.tools.compiler.ast.type.compound.LambdaType)1 GenericType (dyvilx.tools.compiler.ast.type.generic.GenericType)1 InternalGenericType (dyvilx.tools.compiler.ast.type.generic.InternalGenericType)1 InternalType (dyvilx.tools.compiler.ast.type.raw.InternalType)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1